Skip to content

Lab: corpus diff folds "same message moved ≤3 lines" pairs #4

Closed

Description

@mareklangiewicz

Lab issue (neospector lua/myemmylab*.lua).

Problem

gndx emmylua corpus diff reports some pairs as removed-and-added when they are really one hit that moved a line or two. The message is the same and the line differs by ≤3. They flip from run to run, for example gitsigns compat.lua 144↔152, nvim lsp/util.lua 1830↔1831, snacks diff.lua 283↔284 (the root cause is #9). They bury the real changes.

Want

Fold such pairs into a separate "moved" section, or just a count, with a flag to show them. The --summary totals should leave them out of added/removed.

Activity

  1. added
    ready-for-agent
    enhancement
    and removed
    needs-triage
    on Nov 17, 2026
  2. mareklangiewicz commented on Nov 17, 2026

    @mareklangiewicz
    OwnerAuthor

    This was generated by AI during triage.

    Agent Brief

    Category: enhancement
    Summary: gndx emmylua corpus diff folds a hit that only moved by ≤3 lines into a separate "moved" count instead of reporting it as one removed line plus one added line

    Where: the gndx emmylua lab in neospector (myvi). Pure logic is in the myemmylab module (myemmylab.diff, myemmylab.hits, myemmylab.message_key), the command is in myemmylabcli (corpus diff), and the ONest tests are in myemmylabtree.

    Current behavior:
    myemmylab.hits keys every diagnostic as file:line code message_key and counts them. myemmylab.diff compares the two runs' counts per key, so a hit that the engine reports one line lower in B (for example gitsigns compat.lua 144↔152, nvim lsp/util.lua 1830↔1831, snacks diff.lua 283↔284) shows up twice: as -1 …:1830 … and +1 …:1831 …. It is also counted under its code as +1 and −1. These pairs flip from run to run (cause tracked in #9) and bury the real changes.

    Desired behavior:

    • Within one tree, a removed unit and an added unit are a moved pair when file, code and message key are equal and the two lines are at most MOVE_WINDOW (= 3) apart. Expose the window as a constant on the module.
    • Pairing is per unit of count: 2 removed and 1 added on nearby lines make 1 moved pair, and 1 removal stays a change. When several pairings are possible, pair each removal with the nearest addition, with ties broken deterministically (for example the lower line). The same input must always give the same output.
    • Moved pairs are left out of Diff.lines and out of Diff.by_code. Diff.totals stays the raw diagnostic count on each side.
    • Diff gains the moved pairs (or their count plus a list) so the CLI can report them. With --against, moved pairs are not tagged and are not counted in against.
    • corpus diff prints one line, corpus diff: N moved hit(s) (≤3 lines) folded, next to the totals line (also with --summary), and a new --moved flag lists the folded pairs (tree: file:A->B code message).
    • Refusals (problems) and the exit codes (0 = compared, 2 = not comparable) do not change.

    Key interfaces:

    • myemmylab.Diff: new field holding the moved pairs. Keep lines, by_code, totals, problems and against meaning what they mean today, minus the folded units.
    • myemmylab.MOVE_WINDOW: the 3-line window.
    • corpus diff's cmdmeta: the new --moved boolean, documented like --summary.

    Acceptance criteria:

    • A new ONest case in myemmylabtree shows the old behaviour fails first: a hit at line 1830 in A and at 1831 in B gives no lines and no by_code entry, and one moved pair.
    • A move of exactly 3 lines folds; a move of 4 does not.
    • A different message key, code or file on the nearby line does not fold.
    • 2 removed + 1 added nearby → 1 moved pair and a -1 line.
    • Two runs of diff on the same input give identical output (deterministic pairing).
    • With a reference run, folded pairs are absent from against counts.
    • gndx spector tree passes, and gndx spector check emmylua is clean.
    • A real gndx emmylua corpus diff <old> <new> --summary on two existing corpus labels prints the moved line (record the numbers in the issue).

    Out of scope:

  3. mareklangiewicz commented on Nov 17, 2026

    @mareklangiewicz
    OwnerAuthor

    Done in myvi 197bc96 (neospector myemmylab.diff + corpus diff --moved). Not pushed yet.

    • myemmylab.MOVE_WINDOW = 3; Diff.moved = sorted tree: file:A->B code message, left out of lines, by_code and against; totals stay raw.
    • Pairing: candidates within the window, sorted by (distance, removed line, added line), taken greedily per unit of count. Deterministic.
    • New ONest node emmylab/diff/moves (6 cases, all red on the old code first). gndx spector tree 1088/1088, gndx spector check emmylua CLEAN.

    Real run, gndx emmylua corpus diff fix3-9629b372 fix4-c6fd72f0:

    • before: 4 changed lines, assign-type-mismatch +2 -2
    • after: 2 changed lines, +1 -1, 1 moved hit(s) (≤3 lines) folded (snacks picker/source/diff.lua:284->283)
    • gitsigns compat.lua 144↔152 is 8 lines apart, so it stays a change. Widening the window for it would be a separate decision.

    up-2c400ee2 fix4-c6fd72f0: 7 folded, but that pair is refused anyway (upstream crashed on 5 trees).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementready-for-agent

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions