fix(tests): session-scoped engine-state isolation — close the module-scope escape to the live life-store #100

Merged
core-labs merged 1 commit from fix/test-engine-state-isolation into main 2026-07-23 04:02:22 +00:00
Owner

T10 from the 2026-07-22 weekly audit (root cause behind the T2 warning churn).

Defect

The root-conftest isolation fixture (_isolate_engine_state_default) is function-scoped, and pytest sets up higher-scoped fixtures first — so a module-/session-scoped fixture constructing a bare ChatRuntime() binds engine_state._DEFAULT_DIR before any patch exists. tests/test_achat.py's module-scoped runtime did exactly that during smoke runs: it loaded the live life-store (emitting the ADR-0157 revision-mismatch warning against the real checkpoint — the "warning fatigue" T2 flagged) and committed real generations (observed: live turn_count 14989→14990, written_at_revision re-stamped by the suite). Content pollution was nil in the observed instance (recognizers/candidates byte-identical), but lineage provenance was not test-free.

Fix (TDD)

  • RED: new regression pin tests/test_conftest_engine_state_isolation.py::test_module_scoped_construction_cannot_bind_the_live_store — a module-scoped fixture constructs the default store and fails if it resolves to the repo dir (verified failing before the fix).
  • GREEN: _isolate_engine_state_session_baseline in root conftest.py — session-scoped autouse fixture (set up before any narrower scope) pointing engine_state._DEFAULT_DIR + CORE_ENGINE_STATE_DIR at a session temp dir. The per-test fixture keeps providing per-test freshness on top; uses_default_engine_state still opts out of the per-test layer only (resolution semantics preserved; the live store is unreachable at every scope).
  • docs/issues/default-engine-state-test-hygiene.md: status updated + 2026-07-22 addendum with the evidence.

Validation

  • Isolation file + achat: 15 passed, no revision warning, zero generations written to the repo store.
  • Fast lane (-m "not quarantine and not slow" -n auto): 12,396 passed, 1 failed — the single failure (test_warmed_session_lane.py::…::test_telemetry_consistency_rate_is_one, rate 0.9444) is pre-existing on unmodified main (verified failing there both plain and state-isolated; it is the T13 #96 surface-override regression, ledgered separately). Zero new failures from this change.
  • Nightly full lane remains the final suite-wide confirmation per the issue doc's criterion #4.

[Verification]: uv run core test --suite smoke -q in worktree core-wt-t2fix @ HEAD — 180 passed in 131.58s, exit 0.

Merge on your authorization. Residual rulings tracked as T11 (live-store provenance review) in the audit ledger.

T10 from the 2026-07-22 weekly audit (root cause behind the T2 warning churn). ## Defect The root-conftest isolation fixture (`_isolate_engine_state_default`) is function-scoped, and pytest sets up **higher-scoped fixtures first** — so a module-/session-scoped fixture constructing a bare `ChatRuntime()` binds `engine_state._DEFAULT_DIR` before any patch exists. `tests/test_achat.py`'s module-scoped `runtime` did exactly that during smoke runs: it **loaded the live life-store** (emitting the ADR-0157 revision-mismatch warning against the real checkpoint — the "warning fatigue" T2 flagged) and **committed real generations** (observed: live `turn_count` 14989→14990, `written_at_revision` re-stamped by the suite). Content pollution was nil in the observed instance (recognizers/candidates byte-identical), but lineage provenance was not test-free. ## Fix (TDD) - **RED**: new regression pin `tests/test_conftest_engine_state_isolation.py::test_module_scoped_construction_cannot_bind_the_live_store` — a module-scoped fixture constructs the default store and fails if it resolves to the repo dir (verified failing before the fix). - **GREEN**: `_isolate_engine_state_session_baseline` in root `conftest.py` — session-scoped autouse fixture (set up before any narrower scope) pointing `engine_state._DEFAULT_DIR` + `CORE_ENGINE_STATE_DIR` at a session temp dir. The per-test fixture keeps providing per-test freshness on top; `uses_default_engine_state` still opts out of the per-test layer only (resolution semantics preserved; the live store is unreachable at every scope). - `docs/issues/default-engine-state-test-hygiene.md`: status updated + 2026-07-22 addendum with the evidence. ## Validation - Isolation file + achat: 15 passed, **no revision warning**, zero generations written to the repo store. - Fast lane (`-m "not quarantine and not slow" -n auto`): **12,396 passed, 1 failed** — the single failure (`test_warmed_session_lane.py::…::test_telemetry_consistency_rate_is_one`, rate 0.9444) is **pre-existing on unmodified main** (verified failing there both plain and state-isolated; it is the T13 #96 surface-override regression, ledgered separately). Zero new failures from this change. - Nightly full lane remains the final suite-wide confirmation per the issue doc's criterion #4. [Verification]: `uv run core test --suite smoke -q` in worktree `core-wt-t2fix` @ HEAD — **180 passed in 131.58s**, exit 0. Merge on your authorization. Residual rulings tracked as T11 (live-store provenance review) in the audit ledger.
core-labs added 1 commit 2026-07-23 03:34:46 +00:00
core-labs merged commit 80100c1831 into main 2026-07-23 04:02:22 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: core-labs/core#100
No description provided.