Skip to content

refactor(diffguard-core): split run_check into SRP submodules#1614

Draft
EffortlessSteven wants to merge 1 commit into
mainfrom
claude/refactor-srp-modules-jBB1a
Draft

refactor(diffguard-core): split run_check into SRP submodules#1614
EffortlessSteven wants to merge 1 commit into
mainfrom
claude/refactor-srp-modules-jBB1a

Conversation

@EffortlessSteven
Copy link
Copy Markdown
Member

Summary

run_check in diffguard-core/src/check.rs was a 165-line function doing seven distinct things: diff parsing & filtering, rule tag filtering, evaluation dispatch, false-positive filtering, verdict computation, receipt assembly, and output rendering. Promote check.rs to a check/ module directory and extract each concern into its own SRP submodule:

Submodule Single responsibility
diff_prep Parse the unified diff, apply path globs + allowed-lines + dedup
rule_filter Tag-based rule selection (only_tags / enable_tags / disable_tags)
false_positive Fingerprint-based filtering + per-rule analytics tallies
verdict Verdict status + exit code from counts
annotations GitHub Actions annotation rendering
rule_hits Map domain stats → core stats, apply FP adjustments
path_filter Glob compilation + PathFilterError

run_check now reads as a 7-step pipeline. The orchestrator went from ~165 lines of intermixed logic to ~85 lines that call each step by name.

Public API

Unchanged. CheckPlan, CheckRun, RuleHitStat, PathFilterError, and run_check are still re-exported from diffguard_core at the same paths. sensor_api.rs continues to import crate::check::{CheckPlan, run_check}; the CLI and LSP need no edits.

Snapshots

diffguard_core__check__tests__snapshot_*.snap files moved from src/snapshots/ to src/check/snapshots/ to match insta's source-relative discovery (file bodies byte-identical, only source: header path updated).

Tests

  • Tag-filter tests moved next to rule_filter
  • Exit-code tests moved next to verdict (plus three new tests covering compute_verdict_status directly)
  • Annotations proptest moved next to annotations
  • The run_check-level integration tests and the two existing snapshot tests stay in check/mod.rs so snapshot file names remain stable

Test plan

  • cargo build -p diffguard-core — clean
  • cargo test -p diffguard-core — 144 lib + all integration tests pass (3 added verdict tests)
  • cargo test --workspace — all green except 26 pre-existing diffguard --bin failures unrelated to this change (sandbox can't run git commit; reproduces on main worktree)
  • cargo clippy --workspace --all-targets -- -D warnings — clean
  • cargo fmt --check — clean

Generated by Claude Code

The 165-line run_check function in check.rs did seven distinct things in
one body. Promote check.rs to a check/ module directory and extract each
concern into its own submodule:

- diff_prep      — parse, path-filter, allowed-line filter, dedup
- rule_filter    — tag-based rule selection (only/enable/disable)
- false_positive — fingerprint filtering + per-rule analytics tallies
- verdict        — status + exit code from counts
- annotations    — GitHub Actions annotation rendering
- rule_hits      — domain stats → core stats, with FP adjustments
- path_filter    — glob compilation + PathFilterError

run_check now reads as a 7-step pipeline. The public surface
(CheckPlan, CheckRun, RuleHitStat, PathFilterError, run_check) is
unchanged; sensor_api, the CLI, and the LSP keep working without
edits. Snapshot files relocated to check/snapshots/ to match insta's
source-relative discovery; their bodies are byte-identical.

Tests co-locate with the code they cover: tag-filter tests under
rule_filter, exit-code tests under verdict, the annotations proptest
under annotations. The run_check-level integration tests and snapshot
tests stay in check/mod.rs so snapshot file names remain stable.
@gemini-code-assist
Copy link
Copy Markdown

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 16, 2026

Warning

Rate limit exceeded

@EffortlessSteven has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 30 minutes and 59 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: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: db85ba86-d0e0-4b03-bc33-b04f159d0990

📥 Commits

Reviewing files that changed from the base of the PR and between 8296c64 and 5bf279e.

⛔ Files ignored due to path filters (2)
  • crates/diffguard-core/src/check/snapshots/diffguard_core__check__tests__snapshot_annotations_with_multiple_severities.snap is excluded by !**/*.snap
  • crates/diffguard-core/src/check/snapshots/diffguard_core__check__tests__snapshot_json_receipt_pretty.snap is excluded by !**/*.snap
📒 Files selected for processing (8)
  • crates/diffguard-core/src/check/annotations.rs
  • crates/diffguard-core/src/check/diff_prep.rs
  • crates/diffguard-core/src/check/false_positive.rs
  • crates/diffguard-core/src/check/mod.rs
  • crates/diffguard-core/src/check/path_filter.rs
  • crates/diffguard-core/src/check/rule_filter.rs
  • crates/diffguard-core/src/check/rule_hits.rs
  • crates/diffguard-core/src/check/verdict.rs
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/refactor-srp-modules-jBB1a

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.

2 participants