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

claude-code / mods / diff / tests / fixtures / in-slow-repository.ts
53 lines · 1.6 KBRaw
1import type { Args, On } from 'claude-code'
2import { mock } from 'claude-code/testing'
3
4import { gitIn } from './git-in.js'
5import { HINT_DRAWN } from './hint-drawn.js'
6import { keeping } from './keeping.js'
7import { REPOSITORY } from './repository.js'
8import { startsSession } from './starts-session.js'
9
10/**
11 * A session in a repository as inRepository keeps one, where git takes a
12 * millisecond of the clock to answer each `--numstat`: time for a test to
13 * land an edit or a `/clear` while the diff is being read.
14 *
15 * What git answers is settled as the read starts, from the script as it
16 * stands then.
17 *
18 * @param on the test's `on`
19 * @param script git's output for each invocation whose line holds the key
20 * @returns the clock's time as each read started, the panes opened, the
21 * clock
22 */
23export function inSlowRepository(
24 on: On,
25 script: Readonly<Record<string, string>> = REPOSITORY,
26) {
27 const reads: number[] = []
28 const opened = keeping<Args<'ui.open'>>()
29 const clock = startsSession(on)
30
31 on('process.run', async ($, e) => {
32 const value = gitIn(e.argv, script)
33
34 if (e.argv.includes('--numstat')) {
35 reads.push(await clock.now())
36 await clock.sleep(1)
37 }
38
39 return { value }
40 })
41
42 on('ui.open', opened.hook)
43 on('ui.close', () => ({ value: undefined }))
44 on('ui.status', () => ({ value: undefined }))
45 on('ui.invalidate', () => ({ value: undefined }))
46 on('ui.render', { component: 'PromptHint' }, () => HINT_DRAWN)
47 on('session.messages', () => ({ value: [] }))
48 on('settings.read', () => ({ value: {} }))
49 mock.store(on, {})
50 mock.env(on, {})
51
52 return { reads, opened: opened.kept, clock }
53}