Files
gastown/internal/beads/routes_test.go
Steve Yegge 16076913ae fix: use rig-specific prefix for agent bead IDs (bd-otyh)
When spawning polecats in non-gastown rigs like beads, the agent bead ID
was incorrectly using the hardcoded "gt-" prefix instead of the rig's
configured prefix (e.g., "bd-" for beads).

Changes:
- Add GetPrefixForRig() in routes.go to look up prefix from routes.jsonl
- Update agentIDToBeadID() in sling.go to use rig's prefix via the new
  *WithPrefix functions instead of hardcoded "gt"
- Add unit tests for the new functionality

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-30 01:02:23 -08:00

87 lines
2.2 KiB
Go

package beads
import (
"os"
"path/filepath"
"testing"
)
func TestGetPrefixForRig(t *testing.T) {
// Create a temporary directory with routes.jsonl
tmpDir := t.TempDir()
beadsDir := filepath.Join(tmpDir, ".beads")
if err := os.MkdirAll(beadsDir, 0755); err != nil {
t.Fatal(err)
}
routesContent := `{"prefix": "gt-", "path": "gastown/mayor/rig"}
{"prefix": "bd-", "path": "beads/mayor/rig"}
{"prefix": "hq-", "path": "."}
`
if err := os.WriteFile(filepath.Join(beadsDir, "routes.jsonl"), []byte(routesContent), 0644); err != nil {
t.Fatal(err)
}
tests := []struct {
rig string
expected string
}{
{"gastown", "gt"},
{"beads", "bd"},
{"unknown", "gt"}, // default
{"", "gt"}, // empty rig -> default
}
for _, tc := range tests {
t.Run(tc.rig, func(t *testing.T) {
result := GetPrefixForRig(tmpDir, tc.rig)
if result != tc.expected {
t.Errorf("GetPrefixForRig(%q, %q) = %q, want %q", tmpDir, tc.rig, result, tc.expected)
}
})
}
}
func TestGetPrefixForRig_NoRoutesFile(t *testing.T) {
tmpDir := t.TempDir()
// No routes.jsonl file
result := GetPrefixForRig(tmpDir, "anything")
if result != "gt" {
t.Errorf("Expected default 'gt' when no routes file, got %q", result)
}
}
func TestAgentBeadIDsWithPrefix(t *testing.T) {
tests := []struct {
name string
fn func() string
expected string
}{
{"PolecatBeadIDWithPrefix bd beads obsidian",
func() string { return PolecatBeadIDWithPrefix("bd", "beads", "obsidian") },
"bd-beads-polecat-obsidian"},
{"PolecatBeadIDWithPrefix gt gastown Toast",
func() string { return PolecatBeadIDWithPrefix("gt", "gastown", "Toast") },
"gt-gastown-polecat-Toast"},
{"WitnessBeadIDWithPrefix bd beads",
func() string { return WitnessBeadIDWithPrefix("bd", "beads") },
"bd-beads-witness"},
{"RefineryBeadIDWithPrefix bd beads",
func() string { return RefineryBeadIDWithPrefix("bd", "beads") },
"bd-beads-refinery"},
{"CrewBeadIDWithPrefix bd beads max",
func() string { return CrewBeadIDWithPrefix("bd", "beads", "max") },
"bd-beads-crew-max"},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
result := tc.fn()
if result != tc.expected {
t.Errorf("got %q, want %q", result, tc.expected)
}
})
}
}