Skip to content

test(coverage): closure matrix YAML + lint (#1186) - #1191

Merged
Sinity merged 1 commit into
masterfrom
feature/test/closure-matrix-1186
May 17, 2026
Merged

Sinity merged 1 commit into
masterfrom
feature/test/closure-matrix-1186

Conversation

@Sinity

@Sinity Sinity commented May 17, 2026 •

Copy link
Copy Markdown
Owner

Summary

Adds docs/plans/test-closure-matrix.yaml as the executable per-domain test-closure matrix the #997 close-out promised, plus a new devtools verify-closure-matrix lint that fails when reality drifts from the manifest. Wired into devtools verify so closure-matrix drift fails locally before a PR is opened.

Problem

#997 left the closure matrix as a known follow-up: the existing docs/plans/test-coverage-domains.yaml documents qualitative coverage notes but is not consumed by any verification gate, and it does not carry the four-column closure shape (target files × representative tests × gate × known gaps) the AC asked for. #1186 tracks the missing artifact and lint.

Solution

  • docs/plans/test-closure-matrix.yaml — 31 rows covering the substrate, derived read models, surfaces, and verification rings. Each row carries:
    • domain (stable dotted identifier, e.g. storage.blob_store, sources.parsers.codex)
    • target_files (production paths under polylogue/, file or directory form)
    • representative_tests (test file paths or path::Class::test nodeids)
    • gate ∈ required / optional / absent
    • known_gaps (free-text bullets; required for absent rows)
    • explicit deprecated_pointer back-reference so test-coverage-domains.yaml stays as the free-text companion catalog.
  • devtools/verify_closure_matrix.py — new lint that checks every declared path exists on disk, gate is one of the legal values, absent rows carry at least one known_gaps bullet, required/optional rows list at least one representative test, and domain values are unique. Outputs human/JSON forms in the same shape as devtools verify-file-budgets.
  • devtools/command_catalog.py — registers verify-closure-matrix under the verification category so devtools --list-commands, the help surfaces, and the rendered devtools reference all pick it up.
  • devtools/verify.py — adds verify-closure-matrix to the default build_verify_steps() chain (runs in both devtools verify and devtools verify --quick).
  • devtools/render_quality_reference.py — generates a new "Closure Matrix" section in docs/test-quality-workflows.md explaining the schema, the gate semantics, and the lint behavior so future test additions update the matrix.
  • tests/unit/devtools/test_verify_closure_matrix.py — 8 cases: committed matrix passes, missing target/test paths fail, gate validation, absent-without-gaps fails, required-without-tests fails, duplicate domains fail, and pytest nodeid form is accepted.

Pattern follows the existing manifest+lint pairs (verify-file-budgets, verify-test-ownership, verify-topology) per the §10 evidence-driven structural specifications pattern; the matrix is the executable backstop for the qualitative test-coverage-domains.yaml.

The eight domains called out in the #997 close-out (codex events, browser capture, site/rendering, blob store, CLI insights, auth, schema migration, Claude-AI/Gemini parsers) are all present as dedicated rows with their representative tests and any remaining gaps spelled out.

Verification

$ python -m devtools verify_closure_matrix
closure-matrix: clean (31 domains)
blocking=False

$ pytest tests/unit/devtools/test_verify_closure_matrix.py -q
8 passed in 10.86s

$ python -m devtools verify --quick
... exit_code: 0

Closes #1186

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Added a test-closure matrix to systematically document test coverage across repository domains.
    • Introduced a verification command to validate that test coverage documentation remains accurate and grounded in the codebase.
  • Documentation

    • Updated devtools documentation with the new verification command.
    • Added workflow guidance for maintaining test coverage documentation when test representatives change.
  • Tests

    • Added comprehensive test coverage for the new verification functionality.

Review Change Stack

Add docs/plans/test-closure-matrix.yaml as the executable per-domain
test-closure matrix (rows of domain × target_files × representative_tests ×
gate × known_gaps) plus the devtools verify-closure-matrix lint that fails
when declared paths drift from the realized tree.

The lint is wired into devtools verify under the §10 manifest+lint pattern
so closure-matrix drift fails locally before a PR is opened. The legacy
qualitative catalog at docs/plans/test-coverage-domains.yaml is retained as
free-text notes and pointed back to from the new matrix.

Closes #1186

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@Sinity
Sinity merged commit dd059e0 into master May 17, 2026
2 of 3 checks passed
@Sinity
Sinity deleted the feature/test/closure-matrix-1186 branch May 17, 2026 17:18
@coderabbitai

coderabbitai Bot commented May 17, 2026 •

Copy link
Copy Markdown

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: b2c4a7ff-eb7b-4fa9-a60c-d0386c23327e

📥 Commits

Reviewing files that changed from the base of the PR and between 5254179 and 1d0f53e.

📒 Files selected for processing (9)
  • AGENTS.md
  • devtools/command_catalog.py
  • devtools/render_quality_reference.py
  • devtools/verify.py
  • devtools/verify_closure_matrix.py
  • docs/devtools.md
  • docs/plans/test-closure-matrix.yaml
  • docs/test-quality-workflows.md
  • tests/unit/devtools/test_verify_closure_matrix.py

📝 Walkthrough

Walkthrough

This PR delivers the test-closure matrix as a tracked artifact. A new YAML file documents per-domain coverage mappings (target files, representative tests, gate classification, and known gaps), a new devtools verify-closure-matrix command validates the matrix against the repository tree, and the command is wired into the standard devtools verify pre-push checks. Quality workflows and devtools documentation are updated to reference the matrix.

Changes

Test Closure Matrix Definition and Verification

Layer / File(s) Summary
Closure Matrix Specification and Workflow Documentation
docs/plans/test-closure-matrix.yaml, docs/test-quality-workflows.md
docs/plans/test-closure-matrix.yaml defines the per-domain matrix with rows mapping domain, target_files, representative_tests, and gate (required/optional/absent), plus optional known_gaps. Covers substrate (parsers, storage, pipeline), schema, surface (CLI, API, MCP), and ops domains. docs/test-quality-workflows.md documents the closure matrix structure and adds workflow guidance to update it when tests change.
Closure Matrix Verifier Implementation and Tests
devtools/verify_closure_matrix.py, tests/unit/devtools/test_verify_closure_matrix.py
New verify_closure_matrix.py module loads and validates the matrix: checks domain uniqueness, confirms target files and representative test paths exist in the tree, enforces gate-specific constraints (e.g., absent requires known_gaps), and outputs JSON or human-readable diagnostics. Test suite validates clean matrix, missing paths, invalid gates, duplicate domains, and pytest nodeid acceptance.
Devtools Integration and Documentation
devtools/command_catalog.py, devtools/verify.py, devtools/render_quality_reference.py, docs/devtools.md, AGENTS.md
Registers verify-closure-matrix in the devtools command catalog with description and examples. Adds the command as a verification step in build_verify_steps() for non-commit tiers. Updates generated quality reference and devtools documentation to describe the closure-matrix validation concept and command.

Sequence Diagram

sequenceDiagram
    participant Developer
    participant CLI as devtools verify
    participant Verifier as verify-closure-matrix
    participant Matrix as test-closure-matrix.yaml
    participant Tree as Repository Tree

    Developer->>CLI: devtools verify --quick
    CLI->>Verifier: spawn verify-closure-matrix step
    Verifier->>Matrix: load YAML
    Matrix-->>Verifier: matrix rows
    loop Validate each row
        Verifier->>Tree: confirm domain target_files exist
        Tree-->>Verifier: file/dir status
        Verifier->>Tree: confirm representative_tests path exist
        Tree-->>Verifier: file status
        Verifier->>Verifier: check gate constraints (known_gaps, required tests)
    end
    Verifier->>CLI: report blocking=true/false + error count
    CLI->>Developer: exit 0 (clean) or 1 (blocking)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • Sinity/polylogue#450: Both PRs extend devtools/verify.py's build_verify_steps() by appending a new verification gate to the suite (verify-closure-matrix vs. verify-test-ownership).
  • Sinity/polylogue#438: Both PRs add new devtools verification commands by extending devtools/command_catalog.py and wiring them into devtools/verify.py's verification pipeline (verify-closure-matrix vs. verify-topology/cohesion).
  • Sinity/polylogue#1073: Both PRs modify the verification-step logic in devtools/verify.py's build_verify_steps() to adjust which gates are enabled and under what conditions (main adds verify-closure-matrix for non-commit tiers; retrieved changes tier classification).

Poem

🐰 A rabbit hops through closure rows,
Each domain mapped to tests that grow.
The matrix grounded, gates align—
No stale paths in this verified design!
Coverage tales now truly shine. ✨

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/test/closure-matrix-1186

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.

Sinity added a commit that referenced this pull request May 17, 2026
## Summary

The `devtools` CLI shell wrapper required `POLYLOGUE_REPO_ROOT` and
dispatched against it unconditionally. The devshell exports that
variable once at entry and it is then inherited by every subshell —
including ones cd'd into a worktree — so `devtools verify --quick` run
from a worktree silently validated the *main checkout*. This PR makes
the wrapper worktree-aware and audits the other CLI wrappers
(`polylogue`, `polylogued`, `polylogue-mcp`) for the same anti-pattern.

## Problem

- Observed during PR #1191 implementation, filed as #1193: agent ran
`devtools verify --quick` from an isolated worktree, got false-positive
green, and the pre-push hook (which also calls `devtools verify
--quick`) had the same blind spot.
- #1209 is the audit companion: ensure no installed wrapper in this
flake bakes a developer-specific path or inherits the wrong root from
env.

## Solution

- Move the wrapper body to `nix/devtools-wrapper.sh` so the same shell
script is read into the Nix `writeShellScriptBin` (via
`builtins.readFile`) and exercised by unit tests directly — no Nix build
required for the regression test.
- New resolution order in the wrapper:
1. `git rev-parse --show-toplevel` from the caller's cwd, validated by
the presence of `devtools/__main__.py`. This is the normal path and
makes the wrapper worktree-aware.
2. `POLYLOGUE_REPO_ROOT`, only when set and pointing at a real checkout.
Documented fallback for tarball / non-git extraction cases.
  3. Loud error otherwise. No silent dispatch to a stale or wrong path.
- Audit of the other wrappers:
- `polylogue`, `polylogued`, `polylogue-mcp` are Python console-script
entry points (`[project.scripts]` in `pyproject.toml`) — no path baking,
they import the installed package.
- `flake.nix` `postFixup` wraps them with `wrapProgram` that only scrubs
PYTHON* env vars — no path pin.
- `nix/module.nix` (NixOS module) sets only `POLYLOGUE_CONFIG`; no
checkout path.
- No `/realm/project/polylogue` literal exists anywhere in `flake.nix`
or `nix/` (only in a docstring example and test fixtures, both unrelated
to the install surface).
- The static side of the audit is enforced by
`test_repo_wrapper_script_has_no_hardcoded_paths`, which keeps the
script free of `/realm/project/polylogue` and free of any
"POLYLOGUE_REPO_ROOT is not set" hard requirement.

The `POLYLOGUE_REPO_ROOT="$PWD"` export in the devshell `shellHook` is
retained because it still serves as the documented fallback for tooling
that wants an explicit hint; it is no longer load-bearing for `devtools`
worktree dispatch.

## Verification

```
$ python -m pytest tests/unit/devtools/test_cli_wrapper.py
6 passed in 8.41s

$ python -m devtools verify --quick
... "exit_code": 0
```

The new tests cover: cwd resolution, cwd-wins-over-env (the #1193
scenario), env-fallback outside git, invalid env-var ignored,
no-checkout error path, and the static no-hardcoded-paths guard.

Closes #1209
Closes #1193
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.

test(coverage): commit per-domain closure matrix as tracked artifact under docs/plans/

1 participant