fix(sync): use town-level routes for prefix validation

Follow-up to 828fc11b addressing code review feedback:

1. Added LoadTownRoutes() - exported function that walks up to find
   town-level routes.jsonl (e.g., ~/gt/.beads/routes.jsonl)

2. Updated buildAllowedPrefixSet to use LoadTownRoutes instead of
   LoadRoutes, so it finds routes even when importing from a rig's
   local beads directory

3. Added unit tests for buildAllowedPrefixSet covering:
   - Primary prefix inclusion
   - allowed_prefixes config parsing
   - Routes from routes.jsonl
   - Missing routes.jsonl handling
   - Empty beadsDir handling

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
dennis
2026-01-17 09:51:36 -08:00
committed by Steve Yegge
parent 4f0f5744a6
commit 1f59119144
3 changed files with 108 additions and 8 deletions

View File

@@ -55,6 +55,16 @@ func LoadRoutes(beadsDir string) ([]Route, error) {
return routes, scanner.Err()
}
// LoadTownRoutes loads routes from the town-level routes.jsonl.
// It first checks the given beadsDir, then walks up to find the town root
// and loads routes from there. This is useful for multi-rig setups (Gas Town)
// where routes.jsonl lives at ~/gt/.beads/ rather than in individual rig directories.
// Returns routes and nil error on success, or nil routes if not in a town or no routes found.
func LoadTownRoutes(beadsDir string) ([]Route, error) {
routes, _ := findTownRoutes(beadsDir)
return routes, nil
}
// ExtractPrefix extracts the prefix from an issue ID.
// For "gt-abc123", returns "gt-".
// For "bd-abc123", returns "bd-".