spacehub

surshar / claude-code

Claude Code is an agentic coding tool that lives in your terminal, understands your codebase, and helps you code faster by executing routine tasks, explaining complex code, and handling git workflows - all through natural language commands.

Built by Anthropic · github.com/anthropics

diff: a test that a moving window reads only its new rowsBrowse files
poteat authored 22 days ago parent 6a0585e · commit 0e4d45343bf6
3 changed files+53 -9compared with 6a0585e
Mmods/diff/hooks/register.ts
Mmods/diff/tests/fixtures/old-files.ts
Mmods/diff/tests/views.test.ts
@@ -730,8 +730,10 @@
730730
731731 /**
732732 * A seat that changed since the last drawing lists other rows, whose
733- * bodies are read once: the model takes the new seat in this same pass,
734- * so the drawing that read asks for finds the seat unchanged.
733+ * bodies are read once.
734+ *
735+ * The model takes the new seat in this same pass, so the drawing that
736+ * read asks for finds the seat unchanged.
735737 */
736738 const isReseated = e.props.placement !== model.placement
737739
@@ -1,17 +1,23 @@
11 import type { On } from 'claude-code'
22
33 /**
4- * Answers `$.fs` over /work holding MOVED_IN's two files, both last
5- * written at time 0, before any session began.
4+ * Answers `$.fs` over /work holding the named files, MOVED_IN's two when
5+ * none is given, each last written at time 0, before any session began.
66 *
77 * @param on the test's `on`
8+ * @param names the files /work holds
89 */
9-export function oldFiles(on: On) {
10+export function oldFiles(
11+ on: On,
12+ names: readonly string[] = ['old.ts', 'moved.ts'],
13+) {
1014 on('fs.list', () => ({
11- value: [
12- { name: 'old.ts', kind: 'file', size: 2, isLink: false },
13- { name: 'moved.ts', kind: 'file', size: 2, isLink: false },
14- ],
15+ value: names.map(name => ({
16+ name,
17+ kind: 'file' as const,
18+ size: 2,
19+ isLink: false,
20+ })),
1521 }))
1622
1723 on('fs.stat', () => ({
@@ -147,6 +147,42 @@
147147 expect(drawn).toContain('+"left": "1.0.1"')
148148 })
149149
150+ test('inline, a window that moves reads only its new rows', async ($, on) => {
151+ const world = Fixtures.inRepository(on, Fixtures.MANY_FILES)
152+
153+ on('session.usage', () => ({ value: Fixtures.usageAt(Fixtures.SETTLE_MS) }))
154+
155+ Fixtures.oldFiles(
156+ on,
157+ Array.from(
158+ { length: Fixtures.MANY_FILE_COUNT },
159+ (_, at) => `file${at}.ts`,
160+ ),
161+ )
162+
163+ await $.session.start(Fixtures.SESSION)
164+ await $.command.run(Fixtures.DIALOG_DIFF)
165+ await world.clock.advance(Fixtures.SETTLE_MS)
166+ await $.ui.render(Fixtures.INLINE_PANE)
167+ await world.clock.advance(Fixtures.SETTLE_MS)
168+ await $.ui.focus(Fixtures.ringOnto('file:file3.ts'))
169+ await world.clock.advance(Fixtures.SETTLE_MS)
170+ await $.ui.render(Fixtures.INLINE_PANE)
171+ await $.ui.press({ plugin: 'diff', key: 'file:file5.ts' })
172+ await world.clock.advance(Fixtures.SETTLE_MS)
173+
174+ expect(
175+ world.runs
176+ .filter(run => run.argv.includes('--raw'))
177+ .map(run => run.argv.slice(run.argv.indexOf('--') + 1).join(' ')),
178+ 'the first five, the one the walk brought in, the two the press did',
179+ ).toEqual([
180+ 'file0.ts file1.ts file2.ts file3.ts file4.ts',
181+ 'file5.ts',
182+ 'file6.ts file7.ts',
183+ ])
184+ })
185+
150186 test('docked, a wheel tick moves the body, not the list', async ($, on) => {
151187 const world = Fixtures.inRepository(on, Fixtures.MANY_FILES)
152188