Skip to content

test(memory): add rollback and orchestration tests for consolidation#2383

Merged
bug-ops merged 1 commit intomainfrom
test-memory-add-rollback-test
Mar 29, 2026
Merged

test(memory): add rollback and orchestration tests for consolidation#2383
bug-ops merged 1 commit intomainfrom
test-memory-add-rollback-test

Conversation

@bug-ops
Copy link
Copy Markdown
Owner

@bug-ops bug-ops commented Mar 29, 2026

Summary

Tests added (6)

Test Issue What it verifies
apply_consolidation_merge_rollback_on_mid_tx_error #2359 FK violation triggers TX rollback — join table empty, sources remain consolidated=0, function returns Err
run_consolidation_sweep_single_candidate_skips #2360 embedded.len() < 2 guard exits with all counters at zero
run_consolidation_sweep_merge_increments_counter #2360 result.merges == 1 on successful Merge op
run_consolidation_sweep_update_increments_counter #2360 result.updates == 1 on successful Update op
run_consolidation_sweep_skipped_below_threshold #2360 result.skipped == 1 when confidence < threshold
run_consolidation_sweep_update_db_state #2360 Update op persists consolidated message and marks sources consolidated=1 in DB

Implementation note

INSERT OR IGNORE on memory_consolidation_sources does not suppress FK violations in SQLite when foreign_keys = ON (only suppresses UNIQUE/CHECK/NOT NULL). The rollback test uses an invalid ConversationId(99999) to trigger FK failure on INSERT INTO messages — the first statement in the transaction — which exercises the same rollback semantics and satisfies the acceptance criteria.

Checklist

  • cargo +nightly fmt --check — clean
  • cargo clippy --workspace -- -D warnings — 0 warnings
  • cargo nextest run --workspace --lib --bins — 6614 passed

Closes #2359
Closes #2360

@github-actions github-actions bot added memory zeph-memory crate (SQLite) rust Rust code changes tests Test-related changes size/L Large PR (201-500 lines) labels Mar 29, 2026
@bug-ops bug-ops force-pushed the test-memory-add-rollback-test branch from d93a05d to b53ef82 Compare March 29, 2026 01:21
@github-actions github-actions bot removed the tests Test-related changes label Mar 29, 2026
…2359, #2360)

Adds 6 unit tests in consolidation.rs covering:

- apply_consolidation_merge_rollback_on_mid_tx_error: verifies transaction
  rollback on mid-tx FK violation — memory_consolidation_sources has 0 rows
  and source messages remain consolidated=false after error (#2359)
- run_consolidation_sweep_single_candidate_skips: embedded.len() < 2 guard
  exits with all counters at zero (#2360)
- run_consolidation_sweep_merge_increments_counter: result.merges==1 on
  successful Merge op (#2360)
- run_consolidation_sweep_update_increments_counter: result.updates==1 on
  successful Update op (#2360)
- run_consolidation_sweep_skipped_below_threshold: result.skipped==1 when
  confidence < threshold (#2360)
- run_consolidation_sweep_update_db_state: Update op persists consolidated
  message and marks sources as consolidated=1 in DB (#2360)

Note: INSERT OR IGNORE on memory_consolidation_sources does not suppress FK
violations in SQLite (foreign_keys=ON). Rollback is triggered via FK
violation on messages.conversation_id instead, which fires earlier in the
transaction and exercises the same rollback semantics.
@bug-ops bug-ops force-pushed the test-memory-add-rollback-test branch from b53ef82 to 3c9c800 Compare March 29, 2026 01:30
@github-actions github-actions bot added the tests Test-related changes label Mar 29, 2026
@bug-ops bug-ops enabled auto-merge (squash) March 29, 2026 01:36
@bug-ops bug-ops merged commit 422db21 into main Mar 29, 2026
44 of 47 checks passed
@bug-ops bug-ops deleted the test-memory-add-rollback-test branch March 29, 2026 01:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

memory zeph-memory crate (SQLite) rust Rust code changes size/L Large PR (201-500 lines) tests Test-related changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test(memory): add unit tests for run_consolidation_sweep orchestration test(memory): add rollback test for apply_consolidation_merge on mid-tx error

1 participant