Skip to content

Commit 3ce2f3b

Browse files
committed
test: cover MCP resource data-URL blobs and default-case chat image rendering
1 parent 849e0e1 commit 3ce2f3b

2 files changed

Lines changed: 73 additions & 0 deletions

File tree

src/core/tools/__tests__/useMcpToolTool.spec.ts

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -979,6 +979,63 @@ describe("useMcpToolTool", () => {
979979
)
980980
})
981981

982+
it("should not double-prefix image resource blobs already formatted as data URLs", async () => {
983+
const block: ToolUse<"use_mcp_tool"> = {
984+
type: "tool_use",
985+
name: "use_mcp_tool",
986+
params: {
987+
server_name: "godot-server",
988+
tool_name: "game_screenshot",
989+
arguments: "{}",
990+
},
991+
nativeArgs: {
992+
server_name: "godot-server",
993+
tool_name: "game_screenshot",
994+
arguments: {},
995+
},
996+
partial: false,
997+
}
998+
999+
mockAskApproval.mockResolvedValue(true)
1000+
1001+
const mockToolResult = {
1002+
content: [
1003+
{
1004+
type: "resource",
1005+
resource: {
1006+
uri: "godot://screenshot/latest",
1007+
mimeType: "image/png",
1008+
blob: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJ",
1009+
},
1010+
},
1011+
],
1012+
isError: false,
1013+
}
1014+
1015+
mockProviderRef.deref.mockReturnValue({
1016+
getMcpHub: () => ({
1017+
callTool: vi.fn().mockResolvedValue(mockToolResult),
1018+
getAllServers: vi.fn().mockReturnValue([
1019+
{
1020+
name: "godot-server",
1021+
tools: [{ name: "game_screenshot", description: "Capture screenshot" }],
1022+
},
1023+
]),
1024+
}),
1025+
postMessageToWebview: vi.fn(),
1026+
})
1027+
1028+
await useMcpToolTool.handle(mockTask as Task, block, {
1029+
askApproval: mockAskApproval,
1030+
handleError: mockHandleError,
1031+
pushToolResult: mockPushToolResult,
1032+
})
1033+
1034+
expect(mockTask.say).toHaveBeenCalledWith("mcp_server_response", expect.any(String), [
1035+
"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJ",
1036+
])
1037+
})
1038+
9821039
it("should handle multiple images in response", async () => {
9831040
const block: ToolUse = {
9841041
type: "tool_use",

webview-ui/src/components/chat/__tests__/ChatRow.mcp-server-response.spec.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,20 @@ describe("ChatRow - mcp_server_response", () => {
8787

8888
expect(screen.queryByRole("img")).toBeNull()
8989
})
90+
91+
it("renders attached images for say types that use the default renderer", () => {
92+
const message: any = {
93+
type: "say",
94+
say: "command_output",
95+
ts: Date.now(),
96+
partial: false,
97+
text: "Some output",
98+
images: ["data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJ"],
99+
}
100+
101+
renderChatRow(message)
102+
103+
const img = screen.getByRole("img")
104+
expect(img).toHaveAttribute("src", "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJ")
105+
})
90106
})

0 commit comments

Comments
 (0)