Files
gastown/internal/session/identity_test.go
markov-kernel e7145cfd77 fix: Make Mayor/Deacon session names include town name
Session names `gt-mayor` and `gt-deacon` were hardcoded, causing tmux
session name collisions when running multiple towns simultaneously.

Changed to `gt-{town}-mayor` and `gt-{town}-deacon` format (e.g.,
`gt-ai-mayor`) to allow concurrent multi-town operation.

Key changes:
- session.MayorSessionName() and DeaconSessionName() now take townName param
- Added workspace.GetTownName() helper to load town name from config
- Updated all callers in cmd/, daemon/, doctor/, mail/, rig/, templates/
- Updated tests with new session name format
- Bead IDs remain unchanged (already scoped by .beads/ directory)

Fixes #60

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-03 21:37:05 +01:00

276 lines
6.2 KiB
Go

package session
import (
"testing"
)
func TestParseSessionName(t *testing.T) {
tests := []struct {
name string
session string
wantRole Role
wantTown string
wantRig string
wantName string
wantErr bool
}{
// Town-level roles (mayor/deacon with town name)
{
name: "mayor simple town",
session: "gt-ai-mayor",
wantRole: RoleMayor,
wantTown: "ai",
},
{
name: "mayor hyphenated town",
session: "gt-my-town-mayor",
wantRole: RoleMayor,
wantTown: "my-town",
},
{
name: "deacon simple town",
session: "gt-alpha-deacon",
wantRole: RoleDeacon,
wantTown: "alpha",
},
{
name: "deacon hyphenated town",
session: "gt-my-town-deacon",
wantRole: RoleDeacon,
wantTown: "my-town",
},
// Witness (simple rig)
{
name: "witness simple rig",
session: "gt-gastown-witness",
wantRole: RoleWitness,
wantRig: "gastown",
},
{
name: "witness hyphenated rig",
session: "gt-foo-bar-witness",
wantRole: RoleWitness,
wantRig: "foo-bar",
},
// Refinery (simple rig)
{
name: "refinery simple rig",
session: "gt-gastown-refinery",
wantRole: RoleRefinery,
wantRig: "gastown",
},
{
name: "refinery hyphenated rig",
session: "gt-my-project-refinery",
wantRole: RoleRefinery,
wantRig: "my-project",
},
// Crew (with marker)
{
name: "crew simple",
session: "gt-gastown-crew-max",
wantRole: RoleCrew,
wantRig: "gastown",
wantName: "max",
},
{
name: "crew hyphenated rig",
session: "gt-foo-bar-crew-alice",
wantRole: RoleCrew,
wantRig: "foo-bar",
wantName: "alice",
},
{
name: "crew hyphenated name",
session: "gt-gastown-crew-my-worker",
wantRole: RoleCrew,
wantRig: "gastown",
wantName: "my-worker",
},
// Polecat (fallback)
{
name: "polecat simple",
session: "gt-gastown-morsov",
wantRole: RolePolecat,
wantRig: "gastown",
wantName: "morsov",
},
{
name: "polecat hyphenated rig",
session: "gt-foo-bar-Toast",
wantRole: RolePolecat,
wantRig: "foo-bar",
wantName: "Toast",
},
// Error cases
{
name: "missing prefix",
session: "gastown-witness",
wantErr: true,
},
{
name: "empty after prefix",
session: "gt-",
wantErr: true,
},
{
name: "just prefix single segment",
session: "gt-x",
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := ParseSessionName(tt.session)
if (err != nil) != tt.wantErr {
t.Errorf("ParseSessionName(%q) error = %v, wantErr %v", tt.session, err, tt.wantErr)
return
}
if err != nil {
return
}
if got.Role != tt.wantRole {
t.Errorf("ParseSessionName(%q).Role = %v, want %v", tt.session, got.Role, tt.wantRole)
}
if got.Town != tt.wantTown {
t.Errorf("ParseSessionName(%q).Town = %v, want %v", tt.session, got.Town, tt.wantTown)
}
if got.Rig != tt.wantRig {
t.Errorf("ParseSessionName(%q).Rig = %v, want %v", tt.session, got.Rig, tt.wantRig)
}
if got.Name != tt.wantName {
t.Errorf("ParseSessionName(%q).Name = %v, want %v", tt.session, got.Name, tt.wantName)
}
})
}
}
func TestAgentIdentity_SessionName(t *testing.T) {
tests := []struct {
name string
identity AgentIdentity
want string
}{
{
name: "mayor with town",
identity: AgentIdentity{Role: RoleMayor, Town: "ai"},
want: "gt-ai-mayor",
},
{
name: "mayor hyphenated town",
identity: AgentIdentity{Role: RoleMayor, Town: "my-town"},
want: "gt-my-town-mayor",
},
{
name: "deacon with town",
identity: AgentIdentity{Role: RoleDeacon, Town: "alpha"},
want: "gt-alpha-deacon",
},
{
name: "witness",
identity: AgentIdentity{Role: RoleWitness, Rig: "gastown"},
want: "gt-gastown-witness",
},
{
name: "refinery",
identity: AgentIdentity{Role: RoleRefinery, Rig: "my-project"},
want: "gt-my-project-refinery",
},
{
name: "crew",
identity: AgentIdentity{Role: RoleCrew, Rig: "gastown", Name: "max"},
want: "gt-gastown-crew-max",
},
{
name: "polecat",
identity: AgentIdentity{Role: RolePolecat, Rig: "gastown", Name: "morsov"},
want: "gt-gastown-morsov",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.identity.SessionName(); got != tt.want {
t.Errorf("AgentIdentity.SessionName() = %v, want %v", got, tt.want)
}
})
}
}
func TestAgentIdentity_Address(t *testing.T) {
tests := []struct {
name string
identity AgentIdentity
want string
}{
{
name: "mayor",
identity: AgentIdentity{Role: RoleMayor},
want: "mayor",
},
{
name: "deacon",
identity: AgentIdentity{Role: RoleDeacon},
want: "deacon",
},
{
name: "witness",
identity: AgentIdentity{Role: RoleWitness, Rig: "gastown"},
want: "gastown/witness",
},
{
name: "refinery",
identity: AgentIdentity{Role: RoleRefinery, Rig: "my-project"},
want: "my-project/refinery",
},
{
name: "crew",
identity: AgentIdentity{Role: RoleCrew, Rig: "gastown", Name: "max"},
want: "gastown/crew/max",
},
{
name: "polecat",
identity: AgentIdentity{Role: RolePolecat, Rig: "gastown", Name: "Toast"},
want: "gastown/polecats/Toast",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.identity.Address(); got != tt.want {
t.Errorf("AgentIdentity.Address() = %v, want %v", got, tt.want)
}
})
}
}
func TestParseSessionName_RoundTrip(t *testing.T) {
// Test that parsing then reconstructing gives the same result
sessions := []string{
"gt-ai-mayor",
"gt-alpha-deacon",
"gt-gastown-witness",
"gt-foo-bar-refinery",
"gt-gastown-crew-max",
"gt-gastown-morsov",
}
for _, sess := range sessions {
t.Run(sess, func(t *testing.T) {
identity, err := ParseSessionName(sess)
if err != nil {
t.Fatalf("ParseSessionName(%q) error = %v", sess, err)
}
if got := identity.SessionName(); got != sess {
t.Errorf("Round-trip failed: ParseSessionName(%q).SessionName() = %q", sess, got)
}
})
}
}