From f3b31d7a53f4adbb68ed6096e64a75dfa515be24 Mon Sep 17 00:00:00 2001 From: daniel-lxs Date: Tue, 28 Oct 2025 13:46:11 -0500 Subject: [PATCH] test(images): add CDN URI conversion tests for normalizeImageRefsToDataUrls Add test coverage for HTTPS CDN URL conversion (e.g., https://file+.vscode-resource.vscode-cdn.net/...) to base64 data URLs. This covers the critical URI-to-base64 conversion flow that was previously only tested with legacy file:// URIs. --- .../misc/__tests__/imageDataUrl.spec.ts | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/integrations/misc/__tests__/imageDataUrl.spec.ts b/src/integrations/misc/__tests__/imageDataUrl.spec.ts index 01b100afa8..0ebce80b08 100644 --- a/src/integrations/misc/__tests__/imageDataUrl.spec.ts +++ b/src/integrations/misc/__tests__/imageDataUrl.spec.ts @@ -18,6 +18,33 @@ describe("normalizeImageRefsToDataUrls", () => { expect(result).toEqual([dataUrl]) }) + it("should convert CDN webview URIs to data URLs", async () => { + const cdnUri = "https://file+.vscode-resource.vscode-cdn.net/path/to/test.png" + const mockBuffer = Buffer.from("test image data") + + vi.mocked(fs.readFile).mockResolvedValue(mockBuffer) + + const result = await normalizeImageRefsToDataUrls([cdnUri]) + + expect(result).toHaveLength(1) + expect(result[0]).toMatch(/^data:image\/png;base64,/) + expect(fs.readFile).toHaveBeenCalledWith("/path/to/test.png") + }) + + it("should handle mixed arrays of data URLs and CDN URIs", async () => { + const dataUrl = "data:image/jpeg;base64,test123" + const cdnUri = "https://file+.vscode-resource.vscode-cdn.net/path/to/test.png" + const mockBuffer = Buffer.from("test image data") + + vi.mocked(fs.readFile).mockResolvedValue(mockBuffer) + + const result = await normalizeImageRefsToDataUrls([dataUrl, cdnUri]) + + expect(result).toHaveLength(2) + expect(result[0]).toBe(dataUrl) // Data URL unchanged + expect(result[1]).toMatch(/^data:image\/png;base64,/) // CDN URI converted + }) + it("should handle errors gracefully by skipping problematic images", async () => { const validDataUrl = "data:image/png;base64,valid" const invalidCdnUri = "vscode-file://vscode-app/nonexistent/test.png"