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>
This commit is contained in:
@@ -61,6 +61,14 @@ func TestExportUpdatesDatabaseMtime(t *testing.T) {
|
||||
t.Fatalf("Export failed: %v", err)
|
||||
}
|
||||
|
||||
// Update metadata after export (bd-ymj fix)
|
||||
mockLogger := daemonLogger{
|
||||
logFunc: func(format string, args ...interface{}) {
|
||||
t.Logf(format, args...)
|
||||
},
|
||||
}
|
||||
updateExportMetadata(ctx, store, jsonlPath, mockLogger, "")
|
||||
|
||||
// Get JSONL mtime
|
||||
jsonlInfo, err := os.Stat(jsonlPath)
|
||||
if err != nil {
|
||||
@@ -158,6 +166,14 @@ func TestDaemonExportScenario(t *testing.T) {
|
||||
t.Fatalf("Daemon export failed: %v", err)
|
||||
}
|
||||
|
||||
// Daemon updates metadata after export (bd-ymj fix)
|
||||
mockLogger := daemonLogger{
|
||||
logFunc: func(format string, args ...interface{}) {
|
||||
t.Logf(format, args...)
|
||||
},
|
||||
}
|
||||
updateExportMetadata(ctx, store, jsonlPath, mockLogger, "")
|
||||
|
||||
// THIS IS THE FIX: daemon now calls TouchDatabaseFile after export
|
||||
if err := TouchDatabaseFile(dbPath, jsonlPath); err != nil {
|
||||
t.Fatalf("TouchDatabaseFile failed: %v", err)
|
||||
@@ -229,6 +245,14 @@ func TestMultipleExportCycles(t *testing.T) {
|
||||
t.Fatalf("Cycle %d: Export failed: %v", i, err)
|
||||
}
|
||||
|
||||
// Update metadata after export (bd-ymj fix)
|
||||
mockLogger := daemonLogger{
|
||||
logFunc: func(format string, args ...interface{}) {
|
||||
t.Logf(format, args...)
|
||||
},
|
||||
}
|
||||
updateExportMetadata(ctx, store, jsonlPath, mockLogger, "")
|
||||
|
||||
// Apply fix
|
||||
if err := TouchDatabaseFile(dbPath, jsonlPath); err != nil {
|
||||
t.Fatalf("Cycle %d: TouchDatabaseFile failed: %v", i, err)
|
||||
|
||||
Reference in New Issue
Block a user