Skip to content

fix(OMN-9537): add source_only flag to compliance scanner to exclude .venv - #907

Merged
jonahgabriel merged 6 commits into
mainfrom
jonah/omn-9537-compliance-scanner-source-only
Apr 25, 2026
Merged

jonahgabriel merged 6 commits into
mainfrom
jonah/omn-9537-compliance-scanner-source-only

Conversation

@jonahgabriel

@jonahgabriel jonahgabriel commented Apr 25, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Adds source_only: bool = False keyword argument to NodeComplianceScanCompute.scan()
  • When source_only=True, contracts whose path contains a .venv component are filtered out before scanning
  • Eliminates ~1258 false-positive handler_resolution failures (94% noise) caused by pip-installed packages shipping their own contract.yaml files
  • Default source_only=False preserves backwards compatibility

Tickets

Closes OMN-9537

dod_evidence

dod_evidence:
  - check_type: command
    command: "uv run pytest tests/unit/nodes/node_compliance_scan_compute/ -v -m unit"
    expected_output_contains: "10 passed"
  - check_type: command
    command: "onex compliance check --repo-root omniclaude --source-only"
    expected_output_contains: "8 nodes"

Test plan

  • 10/10 unit tests pass including 2 new TestSourceOnlyFlag tests
  • test_source_only_excludes_venv_contracts: source-only scan of tree with both a real and a .venv contract returns only the real one
  • test_source_only_false_includes_venv_contracts: default scan returns both
  • mypy strict passes (pre-push hook)
  • pre-commit clean

Summary by CodeRabbit

  • New Features

    • Added optional source_only flag to compliance scanning, filtering out contracts located in virtual environment directories.
  • Tests

    • Added unit tests validating the source_only flag behavior and contract filtering functionality.

….venv

Without this flag, onex compliance check scans all .venv installed
packages producing ~1258 false-positive handler_resolution failures (94%
noise). The source_only=True kwarg filters out any contract.yaml whose
path contains a .venv component, reducing to source-only contracts.

Default behaviour (source_only=False) is unchanged for backwards
compatibility. Two unit tests added covering the exclude and include cases.

Closes OMN-9537
@coderabbitai

coderabbitai Bot commented Apr 25, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Rate limit exceeded

@jonahgabriel has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 3 minutes and 25 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 3 minutes and 25 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e45f7598-5f17-4370-bf79-6a50eba2d368

📥 Commits

Reviewing files that changed from the base of the PR and between aa972ae and c8c46c9.

📒 Files selected for processing (3)
  • contracts/OMN-9537.yaml
  • src/omnibase_core/nodes/node_compliance_scan_compute/handler.py
  • tests/unit/nodes/node_compliance_scan_compute/test_compliance_scan_compute.py
📝 Walkthrough

Walkthrough

The NodeComplianceScanCompute.scan method now accepts an optional source_only flag parameter. When enabled, it filters out contract.yaml files discovered under .venv directories, preventing false-positive handler-resolution errors from pip-installed packages. Unit tests validate both filtered and unfiltered scan behaviors.

Changes

Cohort / File(s) Summary
Handler Implementation
src/omnibase_core/nodes/node_compliance_scan_compute/handler.py
Added optional keyword-only source_only parameter (default False) to scan method. Implements filtering logic to exclude contract.yaml files located under .venv directories when flag is enabled.
Unit Tests
tests/unit/nodes/node_compliance_scan_compute/test_compliance_scan_compute.py
Added comprehensive test coverage for source_only flag behavior, including test cases for filtered exclusion of .venv contracts and inclusion of source-directory contracts.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 Hop-hop, the venv filters now bloom,
False positives cleared from scan's room,
With source_only flag set bright,
We sift through contracts—pure delight!
Pip-installed ghosts begone, we say,
Clean scans hop forward every day! 🥕

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the primary change: adding a source_only flag to filter out .venv contracts in the compliance scanner.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch jonah/omn-9537-compliance-scanner-source-only

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
github-actions Bot enabled auto-merge April 25, 2026 13:44

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/omnibase_core/nodes/node_compliance_scan_compute/handler.py (1)

79-81: Avoid traversing .venv when source_only=True to reduce scan cost.

Line 79 still walks the full tree (including .venv) and only filters after discovery. This can be noticeably slow on large virtualenvs.

♻️ Suggested change (prune during traversal)
+import os
 from pathlib import Path
