Skip to content

Add run-to-run finding diff command and correlation engine - #93

Open
sheikhlimon wants to merge 3 commits into
prooflinedev:mainfrom
sheikhlimon-dev:feat/run-diff
Open

sheikhlimon wants to merge 3 commits into
prooflinedev:mainfrom
sheikhlimon-dev:feat/run-diff

Conversation

@sheikhlimon

Copy link
Copy Markdown

Problem

When reviewing pull requests across multiple pushes, developers currently see either individual review reports or aggregate finding counts. The CLI lacked a way to correlate findings between successive runs (e.g. Run 1 vs. Run 2) to answer:

  1. Which findings were resolved by the latest push?
  2. Which findings persisted from previous iterations?
  3. Which findings represent newly introduced or reintroduced regressions?

Additionally, CI jobs had no mechanism to gate strictly on fresh regressions introduced in a PR without being blocked by pre-existing technical debt or legacy findings.

Approach

  1. Pure Correlation Engine (src/outcome.rs):

    • Implemented diff_findings, which partitions findings between two runs into resolved, persistent, and regressions.
    • Multi-Pass Correlation & Invariant Ordering:
      • Pass 1A & 1B: Matches open target findings against open baseline findings using exact finding_fingerprint identity first, followed by composite fallback (risk_domain, claim, primary_path, start_line). Matching open findings first prevents resolved duplicates from consuming baseline matches and turning unchanged issues into false regressions.
      • Pass 2: Matches target RESOLVED findings against remaining open baseline findings. Unmatched resolved findings are omitted from the diff (treating them as historical resolutions from older runs).
    • Fallback Guard:
      • Enforces that fallback matching only applies when at least one finding lacks a fingerprint (curr.finding_fingerprint.is_none() || prev.finding_fingerprint.is_none()). Conflicting fingerprints are strictly never paired by location.
    • Lifecycle & Cardinality Semantics:
      • Tracks 1-to-1 matches with prev_matched so duplicate occurrences never double-consume.
      • Categorizes REINTRODUCED findings as regressions while marking the baseline counterpart as accounted for.
  2. Terminal & JSON Formatter (src/render.rs):

    • Added render::diff, which prints summary counts followed by severity-sorted sections (Regressions, Resolved, Persistent) with claim, location, impact, fix remediation, and ID.
    • Implemented Serialize on FindingDiff for full --json support.
  3. CLI Subcommand & Pagination (src/lib.rs, src/api.rs):

    • Added proofline diff:
      • Compares PR history: proofline diff --pr <NUM> (defaults to latest recorded run vs. immediate predecessor).
      • Explicit runs: proofline diff --pr <NUM> --base-run <N> --target-run <M>.
      • Direct review IDs: proofline diff --base-review <UUID> --target-review <UUID>.
      • Automatically resolves HEAD to the current PR in a local git checkout.
      • Added --fail-on-regression: exits with code 3 (Verdict::Regressed) on fresh regressions, exits with code 2 (Verdict::NotComplete) if either target or baseline review is incomplete/unfinished, and exits 0 when clean.
    • Added cursor pagination (history_page) with targeted loop termination, ensuring PRs with extensive review histories reliably resolve predecessors and explicit run IDs while filtering runs by repository UUID.

Proofline Self-Review & Evaluation

I installed the Proofline GitHub App on my fork repository and ran real review runs as I iterated on this branch (the review history and bot runs are recorded on sheikhlimon-dev/cli#1):

  1. Fallback Matching Invariant:
    In my initial fallback pass, I was pairing open findings that shared the same line and claim even when both had explicit, conflicting finding_fingerprints. That meant a new regression introduced on an existing line could get falsely labeled as "persistent" and slip past CI. Proofline caught this in Run 1, and I updated claim_fallback_match so fallback only engages when at least one side lacks a fingerprint (for older server revisions).

  2. Matching Priority & Duplicate Order:
    Iteration order caused duplicate issues. If a run had both a resolved duplicate and an open finding with the same fingerprint, processing the resolved one first consumed the baseline match, which turned the still-open finding into a false regression. Proofline identified this edge case, and I split matching into two sequential passes so open target findings always claim baseline matches first, leaving only leftover matches for resolved rows.

  3. CI Completion Guard:
    Proofline caught that running proofline diff --fail-on-regression against a queued or in-progress review would see an empty finding list and exit 0 before the scan finished. I added a status check to return Verdict::NotComplete (exit code 2) unless both the target and baseline reviews are completed.

  4. Pagination Bounds vs. Exhaustion:
    Proofline flagged that stopping after a fixed number of history pages could miss older requested runs. For explicit lookups (--base-run or --target-run), I updated the loop to continue following cursors until the requested runs are found or history is exhausted. For default lookups (latest vs predecessor), I bounded the search to 10 pages (SEARCH_PAGES = 10) to prevent unbounded sequential HTTP requests from hanging on busy PRs with dozens of automated pushes.

Verification & Results

  • Unit Tests (src/outcome.rs, src/render.rs):
    • Empty runs (0 -> 0), clean baseline regressions (0 -> 1), complete resolution (1 -> 0), mixed states, and identical runs.
    • Server version mismatches: Legacy un-fingerprinted findings correlating with upgraded fingerprinted findings.
    • Conflicting fingerprints: Verified fallback matcher refuses to pair distinct fingerprints sharing the same line.
    • Duplicate cardinality: Verified 1 prior and 2 current findings correctly categorizes the second as a regression.
    • Fingerprint precedence: Verified fingerprint match takes priority over fallback match when candidates conflict.
    • Reintroduced finding categorization against open baseline and omission of historical resolved findings.
  • End-to-End Integration Tests (tests/http.rs):
    • Added diff_categorizes_findings_and_honors_fail_on_regression using an in-process Axum mock server.
    • Verified text output, --json serialization with fingerprint assertions in resolved and regressions, --fail-on-regression exit code 3, explicit run selector overrides (--base-run 1 --target-run 2 and --base-run 1 --target-run 3), and direct review comparisons.
    • Verified exit code 0 when comparing regression-free runs, and exit code 2 when either review is incomplete.
  • Repository Verification:
    • cargo fmt --check: Clean.
    • cargo clippy --all-targets -- -D warnings: 0 warnings.
    • cargo test: 148 passed (71 unit, 41 http integration, 14 local patch, 5 mcp, 6 sarif, 10 scan, 1 update).

Reproducible Steps

Run the test suite:

# Verify formatting and clippy
cargo fmt --check && cargo clippy --all-targets -- -D warnings

# Run diff unit and integration tests
cargo test --test http diff_categorizes_findings_and_honors_fail_on_regression
cargo test --lib outcome::tests::diff
cargo test

Test CLI diffing locally:

# Pull request run comparison (human text)
cargo run -- diff --repo owner/repo --pr 7

# Explicit run comparison
cargo run -- diff --repo owner/repo --pr 7 --base-run 1 --target-run 2

# Machine-readable JSON diff
cargo run -- diff --repo owner/repo --pr 7 --json

# CI gating: exits with code 3 on regression, code 2 on incomplete review
cargo run -- diff --repo owner/repo --pr 7 --fail-on-regression

This branch has not been deployed

No deployments
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