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
| 1 | import type { On } from 'claude-code' |
| 2 | import { mock } from 'claude-code/testing' |
| 3 | |
| 4 | import { SESSION } from './session.js' |
| 5 | import type { Started, ToastAsked } from './types' |
| 6 | |
| 7 | /** |
| 8 | * A session that starts untouched beneath the plugins, rooted at SESSION's |
| 9 | * working directory, every toast, transcript line and debug-log line they |
| 10 | * raise kept for the test to read, on a mock clock the test settles before it |
| 11 | * reads them. |
| 12 | * |
| 13 | * A `$.ui.log` line lands in `lines` when it is bound for the transcript and |
| 14 | * in `debugLines` when its `to` is `debug`, so a test tells the two apart. |
| 15 | * |
| 16 | * @param on the test's `on` |
| 17 | * @returns the toasts, lines and walks raised, in order, and the clock |
| 18 | */ |
| 19 | export function startedOf(on: On): Started { |
| 20 | const toasts: ToastAsked[] = [] |
| 21 | const lines: string[] = [] |
| 22 | const debugLines: string[] = [] |
| 23 | |
| 24 | on('session.start', ($, e) => ({ cwd: e.cwd })) |
| 25 | |
| 26 | on('session.root', () => ({ value: SESSION.cwd })) |
| 27 | |
| 28 | on('ui.toast', ($, e) => { |
| 29 | toasts.push(e) |
| 30 | |
| 31 | return { value: undefined } |
| 32 | }) |
| 33 | |
| 34 | on('ui.log', ($, e) => { |
| 35 | const sink = e.to === 'debug' ? debugLines : lines |
| 36 | sink.push(e.text) |
| 37 | |
| 38 | return { value: undefined } |
| 39 | }) |
| 40 | |
| 41 | return { toasts, lines, debugLines, walks: [], clock: mock.clock(on) } |
| 42 | } |