Skip to content

Feat/verification import cycle detection#198

Open
shrutu0929 wants to merge 4 commits into
Refactron-ai:mainfrom
shrutu0929:feat/verification-import-cycle-detection
Open

Feat/verification import cycle detection#198
shrutu0929 wants to merge 4 commits into
Refactron-ai:mainfrom
shrutu0929:feat/verification-import-cycle-detection

Conversation

@shrutu0929
Copy link
Copy Markdown

solve #191
This change implements Step 4 of ImportIntegrityVerifier — project-wide import-cycle detection — completing a long-deferred TODO. Previously a transform could introduce a circular import that still passed the syntax and resolvability checks yet broke at runtime, which undermined confidence in autofix and --verify. ImportIntegrityVerifier now accepts a project_root and builds a bounded, project-wide import graph; on each transform it diffs the changed module's import edges and reports any cycle the transform introduces —pre-existing cycles are deliberately left alone — with a clear blocking_reason such as pkg.a -> pkg.b -> pkg.a. Both absolute and relative imports are resolved, and only first-party modules become graph edges so stdlib and third-party imports are ignored. Several guardrails keep the check cheap and safe: a 2000-file scan cap, a 5-second time budget, a per-instance graph cache, and skip-lists for vendored directories such as venv and pycache; whenever a limit is hit or no project_root is supplied, cycle detection is silently skipped rather than blocking a transform, and the outcome is recorded in details["cycle_check"]. Complexity limits are documented in the class docstring, and new unit tests using minimal fake packages confirm that an introduced cycle is blocked with a clear reason, a non-cyclic transform passes, a pre-existing cycle is not blocked, and the check degrades gracefully when project_root is missing or the file lies outside it. The commit also carries two earlier verification improvements: machine-readable JSON output (to_json_dict() helpers, a format_verification_result_json() formatter, and a refactron verify CLI command with --json), and an optional run-all mode (short_circuit flag plus an --all-checks CLI flag) that runs the full check pipeline so every failure category surfaces in a single run.

shrutu0929 and others added 3 commits April 7, 2026 18:31
TestSuiteGate.verify ran pytest via a hard-coded python3 interpreter
with cwd set to file_path.parent. For nested files this misses the
repo's pyproject.toml / pytest.ini / conftest.py and may use a
different interpreter/venv than the host process, causing false
positives or undiscovered tests and CI-vs-local mismatch.

- Run pytest via sys.executable instead of python3.
- Set cwd to the resolved project root (project_root or file dir).
- Prepend the project root to PYTHONPATH for layouts that rely on it.
- Add tests asserting the interpreter, cwd, and PYTHONPATH.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Implement Step 4 of ImportIntegrityVerifier, completing the deferred
cycle-detection TODO, alongside two earlier verification improvements.

Import cycle detection: transforms could previously introduce circular
imports that pass syntax and resolvability checks yet break at runtime.
ImportIntegrityVerifier now accepts a project_root and builds a bounded
project-wide import graph; on a transform it diffs the changed module's
import edges and reports cycles the transform introduces (pre-existing
cycles are left untouched) with a clear blocking_reason such as
"pkg.a -> pkg.b -> pkg.a". Both absolute and relative imports are
handled; only first-party modules become graph edges. Guardrails keep
it cheap: a 2000-file cap, a 5s time budget, a per-instance graph
cache, and skip-lists for vendored directories; when any limit is hit
or no project_root is given, the check is skipped rather than blocking.
Complexity limits are documented in the class docstring.

Also included: machine-readable JSON verification output via
to_json_dict() helpers, a format_verification_result_json() formatter,
and a `refactron verify` CLI command with --json; and an optional
run-all mode (short_circuit flag plus --all-checks) that runs the full
check pipeline so every failure category surfaces in a single run.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 16, 2026

Warning

Rate limit exceeded

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

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ 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: 690774b7-8679-4f02-b3b1-9fb5ce09905e

📥 Commits

Reviewing files that changed from the base of the PR and between 2f04295 and 5d407c3.

📒 Files selected for processing (11)
  • refactron/cli/main.py
  • refactron/cli/verify.py
  • refactron/verification/checks/imports.py
  • refactron/verification/checks/test_gate.py
  • refactron/verification/engine.py
  • refactron/verification/report.py
  • refactron/verification/result.py
  • tests/test_import_verifier.py
  • tests/test_test_gate.py
  • tests/test_verification_engine.py
  • tests/test_verification_result.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

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