mirror of
https://github.com/deepseek-ai/deepseek-harness
synced 2026-08-15 21:04:50 +00:00
Address review on the event-taxonomy PR: - ui-stdio built its session-id→agent-id label map only from live `agent/created` events, so an agent registered before the UI fiber installed — the pre-created `main` agent, or any agent surviving an HMR reload of just this fiber — was missed and its turns rendered the raw session id instead of `[main turn N]`. Seed the map from `ctx.agents.list()` at install, then keep it live. Regression test proven red without the seed. - The agent event-domain doc still listed "the turn boundaries" among the TRANSIENT `agent/*` emits, contradicting the rule ten lines below that a turn/step boundary is a durable `session/event`, not an `agent/*` mirror.
54 lines
1.7 KiB
TypeScript
54 lines
1.7 KiB
TypeScript
import { EventEmitter } from 'node:events'
|
|
import type { Readable, Writable } from 'node:stream'
|
|
import { describe, expect, it, vi } from 'vitest'
|
|
import type { Context } from 'cordis'
|
|
import type { StdioRuntime } from '../src/index.ts'
|
|
|
|
const createInterface = vi.hoisted(() => vi.fn(() => {
|
|
const reader = new EventEmitter() as EventEmitter & { close(): void }
|
|
reader.close = vi.fn()
|
|
return reader
|
|
}))
|
|
|
|
vi.mock('node:readline', () => ({ createInterface }))
|
|
|
|
function fakeContext(): Context {
|
|
return {
|
|
on: vi.fn(() => vi.fn()),
|
|
effect: vi.fn((callback: () => () => void) => callback()),
|
|
// The UI seeds its label map from the registry at install; this suite only
|
|
// exercises readline terminal-mode selection, so an empty roster suffices.
|
|
agents: { list: vi.fn(() => []) },
|
|
} as unknown as Context
|
|
}
|
|
|
|
function fakeRuntime(inputIsTTY: boolean, outputIsTTY: boolean): StdioRuntime {
|
|
return {
|
|
input: { isTTY: inputIsTTY } as Readable & { isTTY: boolean },
|
|
output: { isTTY: outputIsTTY, write: vi.fn(() => true) } as unknown as Writable & { isTTY: boolean },
|
|
exit: vi.fn(),
|
|
}
|
|
}
|
|
|
|
describe('createStdioChat readline mode', () => {
|
|
it('enables terminal editing only when both stdio streams are TTYs', async () => {
|
|
const { createStdioChat } = await import('../src/index.ts')
|
|
|
|
const tty = fakeRuntime(true, true)
|
|
createStdioChat(fakeContext(), {}, tty)
|
|
expect(createInterface).toHaveBeenLastCalledWith({
|
|
input: tty.input,
|
|
output: tty.output,
|
|
terminal: true,
|
|
})
|
|
|
|
const piped = fakeRuntime(true, false)
|
|
createStdioChat(fakeContext(), {}, piped)
|
|
expect(createInterface).toHaveBeenLastCalledWith({
|
|
input: piped.input,
|
|
output: piped.output,
|
|
terminal: false,
|
|
})
|
|
})
|
|
})
|