From 88a62b3b5e11994f648e7d219628ab311f691c47 Mon Sep 17 00:00:00 2001 From: 134 Date: Mon, 12 Oct 2026 15:35:01 +0800 Subject: [PATCH] test(canvas): verify batch downloads reuse stored PNG variants --- tests/routes/canvas-download-speed.test.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/routes/canvas-download-speed.test.ts b/tests/routes/canvas-download-speed.test.ts index 4f6271041..5d3acdad0 100644 --- a/tests/routes/canvas-download-speed.test.ts +++ b/tests/routes/canvas-download-speed.test.ts @@ -164,3 +164,16 @@ test("single-image route preserves authentication and returns a small CDN respon expect(response.status).toBe(200); expect(response.headers.get("Cache-Control")).toBe("no-store"); expect((await response.json()).delivery).toBe("cdn"); expect(lookups).toBe(1); }); +test("batch downloads use the durable prepared PNG even when the source cache is cold", async () => { + const original = `https://provider.example/${crypto.randomUUID()}.jpg`; + const prepared = `https://cdn.example/${crypto.randomUUID()}.png`; + const bytes = await sharp({ create: { width: 12, height: 20, channels: 4, background: "#abcdef80" } }).png().toBuffer(); + const fetched: string[] = []; + const module = serverLoader({ + "@/lib/storage/image-archive-db": { findImageArchiveDownloadTask: async () => ({ targetUrl: original, metadata: { downloadAsset: { status: "ready", url: prepared, contentType: "image/png" } } }) }, + fetch: async (url: string) => { fetched.push(url); expect(url).toBe(prepared); return new Response(bytes, { headers: { "Content-Type": "image/png" } }); }, + }, { POSTGRES_URL: "mock-only" })("lib/canvas/photoshop-safe-download.ts"); + const result = await module.fetchCanvasDownloadAsset({ file: { url: original, name: "作品" }, index: 0, requestOrigin: "https://app.example", cookie: "", retryCount: 1 }); + expect(result.ok).toBe(true); expect(result.bytes.equals(bytes)).toBe(true); + expect(result.filename).toBe("001-作品.png"); expect(fetched).toEqual([prepared]); +});