fix(create): use agent-aware prefix extraction for agent beads
The generic ValidateIDFormat() used isLikelyHash() which treated 3-character suffixes like "nux" as valid hashes, causing agent IDs like "nx-nexus-polecat-nux" to extract prefix as "nx-nexus-polecat" instead of the correct "nx". Fix: For --type=agent, validate agent ID format first and use ExtractAgentPrefix() which correctly extracts prefix from the first hyphen for agent IDs. Fixes #591 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
committed by
gastown/crew/dennis
parent
2c00d6d203
commit
87f84c5fa6
@@ -404,3 +404,43 @@ func TestValidateAgentID(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestExtractAgentPrefix(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
id string
|
||||
wantPrefix string
|
||||
}{
|
||||
// Town-level agents
|
||||
{"mayor", "gt-mayor", "gt"},
|
||||
{"deacon", "gt-deacon", "gt"},
|
||||
{"bd mayor", "bd-mayor", "bd"},
|
||||
|
||||
// Per-rig agents
|
||||
{"witness", "gt-gastown-witness", "gt"},
|
||||
{"refinery", "bd-beads-refinery", "bd"},
|
||||
|
||||
// Named agents - the bug case
|
||||
{"polecat 3-char name", "nx-nexus-polecat-nux", "nx"},
|
||||
{"polecat regular", "gt-gastown-polecat-phoenix", "gt"},
|
||||
{"crew", "gt-beads-crew-dave", "gt"},
|
||||
|
||||
// Hyphenated rig names
|
||||
{"hyphenated rig", "gt-my-project-witness", "gt"},
|
||||
{"multi-hyphen rig polecat", "bd-my-cool-app-polecat-bob", "bd"},
|
||||
|
||||
// Edge cases
|
||||
{"no hyphen", "nohyphen", ""},
|
||||
{"empty", "", ""},
|
||||
{"just prefix", "gt-", "gt"},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got := ExtractAgentPrefix(tt.id)
|
||||
if got != tt.wantPrefix {
|
||||
t.Errorf("ExtractAgentPrefix(%q) = %q, want %q", tt.id, got, tt.wantPrefix)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user