Fix crew worker mail identity mismatch (gt-2xiv)
Normalize crew/ and polecats/ to canonical form in addressToIdentity(): - gastown/crew/dave -> gastown/dave - gastown/polecats/Toast -> gastown/Toast Follows Postels Law: be liberal in what you accept.
This commit is contained in:
@@ -276,13 +276,17 @@ func ParseMessageType(s string) MessageType {
|
|||||||
|
|
||||||
// addressToIdentity converts a GGT address to a beads identity.
|
// addressToIdentity converts a GGT address to a beads identity.
|
||||||
//
|
//
|
||||||
// Addresses use slash format matching directory structure:
|
// Liberal normalization: accepts multiple address formats and normalizes
|
||||||
|
// to canonical form (Postel's Law - be liberal in what you accept).
|
||||||
|
//
|
||||||
|
// Addresses use slash format:
|
||||||
// - "mayor/" → "mayor/"
|
// - "mayor/" → "mayor/"
|
||||||
// - "mayor" → "mayor/"
|
// - "mayor" → "mayor/"
|
||||||
// - "deacon/" → "deacon/"
|
// - "deacon/" → "deacon/"
|
||||||
// - "deacon" → "deacon/"
|
// - "deacon" → "deacon/"
|
||||||
// - "gastown/polecats/Toast" → "gastown/polecats/Toast"
|
// - "gastown/polecats/Toast" → "gastown/Toast" (normalized)
|
||||||
// - "gastown/crew/max" → "gastown/crew/max"
|
// - "gastown/crew/max" → "gastown/max" (normalized)
|
||||||
|
// - "gastown/Toast" → "gastown/Toast" (already canonical)
|
||||||
// - "gastown/refinery" → "gastown/refinery"
|
// - "gastown/refinery" → "gastown/refinery"
|
||||||
// - "gastown/" → "gastown" (rig broadcast)
|
// - "gastown/" → "gastown" (rig broadcast)
|
||||||
func addressToIdentity(address string) string {
|
func addressToIdentity(address string) string {
|
||||||
@@ -299,17 +303,25 @@ func addressToIdentity(address string) string {
|
|||||||
address = address[:len(address)-1]
|
address = address[:len(address)-1]
|
||||||
}
|
}
|
||||||
|
|
||||||
// Keep slashes - addresses map to directory structure
|
// Normalize crew/ and polecats/ to canonical form:
|
||||||
|
// "rig/crew/name" → "rig/name"
|
||||||
|
// "rig/polecats/name" → "rig/name"
|
||||||
|
parts := strings.Split(address, "/")
|
||||||
|
if len(parts) == 3 && (parts[1] == "crew" || parts[1] == "polecats") {
|
||||||
|
return parts[0] + "/" + parts[2]
|
||||||
|
}
|
||||||
|
|
||||||
return address
|
return address
|
||||||
}
|
}
|
||||||
|
|
||||||
// identityToAddress converts a beads identity back to a GGT address.
|
// identityToAddress converts a beads identity back to a GGT address.
|
||||||
//
|
//
|
||||||
// Identity format matches address format (slash-based):
|
// Liberal normalization (Postel's Law):
|
||||||
// - "mayor/" → "mayor/"
|
// - "mayor/" → "mayor/"
|
||||||
// - "deacon/" → "deacon/"
|
// - "deacon/" → "deacon/"
|
||||||
// - "gastown/polecats/Toast" → "gastown/polecats/Toast"
|
// - "gastown/polecats/Toast" → "gastown/Toast" (normalized)
|
||||||
// - "gastown/crew/max" → "gastown/crew/max"
|
// - "gastown/crew/max" → "gastown/max" (normalized)
|
||||||
|
// - "gastown/Toast" → "gastown/Toast" (already canonical)
|
||||||
// - "gastown/refinery" → "gastown/refinery"
|
// - "gastown/refinery" → "gastown/refinery"
|
||||||
func identityToAddress(identity string) string {
|
func identityToAddress(identity string) string {
|
||||||
// Town-level agents ensure trailing slash
|
// Town-level agents ensure trailing slash
|
||||||
@@ -320,6 +332,11 @@ func identityToAddress(identity string) string {
|
|||||||
return "deacon/"
|
return "deacon/"
|
||||||
}
|
}
|
||||||
|
|
||||||
// Identity already in slash format, return as-is
|
// Normalize crew/ and polecats/ to canonical form
|
||||||
|
parts := strings.Split(identity, "/")
|
||||||
|
if len(parts) == 3 && (parts[1] == "crew" || parts[1] == "polecats") {
|
||||||
|
return parts[0] + "/" + parts[2]
|
||||||
|
}
|
||||||
|
|
||||||
return identity
|
return identity
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,9 +13,11 @@ func TestAddressToIdentity(t *testing.T) {
|
|||||||
{"deacon", "deacon/"},
|
{"deacon", "deacon/"},
|
||||||
{"deacon/", "deacon/"},
|
{"deacon/", "deacon/"},
|
||||||
|
|
||||||
// Rig-level agents: slash format matches directory structure
|
// Rig-level agents: crew/ and polecats/ normalized to canonical form
|
||||||
{"gastown/polecats/Toast", "gastown/polecats/Toast"},
|
{"gastown/polecats/Toast", "gastown/Toast"},
|
||||||
{"gastown/crew/max", "gastown/crew/max"},
|
{"gastown/crew/max", "gastown/max"},
|
||||||
|
{"gastown/Toast", "gastown/Toast"}, // Already canonical
|
||||||
|
{"gastown/max", "gastown/max"}, // Already canonical
|
||||||
{"gastown/refinery", "gastown/refinery"},
|
{"gastown/refinery", "gastown/refinery"},
|
||||||
{"gastown/witness", "gastown/witness"},
|
{"gastown/witness", "gastown/witness"},
|
||||||
|
|
||||||
@@ -44,9 +46,10 @@ func TestIdentityToAddress(t *testing.T) {
|
|||||||
{"deacon", "deacon/"},
|
{"deacon", "deacon/"},
|
||||||
{"deacon/", "deacon/"},
|
{"deacon/", "deacon/"},
|
||||||
|
|
||||||
// Rig-level agents: identity == address (slash format)
|
// Rig-level agents: crew/ and polecats/ normalized
|
||||||
{"gastown/polecats/Toast", "gastown/polecats/Toast"},
|
{"gastown/polecats/Toast", "gastown/Toast"},
|
||||||
{"gastown/crew/max", "gastown/crew/max"},
|
{"gastown/crew/max", "gastown/max"},
|
||||||
|
{"gastown/Toast", "gastown/Toast"}, // Already canonical
|
||||||
{"gastown/refinery", "gastown/refinery"},
|
{"gastown/refinery", "gastown/refinery"},
|
||||||
{"gastown/witness", "gastown/witness"},
|
{"gastown/witness", "gastown/witness"},
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user