Skip to content

feat: offline before/after project comparison - #4

Merged
he-yufeng merged 2 commits into
mainfrom
feat/delivery-comparison
Oct 21, 2026
Merged

he-yufeng merged 2 commits into
mainfrom
feat/delivery-comparison

Conversation

@he-yufeng

Copy link
Copy Markdown
Owner

What

Adds an offline before/after comparison to CodeABC:

  • POST /api/project/compare — accepts two uploaded snapshots (max 500 files / 5 MiB of text each), matches files by relative path, and reports added / deleted / modified files with a bounded unified diff (80 lines / 8000 chars, skipped for files over 2000 source lines).
  • A /compare page (linked from the home page) with two drop zones and a plain-language result view: what changed, byte deltas, and the diff preview per file.
  • Security-warning delta: the static pattern scan runs on both snapshots and findings are matched as a multiset on (file, category, snippet), so inserting a line above a warning does not manufacture a fake "resolved + new" pair.

Design decisions

  • A path filtered out on either side (dependency directories, binaries, size caps) is reported as not compared, never as a deletion — an unreadable new version is unknown, not gone.
  • Risk findings are static pattern matches, not confirmed vulnerabilities; the response carries a notes array saying exactly that, plus "no source is executed and no language model is called".
  • complete: false on the security section when either side hits the 5000-finding cap, so the UI never presents a partial delta as authoritative.

Also fixes the pre-existing react-hooks/set-state-in-effect lint failure in PrView (wrapper + key={url} remount, missing-URL error derived during render).

Verification

  • pytest tests/test_comparison.py: 16 passed (classification, excluded-path handling, diff bounds, security multiset matching, caps, route 400s).
  • Full backend suite: 789 passed.
  • Live server smoke: add/delete/modify classification, diff preview, and the introduced hardcoded_secret finding all verified over HTTP.
  • ruff check clean; new files ruff format-clean.
  • npm run lint and npm run build pass (lint was previously red on the PrView rule).

The URL-driven fetch lived in an effect that also called setError and
setLoading synchronously, which the current react-hooks plugin flags.
Split PrView into a wrapper that remounts the inner reader with key=url
and derive the missing-URL error during render instead.
New POST /api/project/compare plus a /compare page: drop the folder as
delivered and the folder that came back, and CodeABC shows which files
were added, deleted or modified with a bounded unified diff, plus the
delta in static risk warnings.

Matching is by relative path; a path filtered out on either side
(dependency dirs, binaries, over limits) is reported as not compared
rather than as a deletion. Security findings are matched as a multiset
on (file, category, snippet) so a line shift does not manufacture a
resolved/new pair. Snapshots cap at 500 files and 5 MiB of text; no
source is executed and no LLM is called.
@he-yufeng
he-yufeng merged commit ca66cd1 into main Oct 21, 2026
7 checks passed
@he-yufeng
he-yufeng deleted the feat/delivery-comparison branch October 21, 2026 16:15
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