Skip to content

feat(devtools): audit testmon blind spots - #3787

Merged
Sinity merged 3 commits into
masterfrom
feature/test/testmon-blind-spot-audit
Aug 5, 2026
Merged

Sinity merged 3 commits into
masterfrom
feature/test/testmon-blind-spot-audit

Conversation

@Sinity

@Sinity Sinity commented Aug 5, 2026 •

Copy link
Copy Markdown
Owner

Summary

Add an on-demand audit that compares existing coverage metadata with pytest-testmon fingerprints and distinguishes declaration-only modules from executable blind spots.

Problem

Affected-test selection can miss coverage-known executable files that are absent from testmon's dependency graph. Existing readiness checks did not expose that gap without regenerating coverage.

Solution

Add devtools lab testmon-blind-spots, a read-only coverage/testmon audit backed by AST classification. It reports declaration-only misses separately and exits nonzero for unfingerprinted executable validators.

Verification

  • POLYLOGUE_PYTEST_WORKERS=1 direnv exec . devtools test tests/unit/devtools/test_testmon_blind_spot_audit.py
    • 4 passed
  • POLYLOGUE_PYTEST_WORKERS=1 direnv exec . devtools verify --quick
    • all quick verification steps passed
  • POLYLOGUE_PYTEST_WORKERS=1 direnv exec . devtools lab testmon-blind-spots --inner-help
    • command surface resolved

Ref polylogue-vyxq

Summary by CodeRabbit

  • New Features

    • Added a testmon-blind-spots verification-lab command to identify coverage and test-selection gaps.
    • Supports human-readable and JSON reports without running tests or modifying existing coverage data.
    • Highlights unreadable, untracked, and potentially risky source files.
  • Documentation

    • Added command usage guidance and examples to the developer tools reference.
  • Tests

    • Added validation for source classification, stale coverage data, risk reporting, and read-only behavior.

Problem: coverage metadata can name executable validation code that has no file fingerprint in pytest-testmon, while declaration-only modules create harmless noise.\n\nWhat changed: add an on-demand lab audit that reads existing coverage JSON and testmon SQLite metadata, classifies source ASTs conservatively, reports declaration-only gaps separately, and returns a failing status for unfingerprinted executable code. Add synthetic fixtures, a mutation-proof test, command catalog wiring, and generated docs. The audit never runs pytest or regenerates coverage.\n\nCompatibility/migration: no verify-path or schema changes.
@coderabbitai

coderabbitai Bot commented Aug 5, 2026 •

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@Sinity, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 22 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 039a70c1-4cf9-42cc-b445-1b2520b2e899

📥 Commits

Reviewing files that changed from the base of the PR and between 8257ff9 and ba6bc68.

📒 Files selected for processing (2)
  • devtools/testmon_blind_spot_audit.py
  • tests/unit/devtools/test_testmon_blind_spot_audit.py
📝 Walkthrough

Walkthrough

Adds lab testmon-blind-spots, a read-only audit that compares coverage.py JSON metadata with pytest-testmon fingerprints. It classifies source files, reports executable blind spots, supports JSON or text output, and returns a risk-based exit code.

Changes

Testmon blind-spot audit

Layer / File(s) Summary
Audit inputs and risk classification
devtools/testmon_blind_spot_audit.py
Adds structured report models, coverage and testmon readers, AST-based executable-code classification, and blind-spot aggregation.
CLI behavior and validation
devtools/testmon_blind_spot_audit.py, tests/unit/devtools/test_testmon_blind_spot_audit.py
Adds configurable CLI output and paths. Tests validate classifications, mutation handling, risk exit codes, and unchanged inputs.
Command registration and reference
devtools/command_catalog.py, docs/devtools.md
Registers lab testmon-blind-spots and documents its audit behavior and usage examples.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant CLI
  participant MetadataReaders
  participant BlindSpotAudit
  CLI->>MetadataReaders: Read coverage JSON and testmon SQLite fingerprints
  MetadataReaders-->>CLI: Return normalized metadata
  CLI->>BlindSpotAudit: Compare files and classify source code
  BlindSpotAudit-->>CLI: Return findings and risk counts
  CLI-->>CLI: Render output and set exit code
Loading

Possibly related PRs

  • Sinity/polylogue#701: Adds related verification tooling and command-catalog support for coverage and test-quality gap auditing.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the addition of a developer tool that audits testmon blind spots.
