import { describe, expect, it } from "vitest"; import { CACHE_POLICY, createReleaseFixture } from "./release-fixture.ts"; /** * 11-05. A contract of the in-memory hosting model in `release-fixture.ts` * against `config/hosting/cache-policy.json`: no product code, deploy script or * browser runs here. Keeping old assets reachable is the hosting provider's * job (`docs/operations/release-cache-rollback.md`). What an old tab does when * an asset is gone anyway is checked in a real browser by * `tests/e2e/old-tab-chunk-recovery.spec.ts`. */ describe("old hashed-asset reachability (hosting fixture contract)", () => { it("keeps R10 hashed assets reachable after R11 becomes active", async () => { const deployment = createReleaseFixture(["R10", "R11"]); deployment.activate("R11"); expect(await deployment.fetch("/releases/R10/assets/app.aaaa.js")) .toMatchObject({ status: 200 }); expect(await deployment.fetch("/assets/app.aaaa.js")).toMatchObject({ status: 200, release: "R10", }); }); it("serves distinct, never-overwritten hashed names per release", async () => { const deployment = createReleaseFixture(["R10", "R11"]); const old = await deployment.fetch("/assets/app.aaaa.js"); const current = await deployment.fetch("/assets/app.bbbb.js"); expect(old.body).toContain('"R10"'); expect(current.body).toContain('"R11"'); expect(old.headers["cache-control"]).toBe(CACHE_POLICY.surfaces.hashedAsset.cacheControl); }); it("switches mutable surfaces to the active release only", async () => { const deployment = createReleaseFixture(["R10", "R11"]); deployment.activate("R11"); expect((await deployment.fetch("/")).release).toBe("R11"); expect((await deployment.fetch("/config.json")).release).toBe("R11"); expect((await deployment.fetch("/release-manifest.json")).release).toBe("R11"); expect((await deployment.fetch("/config.json")).headers["cache-control"]).toBe("no-store"); }); it("detects an unsafe deploy that removed old assets inside the rolling window", async () => { const deployment = createReleaseFixture(["R10", "R11"]); deployment.activate("R11"); deployment.retireAssets("R10"); expect(await deployment.fetch("/assets/app.aaaa.js")).toMatchObject({ status: 404 }); }); });