From b2b5c42f6138b73ec4b2f49ec0ca468800f88586 Mon Sep 17 00:00:00 2001 From: Armin Ronacher Date: Mon, 5 Oct 2026 00:58:33 +0200 Subject: [PATCH] fix(coding-agent): expect saved image label in codemode MCP test (#10463) The codemode image() output now names the saved temp file before each image, so the MCP integration test must expect the extra text item. --- .../test/suite/agent-session-mcp.test.ts | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/packages/coding-agent/test/suite/agent-session-mcp.test.ts b/packages/coding-agent/test/suite/agent-session-mcp.test.ts index 30761608d..6fe69e24a 100644 --- a/packages/coding-agent/test/suite/agent-session-mcp.test.ts +++ b/packages/coding-agent/test/suite/agent-session-mcp.test.ts @@ -1,3 +1,4 @@ +import { readFileSync, rmSync } from "node:fs"; import { fauxAssistantMessage, fauxToolCall } from "@earendil-works/pi-ai"; import type { SystemMessage, ToolResultMessage } from "@earendil-works/pi-ai/compat"; import { type JsonRpcRequest, LATEST_PROTOCOL_VERSION } from "@earendil-works/pi-mcp"; @@ -254,15 +255,24 @@ describe("AgentSession MCP integration", () => { const result = toolResult(harness, "codemode"); expect(result.isError).toBe(false); - // Output items keep the order the script produced them in. - expect(result.content[1]).toEqual({ type: "image", data: TINY_PNG_BASE64, mimeType: "image/png" }); - expect(JSON.parse((result.content[2] as { text: string }).text)).toEqual({ + // Output items keep the order the script produced them in; each image follows the path it was saved to. + const savedPath = /^\[Image saved to (\S+\.png) \(image\/png, \d+B\)\]$/.exec( + (result.content[1] as { text: string }).text, + )?.[1]; + expect(savedPath).toBeDefined(); + try { + expect(readFileSync(savedPath!).toString("base64")).toBe(TINY_PNG_BASE64); + } finally { + if (savedPath) rmSync(savedPath, { force: true }); + } + expect(result.content[2]).toEqual({ type: "image", data: TINY_PNG_BASE64, mimeType: "image/png" }); + expect(JSON.parse((result.content[3] as { text: string }).text)).toEqual({ hits: ["mcp guide", "mcp faq", "pi guide", "pi faq"], failed: true, failure: "server exploded", found: [searchName], }); - expect(result.content).toHaveLength(3); + expect(result.content).toHaveLength(4); expect(calls).toEqual(['search:{"query":"mcp"}', 'search:{"query":"pi"}', "fail:{}", "shot:{}"]); });