beads/internal/storage/sqlite
Steve Yegge cd8cb8b86a Fix bd-ar2 code review issues: metadata tracking and multi-repo support
This commit addresses critical code review findings from bd-dvd and bd-ymj fixes:

## Completed Tasks

### bd-ar2.1: Extract duplicated metadata update code
- Created `updateExportMetadata()` helper function
- Eliminated 22-line duplication between createExportFunc and createSyncFunc
- Single source of truth for metadata updates

### bd-ar2.2: Add multi-repo support to export metadata updates
- Added per-repo metadata key tracking with keySuffix parameter
- Both export and sync functions now update metadata for all repos

### bd-ar2.3: Fix tests to use actual daemon functions
- TestExportUpdatesMetadata now calls updateExportMetadata() directly
- Added TestUpdateExportMetadataMultiRepo() for multi-repo testing
- Fixed export_mtime_test.go tests to call updateExportMetadata()

### bd-ar2.9: Fix variable shadowing in GetNextChildID
- Changed `err` to `resurrectErr` to avoid shadowing
- Improves code clarity and passes linter checks

### bd-ar2.10: Fix hasJSONLChanged to support per-repo keys
- Updated hasJSONLChanged() to accept keySuffix parameter
- Reads metadata with correct per-repo keys
- All callers updated (validatePreExport, daemon import, sync command)

### bd-ar2.11: Use stable repo identifiers instead of paths
- Added getRepoKeyForPath() helper function
- Uses stable identifiers like ".", "../frontend" instead of absolute paths
- Metadata keys now portable across machines and clones
- Prevents orphaned metadata when repos are moved

