|
| 1 | +import { describe, expect, it } from "vitest"; |
| 2 | +import { extractRenderableMcpAppDocument } from "../mcpAppPayload"; |
| 3 | +import type { McpAppPayload } from "@/shared/types/messages"; |
| 4 | + |
| 5 | +function createPayload(csp: unknown): McpAppPayload { |
| 6 | + return { |
| 7 | + sessionId: "session-1", |
| 8 | + gooseSessionId: null, |
| 9 | + toolCallId: "tool-1", |
| 10 | + toolCallTitle: "inspect app", |
| 11 | + source: "toolCallUpdateMeta", |
| 12 | + tool: { |
| 13 | + name: "inspect-app", |
| 14 | + extensionName: "mcpappbench", |
| 15 | + resourceUri: "ui://inspect-app", |
| 16 | + }, |
| 17 | + resource: { |
| 18 | + result: { |
| 19 | + contents: [ |
| 20 | + { |
| 21 | + uri: "ui://inspect-app", |
| 22 | + mimeType: "text/html;profile=mcp-app", |
| 23 | + text: "<div>App</div>", |
| 24 | + _meta: { |
| 25 | + ui: { |
| 26 | + csp, |
| 27 | + }, |
| 28 | + }, |
| 29 | + }, |
| 30 | + ], |
| 31 | + }, |
| 32 | + }, |
| 33 | + }; |
| 34 | +} |
| 35 | + |
| 36 | +describe("extractRenderableMcpAppDocument", () => { |
| 37 | + it("normalizes MCP app CSP metadata to string arrays", () => { |
| 38 | + const document = extractRenderableMcpAppDocument( |
| 39 | + createPayload({ |
| 40 | + connectDomains: "https://api.example.com", |
| 41 | + resourceDomains: ["https://cdn.example.com", 42], |
| 42 | + frameDomains: ["https://frame.example.com"], |
| 43 | + baseUriDomains: { origin: "https://base.example.com" }, |
| 44 | + scriptDomains: ["https://scripts.example.com"], |
| 45 | + }), |
| 46 | + ); |
| 47 | + |
| 48 | + expect(document?.csp).toEqual({ |
| 49 | + resourceDomains: ["https://cdn.example.com"], |
| 50 | + frameDomains: ["https://frame.example.com"], |
| 51 | + scriptDomains: ["https://scripts.example.com"], |
| 52 | + }); |
| 53 | + }); |
| 54 | + |
| 55 | + it("drops malformed MCP app CSP metadata", () => { |
| 56 | + const document = extractRenderableMcpAppDocument( |
| 57 | + createPayload({ |
| 58 | + connectDomains: "https://api.example.com", |
| 59 | + resourceDomains: [], |
| 60 | + frameDomains: { origin: "https://frame.example.com" }, |
| 61 | + }), |
| 62 | + ); |
| 63 | + |
| 64 | + expect(document?.csp).toBeNull(); |
| 65 | + }); |
| 66 | +}); |
0 commit comments