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

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

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

opened this

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 index is 0 and current is that hunk.
  • Null file: setting null leaves hunks empty and current undefined.
  • Section words: sectionLabel and sectionNote each 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.

Closes #6658

commented

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 index is 0 and current is that hunk.
  • Null file: setting null leaves hunks empty and current undefined.
  • Section words: sectionLabel and sectionNote each 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

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.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs