From 9a56741357d1f4876a89cb5f1955291235fb4d85 Mon Sep 17 00:00:00 2001 From: DongHyeonka Date: Fri, 25 Sep 2026 23:59:53 +0900 Subject: [PATCH] test(cache-storage): pin the anonymous same-origin stage request (02-02) Cache Storage has no logout purge, so credentials omit and same-origin mode are what keep per-user responses out of it. Removing either line, switching credentials to include or dropping redirect error now fails this test. Co-Authored-By: Claude Opus 5.5 --- tests/unit/public-response-cache.test.ts | 48 ++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/tests/unit/public-response-cache.test.ts b/tests/unit/public-response-cache.test.ts index 30dd1df8..e0b2c0aa 100644 --- a/tests/unit/public-response-cache.test.ts +++ b/tests/unit/public-response-cache.test.ts @@ -112,6 +112,54 @@ describe("public response Cache Storage adapter", () => { expect(match.ok && match.value !== null).toBe(true); }); + it("stages with an anonymous same-origin request that fails on redirect (02-02)", async () => { + const policy = createDefaultPublicCachePolicy( + "https://assets.example.test", + ); + const bytes = new Uint8Array([5, 5, 5, 5]); + const asset: PublicCacheAsset = { + absoluteUrl: "https://assets.example.test/anonymous.js", + expectedByteLength: bytes.byteLength, + expectedContentType: "application/javascript", + integrity: { + algorithm: "SHA-256", + digestHex: await digestHex(bytes), + }, + }; + const requests: Request[] = []; + const adapter = createPublicResponseCacheAdapter({ + cacheStorage: new MemoryCacheStorage() as unknown as CacheStorage, + crypto: globalThis.crypto, + mutationLock: immediateLock, + policy, + fetcher: async (request) => { + requests.push(request); + return new Response(bytes, { + headers: { + "cache-control": "public, max-age=31536000, immutable", + "content-type": "application/javascript", + }, + }); + }, + }); + const manifest = await manifestFor("anonymous-release", [asset], policy); + + expect(await adapter.admin.stageRelease(manifest)).toMatchObject({ + ok: true, + }); + // The Cache Storage is origin-wide and has no logout purge, so a cookie + // on this request would let a per-user response outlive the session. + expect( + requests.map(({ credentials, mode, redirect }) => ({ + credentials, + mode, + redirect, + })), + ).toEqual([ + { credentials: "omit", mode: "same-origin", redirect: "error" }, + ]); + }); + it("restages an evicted entry even when the release marker remains", async () => { const policy = createDefaultPublicCachePolicy( "https://assets.example.test",