Fix bd-c6cf: Force full export when export_hashes is cleared
When validateJSONLIntegrity() clears export_hashes due to hash mismatch or missing JSONL, the subsequent export now correctly exports ALL issues instead of only dirty ones, preventing permanent database divergence. Changes: - validateJSONLIntegrity() returns (needsFullExport, error) to signal when export_hashes was cleared - flushToJSONL() moved integrity check BEFORE isDirty gate so integrity issues trigger export even when nothing is dirty - Missing JSONL treated as non-fatal force-full-export case - Increased scanner buffer from 64KB to 2MB to handle large JSON lines - Added scanner.Err() check to catch buffer overflow errors - Updated all tests to verify needsFullExport flag Fixes database divergence issue where clearing export_hashes didn't trigger re-export, causing 5 issues to disappear from JSONL in fred clone. Amp-Thread-ID: https://ampcode.com/threads/T-bf2fdcd6-7bbd-4c30-b1db-746b928c93b8 Co-authored-by: Amp <amp@ampcode.com>
This commit is contained in:
@@ -85,9 +85,13 @@ func TestJSONLIntegrityValidation(t *testing.T) {
|
||||
|
||||
// Test 1: Validate with matching hash (should succeed)
|
||||
t.Run("MatchingHash", func(t *testing.T) {
|
||||
if err := validateJSONLIntegrity(ctx, jsonlPath); err != nil {
|
||||
needsFullExport, err := validateJSONLIntegrity(ctx, jsonlPath)
|
||||
if err != nil {
|
||||
t.Fatalf("validation failed with matching hash: %v", err)
|
||||
}
|
||||
if needsFullExport {
|
||||
t.Fatalf("expected needsFullExport=false for matching hash")
|
||||
}
|
||||
})
|
||||
|
||||
// Test 2: Modify JSONL file (simulating git pull) and validate
|
||||
@@ -103,9 +107,13 @@ func TestJSONLIntegrityValidation(t *testing.T) {
|
||||
}
|
||||
|
||||
// Validate should detect mismatch and clear export_hashes
|
||||
if err := validateJSONLIntegrity(ctx, jsonlPath); err != nil {
|
||||
needsFullExport, err := validateJSONLIntegrity(ctx, jsonlPath)
|
||||
if err != nil {
|
||||
t.Fatalf("validation failed: %v", err)
|
||||
}
|
||||
if !needsFullExport {
|
||||
t.Fatalf("expected needsFullExport=true after clearing export_hashes")
|
||||
}
|
||||
|
||||
// Verify export_hashes were cleared
|
||||
hash, err := testStore.GetExportHash(ctx, "bd-1")
|
||||
@@ -135,9 +143,13 @@ func TestJSONLIntegrityValidation(t *testing.T) {
|
||||
}
|
||||
|
||||
// Validate should detect missing file and clear export_hashes
|
||||
if err := validateJSONLIntegrity(ctx, jsonlPath); err != nil {
|
||||
needsFullExport, err := validateJSONLIntegrity(ctx, jsonlPath)
|
||||
if err != nil {
|
||||
t.Fatalf("validation failed: %v", err)
|
||||
}
|
||||
if !needsFullExport {
|
||||
t.Fatalf("expected needsFullExport=true after clearing export_hashes")
|
||||
}
|
||||
|
||||
// Verify export_hashes were cleared
|
||||
hash, err := testStore.GetExportHash(ctx, "bd-1")
|
||||
|
||||
Reference in New Issue
Block a user