Fix bd-160: Implement JSONL integrity validation and prevent export deduplication data loss
## Problem Export deduplication feature broke when JSONL and export_hashes diverged (e.g., after git pull/reset). This caused exports to skip issues that weren't actually in the file, leading to silent data loss. ## Solution 1. JSONL integrity validation before every export - Store JSONL file hash after export - Validate hash before export, clear export_hashes if mismatch - Automatically recovers from git operations changing JSONL 2. Clear export_hashes on all imports - Prevents stale hashes from causing future export failures - Import operations invalidate export_hashes state 3. Add Storage interface methods: - GetJSONLFileHash/SetJSONLFileHash for integrity tracking - ClearAllExportHashes for recovery ## Tests Added - TestJSONLIntegrityValidation: Unit tests for validation logic - TestImportClearsExportHashes: Verifies imports clear hashes - TestExportIntegrityAfterJSONLTruncation: Simulates git reset (would have caught bd-160) - TestExportIntegrityAfterJSONLDeletion: Tests recovery from file deletion - TestMultipleExportsStayConsistent: Tests repeated export integrity ## Follow-up Created bd-179 epic for remaining integration test gaps (multi-repo sync, daemon auto-sync, corruption recovery tests). Closes bd-160
This commit is contained in:
@@ -595,6 +595,24 @@ func (m *MemoryStorage) SetExportHash(ctx context.Context, issueID, hash string)
|
||||
return nil
|
||||
}
|
||||
|
||||
// ClearAllExportHashes clears all export hashes
|
||||
func (m *MemoryStorage) ClearAllExportHashes(ctx context.Context) error {
|
||||
// Memory storage doesn't track export hashes, no-op
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetJSONLFileHash gets the JSONL file hash
|
||||
func (m *MemoryStorage) GetJSONLFileHash(ctx context.Context) (string, error) {
|
||||
// Memory storage doesn't track JSONL file hashes, return empty string
|
||||
return "", nil
|
||||
}
|
||||
|
||||
// SetJSONLFileHash sets the JSONL file hash
|
||||
func (m *MemoryStorage) SetJSONLFileHash(ctx context.Context, fileHash string) error {
|
||||
// Memory storage doesn't track JSONL file hashes, no-op
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetDependencyTree gets the dependency tree for an issue
|
||||
func (m *MemoryStorage) GetDependencyTree(ctx context.Context, issueID string, maxDepth int, showAllPaths bool, reverse bool) ([]*types.TreeNode, error) {
|
||||
// Simplified implementation - just return direct dependencies
|
||||
|
||||
@@ -50,3 +50,36 @@ func (s *SQLiteStorage) ClearAllExportHashes(ctx context.Context) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetJSONLFileHash retrieves the stored hash of the JSONL file.
|
||||
// Returns empty string if no hash is stored (bd-160).
|
||||
func (s *SQLiteStorage) GetJSONLFileHash(ctx context.Context) (string, error) {
|
||||
var hash string
|
||||
err := s.db.QueryRowContext(ctx, `
|
||||
SELECT value FROM metadata WHERE key = 'jsonl_file_hash'
|
||||
`).Scan(&hash)
|
||||
|
||||
if err == sql.ErrNoRows {
|
||||
return "", nil // No hash stored yet
|
||||
}
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed to get jsonl_file_hash: %w", err)
|
||||
}
|
||||
|
||||
return hash, nil
|
||||
}
|
||||
|
||||
// SetJSONLFileHash stores the hash of the JSONL file after export (bd-160).
|
||||
func (s *SQLiteStorage) SetJSONLFileHash(ctx context.Context, fileHash string) error {
|
||||
_, err := s.db.ExecContext(ctx, `
|
||||
INSERT INTO metadata (key, value)
|
||||
VALUES ('jsonl_file_hash', ?)
|
||||
ON CONFLICT(key) DO UPDATE SET value = excluded.value
|
||||
`, fileHash)
|
||||
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to set jsonl_file_hash: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -59,6 +59,11 @@ type Storage interface {
|
||||
// Export hash tracking (for timestamp-only dedup, bd-164)
|
||||
GetExportHash(ctx context.Context, issueID string) (string, error)
|
||||
SetExportHash(ctx context.Context, issueID, contentHash string) error
|
||||
ClearAllExportHashes(ctx context.Context) error
|
||||
|
||||
// JSONL file integrity (bd-160)
|
||||
GetJSONLFileHash(ctx context.Context) (string, error)
|
||||
SetJSONLFileHash(ctx context.Context, fileHash string) error
|
||||
|
||||
// Config
|
||||
SetConfig(ctx context.Context, key, value string) error
|
||||
|
||||
Reference in New Issue
Block a user