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-repository.ts
38 lines · 1.1 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 { startsSession } from './starts-session.js'
8
9/**
10 * A session in /work (REPOSITORY), keeping each git run and each pane
11 * opened or closed.
12 *
13 * The store starts empty, the clock at 0, and the engine draws the hint.
14 *
15 * @param on the test's `on`
16 * @returns the runs, the panes opened and closed, and the session's clock
17 */
18export function inRepository(on: On) {
19 const runs: Args<'process.run'>[] = []
20 const opened = keeping<Args<'ui.open'>>()
21 const closed = keeping<Args<'ui.close'>>()
22 const clock = startsSession(on)
23
24 on('process.run', ($, e) => {
25 runs.push(e)
26
27 return { value: gitIn(e.argv) }
28 })
29
30 on('ui.open', opened.hook)
31 on('ui.close', closed.hook)
32 on('ui.invalidate', () => ({ value: undefined }))
33 on('ui.render', { component: 'PromptHint' }, () => HINT_DRAWN)
34 on('session.messages', () => ({ value: [] }))
35 mock.store(on)
36
37 return { runs, opened: opened.kept, closed: closed.kept, clock }
38}