Skip to content

test(preflight): #357 backfill — de-mock test_preflight_dedup_v2.py + decrement trap cap 8→5#365

Merged
silongtan merged 1 commit into
devfrom
infra/357-backfill-preflight-traps
May 15, 2026
Merged

test(preflight): #357 backfill — de-mock test_preflight_dedup_v2.py + decrement trap cap 8→5#365
silongtan merged 1 commit into
devfrom
infra/357-backfill-preflight-traps

Conversation

@silongtan

Copy link
Copy Markdown
Collaborator

Summary

First trap-row backfill PR driven by the #359 sub-task 1 audit. Converts the two integration tests in `tests/test_preflight_dedup_v2.py` from `MagicMock`-based ctx to a real `memory://` SurrealDB adapter. Drops trap count from 8 to 5 in one go — all three preflight-cluster traps (`get_decisions_for_files`, `get_collision_pending_decisions`, `get_context_for_ready_decisions`) flip from solitary to direct-sociable.

What changed

`tests/test_preflight_dedup_v2.py`:

  • New `_fresh_real_ctx` helper: builds a per-test `memory://` SurrealDB with schema migrated, returns the ctx + client
  • The 9 pure-function tests stay solitary (testing pure functions — correct posture)
  • The 2 integration tests are now `async def` and use the real adapter
  • Retained narrow-seam mocks (per CLAUDE.md):
    • `ledger.queries.get_ledger_revision` — the SPECIFIC failure/success behavior under test
    • `handlers.sync_middleware.ensure_ledger_synced` — keeps the auto-sync from touching the working tree

`tests/test_ledger_mock_regression.py`:

  • `EXPECTED_TRAP_CAP`: 8 → 5 (locks in the one-way-ratchet improvement)

Audit impact

Category Before After Δ
Direct sociable 24 27 +3
Solitary trap 8 5 -3
Indirect sociable 25 25 0
Uncovered 0 0 0

The three preflight-cluster trap rows are gone. Remaining traps are in two clusters:

  • remove_source (4 fns): `decision_exists`, `get_decisions_for_span`, `input_span_exists`, `get_input_span_row`
  • link_commit (1 fn): `get_region_metadata`

Out of scope

  • `tests/test_preflight_dedup_telemetry.py` and `tests/test_v055_region_anchored_preflight.py` still mock the preflight-cluster functions, but they no longer contribute to trap status (every preflight function is now sociable-covered via this PR's de-mocked tests). They get optional follow-up PRs.
  • The remove_source and link_commit cluster traps are separate follow-up PRs.

Verification

```
$ pytest tests/test_preflight_dedup_v2.py
18 passed in 0.77s

$ pytest tests/test_ledger_mock_regression.py
3 passed
```

Ruff check + format clean.

Test plan

  • CI green
  • Adjacent: `tests/test_preflight_dedup_telemetry.py` and `tests/test_v055_region_anchored_preflight.py` unchanged → no regression

🤖 Generated with Claude Code

… decrement trap cap 8→5

The Phase A audit (PR #359) flagged three solitary-trap rows in the
preflight cluster — get_decisions_for_files, get_collision_pending_decisions,
get_context_for_ready_decisions — all of which had test_preflight_dedup_v2.py
as one of their direct mock-only callers. This PR converts the two
integration tests in that file from MagicMock-based ctx to a real
memory:// SurrealDB adapter. The two helper-fn tests (pure
_normalize_file_paths_for_key / _dedup_key_for / _check_dedup checks)
remain solitary because they're testing pure functions.

The retained AsyncMock on `ledger.queries.get_ledger_revision` is the
SPECIFIC behavior under test in both integration cases ("returns None"
and "returns stable-rev-1") — narrow seam permitted by CLAUDE.md, same
class as the `patch time.monotonic for TTL math` example. The retained
mock on `handlers.sync_middleware.ensure_ledger_synced` keeps the auto-
sync from touching the working tree, same narrow-seam pattern.

Audit before/after:
- Direct sociable: 24 → 27 (+3 — all 3 preflight cluster functions)
- Solitary trap:   8  → 5  (-3 — preflight cluster cleared)
- Indirect:        25 (unchanged)
- Uncovered:       0  (unchanged)

EXPECTED_TRAP_CAP decremented 8→5 to lock in the improvement (per the
one-way-ratchet convention in tests/test_ledger_mock_regression.py).

Out of scope:
- test_preflight_dedup_telemetry.py and test_v055_region_anchored_preflight.py
  still use the old MagicMock pattern but no longer contribute to trap
  status (every preflight-cluster function is now sociable-covered).
  They get follow-up PRs if review-effort budget allows; the trap cap
  doesn't strictly require them.
- The remove_source cluster (4 trap rows) and the link_commit cluster
  (1 trap row) are separate follow-up PRs.

Verified:
- pytest tests/test_preflight_dedup_v2.py: 18/18 passing (0.77s)
- pytest tests/test_ledger_mock_regression.py: 3/3 passing (cap=5 holds)
- ruff check + format clean

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@silongtan silongtan added flow:feature Standard feature/fix PR targeting BicameralAI/dev (the default flow) P2 Medium: next milestone or two; default for new issues post-triage test Test infrastructure, fixtures, or coverage work labels May 15, 2026
@coderabbitai

coderabbitai Bot commented May 15, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: cb78a04a-2334-470c-b7f2-da85814ad9df

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch infra/357-backfill-preflight-traps

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

flow:feature Standard feature/fix PR targeting BicameralAI/dev (the default flow) P2 Medium: next milestone or two; default for new issues post-triage test Test infrastructure, fixtures, or coverage work

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant