diff --git a/src/adapters/cache-storage/public-response-cache-adapter.ts b/src/adapters/cache-storage/public-response-cache-adapter.ts index 380228af..fb45c70f 100644 --- a/src/adapters/cache-storage/public-response-cache-adapter.ts +++ b/src/adapters/cache-storage/public-response-cache-adapter.ts @@ -491,8 +491,10 @@ export function createPublicResponseCacheAdapter( } if (verified.kind === "UNKNOWN") { // Abort or an unreadable candidate is never stage success and - // never silently deletes an owned candidate. - return verified.failure; + // never silently deletes an owned candidate. 2026-11-01 + // 02-03: the verdict is shared with activation, so the + // failure is re-labelled as this stage call's own. + return rebaseFailure(verified.failure.error, "CACHE_STAGE"); } } } diff --git a/tests/unit/public-response-cache-repair.test.ts b/tests/unit/public-response-cache-repair.test.ts index 1ad2757e..bd29d254 100644 --- a/tests/unit/public-response-cache-repair.test.ts +++ b/tests/unit/public-response-cache-repair.test.ts @@ -17,7 +17,10 @@ import { * yet earned the right to delete what still works. */ describe("public response cache repair is failure-atomic", () => { - async function stagedRelease(releaseRegistryId: string) { + async function stagedRelease( + releaseRegistryId: string, + observer?: (event: unknown) => void, + ) { const policy = createDefaultPublicCachePolicy( "https://assets.example.test", ); @@ -55,6 +58,7 @@ describe("public response cache repair is failure-atomic", () => { crypto: globalThis.crypto, mutationLock: immediateLock, policy, + ...(observer ? { observer } : {}), fetcher: async (request: Request) => { fetchLog.push(request.url); if (failFrom !== null && request.url === failFrom) { @@ -127,6 +131,40 @@ describe("public response cache repair is failure-atomic", () => { ).toMatchObject({ ok: true }); }); + it("reports a failed re-verification of a staged candidate as CACHE_STAGE (2026-11-01 02-03)", async () => { + const observations: Readonly<{ outcome?: string }>[] = []; + const release = await stagedRelease("reverify-unreadable", (event) => + observations.push(event as Readonly<{ outcome?: string }>), + ); + const cache = release.cacheStorage.caches.get(release.cacheName)!; + const realMatch = cache.match.bind(cache); + const assetUrls = new Set(release.assets.map((asset) => asset.absoluteUrl)); + cache.match = async (request: RequestInfo | URL) => { + const url = + request instanceof Request ? request.url : String(request); + if (assetUrls.has(url)) { + throw new DOMException("Storage is busy", "InvalidStateError"); + } + return await realMatch(request); + }; + observations.length = 0; + + const restaged = await release.adapter.admin.stageRelease(release.manifest); + + expect(restaged).toMatchObject({ + ok: false, + error: { code: "UNAVAILABLE", operation: "CACHE_STAGE" }, + }); + expect( + observations.filter(({ outcome }) => outcome === "FAILED"), + ).toEqual([ + expect.objectContaining({ + operation: "CACHE_STAGE", + failureCode: "UNAVAILABLE", + }), + ]); + }); + it("keeps every healthy asset when one repair fetch fails", async () => { const release = await stagedRelease("partial-repair"); const cache = release.cacheStorage.caches.get(release.cacheName)!;