Skip to content

The agent that grows with you

fix(install-e2e): log what the mock parsed, not just the request line

ethernet999a923e8061
diff --git a/tests-js/scripts/desktop-smoke.test.ts b/tests-js/scripts/desktop-smoke.test.ts
index 756e1f95a1c..2bffcbb7331 100644
--- a/tests-js/scripts/desktop-smoke.test.ts
+++ b/tests-js/scripts/desktop-smoke.test.ts
@@ -31,6 +31,22 @@ test('one server owns inference and a fresh, per-server prompt witness', async (
body: JSON.stringify({ messages: [{ role: 'user', content: [{ type: 'text', text: 'NEW multipart prompt' }] }] }),
})
expect(await readMockPrompts(first.url)).toEqual([prompt, 'NEW multipart prompt'])
+ // A body shape the witness does not recognize records nothing rather than a
+ // half-parsed string — that is the empty-witness case the desktop smoke
+ // reports as a poll timeout, so the mock logs the parsed shape on this path.
+ for (const content of [{ type: 'text', text: 'unrecognized shape' }, 42]) {
+ await fetch(`${first.url}/v1/chat/completions`, {
+ method: 'POST', headers: { 'Content-Type': 'application/json' },
+ body: JSON.stringify({ messages: [{ role: 'user', content }] }),
+ })
+ }
+ // No user turn at all leaves `lastUserMessage` undefined — the shape the
+ // diagnostic must still describe without throwing.
+ await fetch(`${first.url}/v1/chat/completions`, {
+ method: 'POST', headers: { 'Content-Type': 'application/json' },
+ body: JSON.stringify({ messages: [{ role: 'assistant', content: 'no user turn' }] }),
+ })
+ expect(await readMockPrompts(first.url)).toEqual([prompt, 'NEW multipart prompt'])
expect(await readMockPrompts(second.url)).toEqual([])
} finally {
await first.close()
diff --git a/tests-js/scripts/mock-server.ts b/tests-js/scripts/mock-server.ts
index 7254a1af845..c9e558562cf 100644
--- a/tests-js/scripts/mock-server.ts
+++ b/tests-js/scripts/mock-server.ts
@@ -516,6 +516,37 @@ function includesBlockingClarifyTrigger(value: unknown): boolean {
return false
}
+/**
+ * The prompt text this mock records as the witness for a chat completion, or
+ * `null` when the body carries a shape it does not recognize. Only two shapes
+ * are recorded (`lastUserMessage.content` as a string, or content parts with
+ * `type === 'text'`); anything else makes the witness empty and the desktop
+ * smoke's `GET /__e2e__/prompts` poll time out with no clue as to why.
+ */
+function promptTextFromLastUserMessage(lastUserMessage: any): string | null {
+ if (typeof lastUserMessage?.content === 'string') {
+ return lastUserMessage.content
+ }
+
+ if (Array.isArray(lastUserMessage?.content)) {
+ const parts = z.array(z.object({ type: z.string(), text: z.string().optional() })).parse(lastUserMessage.content)
+
+ return parts.filter((part): boolean => part.type === 'text')
+ .map((part): string => part.text ?? '').join('\n')
+ }
+
+ return null
+}
+
+/** Compact a value for a single log line, truncated so a full transcript cannot flood mock.log. */
+function describeForLog(value: unknown): string {
+ // `JSON.stringify(undefined)` is `undefined`, not a string — an absent
+ // lastUserMessage is a shape this must still describe.
+ const text = (typeof value === 'string' ? value : JSON.stringify(value)) ?? String(value)
+
+ return text.length > 1000 ? `${text.slice(0, 1000)}…[${text.length} chars]` : text
+}
+
/**
* Start the mock server on an ephemeral port.
*
@@ -603,12 +634,20 @@ export function startMockServer(options: MockServerOptions = {}): Promise<MockSe
.reverse()
.find((message: { role?: unknown }) => message?.role === 'user')
- if (typeof lastUserMessage?.content === 'string') {
- receivedPrompts.push(lastUserMessage.content)
- } else if (Array.isArray(lastUserMessage?.content)) {
- const parts = z.array(z.object({ type: z.string(), text: z.string().optional() })).parse(lastUserMessage.content)
- receivedPrompts.push(parts.filter((part): boolean => part.type === 'text')
- .map((part): string => part.text ?? '').join('\n'))
+ const recordedPrompt = promptTextFromLastUserMessage(lastUserMessage)
+
+ if (recordedPrompt === null) {
+ // The desktop smoke asserts this witness holds its checkpoint
+ // prompt; a POST that records nothing is exactly the 90 s
+ // predicate timeout it reports, with the body's shape as the
+ // only clue. Log that shape here.
+ console.log(
+ `[mock-server] POST /v1/chat/completions recorded NO prompt; ` +
+ `lastUserMessage=${describeForLog(lastUserMessage)} body=${describeForLog(body)}`,
+ )
+ } else {
+ receivedPrompts.push(recordedPrompt)
+ console.log(`[mock-server] recorded prompt: ${describeForLog(recordedPrompt)}`)
}
const stream = parsed.stream === true