Merge branch 'codex/simp-compaction-surface' into codex/simp-agent-entry-state
This commit is contained in:
@@ -107,6 +107,7 @@ export function launchAcpTestAgent(options: AcpTestLaunchOptions): LaunchedAcpTe
|
|||||||
const updateWaiters: {
|
const updateWaiters: {
|
||||||
match: (update: SessionNotification['update']) => boolean
|
match: (update: SessionNotification['update']) => boolean
|
||||||
resolve: (update: SessionNotification['update']) => void
|
resolve: (update: SessionNotification['update']) => void
|
||||||
|
reject: (reason: unknown) => void
|
||||||
}[] = []
|
}[] = []
|
||||||
const stream = ndJsonStream(
|
const stream = ndJsonStream(
|
||||||
Writable.toWeb(child.stdin) as WritableStream<Uint8Array>,
|
Writable.toWeb(child.stdin) as WritableStream<Uint8Array>,
|
||||||
@@ -119,7 +120,15 @@ export function launchAcpTestAgent(options: AcpTestLaunchOptions): LaunchedAcpTe
|
|||||||
const waiter = updateWaiters[index]
|
const waiter = updateWaiters[index]
|
||||||
/* v8 ignore next 1 -- index is bounded by the array length */
|
/* v8 ignore next 1 -- index is bounded by the array length */
|
||||||
if (waiter === undefined) continue
|
if (waiter === undefined) continue
|
||||||
if (!waiter.match(params.update)) continue
|
let matches: boolean
|
||||||
|
try {
|
||||||
|
matches = waiter.match(params.update)
|
||||||
|
} catch (error: unknown) {
|
||||||
|
updateWaiters.splice(index, 1)
|
||||||
|
waiter.reject(error)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if (!matches) continue
|
||||||
updateWaiters.splice(index, 1)
|
updateWaiters.splice(index, 1)
|
||||||
waiter.resolve(params.update)
|
waiter.resolve(params.update)
|
||||||
}
|
}
|
||||||
@@ -136,7 +145,7 @@ export function launchAcpTestAgent(options: AcpTestLaunchOptions): LaunchedAcpTe
|
|||||||
updates,
|
updates,
|
||||||
rawStdout: () => Buffer.concat(rawBuffers).toString('utf8'),
|
rawStdout: () => Buffer.concat(rawBuffers).toString('utf8'),
|
||||||
stderr: () => stderrChunks.join(''),
|
stderr: () => stderrChunks.join(''),
|
||||||
waitForUpdate: match => new Promise(resolve => updateWaiters.push({ match, resolve })),
|
waitForUpdate: match => new Promise((resolve, reject) => updateWaiters.push({ match, resolve, reject })),
|
||||||
async close(signal?: NodeJS.Signals): Promise<void> {
|
async close(signal?: NodeJS.Signals): Promise<void> {
|
||||||
if (child.exitCode !== null || child.signalCode !== null) return
|
if (child.exitCode !== null || child.signalCode !== null) return
|
||||||
if (signal === undefined) child.stdin.end()
|
if (signal === undefined) child.stdin.end()
|
||||||
|
|||||||
@@ -57,7 +57,11 @@ describe('runScenario', () => {
|
|||||||
await launched.client.initialize({ protocolVersion: PROTOCOL_VERSION, clientCapabilities: {} })
|
await launched.client.initialize({ protocolVersion: PROTOCOL_VERSION, clientCapabilities: {} })
|
||||||
const { sessionId } = await launched.client.newSession({ cwd: dir, mcpServers: [] })
|
const { sessionId } = await launched.client.newSession({ cwd: dir, mcpServers: [] })
|
||||||
const nextChunk = launched.waitForUpdate(update => update.sessionUpdate === 'agent_message_chunk')
|
const nextChunk = launched.waitForUpdate(update => update.sessionUpdate === 'agent_message_chunk')
|
||||||
|
const predicateFailure = new Error('predicate failed')
|
||||||
|
const failedPredicate = launched.waitForUpdate(() => { throw predicateFailure })
|
||||||
|
.catch((error: unknown): unknown => error)
|
||||||
await launched.client.prompt({ sessionId, prompt: [{ type: 'text', text: 'go' }] })
|
await launched.client.prompt({ sessionId, prompt: [{ type: 'text', text: 'go' }] })
|
||||||
|
expect(await failedPredicate).toBe(predicateFailure)
|
||||||
expect((await nextChunk).sessionUpdate).toBe('agent_message_chunk')
|
expect((await nextChunk).sessionUpdate).toBe('agent_message_chunk')
|
||||||
expect(launched.updates.some(update => update.sessionUpdate === 'agent_message_chunk')).toBe(true)
|
expect(launched.updates.some(update => update.sessionUpdate === 'agent_message_chunk')).toBe(true)
|
||||||
expect(launched.rawStdout()).toContain('permission:{\\"outcome\\":\\"cancelled\\"}')
|
expect(launched.rawStdout()).toContain('permission:{\\"outcome\\":\\"cancelled\\"}')
|
||||||
|
|||||||
Reference in New Issue
Block a user