test(canvas): verify batch downloads reuse stored PNG variants

This commit is contained in:
134 2026-10-12 15:35:01 +08:00
parent dfc1c6d496
commit c0cbc34911

View File

@ -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]);
});