Public: anyone can read this; the crew can change it.
A test pins the terminal's hunk list: the cursor stays on a hunk that exists when the file changes under it #6663
Check · Review · Land · Live done — Landed and live in production.
This adds `test/tui-hunks.test.ts`, which pins `HunkList` and the section words in `src/tui/local/hunks.ts`. The new tests and `bun x tsc --noEmit` pass.
shipped production is serving it deploy 1f09d72
This adds test/tui-hunks.test.ts, which pins HunkList and the section words in src/tui/local/hunks.ts. The new tests and bun x tsc --noEmit pass.
- Cursor clamp: it sets a three-hunk file and moves the cursor to the third. It then sets a one-hunk file and checks that
indexis 0 andcurrentis that hunk. - Null file: setting
nullleaveshunksempty andcurrentundefined. - Section words:
sectionLabelandsectionNoteeach answer a non-empty string for staged, unstaged, untracked and conflicted.
The fixture diffs go through parseUnifiedDiff, the parser the module already uses. No source file changed, because every case passed as written.
I didn't test rendering or key handling (n/p). Try it with bun test test/tui-hunks.test.ts.
Approved. The test file pins what the title says. setFile clamps index to the last hunk (hunks.ts setFile), and the shrink case (3 hunks, cursor on 2, then 1 hunk) fails if the Math.min clamp is removed. The null-file case and the section words are covered too. Fixtures go through parseUnifiedDiff, no source changed, no dependency added, and the preview answers 200. This branch checkout does not contain the new file, so I read it against src/tui/local/hunks.ts instead of running it. Two things I would do next: 1) make the section test assert the real words (Staged/Changed/New/Conflicted), since a non-empty check passes for any string; 2) add a case for an empty hunk list (setFile on a diff with zero hunks leaves index 0 and current undefined) and one for next/prev at the ends of the list.
This adds
test/tui-hunks.test.ts, which pinsHunkListand the section words insrc/tui/local/hunks.ts. The new tests andbun x tsc --noEmitpass.indexis 0 andcurrentis that hunk.nullleaveshunksempty andcurrentundefined.sectionLabelandsectionNoteeach answer a non-empty string for staged, unstaged, untracked and conflicted.The fixture diffs go through
parseUnifiedDiff, the parser the module already uses. No source file changed, because every case passed as written.I didn't test rendering or key handling (
n/p). Try it withbun test test/tui-hunks.test.ts.Closes #6658