Bläddra i källkod

Merge branch 'codex/simp-shared-acp-test-launcher' into codex/simp-trim-hook-snapshot-noise

Tianyi Cui 2 månader sedan
förälder
incheckning
c544d4e784

+ 11 - 2
packages/support/acp-snapshot/src/launcher.ts

@@ -107,6 +107,7 @@ export function launchAcpTestAgent(options: AcpTestLaunchOptions): LaunchedAcpTe
   const updateWaiters: {
     match: (update: SessionNotification['update']) => boolean
     resolve: (update: SessionNotification['update']) => void
+    reject: (reason: unknown) => void
   }[] = []
   const stream = ndJsonStream(
     Writable.toWeb(child.stdin) as WritableStream<Uint8Array>,
@@ -119,7 +120,15 @@ export function launchAcpTestAgent(options: AcpTestLaunchOptions): LaunchedAcpTe
         const waiter = updateWaiters[index]
         /* v8 ignore next 1 -- index is bounded by the array length */
         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)
         waiter.resolve(params.update)
       }
@@ -136,7 +145,7 @@ export function launchAcpTestAgent(options: AcpTestLaunchOptions): LaunchedAcpTe
     updates,
     rawStdout: () => Buffer.concat(rawBuffers).toString('utf8'),
     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> {
       if (child.exitCode !== null || child.signalCode !== null) return
       if (signal === undefined) child.stdin.end()

+ 4 - 0
packages/support/acp-snapshot/tests/harness.spec.ts

@@ -57,7 +57,11 @@ describe('runScenario', () => {
     await launched.client.initialize({ protocolVersion: PROTOCOL_VERSION, clientCapabilities: {} })
     const { sessionId } = await launched.client.newSession({ cwd: dir, mcpServers: [] })
     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' }] })
+    expect(await failedPredicate).toBe(predicateFailure)
     expect((await nextChunk).sessionUpdate).toBe('agent_message_chunk')
     expect(launched.updates.some(update => update.sessionUpdate === 'agent_message_chunk')).toBe(true)
     expect(launched.rawStdout()).toContain('permission:{\\"outcome\\":\\"cancelled\\"}')