fix(beads): prevent routes.jsonl corruption and add doctor check for rig-level routes.jsonl (#377)
* fix(beads): prevent routes.jsonl corruption from bd auto-export When issues.jsonl doesn't exist, bd's auto-export mechanism writes issue data to routes.jsonl, corrupting the routing configuration. Changes: - install.go: Create issues.jsonl before routes.jsonl at town level - manager.go: Create issues.jsonl in rig beads; don't create routes.jsonl (rig-level routes.jsonl breaks bd's walk-up routing to town routes) - Add integration tests for routes.jsonl corruption prevention Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix(doctor): add check to detect and fix rig-level routes.jsonl Add RigRoutesJSONLCheck to detect routes.jsonl files in rig .beads directories. These files break bd's walk-up routing to town-level routes.jsonl, causing cross-rig routing failures. The fix unconditionally deletes rig-level routes.jsonl files since bd will auto-export to issues.jsonl on next run. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * test(rig): add verification that routes.jsonl does NOT exist in rig .beads Add explicit test assertion and detailed comment explaining why rig-level routes.jsonl files must not exist (breaks bd walk-up routing to town routes). Also verify that issues.jsonl DOES exist (prevents bd auto-export corruption). Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix(doctor): ensure town root route exists in routes.jsonl The RoutesCheck now detects and fixes missing town root routes (hq- -> .). This can happen when routes.jsonl is corrupted or was created without the town route during initialization. Changes: - Detect missing hq- route in Run() - Add hq- route in Fix() when missing - Handle case where routes.jsonl is corrupted (regenerate with town route) - Add comprehensive unit tests for route detection and fixing Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * test(beads): fix routing integration test for routes.jsonl corruption The TestBeadsRoutingFromTownRoot test was failing because bd's auto-export mechanism writes issue data to routes.jsonl when issues.jsonl doesn't exist. This corrupts the routing configuration. Fix: Create empty issues.jsonl after bd init to prevent corruption. This mirrors what gt install does to prevent the same bug. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> --------- Co-authored-by: julianknutsen <julianknutsen@users.noreply.github> Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -341,6 +341,49 @@ func TestRigAddInitializesBeads(t *testing.T) {
|
||||
t.Errorf("config.yaml doesn't contain expected prefix, got: %s", string(content))
|
||||
}
|
||||
}
|
||||
|
||||
// =========================================================================
|
||||
// IMPORTANT: Verify routes.jsonl does NOT exist in the rig's .beads directory
|
||||
// =========================================================================
|
||||
//
|
||||
// WHY WE DON'T CREATE routes.jsonl IN RIG DIRECTORIES:
|
||||
//
|
||||
// 1. BD'S WALK-UP ROUTING MECHANISM:
|
||||
// When bd needs to find routing configuration, it walks up the directory
|
||||
// tree looking for a .beads directory with routes.jsonl. It stops at the
|
||||
// first routes.jsonl it finds. If a rig has its own routes.jsonl, bd will
|
||||
// use that and NEVER reach the town-level routes.jsonl, breaking cross-rig
|
||||
// routing entirely.
|
||||
//
|
||||
// 2. TOWN-LEVEL ROUTING IS THE SOURCE OF TRUTH:
|
||||
// All routing configuration belongs in the town's .beads/routes.jsonl.
|
||||
// This single file contains prefix->path mappings for ALL rigs, enabling
|
||||
// bd to route issue IDs like "tr-123" to the correct rig directory.
|
||||
//
|
||||
// 3. HISTORICAL BUG - BD AUTO-EXPORT CORRUPTION:
|
||||
// There was a bug where bd's auto-export feature would write issue data
|
||||
// to routes.jsonl if issues.jsonl didn't exist. This corrupted routing
|
||||
// config with issue JSON objects. We now create empty issues.jsonl files
|
||||
// proactively to prevent this, but we also verify routes.jsonl doesn't
|
||||
// exist as a defense-in-depth measure.
|
||||
//
|
||||
// 4. DOCTOR CHECK EXISTS:
|
||||
// The "rig-routes-jsonl" doctor check detects and can fix (delete) any
|
||||
// routes.jsonl files that appear in rig .beads directories.
|
||||
//
|
||||
// If you're modifying rig creation and thinking about adding routes.jsonl
|
||||
// to the rig's .beads directory - DON'T. It will break cross-rig routing.
|
||||
// =========================================================================
|
||||
rigRoutesPath := filepath.Join(beadsDir, "routes.jsonl")
|
||||
if _, err := os.Stat(rigRoutesPath); err == nil {
|
||||
t.Errorf("routes.jsonl should NOT exist in rig .beads directory (breaks bd walk-up routing)")
|
||||
}
|
||||
|
||||
// Verify issues.jsonl DOES exist (prevents bd auto-export corruption)
|
||||
rigIssuesPath := filepath.Join(beadsDir, "issues.jsonl")
|
||||
if _, err := os.Stat(rigIssuesPath); err != nil {
|
||||
t.Errorf("issues.jsonl should exist in rig .beads directory (prevents auto-export corruption): %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// TestRigAddUpdatesRoutes verifies that routes.jsonl is updated
|
||||
|
||||
Reference in New Issue
Block a user