fix(agent): support hyphenated rig names in parseAgentIDFields (GH#868)
Complements the validation fix from c6fe9d71 - the parseAgentIDFields
function now also scans right-to-left for known role tokens instead
of using fixed position parsing.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -781,7 +781,7 @@ func parseAgentIDFields(agentID string) (roleType, rig string) {
|
|||||||
rigLevelRoles := map[string]bool{"witness": true, "refinery": true}
|
rigLevelRoles := map[string]bool{"witness": true, "refinery": true}
|
||||||
namedRoles := map[string]bool{"crew": true, "polecat": true}
|
namedRoles := map[string]bool{"crew": true, "polecat": true}
|
||||||
|
|
||||||
// Case 1: Town-level roles (gt-mayor, gt-deacon)
|
// Case 1: Town-level roles (gt-mayor, gt-deacon) - single part after prefix
|
||||||
if len(parts) == 1 {
|
if len(parts) == 1 {
|
||||||
role := parts[0]
|
role := parts[0]
|
||||||
if townLevelRoles[role] {
|
if townLevelRoles[role] {
|
||||||
@@ -790,20 +790,23 @@ func parseAgentIDFields(agentID string) (roleType, rig string) {
|
|||||||
return "", "" // Unknown format
|
return "", "" // Unknown format
|
||||||
}
|
}
|
||||||
|
|
||||||
// Case 2: Rig-level roles (<prefix>-<rig>-witness, <prefix>-<rig>-refinery)
|
// For 2+ parts, scan from the right to find a known role.
|
||||||
if len(parts) == 2 {
|
// This allows rig names to contain hyphens (e.g., "my-project").
|
||||||
potentialRig, potentialRole := parts[0], parts[1]
|
for i := len(parts) - 1; i >= 0; i-- {
|
||||||
if rigLevelRoles[potentialRole] {
|
part := parts[i]
|
||||||
return potentialRole, potentialRig
|
|
||||||
}
|
|
||||||
return "", "" // Unknown format
|
|
||||||
}
|
|
||||||
|
|
||||||
// Case 3: Named roles (<prefix>-<rig>-crew-<name>, <prefix>-<rig>-polecat-<name>)
|
// Check for rig-level role (witness, refinery) - must be at end
|
||||||
if len(parts) >= 3 {
|
if rigLevelRoles[part] && i == len(parts)-1 {
|
||||||
potentialRig, potentialRole := parts[0], parts[1]
|
// rig is everything before role
|
||||||
if namedRoles[potentialRole] {
|
rig = strings.Join(parts[:i], "-")
|
||||||
return potentialRole, potentialRig
|
return part, rig
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check for named role (crew, polecat) - must have something after (the name)
|
||||||
|
if namedRoles[part] && i < len(parts)-1 {
|
||||||
|
// rig is everything before role
|
||||||
|
rig = strings.Join(parts[:i], "-")
|
||||||
|
return part, rig
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -101,6 +101,37 @@ func TestParseAgentIDFields(t *testing.T) {
|
|||||||
wantRoleType: "polecat",
|
wantRoleType: "polecat",
|
||||||
wantRig: "gastown",
|
wantRig: "gastown",
|
||||||
},
|
},
|
||||||
|
// Hyphenated rig names (GH#868)
|
||||||
|
{
|
||||||
|
name: "polecat with hyphenated rig",
|
||||||
|
agentID: "gt-my-project-polecat-nux",
|
||||||
|
wantRoleType: "polecat",
|
||||||
|
wantRig: "my-project",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "crew with hyphenated rig",
|
||||||
|
agentID: "bd-infra-dashboard-crew-alice",
|
||||||
|
wantRoleType: "crew",
|
||||||
|
wantRig: "infra-dashboard",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "witness with hyphenated rig",
|
||||||
|
agentID: "gt-my-cool-rig-witness",
|
||||||
|
wantRoleType: "witness",
|
||||||
|
wantRig: "my-cool-rig",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "refinery with hyphenated rig",
|
||||||
|
agentID: "bd-super-long-rig-name-refinery",
|
||||||
|
wantRoleType: "refinery",
|
||||||
|
wantRig: "super-long-rig-name",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "polecat with multi-hyphen rig and name",
|
||||||
|
agentID: "gt-my-awesome-project-polecat-worker-1",
|
||||||
|
wantRoleType: "polecat",
|
||||||
|
wantRig: "my-awesome-project",
|
||||||
|
},
|
||||||
// Edge cases
|
// Edge cases
|
||||||
{
|
{
|
||||||
name: "no hyphen",
|
name: "no hyphen",
|
||||||
|
|||||||
Reference in New Issue
Block a user