Files
gastown/internal/cmd/nudge_test.go
joe 4bcf50bf1c Revert to simple gt-mayor/gt-deacon session names
Reverts the session naming changes from PR #70. Multi-town support
on a single machine is not a real use case - rigs provide project
isolation, and true isolation should use containers/VMs.

Changes:
- MayorSessionName() and DeaconSessionName() no longer take townName parameter
- ParseSessionName() handles simple gt-mayor and gt-deacon formats
- Removed Town field from AgentIdentity and AgentSession structs
- Updated all callers and tests

Generated with Claude Code

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-03 14:33:24 -08:00

113 lines
2.9 KiB
Go

package cmd
import (
"testing"
)
func TestResolveNudgePattern(t *testing.T) {
// Create test agent sessions (no Town field for mayor/deacon anymore)
agents := []*AgentSession{
{Name: "gt-mayor", Type: AgentMayor},
{Name: "gt-deacon", Type: AgentDeacon},
{Name: "gt-gastown-witness", Type: AgentWitness, Rig: "gastown"},
{Name: "gt-gastown-refinery", Type: AgentRefinery, Rig: "gastown"},
{Name: "gt-gastown-crew-max", Type: AgentCrew, Rig: "gastown", AgentName: "max"},
{Name: "gt-gastown-crew-jack", Type: AgentCrew, Rig: "gastown", AgentName: "jack"},
{Name: "gt-gastown-alpha", Type: AgentPolecat, Rig: "gastown", AgentName: "alpha"},
{Name: "gt-gastown-beta", Type: AgentPolecat, Rig: "gastown", AgentName: "beta"},
{Name: "gt-beads-witness", Type: AgentWitness, Rig: "beads"},
{Name: "gt-beads-gamma", Type: AgentPolecat, Rig: "beads", AgentName: "gamma"},
}
tests := []struct {
name string
pattern string
expected []string
}{
{
name: "mayor special case",
pattern: "mayor",
expected: []string{"gt-mayor"},
},
{
name: "deacon special case",
pattern: "deacon",
expected: []string{"gt-deacon"},
},
{
name: "specific witness",
pattern: "gastown/witness",
expected: []string{"gt-gastown-witness"},
},
{
name: "all witnesses",
pattern: "*/witness",
expected: []string{"gt-gastown-witness", "gt-beads-witness"},
},
{
name: "specific refinery",
pattern: "gastown/refinery",
expected: []string{"gt-gastown-refinery"},
},
{
name: "all polecats in rig",
pattern: "gastown/polecats/*",
expected: []string{"gt-gastown-alpha", "gt-gastown-beta"},
},
{
name: "specific polecat",
pattern: "gastown/polecats/alpha",
expected: []string{"gt-gastown-alpha"},
},
{
name: "all crew in rig",
pattern: "gastown/crew/*",
expected: []string{"gt-gastown-crew-max", "gt-gastown-crew-jack"},
},
{
name: "specific crew member",
pattern: "gastown/crew/max",
expected: []string{"gt-gastown-crew-max"},
},
{
name: "legacy polecat format",
pattern: "gastown/alpha",
expected: []string{"gt-gastown-alpha"},
},
{
name: "no matches",
pattern: "nonexistent/polecats/*",
expected: nil,
},
{
name: "invalid pattern",
pattern: "invalid",
expected: nil,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := resolveNudgePattern(tt.pattern, agents)
if len(got) != len(tt.expected) {
t.Errorf("resolveNudgePattern(%q) returned %d results, want %d: got %v, want %v",
tt.pattern, len(got), len(tt.expected), got, tt.expected)
return
}
// Check each expected value is present
gotMap := make(map[string]bool)
for _, g := range got {
gotMap[g] = true
}
for _, e := range tt.expected {
if !gotMap[e] {
t.Errorf("resolveNudgePattern(%q) missing expected %q, got %v",
tt.pattern, e, got)
}
}
})
}
}