Files
gastown/internal/cmd/statusline_test.go
Steve Yegge 19fd7e05b2 Fix witness session parsing in categorizeSession
Witness sessions use format gt-witness-<rig> but categorizeSession was
parsing them as gt-<rig>-<type>, incorrectly setting Rig="witness".
This caused the mayor status line to count "witness" as a third rig.

Added special case to handle gt-witness-<rig> format before the generic
rig-level parsing. Also updated tests to cover both actual and legacy formats.

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-21 23:07:52 -08:00

87 lines
2.0 KiB
Go

package cmd
import "testing"
func TestCategorizeSessionRig(t *testing.T) {
tests := []struct {
session string
wantRig string
}{
// Standard polecat sessions
{"gt-gastown-slit", "gastown"},
{"gt-gastown-Toast", "gastown"},
{"gt-myrig-worker", "myrig"},
// Crew sessions
{"gt-gastown-crew-max", "gastown"},
{"gt-myrig-crew-user", "myrig"},
// Witness sessions (actual format: gt-witness-<rig>)
{"gt-witness-gastown", "gastown"},
{"gt-witness-myrig", "myrig"},
// Legacy format still works as fallback
{"gt-gastown-witness", "gastown"},
{"gt-myrig-witness", "myrig"},
// Refinery sessions
{"gt-gastown-refinery", "gastown"},
{"gt-myrig-refinery", "myrig"},
// Edge cases
{"gt-a-b", "a"}, // minimum valid
// Town-level agents (no rig)
{"gt-mayor", ""},
{"gt-deacon", ""},
}
for _, tt := range tests {
t.Run(tt.session, func(t *testing.T) {
agent := categorizeSession(tt.session)
gotRig := ""
if agent != nil {
gotRig = agent.Rig
}
if gotRig != tt.wantRig {
t.Errorf("categorizeSession(%q).Rig = %q, want %q", tt.session, gotRig, tt.wantRig)
}
})
}
}
func TestCategorizeSessionType(t *testing.T) {
tests := []struct {
session string
wantType AgentType
}{
// Polecat sessions
{"gt-gastown-slit", AgentPolecat},
{"gt-gastown-Toast", AgentPolecat},
{"gt-myrig-worker", AgentPolecat},
{"gt-a-b", AgentPolecat},
// Non-polecat sessions
{"gt-witness-gastown", AgentWitness}, // actual format
{"gt-gastown-witness", AgentWitness}, // legacy fallback
{"gt-gastown-refinery", AgentRefinery},
{"gt-gastown-crew-max", AgentCrew},
{"gt-myrig-crew-user", AgentCrew},
// Town-level agents
{"gt-mayor", AgentMayor},
{"gt-deacon", AgentDeacon},
}
for _, tt := range tests {
t.Run(tt.session, func(t *testing.T) {
agent := categorizeSession(tt.session)
if agent == nil {
t.Fatalf("categorizeSession(%q) returned nil", tt.session)
}
if agent.Type != tt.wantType {
t.Errorf("categorizeSession(%q).Type = %v, want %v", tt.session, agent.Type, tt.wantType)
}
})
}
}