Skip to content

Statement coverage to 82% with an enforced floor; resolve the four zero-importer modules (#196) - #229

Merged
cdeust merged 1 commit into
mainfrom
feat/coverage-floor-196-v2
Jul 28, 2026
Merged

Statement coverage to 82% with an enforced floor; resolve the four zero-importer modules (#196)#229
cdeust merged 1 commit into
mainfrom
feat/coverage-floor-196-v2

Conversation

@cdeust

@cdeust cdeust commented Jul 28, 2026

Copy link
Copy Markdown
Owner

Closes #196.

What this PR does

  1. Wires condense_assembled_context as pg_recall.assemble_context's missing truncation-awareness pass — the stage assembler's three phases each enforce only their own sub-budget, so their sum could exceed the caller's token_budget; the new pass is a byte-identical no-op when the sections fit and priority-condenses (own > adjacent > summaries) through decomposer.assemble_prompt when they don't. This also gives decomposer.py its production call site (partially addresses context_assembly: decomposer + active_retrieval have no call site #201).
  2. Raises statement coverage over mcp_server from 74.83% to 82.02% (CI coverage job, run 30316539703, coverage.py 7.15.2) via contract tests for: stage_detector, decomposer, ppr_traversal, active_retrieval, coverage, warning, concept_emerger, wiki_view_executor, the pg_recall wiring, agent_briefing, wiki_rule_engine, wiki_file_doc_skeleton, wiki_coverage_dashboard, session_start (the issue's largest named gap, 36% → 82%), batch_sinks/pooled_sink, and viz_client. Measured locally with the same command on the SQLite backend the tree still clears the bar on its own: 80.14% (29,534 of 36,854) with every PG-only test failing-by-environment.
  3. Enforces the floor: --cov-fail-under=82 in the CI coverage job.
  4. Flips test_statement_coverage80 to Met in .bestpractices.json and updates docs/ASSURANCE-CASE.md § "What this assurance case does NOT claim".
  5. Isolates domain_mapping's dev-root scan in conftest — the transitive os.walk over real repo trees killed local --cov runs at the 300 s per-test timeout; CI isolation was accidental (no dev roots on runners), now it is designed.

The four zero-importer modules (criterion 1)

Module Resolution Evidence
infrastructure/git_diff.py Deleted on main by #204 — behaviour proven to live in cortex-viz's independent git_diff_engine.py; its one shared consumer (shared/subprocess_safe.py) docstring names the removal git log --follow shows removal in 1572f61; no importer existed
shared/memory_types.py Deleted on main by #204 — scaffolding types with no call site ever built removal in 1572f61
core/context_assembly/condensers.py Caller built: #204 wired condense_memory_content into stage_phases; THIS PR completes the wiring with condense_assembled_context inside pg_recall.assemble_context tests_py/core/test_pg_recall_assemble_context_condensation.py (3 tests), tests_py/core/context_assembly/test_condensers.py (33 tests)
hooks/preemptive_context.py Caller exists outside the import graph: registered as a PostToolUse hook in .claude-plugin/plugin.json:79; covered by tests_py/hooks/test_preemptive_context.py (22 tests, merged in #204) zero importers is the expected shape for a hook entry point

hooks/agent_briefing.py (SubagentStart) and hooks/session_start.py (SessionStart) share the same entry-point shape — registered in plugin.json, zero importers by design — and are now covered by 29 and 64 tests respectively.

Mutation triage on the changed function (§12)

Scoped mutmut run (only_mutate=condensers.py, 352 mutants) after adding the new tests: 0 non-equivalent survivors in condense_assembled_context — 13 killed by three added contract tests (exact-budget byte-identity; every-section-yields with banner-key labels; adjacent-yields-to-own priority), 1 documented equivalent (summaries priority 3→4: priorities are pure sort keys and the mutation preserves the strict order own < adjacent < summaries — behaviour identical). The 125 survivors in the PRE-existing condenser functions (code this PR does not change) are the sweep-tier backlog, filed as #228. The changed lines in pg_recall.py are pinned by the three wiring tests (over-budget condenses; token_budget=None never invokes the pass; under-budget output unchanged).

Completion Ledger

§13.1 checklist

Item State Evidence
A1 happy paths done full suite: 6029 passed / 3 skipped (CI run 30316539703); e.g. test_over_budget_result_is_condensed, test_assembled_context_under_budget_matches_stage_assembler_format
A2 edge cases done empty/whitespace sections (test_assembled_context_all_empty_returns_empty_string, test_assembled_context_whitespace_only_input_treated_as_empty), boundary (test_assembled_context_exactly_at_budget_is_byte_identical), oversize (test_assembled_context_over_budget_condenses_every_section), unicode-free blobs + sentence content both exercised
A3 failure paths + signals done every degraded arm asserts its emission: test_failed_agent_scoped_query_is_logged_and_team_pass_still_runs, test_failed_team_query_is_logged_and_returns_partial_results, test_unreachable_postgres_is_skipped_with_a_signal, test_unreadable_page_is_skipped_not_fatal, test_unwritable_dashboard_is_skipped_and_the_batch_continues, test_unwritable_index_does_not_lose_the_dashboards, test_write_dashboards_registry_failure_writes_nothing, test_invalid_regex_silently_does_not_match
A4 trust boundaries done hook stdin gates: test_main_ignores_malformed_json, test_main_ignores_empty_stdin, test_main_ignores_an_interactive_terminal; non-string tags: test_tag_match_is_case_insensitive
A5 invariants stated done condense_assembled_context docstring states pre/postconditions incl. the banner-length caveat; unreachable-arm proof comment at the condense_assistant_message final return
A6 idempotency N/A pure functions (condensers, rule engine, skeleton) and read-only queries; write_dashboards re-run overwrites deterministically (test_write_dashboards_emits_one_page_per_domain_plus_index)
B1-B3 concurrency N/A no concurrency touched; all new code is synchronous pure logic + per-call DB reads
C1 scalability done dashboard caps its uncovered listing at 30 (test_resolved_source_root_reports_file_coverage_and_caps_the_list); keyword extraction caps at 8; briefing capped at _MAX_MEMORIES
C2 resource lifecycle done connection closed on every arm: conn.close asserted in test_briefing_prints_header_marker_and_one_line_per_memory and test_no_relevant_memories_is_skipped_and_connection_closed; temp dirs via tmp_path
C3 hot paths N/A no hot path touched; condensation pass is a no-op (total <= token_budget fast path) in the common case, asserted byte-identical
D1-D3 security done/N/A briefing SQL uses parametrized queries only (asserted through call_args); no secrets; no new privileges; no query built from user strings
E1 API compat done additive only — assemble_context return keys unchanged; raw phase fields stay uncondensed (test_over_budget_result_is_condensed asserts this consumer contract)
E2 downstream consumers done named: benchmark evaluators matching selected_memories against raw phase fields — pinned by the same test
E3 persisted data N/A no format change
E4 cross-platform done no path/process/encoding logic added beyond tmp_path-based tests; suite green on Windows leg (CI run 30316539703)
F1 failure signals asserted done see A3 row
F2 degraded modes explicit done marker-less briefing on failed receipt: test_failed_receipt_degrades_to_marker_less_briefing; "(no source root resolved)" line: test_fresh_domain_renders_all_slots_as_queued
G1 path ledger done table below
G2 regression tests N/A no bug fixed in this PR (coverage + wiring work)
G3 deterministic tests done tmp_path everywhere, no sleeps, no shared state; monkeypatched Path.home; suite passes under default parallel CI matrix
G4 negative assertions done absence checks throughout: connect.assert_not_called() in the briefing gates, mock_condense.assert_not_called() in test_none_token_budget_skips_condensation, assert "Related Prior Context" not in result, receipt-marker absence in test_failed_receipt_degrades_to_marker_less_briefing
G5 suite + gates done local: 5895 passed / 176 skipped, plus 17 failed + 27 errors that are pre-existing PG-unreachable artifacts (identical on unmodified main via paired control; tracked by #220); CI: 6029 passed / 3 skipped (run 30316539703); ruff format/check clean on touched files; pyright ratchet PASS (no blocking rule regressed)
H1 standards done no layer violation (tests + one core-to-core wiring); sizes within caps; sourced constants (banner threshold cites decomposer defaults)
H2 readable/simplified done no dead code added; unreachable arm documented with proof rather than deleted (future-fallback rationale at use site)
H3 conventions done function-style tests matching each target file's neighbours; one language per file
H4 CHANGELOG/docs done advertised test count synced to 6115 across README/CLAUDE/CONTRIBUTING/ASSURANCE-CASE/bestpractices; assurance-case §6 updated
H5 commit hygiene done conventional commits; formatting isolated in its own commit
H6 CI green done run 30316539703 on the pushed tree
H7 boy-scout (§14) done coverage.xml gitignored (seen untracked artifact); pre-existing SQLite-mode failures reproduced on unmodified main (paired control, 16/16 identical) — in scope of open issue #220; pre-existing mutation survivors filed as #228; no other warnings surfaced

Code-path ledger (new paths introduced by this diff)

Path Asserting test
condense_assembled_context fast path (fits) test_assembled_context_under_budget_matches_stage_assembler_format, test_assembled_context_exactly_at_budget_is_byte_identical
section omitted when empty/whitespace test_assembled_context_omits_empty_sections, test_assembled_context_whitespace_only_input_treated_as_empty
all-empty → "" test_assembled_context_all_empty_returns_empty_string
over-budget condensation path test_assembled_context_over_budget_result_fits_within_budget, test_assembled_context_condensation_engages_and_reduces_content
priority ordering own>adjacent>summaries test_assembled_context_own_stage_survives_more_than_summaries, test_assembled_context_adjacent_yields_budget_to_own_stage
truncation banner emission + per-key labels test_assembled_context_emits_truncation_warning_banner, test_assembled_context_over_budget_condenses_every_section
over-budget template excludes absent sections test_assembled_context_over_budget_excludes_missing_sections
assemble_context wiring: budget set + over test_over_budget_result_is_condensed
wiring: budget set + fits (no-op) test_under_budget_result_unchanged
wiring: token_budget=None skip test_none_token_budget_skips_condensation
condensers unreachable no-prose-budget return # pragma: no cover with written single-segment proof at the use site (provably unreachable; kept as fallback)

New-test files for previously-uncovered modules map one test per behaviour; per-file counts: session_start 64, agent_briefing 29, wiki_view_executor 57, concept_emerger 51, stage_detector 30, ppr_traversal 27, decomposer 23, active_retrieval 18, wiki_file_doc_skeleton 17, coverage 13, wiki_coverage_dashboard 16, wiki_rule_engine 15, viz_client 12, batch_sinks 7, warning 5, pg_recall wiring 3, condensers +13.

Deferrals (each with its issue number)

🤖 Generated with Claude Code

…four zero-importer modules resolved (#196)

Squash-resolution of feat/coverage-floor-196-v2 onto main after #224:
conflicts were the advertised test count only; re-collected on the merged
tree (6135) and validated with scripts/check_doc_claims.py. The 18
changed/added test files pass on the merged tree (420 passed).

Closes #196.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@cdeust
cdeust force-pushed the feat/coverage-floor-196-v2 branch from 05c4abe to c224fc8 Compare July 28, 2026 00:50
@cdeust
cdeust merged commit d40368d into main Jul 28, 2026
14 checks passed
@cdeust
cdeust deleted the feat/coverage-floor-196-v2 branch July 28, 2026 01:08
cdeust added a commit that referenced this pull request Jul 28, 2026
… or silent_failure-observable (#197)

Squash-resolution of feat/warnings-strict-197-ble onto main after #229:
conflicts were the advertised test count only; resolved to main's side
(preserving the #229 test_statement_coverage80 flip), re-collected on the
merged tree (6199), doc-claims gate OK. Changed test files 67 passed,
invariants 52 passed, ruff check + format clean repo-wide.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
cdeust added a commit that referenced this pull request Jul 28, 2026
… or silent_failure-observable (#197) (#230)

Squash-resolution of feat/warnings-strict-197-ble onto main after #229:
conflicts were the advertised test count only; resolved to main's side
(preserving the #229 test_statement_coverage80 flip), re-collected on the
merged tree (6199), doc-claims gate OK. Changed test files 67 passed,
invariants 52 passed, ruff check + format clean repo-wide.

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Statement coverage to >=80%: finish the unwired modules, then hold the floor

1 participant