## Files Changed
- cmd/bd/daemon_sync.go: Helper functions, metadata updates
- cmd/bd/integrity.go: hasJSONLChanged() with keySuffix support
- cmd/bd/sync.go: Updated to use getRepoKeyForPath()
- cmd/bd/*_test.go: Tests updated for new signatures
- internal/storage/sqlite/hash_ids.go: Fixed variable shadowing

## Testing
All export, sync, and integrity tests pass.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-21 11:28:25 -05:00
..
migrations Add blocked_issues_cache table for GetReadyWork optimization 2025-11-20 19:29:30 -05:00
adaptive_e2e_test.go Context propagation with graceful cancellation (bd-rtp, bd-yb8, bd-2o2) 2025-11-20 21:57:23 -05:00
adaptive_length.go Switch from hex to Base36 encoding for issue IDs (GH #213) 2025-11-03 12:02:15 -08:00
adaptive_length_test.go fix: resolve test failures from speedup changes 2025-11-04 01:08:21 -08:00
batch_ops.go Centralize error handling patterns in storage layer (bd-bwk2) 2025-11-20 19:17:57 -05:00
batch_ops_test.go test: add comprehensive orphan handling mode tests 2025-11-05 00:02:57 -08:00
bench_helpers_test.go Context propagation with graceful cancellation (bd-rtp, bd-yb8, bd-2o2) 2025-11-20 21:57:23 -05:00
blocked_cache.go Add blocked_issues_cache table for GetReadyWork optimization 2025-11-20 19:29:30 -05:00
child_counters_migration_test.go Extract SQLite migrations into separate files (bd-fb95094c.7) 2025-11-06 20:06:45 -08:00
child_counters_test.go Implement 6-char progressive hash IDs (bd-166, bd-167) 2025-10-30 14:04:03 -07:00
child_id_test.go Fix bd-dvd and bd-ymj: Parent resurrection and export metadata 2025-11-21 10:29:30 -05:00
collision.go Document external_ref in content hash behavior (bd-9f4a) 2025-11-08 02:22:15 -08:00
collision_test.go Document external_ref in content hash behavior (bd-9f4a) 2025-11-08 02:22:15 -08:00
comments_test.go test: add comprehensive Comments API tests (bd-d68f) 2025-11-01 22:53:38 -07:00
compact.go Fix FK constraint failures in AddComment and ApplyCompaction (bd-5arw) 2025-11-20 18:55:10 -05:00
compact_bench_test.go Context propagation with graceful cancellation (bd-rtp, bd-yb8, bd-2o2) 2025-11-20 21:57:23 -05:00
compact_test.go Fix FK constraint failures in AddComment and ApplyCompaction (bd-5arw) 2025-11-20 18:55:10 -05:00
cycle_bench_test.go Performance Improvements (#319) 2025-11-15 12:46:13 -08:00
cycle_detection_test.go fix: DetectCycles SQL bug and add comprehensive tests 2025-11-01 22:51:58 -07:00
delete_test.go test: add sqlite collision and delete test coverage 2025-11-01 22:47:07 -07:00
dependencies.go Add cache invalidation for blocked_issues_cache 2025-11-20 19:29:30 -05:00
dependencies_test.go Fix #202: Add dependency_type to bd show --json output (#203) 2025-11-02 08:40:10 -08:00
dirty.go Centralize error handling patterns in storage layer (bd-bwk2) 2025-11-20 19:17:57 -05:00
dirty_helpers.go Refactor: consolidate ID generation and shared helpers (bd-0702, bd-1445) 2025-11-02 14:49:27 -08:00
dirty_test.go test: Add comprehensive test coverage for storage layer 2025-10-15 01:30:28 -07:00
epics.go Enable errcheck linter and fix all production code warnings 2025-10-25 18:44:38 -07:00
epics_test.go Refactor high-complexity test functions (gocyclo) 2025-10-25 13:20:16 -07:00
errors.go Centralize error handling patterns in storage layer (bd-bwk2) 2025-11-20 19:17:57 -05:00
events.go Fix FK constraint failures in AddComment and ApplyCompaction (bd-5arw) 2025-11-20 18:55:10 -05:00
events_helpers.go Refactor: consolidate ID generation and shared helpers (bd-0702, bd-1445) 2025-11-02 14:49:27 -08:00
events_test.go Fix FK constraint failures in AddComment and ApplyCompaction (bd-5arw) 2025-11-20 18:55:10 -05:00
external_ref_test.go Add external_ref UNIQUE constraint and validation 2025-11-02 16:27:42 -08:00
hash.go Fix bd-160: Implement JSONL integrity validation and prevent export deduplication data loss 2025-10-29 21:57:15 -07:00
hash_id_test.go Context propagation with graceful cancellation (bd-rtp, bd-yb8, bd-2o2) 2025-11-20 21:57:23 -05:00
hash_ids.go Fix bd-ar2 code review issues: metadata tracking and multi-repo support 2025-11-21 11:28:25 -05:00
ids.go Centralize error handling patterns in storage layer (bd-bwk2) 2025-11-20 19:17:57 -05:00
issues.go Implement multi-repo hydration layer with mtime caching (bd-307) 2025-11-04 23:12:41 -08:00
labels.go Merge branch 'fix-issue-325' into main 2025-11-20 14:20:45 -05:00
labels_test.go test: Add comprehensive test coverage for storage layer 2025-10-15 01:30:28 -07:00
migration_invariants.go Add migration inspection tools for AI agents (bd-627d Phase 2) 2025-11-02 14:03:14 -08:00
migration_invariants_test.go Add migration inspection tools for AI agents (bd-627d Phase 2) 2025-11-02 14:03:14 -08:00
migrations.go Add blocked_issues_cache table for GetReadyWork optimization 2025-11-20 19:29:30 -05:00
migrations_test.go Extract SQLite migrations into separate files (bd-fb95094c.7) 2025-11-06 20:06:45 -08:00
multirepo.go Fix lint errors: add error check and gosec suppressions 2025-11-05 01:11:09 -08:00
multirepo_export.go Centralize BD_DEBUG logging into internal/debug package 2025-11-06 20:14:34 -08:00
multirepo_test.go Add remaining multi-repo files from bd-307 2025-11-04 23:12:41 -08:00
orphan_handling_test.go test: add comprehensive orphan handling mode tests 2025-11-05 00:02:57 -08:00
prefix_validation_test.go Context propagation with graceful cancellation (bd-rtp, bd-yb8, bd-2o2) 2025-11-20 21:57:23 -05:00
ready.go Optimize GetReadyWork to use blocked_issues_cache 2025-11-20 19:29:30 -05:00
ready_test.go Complete bd-95: Add content-addressable identity (ContentHash field) 2025-10-28 18:57:16 -07:00
resurrection.go Fix lint errors: add error check and gosec suppressions 2025-11-05 01:11:09 -08:00
resurrection_test.go Fix P0 bug: JSONL lookup now returns LAST match (bd-58c0) 2025-11-04 22:25:33 -08:00
schema.go Performance Improvements (#319) 2025-11-15 12:46:13 -08:00
schema_probe.go Fix CI regressions and stabilize tests 2025-11-17 10:06:35 -07:00
schema_probe_test.go Add schema compatibility probe to prevent silent migration failures (bd-ckvw) 2025-11-08 15:40:19 -08:00
sqlite.go Context propagation with graceful cancellation (bd-rtp, bd-yb8, bd-2o2) 2025-11-20 21:57:23 -05:00
sqlite_bench_test.go Performance Improvements (#319) 2025-11-15 12:46:13 -08:00
sqlite_test.go Context propagation with graceful cancellation (bd-rtp, bd-yb8, bd-2o2) 2025-11-20 21:57:23 -05:00
test_helpers.go Context propagation with graceful cancellation (bd-rtp, bd-yb8, bd-2o2) 2025-11-20 21:57:23 -05:00
underlying_db_test.go Context propagation with graceful cancellation (bd-rtp, bd-yb8, bd-2o2) 2025-11-20 21:57:23 -05:00
util.go Centralize error handling patterns in storage layer (bd-bwk2) 2025-11-20 19:17:57 -05:00
util_test.go test: improve coverage for importer and sqlite utils 2025-11-01 11:35:31 -07:00
validators.go Refactor sqlite.go: Extract hash IDs, batch ops, validators (bd-90a5, bd-c796, bd-d9e0) 2025-11-01 19:55:48 -07:00
validators_test.go Refactor sqlite.go: Extract hash IDs, batch ops, validators (bd-90a5, bd-c796, bd-d9e0) 2025-11-01 19:55:48 -07:00