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 = {