test: cover compact_passages_if_worthwhile's four untested branches - #594
Conversation
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
📝 WalkthroughWalkthrough
Changesコンテキスト圧縮テスト
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related issues
Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/registry/context_io.rs`:
- Around line 904-910: Update
compact_passages_if_worthwhile_declines_a_deleted_context so the test retains
the registry entry and sets its slot to Slot::Deleted, following the existing
setup pattern around the referenced Slot::Deleted usage, rather than calling
state.delete(). Keep the assertion focused on exercising the
read_unless_deleted() deleted-entry branch.
- Around line 957-965: 拡張対象は compact_passages_if_worthwhile のテストで、WAL
が空になった確認だけでなく再起動後の復元も検証してください。state を drop して永続化状態から再作成し、lookup_passages で a.md
の passage 内容が期待値どおり復元されることをアサートしてください。
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 128f2529-7725-4245-adef-6bc10d2b8af1
📒 Files selected for processing (1)
src/registry/context_io.rs
The pre-PR mutation gate found one missed mutant: the watermark guard (store.watermark() > 0) replaced with true. PassageStore::load never produces watermark() == 0 together with nonzero log_bytes or snapshot_bytes — a fresh or healed-clean store always has all three at zero, and compact_if_log_outgrew_snapshot's own condition (log_bytes > floor_bytes.max(ratio * snapshot_bytes)) is then false for every floor_bytes regardless of this guard. No test can kill it because there is no reachable state where it would matter. Refs #587
… guard The CI sweep (dispatched on main before this branch's tests existed) found a second mutant on compact_passages_if_worthwhile's watermark guard that the earlier local --file run had already excluded past: `>` replaced with `>=` rather than the whole guard replaced with `true`. Same equivalence reasoning applies — watermark(): u64 can never be negative, so `watermark() >= 0` is a tautology, identical to `true` for every possible value. Refs #587
- compact_passages_if_worthwhile_declines_a_deleted_context called state.delete(), which removes the entry from the registry entirely — the test exercised lookup()'s None branch, not the intended read_unless_deleted() -> Slot::Deleted branch. Flip the slot directly on a still-registered entry instead, matching the pattern run_maintenance_compaction_skips_a_deleted_entry_without_panicking already uses in this file. - compact_passages_if_worthwhile_compacts_past_the_floor only checked that the WAL file emptied, which an implementation that truncates the log before the snapshot lands would also satisfy while losing the write. Restart AppState from disk and dereference the passage back through lookup_passages to prove it actually survived. Refs #587
…untested # Conflicts: # .cargo/mutants.toml
Summary
compact_passages_if_worthwhile(src/registry/context_io.rs, the sync-only compaction helpertaguru-codecalls, issue taguru-code: passage WALがコンパクションされずディスクを食い続ける #452) had zero tests anywhere in the repository despite four early-return branches: replica, unknown context, deleted context, and zero passage-log watermark.store.watermark() > 0): the whole guard forced totrue, and>replaced with>=. Both are excluded in.cargo/mutants.tomlas equivalent —watermark(): u64can never be negative, so>= 0is a tautology identical totrue, andPassageStore::loadnever produceswatermark() == 0together with nonzero log/snapshot bytes, socompact_if_log_outgrew_snapshot's own condition is unconditionally false there regardless of this guard. No test can observe a difference because there is none.state.delete(), which removes the entry entirely and only exerciseslookup()'sNonebranch, not the intendedread_unless_deleted()→Slot::Deletedbranch — fixed by flipping the slot directly on a still-registered entry (matching the existingrun_maintenance_compaction_skips_a_deleted_entry_without_panickingpattern). The compaction test only checked that the WAL emptied, which an implementation that truncates the log before the snapshot lands would also pass while losing the write — fixed by restartingAppStatefrom disk and dereferencing the passage back throughlookup_passages.This closes out issue #587 (untested-branches audit from #533) together with #595 and #596. A CI mutants-sweep dispatched across all 5 audited files (
context_io.rs,wal.rs,storage.rs,wal_replay.rs,meta_io.rs, 227 mutants total) confirmswal_replay.rs(covered by #586's earlier work) andmeta_io.rs(covered by #585) already have zero missed mutants — no further PR needed for those.Closes #587.
Test plan
cargo fmtcargo clippy --bin taguru --tests(clean)cargo test(full suite green)cargo mutants --in-diff): 0 mutants (test-only diff)cargo mutants --file src/registry/context_io.rs, run in isolation: 53 tested, 45 caught, 8 unviable, 0 missedhttps://claude.ai/code/session_013NPb5cDU8ojZAKGJaq8rYy