Description check ✅ Passed The description covers the Summary, Problem, Solution, and Verification sections with relevant implementation details and exact validation commands.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ 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/testmon-blind-spot-audit

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 `@devtools/testmon_blind_spot_audit.py`:
- Around line 157-164: Update the executable-declaration classification around
the FunctionDef, AsyncFunctionDef, and ClassDef handling to treat evaluated
function defaults, keyword defaults, class bases, and class keyword arguments as
executable before falling back to body analysis. Preserve decorator checks and
inert-body behavior when no evaluated declaration expressions exist, and add
regression fixtures covering both function and class forms.
- Around line 216-224: Update classify_source_ast and the surrounding audit
logic to return a distinct unreadable result when reading a regular source file
raises OSError, then prioritize the existing readable check or that result
before the fingerprinted branch so unreadable files remain unsafe. Add a test
covering a fingerprinted source whose read fails, asserting status
source-unreadable, safe=False, and exit code 1.
🪄 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: ASSERTIVE

Plan: Pro Plus

Run ID: ee655a67-4a17-4e03-bc7c-9689064668ea

📥 Commits

Reviewing files that changed from the base of the PR and between 1f479ab and 8257ff9.

📒 Files selected for processing (4)
  • devtools/command_catalog.py
  • devtools/testmon_blind_spot_audit.py
  • docs/devtools.md
  • tests/unit/devtools/test_testmon_blind_spot_audit.py

Comment on lines +157 to +164
if isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef)):
if node.decorator_list:
return True
return _body_is_executable(node.body)
if isinstance(node, ast.ClassDef):
if node.decorator_list:
return True
return _body_is_executable(node.body)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Classify evaluated declarations as executable.

Function defaults and class bases execute while Python creates the declaration. For example, def marker(value=load_validator()): ... and class Marker(make_base()): ... can run code, but this classifier reports them as declaration-only when their bodies are inert. An unfingerprinted file can then be marked safe and the audit can exit successfully.

Check function defaults and keyword defaults, plus class bases and keyword arguments, before checking the body. Add regression fixtures for both forms.

Proposed fix
 if isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef)):
     if node.decorator_list:
         return True
+    if any(_expression_is_runtime(default) for default in node.args.defaults):
+        return True
+    if any(
+        default is not None and _expression_is_runtime(default)
+        for default in node.args.kw_defaults
+    ):
+        return True
     return _body_is_executable(node.body)
 if isinstance(node, ast.ClassDef):
     if node.decorator_list:
         return True
+    if any(_expression_is_runtime(base) for base in node.bases):
+        return True
+    if any(_expression_is_runtime(keyword.value) for keyword in node.keywords):
+        return True
     return _body_is_executable(node.body)
🤖 Prompt for 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.

In `@devtools/testmon_blind_spot_audit.py` around lines 157 - 164, Update the
executable-declaration classification around the FunctionDef, AsyncFunctionDef,
and ClassDef handling to treat evaluated function defaults, keyword defaults,
class bases, and class keyword arguments as executable before falling back to
body analysis. Preserve decorator checks and inert-body behavior when no
evaluated declaration expressions exist, and add regression fixtures covering
both function and class forms.

Comment thread devtools/testmon_blind_spot_audit.py Resolved
Sinity added 2 commits August 5, 2026 04:48
Problem: declaration headers with evaluated defaults or class arguments were treated as inert, and a source read OSError could be masked by an existing testmon fingerprint.\n\nWhat changed: classify function defaults, keyword defaults, class bases, and class keyword arguments as executable declarations. Return source-unreadable for read failures and keep that result unsafe before fingerprint classification. Add direct regressions for both behaviors.\n\nCompatibility/migration: no external interface or schema changes.
Problem: the synthetic Path.read_text replacement forwarded untyped positional and keyword arguments, which strict mypy rejected.\n\nWhat changed: use the concrete encoding and errors parameters accepted by Path.read_text and forward them by name.\n\nCompatibility/migration: test-only type correction.
@Sinity
Sinity merged commit 3b88c91 into master Aug 5, 2026
3 checks passed
@Sinity
Sinity deleted the feature/test/testmon-blind-spot-audit branch August 5, 2026 03:20
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.

1 participant