| 1 | import { Emitter, type TerminalBackend, type TerminalProcess, type TerminalSpawnOptions } from '@moonshot-ai/agent-core'; |
| 2 | |
| 3 | export class FakeTerminalProcess implements TerminalProcess { |
| 4 | readonly writes: string[] = []; |
| 5 | readonly resizes: Array<{ cols: number; rows: number }> = []; |
| 6 | killed = false; |
| 7 | |
| 8 | private readonly dataEmitter = new Emitter<string>(); |
| 9 | private readonly exitEmitter = new Emitter<{ exitCode: number | null }>(); |
| 10 | |
| 11 | readonly onData = this.dataEmitter.event; |
| 12 | readonly onExit = this.exitEmitter.event; |
| 13 | |
| 14 | write(data: string): void { |
| 15 | this.writes.push(data); |
| 16 | } |
| 17 | |
| 18 | resize(cols: number, rows: number): void { |
| 19 | this.resizes.push({ cols, rows }); |
| 20 | } |
| 21 | |
| 22 | kill(): void { |
| 23 | this.killed = true; |
| 24 | this.exitEmitter.fire({ exitCode: null }); |
| 25 | } |
| 26 | |
| 27 | emitData(data: string): void { |
| 28 | this.dataEmitter.fire(data); |
| 29 | } |
| 30 | |
| 31 | emitExit(exitCode: number | null): void { |
| 32 | this.exitEmitter.fire({ exitCode }); |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | export class FakeTerminalBackend implements TerminalBackend { |
| 37 | readonly spawns: TerminalSpawnOptions[] = []; |
nothing calls this directly
no outgoing calls
no test coverage detected