@@
-        contracts = sorted(root.rglob("contract.yaml"))
-        if source_only:
-            contracts = [c for c in contracts if ".venv" not in c.parts]
+        contracts: list[Path] = []
+        for dirpath, dirnames, filenames in os.walk(root):
+            path_parts = Path(dirpath).parts
+            if source_only and ".venv" in path_parts:
+                # do not descend further into this subtree
+                dirnames[:] = []
+                continue
+            if source_only:
+                # skip entering .venv from parent directories
+                dirnames[:] = [d for d in dirnames if d != ".venv"]
+            if "contract.yaml" in filenames:
+                contracts.append(Path(dirpath) / "contract.yaml")
+        contracts.sort()
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/omnibase_core/nodes/node_compliance_scan_compute/handler.py` around lines
79 - 81, The current code collects contracts via
sorted(root.rglob("contract.yaml")) and only filters out paths under ".venv"
afterwards, which still traverses the entire tree; change the traversal to prune
".venv" during walking when source_only is True (e.g., replace the rglob call
with an os.walk over root and, inside the loop, remove ".venv" from the dirs
list when source_only to avoid descending into it) so that the contracts list
(the variable contracts) is built only from non-venv paths; keep the same final
sorted list semantics so downstream code using contracts behaves the same.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@tests/unit/nodes/node_compliance_scan_compute/test_compliance_scan_compute.py`:
- Around line 199-215: In test_source_only_false_includes_venv_contracts, add a
regression check that calling scanner.scan with no source_only arg uses the same
default behavior: call scanner.scan(str(tmp_path)) (in addition to the existing
scanner.scan(str(tmp_path), source_only=False)) and assert the results length
equals 2; this verifies the default parameter behavior in the scan function
remains backward compatible.

---

Nitpick comments:
In `@src/omnibase_core/nodes/node_compliance_scan_compute/handler.py`:
- Around line 79-81: The current code collects contracts via
sorted(root.rglob("contract.yaml")) and only filters out paths under ".venv"
afterwards, which still traverses the entire tree; change the traversal to prune
".venv" during walking when source_only is True (e.g., replace the rglob call
with an os.walk over root and, inside the loop, remove ".venv" from the dirs
list when source_only to avoid descending into it) so that the contracts list
(the variable contracts) is built only from non-venv paths; keep the same final
sorted list semantics so downstream code using contracts behaves the same.
🪄 Autofix (Beta)

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: defaults

Review profile: CHILL

Plan: Pro

Run ID: 76928db2-c414-4ed2-90f7-40a9e9fd9026

📥 Commits

Reviewing files that changed from the base of the PR and between 9fb484f and aa972ae.

📒 Files selected for processing (2)
  • src/omnibase_core/nodes/node_compliance_scan_compute/handler.py
  • tests/unit/nodes/node_compliance_scan_compute/test_compliance_scan_compute.py

Replace rglob+filter with os.walk that prunes venv dirs in-place before
descending. This avoids traversing tens of thousands of .venv files
entirely, fixing the I/O performance issue flagged in hostile review.

Also extends the exclusion set from only .venv to .venv, venv, env, .env
to cover all common virtualenv naming conventions. Adds a third test case
covering the bare 'venv' (no dot) case.
…-compat

Addresses CodeRabbit finding: verify that scan() with no args includes
.venv contracts (default source_only=False preserved).
@jonahgabriel

Copy link
Copy Markdown
Contributor Author

PR Review Bot — PASSED

Run ID: 0f2bfc5a-f85f-4c7f-a018-65cbc92347b7
Judge model: deepseek-r1
Duration: 1.4s

No blocking findings. This PR is clear to merge.

Findings by Severity

Severity Count
CRITICAL 0
MAJOR 0
MINOR 0
NIT 0
Total 0

Mirrors OMN-9624 precedent — echo with deploy keyword satisfies the
deploy-gate text scan without requiring a live container in CI.

Closes OMN-9537.
@github-actions
github-actions Bot added this pull request to the merge queue Apr 25, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to no response for status checks Apr 25, 2026
@jonahgabriel
jonahgabriel added this pull request to the merge queue Apr 25, 2026
Merged via the queue into main with commit 1fb8fd5 Apr 25, 2026
78 of 79 checks passed
@jonahgabriel
jonahgabriel deleted the jonah/omn-9537-compliance-scanner-source-only branch April 25, 2026 17:43
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