From b705d62fd14e90342cb0aec2ff6b424ca04b9e89 Mon Sep 17 00:00:00 2001 From: Molecule AI Core-FE Date: Tue, 12 May 2026 14:45:18 +0000 Subject: [PATCH] =?UTF-8?q?test(chat):=20add=20extractAgentText=20coverage?= =?UTF-8?q?=20=E2=80=94=206=20cases?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Covers the 4 unique branches not exercised by extractTextsFromParts: artifacts[0].parts fallback, status.message.parts fallback, bare-string passthrough, and the try/catch sentinel on null input. Co-Authored-By: Claude Opus 4.7 --- .../chat/__tests__/message-parser.test.ts | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/canvas/src/components/tabs/chat/__tests__/message-parser.test.ts b/canvas/src/components/tabs/chat/__tests__/message-parser.test.ts index 3a4748a7..e33af39e 100644 --- a/canvas/src/components/tabs/chat/__tests__/message-parser.test.ts +++ b/canvas/src/components/tabs/chat/__tests__/message-parser.test.ts @@ -281,6 +281,41 @@ describe("extractTextsFromParts", () => { }); }); +describe("extractAgentText", () => { + it("extracts from task.parts via extractTextsFromParts", () => { + const task = { parts: [{ kind: "text", text: "Agent reply" }] }; + expect(extractAgentText(task)).toBe("Agent reply"); + }); + + it("falls back to artifacts[0].parts when task.parts is absent", () => { + const task = { + artifacts: [{ parts: [{ kind: "text", text: "Artifact text" }] }], + }; + expect(extractAgentText(task)).toBe("Artifact text"); + }); + + it("falls back to status.message.parts when both parts and artifacts are absent", () => { + const task = { + status: { message: { parts: [{ kind: "text", text: "Status text" }] } }, + }; + expect(extractAgentText(task)).toBe("Status text"); + }); + + it("returns the task as-is when it is a bare string", () => { + expect(extractAgentText("Bare string response")).toBe("Bare string response"); + }); + + it("returns sentinel when nothing extractable is present", () => { + expect(extractAgentText({})).toBe("(Could not extract response text)"); + }); + + it("returns sentinel for null input (caught by try/catch)", () => { + expect(extractAgentText(null as unknown as Record)).toBe( + "(Failed to parse response)" + ); + }); +}); + describe("extractFilesFromTask", () => { it("pulls A2A file parts out of a result", () => { const task = {