beads/cmd/bd/create_prefix_test.go
matt wilkie 3d0031aadf
fix(create): validate global IDs against global prefix (#4957)
* fix(create): validate global IDs against global prefix

Select the opened global store's issue prefix for explicit global IDs while retaining YAML-first validation for ordinary project creates. Add precedence and shared-server integration regressions.

Agent-Signature: codex-gpt-5.6-sol-high on behalf of matt wilkie

* test(create): make global-prefix regression test actually exercise #4646

Write issue-prefix=proj0 into config.yaml explicitly after `bd init`,
since non-no-db init stores the prefix in the DB, not config.yaml (the
generated file only carries a commented `# issue-prefix: ""`). Without
this, the config.yaml assertion always failed when a Dolt container is
available, and the create/show regression steps passed on both patched
and unpatched code because config.GetString("issue-prefix") was empty
in the --global path either way. With config.yaml populated, unpatched
selectCreateIDPrefix would incorrectly prefer the project's YAML prefix
over the global store's prefix even in --global mode, and ID validation
would reject the global ID - so the test now actually guards #4646.

Also replace the hardcoded "global-explicit" prefix literal with
doltserver.GlobalIssuePrefix + "-explicit" to stay coupled to the
constant.

Agent-Signature: claude-fable-5-high on behalf of matt wilkie
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-07-22 21:48:49 -07:00

41 lines
888 B
Go

package main
import "testing"
func TestSelectCreateIDPrefix(t *testing.T) {
tests := []struct {
name string
global bool
yamlPrefix string
storePrefix string
want string
}{
{
name: "global ignores YAML",
global: true,
yamlPrefix: "proj0",
storePrefix: "global",
want: "global",
},
{
name: "ordinary prefers YAML",
yamlPrefix: "proj0",
storePrefix: "store",
want: "proj0",
},
{
name: "ordinary falls back to store",
storePrefix: "store",
want: "store",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := selectCreateIDPrefix(tt.global, tt.yamlPrefix, tt.storePrefix); got != tt.want {
t.Fatalf("selectCreateIDPrefix(%t, %q, %q) = %q, want %q",
tt.global, tt.yamlPrefix, tt.storePrefix, got, tt.want)
}
})
}
}