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 / boot-probe.test.ts
58 lines · 1.4 KBRaw
1import type {
2 CommandRunInput,
3 ProcessRunResult,
4 SessionStartInput,
5} from 'claude-code'
6import { clock, expect, test, tier } from 'claude-code/testing'
7
8tier('builtin')
9
10const SESSION: SessionStartInput = {
11 surface: 'terminal',
12 isInteractive: true,
13 cwd: '/work',
14}
15const DIFF: CommandRunInput = {
16 command: 'diff',
17 args: '',
18 origin: { kind: 'composer' },
19}
20const NOT_A_REPOSITORY: ProcessRunResult = {
21 exitCode: 128,
22 stdout: '',
23 stderr: 'fatal: not a git repository',
24}
25const GIT_TIMEOUT_MS = 5000
26const GIT_HUNG = `git aborted: still running after ${GIT_TIMEOUT_MS}ms`
27
28test('/diff at boot joins the boot probe, then asks again', async ($, on) => {
29 const probes: (readonly string[])[] = []
30 on('session.start', ($, e) => ({ cwd: e.cwd }))
31 on('command.register', ($, e) => ({ value: { command: e.name } }))
32 on('process.run', async ($, e) => {
33 probes.push(e.argv)
34
35 if (probes.length === 1) {
36 await clock.sleep(GIT_TIMEOUT_MS)
37
38 return { deny: GIT_HUNG }
39 }
40
41 return { value: NOT_A_REPOSITORY }
42 })
43
44 const booting = $.session.start(SESSION)
45 await clock.advance(0)
46 const ran = $.command.run(DIFF)
47 await clock.advance(0)
48
49 expect(probes, 'the boot probe, which /diff joined').toHaveLength(1)
50
51 await clock.advance(GIT_TIMEOUT_MS)
52 await booting
53
54 expect(await ran).toEqual({
55 text: expect.stringContaining("isn't in a git repository"),
56 })
57 expect(probes, 'then one more of its own').toHaveLength(2)
58})