chore: sync the frontend template from ebea300 to af3d8e6
Carries 359 template commits, tag v0.2.0 plus one documentation commit: the generator-built feature index with its app, bounded-context and feature declarations, the src/platform kernel and scale tooling, the 2026-09-24 src review fixes, and the 2026-09-25 maturity review round with its CHANGELOG [보안]/[계약] rows. 691 of the 824 template paths are applied, 85 of them merged with product changes; 127 are not carried. Product identity is unchanged: name, version 0.1.0, routes, design and the TechLog domain. Three decisions worth naming. TechLog stays composed directly, as the last two syncs recorded; its directory carries a NOT_INSTALLED marker that says so, and every installed-* composer takes the template's projection with TechLog added on top. The reference sample is no longer installed: the template now installs a feature only through feature-module.ts and context-routes.ts, which load the screens this product deleted, so its three operations, six schemas and one topic leave the registries, recorded as registry change evidence. And AppRouter mounts the platform and TechLog routes only; the template's bounded-context route gateway waits for a generator-installed feature. Required fixes: readSubject on the BFF session owner (without it every HTTP Studio session would close as integration-failed), zod through the facade in nine TechLog files, noUnusedLocals, and public/config.json written out to match the local profile. Derived baselines were recomputed after reproducing both sides' values: CI contract 101 commands / 106 references / 141 artifacts, gate shape c9adcf85; registry approval 2dc6c3a3; the runtime config schema baseline equals the schema at8210d48. Verified here: types, lint, architecture, adapter inventory, CI contract, i18n, design system, diagnostics, browser security, dev release manifest, TechLog contract and build pass; 220 component, 155 integration, 15 contract, 418 TechLog, 43 reference-feature, 18 recipe and 46 release-coherence tests pass, and 2381 of 2383 unit tests. Reproduced at8210d48first and unchanged: check:registries (byte-identical), test:runtime-schema, verify:documentation. Brought by the template and escalated rather than suppressed: check:request-fanout on TechLog's cursor pagination, check:remediation-ledger (fails upstream too), the shared-chunk hash test, and the registry-dependent sample removal and second-feature tests. Playwright suites were not run. Full record, the five open questions and the follow-ups in docs/operations/template-sync-2026-09-29.md. (cherry picked from commit b2170cf265dea45dc9cc05d3c61e627e97f31cdb)
This commit is contained in:
@@ -0,0 +1 @@
|
||||
export const RELEASE = "R10";
|
||||
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"APP_ENV": "production",
|
||||
"API_BASE_URL": "https://api.example.test/",
|
||||
"REQUEST_TIMEOUT_MS": 10000,
|
||||
"MAX_RETRY_ATTEMPTS": 2,
|
||||
"TELEMETRY_ENABLED": false,
|
||||
"AUTH_MODE": "external",
|
||||
"RELEASE_MANIFEST_URL": "/release-manifest.json",
|
||||
"RELEASE_ID": "release-R10",
|
||||
"BUILD_ID": "build-R10",
|
||||
"CONFIG_SCHEMA_VERSION": "2.0",
|
||||
"CAPABILITY_OVERRIDES": {
|
||||
"REALTIME": "DEFAULT",
|
||||
"WEB_WORKER": "DEFAULT",
|
||||
"SERVICE_WORKER": "DEFAULT",
|
||||
"OFFLINE_COMMANDS": "DEFAULT"
|
||||
},
|
||||
"FEATURE_OVERRIDES": {}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<!doctype html>
|
||||
<html lang="ko">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="build-id" content="build-R10" />
|
||||
<title>Release R10</title>
|
||||
<script type="module" crossorigin src="/assets/app.aaaa.js"></script>
|
||||
</head>
|
||||
<body><div id="root"></div></body>
|
||||
</html>
|
||||
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"schemaVersion": 2,
|
||||
"appVersion": "0.1.0",
|
||||
"buildId": "build-R10",
|
||||
"commitSha": "abc123",
|
||||
"configSchemaVersion": "2.0",
|
||||
"assetManifestHash": "assets-aaaa",
|
||||
"releaseId": "release-R10",
|
||||
"builtAt": "2026-09-23T00:00:00Z",
|
||||
"routeChunks": { "route-home": "assets/app.aaaa.js" },
|
||||
"contractSet": {
|
||||
"setAlgorithm": "CA_CONTRACT_SET_V1",
|
||||
"setDigest": "__EMPTY_SET_DIGEST__",
|
||||
"packages": []
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
export const RELEASE = "R11";
|
||||
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"APP_ENV": "production",
|
||||
"API_BASE_URL": "https://api.example.test/",
|
||||
"REQUEST_TIMEOUT_MS": 10000,
|
||||
"MAX_RETRY_ATTEMPTS": 2,
|
||||
"TELEMETRY_ENABLED": false,
|
||||
"AUTH_MODE": "external",
|
||||
"RELEASE_MANIFEST_URL": "/release-manifest.json",
|
||||
"RELEASE_ID": "release-R11",
|
||||
"BUILD_ID": "build-R11",
|
||||
"CONFIG_SCHEMA_VERSION": "2.0",
|
||||
"CAPABILITY_OVERRIDES": {
|
||||
"REALTIME": "DEFAULT",
|
||||
"WEB_WORKER": "DEFAULT",
|
||||
"SERVICE_WORKER": "DEFAULT",
|
||||
"OFFLINE_COMMANDS": "DEFAULT"
|
||||
},
|
||||
"FEATURE_OVERRIDES": {}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<!doctype html>
|
||||
<html lang="ko">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="build-id" content="build-R11" />
|
||||
<title>Release R11</title>
|
||||
<script type="module" crossorigin src="/assets/app.bbbb.js"></script>
|
||||
</head>
|
||||
<body><div id="root"></div></body>
|
||||
</html>
|
||||
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"schemaVersion": 2,
|
||||
"appVersion": "0.1.0",
|
||||
"buildId": "build-R11",
|
||||
"commitSha": "abc123",
|
||||
"configSchemaVersion": "2.0",
|
||||
"assetManifestHash": "assets-bbbb",
|
||||
"releaseId": "release-R11",
|
||||
"builtAt": "2026-09-23T00:00:00Z",
|
||||
"routeChunks": { "route-home": "assets/app.bbbb.js" },
|
||||
"contractSet": {
|
||||
"setAlgorithm": "CA_CONTRACT_SET_V1",
|
||||
"setDigest": "__EMPTY_SET_DIGEST__",
|
||||
"packages": []
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { createReleaseMismatchRecovery } from "../../src/platform/release/release-mismatch-recovery.ts";
|
||||
import {
|
||||
bootAgainstReplicaSequence,
|
||||
createReleaseFixture,
|
||||
memoryStorage,
|
||||
response,
|
||||
runBootSession,
|
||||
type ReleaseName,
|
||||
type Surface,
|
||||
} from "./release-fixture.ts";
|
||||
|
||||
/** A deterministic load balancer that alternates replicas request by request. */
|
||||
function alternatingLoadBalancer(replicas: readonly ReleaseName[], offset = 0) {
|
||||
let request = offset;
|
||||
return (): readonly Readonly<{ kind: Surface; release: ReleaseName }>[] =>
|
||||
(["html", "config", "manifest"] as const).map((kind) =>
|
||||
response(kind, replicas[request++ % replicas.length] as ReleaseName),
|
||||
);
|
||||
}
|
||||
|
||||
describe("mixed-replica routing during a rolling release", () => {
|
||||
it("boots when every response comes from R10", async () => {
|
||||
const result = await bootAgainstReplicaSequence([
|
||||
response("html", "R10"),
|
||||
response("config", "R10"),
|
||||
response("manifest", "R10"),
|
||||
]);
|
||||
expect(result).toMatchObject({ state: "booted", applicationMounted: true, release: "release-R10" });
|
||||
});
|
||||
|
||||
it("boots when every response comes from R11", async () => {
|
||||
const result = await bootAgainstReplicaSequence([
|
||||
response("html", "R11"),
|
||||
response("config", "R11"),
|
||||
response("manifest", "R11"),
|
||||
]);
|
||||
expect(result).toMatchObject({ state: "booted", applicationMounted: true, release: "release-R11" });
|
||||
});
|
||||
|
||||
it("fails closed when HTML and runtime config come from different releases", async () => {
|
||||
const result = await bootAgainstReplicaSequence([
|
||||
response("html", "R10"),
|
||||
response("config", "R11"),
|
||||
response("manifest", "R10"),
|
||||
]);
|
||||
|
||||
expect(result.state).toBe("release-mismatch");
|
||||
expect(result.applicationMounted).toBe(false);
|
||||
});
|
||||
|
||||
it("fails closed when the manifest comes from a different release", async () => {
|
||||
const result = await bootAgainstReplicaSequence([
|
||||
response("html", "R10"),
|
||||
response("config", "R10"),
|
||||
response("manifest", "R11"),
|
||||
]);
|
||||
expect(result).toMatchObject({ state: "release-mismatch", applicationMounted: false });
|
||||
});
|
||||
|
||||
it("never produces a silently mixed boot under an alternating load balancer", async () => {
|
||||
for (let offset = 0; offset < 6; offset += 1) {
|
||||
const next = alternatingLoadBalancer(["R10", "R11"], offset);
|
||||
for (let boot = 0; boot < 10; boot += 1) {
|
||||
const sequence = next();
|
||||
const releases = new Set(sequence.map((entry) => entry.release));
|
||||
const result = await bootAgainstReplicaSequence(sequence);
|
||||
if (releases.size > 1) {
|
||||
expect(result.applicationMounted).toBe(false);
|
||||
} else {
|
||||
expect(result.state).toBe("booted");
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
it("recovers a stale HTML document with exactly one reload once the rollout converges", async () => {
|
||||
const deployment = createReleaseFixture(["R10", "R11"]);
|
||||
const sequences = [
|
||||
[response("html", "R10"), response("config", "R11"), response("manifest", "R11")],
|
||||
[response("html", "R11"), response("config", "R11"), response("manifest", "R11")],
|
||||
];
|
||||
let boot = 0;
|
||||
const session = await runBootSession(
|
||||
() => sequences[Math.min(boot++, sequences.length - 1)] ?? [],
|
||||
createReleaseMismatchRecovery(memoryStorage()),
|
||||
deployment,
|
||||
);
|
||||
expect(session.reloads).toBe(1);
|
||||
expect(session.final).toMatchObject({ state: "booted", release: "release-R11" });
|
||||
});
|
||||
|
||||
it("cannot reload-loop when replicas stay permanently mixed", async () => {
|
||||
const storage = memoryStorage();
|
||||
const session = await runBootSession(
|
||||
() => [response("html", "R10"), response("config", "R11"), response("manifest", "R10")],
|
||||
createReleaseMismatchRecovery(storage),
|
||||
);
|
||||
expect(session.reloads).toBe(1);
|
||||
expect(session.final).toMatchObject({ state: "release-mismatch", applicationMounted: false });
|
||||
expect(storage.size()).toBe(1);
|
||||
});
|
||||
|
||||
it("cannot reload-loop when replicas alternate between two different mismatches", async () => {
|
||||
const sequences = [
|
||||
[response("html", "R10"), response("config", "R11"), response("manifest", "R10")],
|
||||
[response("html", "R11"), response("config", "R10"), response("manifest", "R11")],
|
||||
];
|
||||
let boot = 0;
|
||||
const session = await runBootSession(
|
||||
() => sequences[boot++ % sequences.length] ?? [],
|
||||
createReleaseMismatchRecovery(memoryStorage()),
|
||||
);
|
||||
expect(session.reloads).toBe(1);
|
||||
expect(session.final).toMatchObject({ state: "release-mismatch", applicationMounted: false });
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,50 @@
|
||||
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 });
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,273 @@
|
||||
import { readdirSync, readFileSync } from "node:fs";
|
||||
import path from "node:path";
|
||||
|
||||
import { loadReleaseManifest } from "../../src/bootstrap/load-release-manifest.ts";
|
||||
import { loadRuntimeConfig } from "../../src/bootstrap/load-runtime-config.ts";
|
||||
import { releaseMismatchKey } from "../../src/bootstrap/boot-release-recovery.ts";
|
||||
import { buildContractSet } from "../../scripts/generate-contract-set.ts";
|
||||
import type { ReleaseMismatchRecovery } from "../../src/platform/release/release-mismatch-recovery.ts";
|
||||
|
||||
/**
|
||||
* A static multi-release deployment built from immutable fixture artifacts
|
||||
* (tests/release/fixtures/<release>/). Responses carry the repository's real
|
||||
* cache policy (config/hosting/cache-policy.json), and hashed assets of every
|
||||
* retained release stay addressable after a newer release is activated.
|
||||
*/
|
||||
export type ReleaseName = "R10" | "R11";
|
||||
export type Surface = "html" | "config" | "manifest";
|
||||
|
||||
const FIXTURE_ROOT = path.resolve("tests/release/fixtures");
|
||||
/**
|
||||
* Template sync (af3d8e6). The fixtures are releases of this repository, so
|
||||
* their manifest carries the contract set this build compiles. Upstream that
|
||||
* set is empty and the fixtures say so with `__EMPTY_SET_DIGEST__`; here it
|
||||
* holds TechLog's three packages, so the whole set is substituted.
|
||||
*/
|
||||
const COMPILED_CONTRACT_SET = buildContractSet();
|
||||
|
||||
type CachePolicy = Readonly<{
|
||||
surfaces: Readonly<{
|
||||
index: Readonly<{ cacheControl: string }>;
|
||||
runtimeConfig: Readonly<{ cacheControl: string }>;
|
||||
releaseManifest: Readonly<{ cacheControl: string }>;
|
||||
hashedAsset: Readonly<{ cacheControl: string }>;
|
||||
}>;
|
||||
}>;
|
||||
|
||||
export const CACHE_POLICY = JSON.parse(
|
||||
readFileSync(path.resolve("config/hosting/cache-policy.json"), "utf8"),
|
||||
) as CachePolicy;
|
||||
|
||||
type ReleaseArtifacts = Readonly<{
|
||||
html: string;
|
||||
config: string;
|
||||
manifest: string;
|
||||
assets: ReadonlyMap<string, string>;
|
||||
}>;
|
||||
|
||||
export function readRelease(release: ReleaseName): ReleaseArtifacts {
|
||||
const root = path.join(FIXTURE_ROOT, release);
|
||||
const assets = new Map<string, string>();
|
||||
for (const file of readdirSync(path.join(root, "assets"))) {
|
||||
// Fixtures are stored as `.js.fixture` so no executable JS lives in tests/.
|
||||
assets.set(
|
||||
file.replace(/\.fixture$/u, ""),
|
||||
readFileSync(path.join(root, "assets", file), "utf8"),
|
||||
);
|
||||
}
|
||||
return Object.freeze({
|
||||
html: readFileSync(path.join(root, "index.html"), "utf8"),
|
||||
config: readFileSync(path.join(root, "config.json"), "utf8"),
|
||||
manifest: JSON.stringify({
|
||||
...(JSON.parse(
|
||||
readFileSync(path.join(root, "release-manifest.json"), "utf8"),
|
||||
) as Record<string, unknown>),
|
||||
contractSet: COMPILED_CONTRACT_SET,
|
||||
}),
|
||||
assets,
|
||||
});
|
||||
}
|
||||
|
||||
export type FixtureResponse = Readonly<{
|
||||
status: number;
|
||||
headers: Readonly<Record<string, string>>;
|
||||
body: string;
|
||||
release?: ReleaseName;
|
||||
}>;
|
||||
|
||||
function respond(
|
||||
status: number,
|
||||
cacheControl: string,
|
||||
contentType: string,
|
||||
body: string,
|
||||
release?: ReleaseName,
|
||||
): FixtureResponse {
|
||||
return Object.freeze({
|
||||
status,
|
||||
headers: Object.freeze({ "cache-control": cacheControl, "content-type": contentType }),
|
||||
body,
|
||||
...(release === undefined ? {} : { release }),
|
||||
});
|
||||
}
|
||||
|
||||
const NOT_FOUND = respond(404, "no-store", "text/plain", "not found");
|
||||
|
||||
export function createReleaseFixture(releases: readonly ReleaseName[]) {
|
||||
const retained = new Map<ReleaseName, ReleaseArtifacts>(
|
||||
releases.map((release) => [release, readRelease(release)]),
|
||||
);
|
||||
/** Hashed assets have their own retention: the rolling window. */
|
||||
const assetStores = new Map<ReleaseName, ReadonlyMap<string, string>>(
|
||||
[...retained].map(([release, artifacts]) => [release, artifacts.assets]),
|
||||
);
|
||||
let active: ReleaseName = releases[0] as ReleaseName;
|
||||
const policy = CACHE_POLICY.surfaces;
|
||||
|
||||
function surface(release: ReleaseName, kind: Surface): FixtureResponse {
|
||||
const artifacts = retained.get(release);
|
||||
if (!artifacts) return NOT_FOUND;
|
||||
switch (kind) {
|
||||
case "html":
|
||||
return respond(200, policy.index.cacheControl, "text/html; charset=utf-8", artifacts.html, release);
|
||||
case "config":
|
||||
return respond(200, policy.runtimeConfig.cacheControl, "application/json", artifacts.config, release);
|
||||
case "manifest":
|
||||
return respond(200, policy.releaseManifest.cacheControl, "application/json", artifacts.manifest, release);
|
||||
}
|
||||
}
|
||||
|
||||
function asset(file: string, onlyRelease?: string): FixtureResponse {
|
||||
for (const [release, assets] of assetStores) {
|
||||
if (onlyRelease !== undefined && release !== onlyRelease) continue;
|
||||
const body = assets.get(file);
|
||||
if (body !== undefined) {
|
||||
return respond(200, policy.hashedAsset.cacheControl, "text/javascript", body, release);
|
||||
}
|
||||
}
|
||||
return NOT_FOUND;
|
||||
}
|
||||
|
||||
return Object.freeze({
|
||||
activate(release: ReleaseName) {
|
||||
if (!retained.has(release)) {
|
||||
const artifacts = readRelease(release);
|
||||
retained.set(release, artifacts);
|
||||
assetStores.set(release, artifacts.assets);
|
||||
}
|
||||
active = release;
|
||||
},
|
||||
/**
|
||||
* The rolling window closes for a release's hashed assets (an unsafe
|
||||
* deploy would do this too early). Its mutable surfaces may still be
|
||||
* served by a lagging replica.
|
||||
*/
|
||||
retireAssets(release: ReleaseName) {
|
||||
assetStores.delete(release);
|
||||
},
|
||||
get active() {
|
||||
return active;
|
||||
},
|
||||
surface,
|
||||
/**
|
||||
* Mutable surfaces come from the active release (or an explicit replica);
|
||||
* hashed assets come from any retained release, addressed by name or by
|
||||
* `/releases/<release>/assets/<file>`.
|
||||
*/
|
||||
async fetch(requestPath: string, replica?: ReleaseName): Promise<FixtureResponse> {
|
||||
const releaseAddressed = /^\/releases\/(R\d+)\/assets\/([^/]+)$/u.exec(requestPath);
|
||||
if (releaseAddressed) return asset(releaseAddressed[2] as string, releaseAddressed[1]);
|
||||
const hashed = /^\/assets\/([^/]+)$/u.exec(requestPath);
|
||||
if (hashed) return asset(hashed[1] as string);
|
||||
const release = replica ?? active;
|
||||
if (requestPath === "/" || requestPath === "/index.html") return surface(release, "html");
|
||||
if (requestPath === "/config.json") return surface(release, "config");
|
||||
if (requestPath === "/release-manifest.json") return surface(release, "manifest");
|
||||
return NOT_FOUND;
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export type ReleaseDeployment = ReturnType<typeof createReleaseFixture>;
|
||||
|
||||
export function response(kind: Surface, release: ReleaseName) {
|
||||
return Object.freeze({ kind, release });
|
||||
}
|
||||
|
||||
function toFetchResponse(fixture: FixtureResponse): Response {
|
||||
return new Response(fixture.body, { status: fixture.status, headers: fixture.headers });
|
||||
}
|
||||
|
||||
export type BootResult = Readonly<{
|
||||
state: "booted" | "release-mismatch" | "asset-missing" | "boot-failed";
|
||||
applicationMounted: boolean;
|
||||
mismatchKey?: string;
|
||||
release?: string;
|
||||
}>;
|
||||
|
||||
/**
|
||||
* Boots the real runtime-config and release-manifest loaders against an
|
||||
* explicit sequence of replica responses (html, config, manifest), then loads
|
||||
* the HTML's hashed entry asset. Nothing mounts unless every step is coherent.
|
||||
*/
|
||||
export async function bootAgainstReplicaSequence(
|
||||
sequence: readonly Readonly<{ kind: Surface; release: ReleaseName }>[],
|
||||
deployment: ReleaseDeployment = createReleaseFixture(["R10", "R11"]),
|
||||
): Promise<BootResult> {
|
||||
const pick = (kind: Surface) => {
|
||||
const entry = sequence.find((candidate) => candidate.kind === kind);
|
||||
if (!entry) throw new TypeError(`sequence has no ${kind} response`);
|
||||
return deployment.surface(entry.release, kind);
|
||||
};
|
||||
const html = pick("html");
|
||||
const buildId = /<meta name="build-id" content="([^"]+)"/u.exec(html.body)?.[1];
|
||||
const entryAsset = /src="(\/assets\/[^"]+)"/u.exec(html.body)?.[1];
|
||||
if (html.status !== 200 || !buildId || !entryAsset) {
|
||||
return { state: "boot-failed", applicationMounted: false };
|
||||
}
|
||||
try {
|
||||
const runtime = await loadRuntimeConfig({
|
||||
buildConfig: Object.freeze({
|
||||
buildId,
|
||||
commitSha: "abc123",
|
||||
routerBasePath: "/",
|
||||
runtimeConfigUrl: "/config.json",
|
||||
}),
|
||||
fetcher: async () => toFetchResponse(pick("config")),
|
||||
});
|
||||
const manifest = await loadReleaseManifest(runtime, {
|
||||
fetcher: async () => toFetchResponse(pick("manifest")),
|
||||
});
|
||||
const asset = await deployment.fetch(entryAsset);
|
||||
if (asset.status !== 200) {
|
||||
return { state: "asset-missing", applicationMounted: false };
|
||||
}
|
||||
return { state: "booted", applicationMounted: true, release: manifest.releaseId };
|
||||
} catch (error) {
|
||||
const key = releaseMismatchKey(error);
|
||||
return key === null
|
||||
? { state: "boot-failed", applicationMounted: false }
|
||||
: { state: "release-mismatch", applicationMounted: false, mismatchKey: key };
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Drives a browser session through repeated boots: a mismatch asks the
|
||||
* recovery policy, and `reload-once` triggers another boot. Returns how many
|
||||
* automatic reloads happened before the session settled.
|
||||
*/
|
||||
export async function runBootSession(
|
||||
nextSequence: () => readonly Readonly<{ kind: Surface; release: ReleaseName }>[],
|
||||
recovery: ReleaseMismatchRecovery,
|
||||
deployment?: ReleaseDeployment,
|
||||
maxBoots = 20,
|
||||
): Promise<Readonly<{ reloads: number; final: BootResult }>> {
|
||||
let reloads = 0;
|
||||
for (let boot = 0; boot < maxBoots; boot += 1) {
|
||||
const result = await bootAgainstReplicaSequence(nextSequence(), deployment);
|
||||
if (result.state === "booted") {
|
||||
recovery.markCoherentBoot();
|
||||
return { reloads, final: result };
|
||||
}
|
||||
if (result.mismatchKey !== undefined && recovery.decide(result.mismatchKey) === "reload-once") {
|
||||
reloads += 1;
|
||||
continue;
|
||||
}
|
||||
return { reloads, final: result };
|
||||
}
|
||||
throw new Error("boot session did not settle: reload loop");
|
||||
}
|
||||
|
||||
/** An in-memory session marker store for simulated browser sessions. */
|
||||
export function memoryStorage() {
|
||||
let marker: string | null = null;
|
||||
return {
|
||||
read: () => marker,
|
||||
write: (value: string) => {
|
||||
marker = value;
|
||||
},
|
||||
clear: () => {
|
||||
marker = null;
|
||||
},
|
||||
size: () => (marker === null ? 0 : 1),
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
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";
|
||||
|
||||
/**
|
||||
* Spec §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);
|
||||
}
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user