Repository navigation
feat(devtools): audit testmon blind spots - #3787
Conversation
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.
|
Warning Review limit reached
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 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 configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughAdds ChangesTestmon blind-spot audit
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
Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (4)
devtools/command_catalog.pydevtools/testmon_blind_spot_audit.pydocs/devtools.mdtests/unit/devtools/test_testmon_blind_spot_audit.py
| 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) |
There was a problem hiding this comment.
🎯 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.
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.
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.py4 passedPOLYLOGUE_PYTEST_WORKERS=1 direnv exec . devtools verify --quickPOLYLOGUE_PYTEST_WORKERS=1 direnv exec . devtools lab testmon-blind-spots --inner-helpRef polylogue-vyxq
Summary by CodeRabbit
New Features
testmon-blind-spotsverification-lab command to identify coverage and test-selection gaps.Documentation
Tests