Skip to content

fix(wacdfpp): detect renamed variables and highlight word-level diffs - #105

Merged
jeandet merged 2 commits into
SciQLop:mainfrom
jeandet:fix/wacdfpp-diff-rename-detection
Sep 18, 2026
Merged

jeandet merged 2 commits into
SciQLop:mainfrom
jeandet:fix/wacdfpp-diff-rename-detection

Conversation

@jeandet

@jeandet jeandet commented Sep 17, 2026

Copy link
Copy Markdown
Member

Summary

Fixes #102.

The compare view's diff engine matched variables by exact name only, so a renamed variable showed up as a full "removed" block plus a full "added" block, unrelated to each other. When several variables were renamed at once, the result was a screen full of disconnected +/- blocks the reporter found "messy to understand at first glance." The color hint in the issue (red=removed/green=added coinciding with File A/File B) pointed at the same underlying problem: nothing in the UI told the reader these blocks were actually the same variables, renamed.

  • Rename detection (cdf-diff.js): a greedy content-similarity pass — Jaccard similarity over each variable's shape/type/attributes, the same idea git diff -M uses for file renames — pairs up same-group removed/added variables above a threshold before they're finalized as adds/removes. A pure rename (identical content, new name) collapses to a single line; a rename that also changed content keeps its sub-diff underneath.
  • Its own color + icon: renamed items get a violet accent and a "↦" icon, distinct from add (green)/remove (red)/change (amber) — git's own --color-moved uses the same principle (a third hue for moved content, never reusing red/green) so a "renamed + changed" row can't be misread as a plain change.
  • Word-level highlighting: a changed text field (e.g. a CATDESC differing only in its last few words) now highlights just the differing words instead of tinting the whole line — vendored diff (jsdiff) v9.0.0, BSD-3-Clause. The highlight is a second, independently-chosen color layered on the existing row tint, not a deeper shade of it, matching VS Code's diff editor (insertedTextBackground is picked separately from insertedLineBackground for contrast reasons).
  • Indentation: attribute rows are now indented under their variable's header, so nesting reads from position, not just font-weight (a second issue that came up testing this: it wasn't obvious at a glance what was a variable vs. an attribute).

Test plan

  • tests/wacdfpp_diff (TDD): pure renames, renames with a content change, unrelated adds/removes that must NOT be paired, greedy best-match selection among multiple candidates, summary/buildLines output
  • Full local suite green: 34/34
  • Verified visually in a browser (inline + side-by-side views) against a synthetic rename + CATDESC-diff fixture reproducing the issue's scenario

🤖 Generated with Claude Code

Fixes SciQLop#102. A screen full of unrelated-looking +/- blocks for what were
actually renamed variables read as "messy to understand at first
glance" - the diff engine matched variables by exact name only, so a
rename showed as a full remove plus a full add with no indication they
were the same variable.

- cdf-diff.js: a greedy content-similarity pass (Jaccard over each
  variable's shape/type/attributes, same idea as `git diff -M`) pairs
  up same-group removed/added variables above a similarity threshold
  before they're finalized as adds/removes, producing a "renamed"
  status instead. A pure rename collapses to one line; a rename with
  an actual content change also gets a sub-diff.
- compare.js/wacdfpp.html: renames get their own colour + icon (violet,
  "↦"), distinct from add/remove/change - git's own --color-moved uses
  a similar principle (a third hue for moved content, never reusing
  red/green). Changed text fields (e.g. a CATDESC differing only in
  its last few words) now highlight just the differing words via
  vendored jsdiff, layered as a second, independently-chosen colour on
  top of the existing row tint (not a deeper shade of it - matches VS
  Code's diff editor, which keeps insertedTextBackground separate from
  insertedLineBackground for the same contrast reason). Attribute rows
  are now indented under their variable's header, so nesting reads
  from position, not just font-weight.

Vendored diff (jsdiff) v9.0.0, BSD-3-Clause, as a classic <script> (its
only single-file build is UMD, not ESM) - wacdfpp/jsdiff.js.

TDD: tests/wacdfpp_diff/test.mjs covers pure renames, renames with a
content change, unrelated adds/removes that must NOT be paired,
greedy best-match selection among multiple candidates, and summary/
buildLines output - all passing before this was wired into the
renderer. Verified visually in a browser against a synthetic
rename + CATDESC-diff fixture, in both inline and side-by-side views.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@codecov

codecov Bot commented Sep 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.23%. Comparing base (eafcaf0) to head (7a13637).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #105   +/-   ##
=======================================
  Coverage   93.23%   93.23%           
=======================================
  Files          62       62           
  Lines        4802     4802           
=======================================
  Hits         4477     4477           
  Misses        325      325           
Flag Coverage Δ
unittests 93.23% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

- cdf-diff.js: split diffModels() into partitionVariables() +
  resolveGroupRenames() -- cognitive complexity was 16, over the
  15 allowed (S3776). Each half now does one job (bucket exact-name
  diffs vs. raw removed/added candidates; run the rename pass and
  finalize the leftovers), matching the file's existing style of
  small single-purpose functions.
- compare.js: statusClass() was a 4-deep nested ternary (S3358 x2).
  Replaced with a plain lookup object.

No behavior change -- tests/wacdfpp_diff/test.mjs (45 assertions)
still all pass.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@sonarqubecloud

Copy link
Copy Markdown

@jeandet
jeandet merged commit 10ab5ab into SciQLop:main Sep 18, 2026
53 checks passed
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.

CDFpp Explorer : display is sometimes confused

1 participant