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>
This commit is contained in:
parent
eb266f9db4
commit
3d0031aadf
3 changed files with 90 additions and 7 deletions
|
|
@ -483,12 +483,9 @@ var createCmd = &cobra.Command{
|
|||
|
||||
ctx := createCtx
|
||||
|
||||
var dbPrefix, allowedPrefixes string
|
||||
if yamlPrefix := config.GetString("issue-prefix"); yamlPrefix != "" {
|
||||
dbPrefix = yamlPrefix
|
||||
} else {
|
||||
dbPrefix, _ = store.GetConfig(ctx, "issue_prefix")
|
||||
}
|
||||
storePrefix, _ := store.GetConfig(ctx, "issue_prefix")
|
||||
dbPrefix := selectCreateIDPrefix(globalFlag, config.GetString("issue-prefix"), storePrefix)
|
||||
var allowedPrefixes string
|
||||
allowedPrefixes, _ = store.GetConfig(ctx, "allowed_prefixes")
|
||||
|
||||
if err := validation.ValidateIDPrefixAllowed(explicitID, dbPrefix, allowedPrefixes, forceCreate); err != nil {
|
||||
|
|
@ -700,6 +697,16 @@ func mergeCreateLabels(labels, inheritedLabels []string) []string {
|
|||
return merged
|
||||
}
|
||||
|
||||
func selectCreateIDPrefix(global bool, yamlPrefix, storePrefix string) string {
|
||||
if global {
|
||||
return storePrefix
|
||||
}
|
||||
if yamlPrefix != "" {
|
||||
return yamlPrefix
|
||||
}
|
||||
return storePrefix
|
||||
}
|
||||
|
||||
func renderCreateDryRunPreview(issue *types.Issue, labels, deps []string) {
|
||||
idDisplay := issue.ID
|
||||
if idDisplay == "" {
|
||||
|
|
|
|||
41
cmd/bd/create_prefix_test.go
Normal file
41
cmd/bd/create_prefix_test.go
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
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)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
@ -12,6 +12,7 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/steveyegge/beads/internal/config"
|
||||
"github.com/steveyegge/beads/internal/configfile"
|
||||
"github.com/steveyegge/beads/internal/doltserver"
|
||||
"github.com/steveyegge/beads/internal/testutil"
|
||||
|
|
@ -103,8 +104,42 @@ func TestGlobalDBIdentityCheck(t *testing.T) {
|
|||
t.Errorf("metadata.json global_project_id = %q, want %q",
|
||||
cfg.GlobalProjectID, doltserver.GlobalProjectID)
|
||||
}
|
||||
// bd init (non-no-db) stores the prefix in the DB, not config.yaml
|
||||
// (the generated file only carries a commented `# issue-prefix: ""`).
|
||||
// Write the project prefix into config.yaml explicitly so that the
|
||||
// create/show steps below exercise the YAML-first prefix-selection
|
||||
// path exactly as bd-4646 regressed it: unpatched selectCreateIDPrefix
|
||||
// would then incorrectly prefer this "proj0" YAML prefix over the
|
||||
// global store's prefix even in --global mode, and the ID validation
|
||||
// below would fail. See cmd/bd/init_embedded_test.go for the same
|
||||
// pattern.
|
||||
if err := os.WriteFile(filepath.Join(beadsDir, "config.yaml"), []byte("issue-prefix: proj0\n"), 0o644); err != nil {
|
||||
t.Fatalf("write config.yaml issue-prefix: %v", err)
|
||||
}
|
||||
if yamlPrefix := config.GetStringFromDir(beadsDir, "issue-prefix"); yamlPrefix != "proj0" {
|
||||
t.Fatalf("project YAML issue-prefix = %q, want %q", yamlPrefix, "proj0")
|
||||
}
|
||||
|
||||
out, err := ssExec(ctx, bdBinary, projectDir, env, "list", "--global")
|
||||
explicitGlobalID := doltserver.GlobalIssuePrefix + "-explicit"
|
||||
out, err := ssExec(ctx, bdBinary, projectDir, env,
|
||||
"create", "Global explicit ID", "--global", "--id", explicitGlobalID, "--silent")
|
||||
if err != nil {
|
||||
t.Fatalf("bd create --global --id %s failed: %v\noutput:\n%s", explicitGlobalID, err, out)
|
||||
}
|
||||
if got := strings.TrimSpace(out); got != explicitGlobalID {
|
||||
t.Fatalf("bd create --global --id returned %q, want %q", got, explicitGlobalID)
|
||||
}
|
||||
|
||||
out, err = ssExec(ctx, bdBinary, projectDir, env, "show", "--global", explicitGlobalID)
|
||||
if err != nil {
|
||||
t.Fatalf("bd show --global %s failed: %v\noutput:\n%s", explicitGlobalID, err, out)
|
||||
}
|
||||
if !strings.Contains(out, explicitGlobalID) {
|
||||
t.Fatalf("bd show --global did not return %s from %s:\n%s",
|
||||
explicitGlobalID, doltserver.GlobalDatabaseName, out)
|
||||
}
|
||||
|
||||
out, err = ssExec(ctx, bdBinary, projectDir, env, "list", "--global")
|
||||
if err != nil {
|
||||
t.Fatalf("bd list --global failed: %v\noutput:\n%s", err, out)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue