import { describe, expect, it } from "vitest"; import { createReleaseMismatchRecovery } from "../../src/platform/release/release-mismatch-recovery.ts"; import { bootAgainstReplicaSequence, createReleaseFixture, memoryStorage, response, runBootSession, } from "./release-fixture.ts"; /** * scale-architecture.md ยง46. The multi-replica release matrix. Each row boots the real config * and manifest loaders against a two-release deployment and then loads the * HTML's hashed entry asset. */ describe("multi-replica release-coherence matrix", () => { it("R10/R10/R10 with the old R10 asset => PASS", async () => { const deployment = createReleaseFixture(["R10", "R11"]); const result = await bootAgainstReplicaSequence( [response("html", "R10"), response("config", "R10"), response("manifest", "R10")], deployment, ); expect(result).toMatchObject({ state: "booted", applicationMounted: true }); }); it("R10/R11/R10 => FAIL CLOSED", async () => { const result = await bootAgainstReplicaSequence([ response("html", "R10"), response("config", "R11"), response("manifest", "R10"), ]); expect(result).toMatchObject({ state: "release-mismatch", applicationMounted: false }); }); it("R10/R10/R11 => FAIL CLOSED", async () => { const result = await bootAgainstReplicaSequence([ response("html", "R10"), response("config", "R10"), response("manifest", "R11"), ]); expect(result).toMatchObject({ state: "release-mismatch", applicationMounted: false }); }); it("R10/R10/R10 with only the R11 asset path retained => FAIL", async () => { const deployment = createReleaseFixture(["R10", "R11"]); deployment.activate("R11"); deployment.retireAssets("R10"); const result = await bootAgainstReplicaSequence( [response("html", "R10"), response("config", "R10"), response("manifest", "R10")], deployment, ); expect(result).toMatchObject({ state: "asset-missing", applicationMounted: false }); }); it("R11/R11/R11 with the R11 asset => PASS", async () => { const deployment = createReleaseFixture(["R11"]); const result = await bootAgainstReplicaSequence( [response("html", "R11"), response("config", "R11"), response("manifest", "R11")], deployment, ); expect(result).toMatchObject({ state: "booted", applicationMounted: true, release: "release-R11" }); }); it("R10 client after R11 activation with the R10 hashed asset retained => PASS", async () => { const deployment = createReleaseFixture(["R10", "R11"]); deployment.activate("R11"); // The browser still holds R10 HTML and a lagging replica still answers R10. const result = await bootAgainstReplicaSequence( [response("html", "R10"), response("config", "R10"), response("manifest", "R10")], deployment, ); expect(result).toMatchObject({ state: "booted", applicationMounted: true, release: "release-R10" }); }); it("no mismatch row can produce more than one automatic reload", async () => { const mismatches = [ [response("html", "R10"), response("config", "R11"), response("manifest", "R10")], [response("html", "R10"), response("config", "R10"), response("manifest", "R11")], [response("html", "R11"), response("config", "R10"), response("manifest", "R11")], ] as const; for (const sequence of mismatches) { const session = await runBootSession( () => sequence, createReleaseMismatchRecovery(memoryStorage()), ); expect(session.reloads).toBeLessThanOrEqual(1); expect(session.final.applicationMounted).toBe(false); } }); });