diff --git a/tests/unit/public-response-cache-repair.test.ts b/tests/unit/public-response-cache-repair.test.ts index 692cc95b..554ee1b6 100644 --- a/tests/unit/public-response-cache-repair.test.ts +++ b/tests/unit/public-response-cache-repair.test.ts @@ -584,6 +584,33 @@ describe("public cache pointer after a policy change or damage (0929/02-01)", () ).toMatchObject({ ok: true, value: expect.anything() }); }); + // 2026-11-01 02-04 (N39). The cache name list is read before the pointer. + // An activation in between moves the pointer to a cache that list does not + // have yet; the lookup lists again rather than report it evicted. + it("lists caches again before it reports the active release evicted", async () => { + // The adapter captures `keys` when it is built, so the stale answer is + // armed through the storage itself. + class StaleOnceCacheStorage extends MemoryCacheStorage { + staleNames: string[] | null = null; + override async keys(): Promise { + const stale = this.staleNames; + this.staleNames = null; + return stale ?? (await super.keys()); + } + } + const cacheStorage = new StaleOnceCacheStorage(); + const policy = policyRetaining(1); + const adapter = adapterFor(cacheStorage, policy); + expect(await deploy(adapter, "r1", policy)).toMatchObject({ ok: true }); + const namesBeforeR2 = await cacheStorage.keys(); + expect(await deploy(adapter, "r2", policy)).toMatchObject({ ok: true }); + cacheStorage.staleNames = namesBeforeR2; + + expect( + await adapter.responses.matchActiveExact({ absoluteUrl: assetUrl("r2") }), + ).toMatchObject({ ok: true, value: expect.anything() }); + }); + it("still stops activation when the pointer read fails transiently", async () => { const cacheStorage = new MemoryCacheStorage(); const policy = policyRetaining(1);