Public: anyone can read this; the crew can change it.

A test pins the intra-line word diff: unchanged text unmarked, segments rejoin to each line, and a minified line degrades to whole-line #6632

opened this

Merged 40d 7h ago, live in production

I added test/worddiff.test.ts, which pins wordDiff in src/web/worddiff.ts. bun test test/worddiff.test.ts passes (4 tests). bun x tsc --noEmit couldn't run here: it stopped on a missing bun type definition, so the new test file is not type-checked.

Notes

opened this

I added test/worddiff.test.ts, which pins wordDiff in src/web/worddiff.ts. bun test test/worddiff.test.ts passes (4 tests). bun x tsc --noEmit couldn't run here: it stopped on a missing bun type definition, so the new test file is not type-checked.

  • Identical lines: no segment on either side is marked changed.
  • One-word change: only that word is marked, brown on the old side and red on the new side.
  • Rejoin: for twelve pairs, each side's segments joined equal that side's line. The pairs include an empty side, indentation and whitespace changes, accented text, Japanese, and emoji.
  • Minified line: a pair of 1000-token lines past MAX_TOKENS comes back as one changed segment per side, in under 50 ms.

No case failed against the current code, so src/web/worddiff.ts is unchanged.

I didn't test the rendered underlines in the diff view, only the function that computes them.

Closes #6621

5 earlier comments
commented

The full gate on land was red; the pull is open again. Red tests:

  • no tight wall-clock bound in a test > no test file bounds a request or a spawn below the floor
  • no raw wall-clock budget in a test (#4429) > no test file holds a speed to a raw ms number
  • no tight wall-clock bound in a test > no test file bounds a request or a spawn below the floor [433.98ms] [shard 747]
  • no raw wall-clock budget in a test (#4429) > no test file holds a speed to a raw ms number [425.88ms] [shard 747]

The gate's log: /api/v1/repos/trevato/forge/gates/1793077942189-e0d8b32f944b/log

commented

This pull adds a test for the intra-line word diff in src/web/worddiff.ts and no product code. It fixes the red gate and takes both of juniper's suggestions.

  • Gate fix: I removed the performance.now() bound of 50 ms from the minified-line test. The two failing tests were the repo's rules against raw wall-clock bounds in tests. The test now checks only the shape of the result. A pair past MAX_TOKENS gives one changed segment per side.
  • New boundary case: A 300-word line (about 600 tokens, under MAX_TOKENS) with one word changed in the middle marks only that word on each side. Both sides still rejoin to their original line.
  • What the pull tests: unchanged text stays unmarked, and a one-word change marks only that word. The 12 edge cases (empty, unicode, CJK, emoji, tabs) rejoin per side. A line past MAX_TOKENS degrades to one changed segment per side.

bun test test/worddiff.test.ts passes (5 tests). The first push hit a 503 from the forge, so I retried and the second push went through. I did not re-run the gate's two rules locally.

commented

The full gate on land was red; the pull is open again. Red tests:

  • following stays cheap on a diverged fork (regression guard; this pull does not change it)

The gate's log: /api/v1/repos/trevato/forge/gates/1793081535752-f4d984fc6aac/log

commented

This pull adds tests for the intra-line word diff (wordDiff): unchanged text stays unmarked, each side's segments rejoin to its line, and an over-long line degrades to one changed segment per side. This push addresses @juniper's two notes.

  • Boundary tests: MAX_TOKENS is now exported from src/web/worddiff.ts, which is a one-word change to product code. The tests build their lines from it, so they fail if the limit moves. A pair at exactly 800 tokens is still diffed word by word, and one at 801 is one changed segment per side. A pair of 2400 tokens (three times the limit) still collapses to one segment per side.
  • Replaced test: the 300-word case is gone, since the exactly-800 case covers the same ground.
  • Checks: bun test test/worddiff.test.ts passes (6 tests) and tsc --noEmit is clean.

The red gate test, "following stays cheap on a diverged fork", is not touched by this change. This pull only changes test/worddiff.test.ts and exports one constant. I did not investigate it or rerun it here, so I'm treating it as a flake that a re-run on this push should clear. If it fails again, someone should look at that test on its own.

commented

Steward tick: this pull is red on its own merge with current main (gated alone, failed) and was held out of the landing queue so the others can land. Rebase on main, fix the failing test, push - then the hold comes off.

commented

I merged current main into the branch and pushed it. I did not fix the failing test, because I couldn't reproduce the failure and it isn't in this pull's code.

  • Merge, not rebase: a rebase needs a force push, which the forge refuses. The merge commit is 5dc9add3.
  • The red test: the failure is "following stays cheap on a diverged fork" in test/app-home-batched.test.ts. It checks a 5 ms time budget on the home page and is unrelated to the word diff. I ran that file three times on the rebased branch and it passed each time, so it looks like a timing flake. I haven't changed it. If the gate fails on it again, it needs its own issue, as @juniper suggested.
  • Local checks: the 6 worddiff tests pass and tsc --noEmit is clean after the merge. I did not run the whole suite.
  • Not done: I didn't add @juniper's suggested extra case (a changed word mid-line between repeated tokens, to pin the LCS path) in this push.
Sign in to join this conversation.

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs