diff --git a/docs/reviews/2026-09-23-extreme-scale-acceptance.md b/docs/reviews/2026-09-23-extreme-scale-acceptance.md index b12c2e43..264c9935 100644 --- a/docs/reviews/2026-09-23-extreme-scale-acceptance.md +++ b/docs/reviews/2026-09-23-extreme-scale-acceptance.md @@ -20,7 +20,7 @@ Plan bundle: `docs/reviews/2026-09-23-extreme-scale-frontend-plan-bundle/`. One | 14 | Telemetry failure does not fail business behavior. | 완료 | `tests/platform/telemetry/telemetry-pipeline.test.ts` (transport throw/reject); `tests/platform/telemetry/telemetry-port.test.ts` (`failOpenTelemetryPort`); `tests/features/reference-feature/reference-telemetry.test.ts`; collector outage in `tests/scale/telemetry/telemetry-storm.test.ts` | | 15 | Failure boundaries prevent one feature/context from unnecessarily collapsing unrelated UI. | 완료 | `src/platform/errors/{scoped-error-boundary,feature-error-boundary,context-error-boundary}.tsx`; wiring in `src/presentation/routes/app-router.tsx`; `tests/platform/errors/failure-boundary.test.tsx` | | 16 | Spike and sustained-load tests detect request, retry, telemetry, and memory amplification. | 완료 | `tests/scale/traffic/*`, `tests/scale/telemetry/telemetry-storm.test.ts`, `tests/scale/session/*`; real Chromium soak `scripts/scale/browser-soak.ts` against the fresh build with telemetry on and a 503 API: 2,012 cycles, heap/listeners/timers/storage stable, 0 in-flight at end, 1.43 API requests per reference visit (≤ 3), telemetry ≤ 14 posts/min (≤ 40), checks in `artifacts/scale/nightly/browser-soak.json`; evaluator tests `tests/scale/browser-soak.contract.test.ts`; skipped ⇒ tier `incomplete` (non-zero). Platform telemetry adapter now send-rate limited (`src/adapters/telemetry/best-effort-telemetry.ts`, tests in `tests/unit/telemetry.test.ts`) | -| 17 | Multi-replica release tests verify fail-closed coherence and old-asset reachability. | 완료 | `src/platform/release/release-coherence.ts` (delegated to by `src/bootstrap/load-runtime-config.ts`, `src/bootstrap/load-release-manifest.ts`); `src/platform/release/release-mismatch-recovery.ts` + `src/bootstrap/boot-release-recovery.ts`; `tests/platform/release/*.test.ts`; `tests/release/{old-asset-reachability,mixed-replica,release-matrix}.test.ts`; `pnpm check:release-coherence` | +| 17 | Multi-replica release tests verify fail-closed coherence and old-asset reachability. | 완료 | `src/platform/release/release-coherence.ts` (delegated to by `src/bootstrap/load-runtime-config.ts`, `src/bootstrap/load-release-manifest.ts`); `src/platform/release/release-mismatch-recovery.ts` + `src/bootstrap/boot-release-recovery.ts`; `tests/platform/release/*.test.ts`; `tests/release/{mixed-replica,release-matrix}.test.ts`; `pnpm check:release-coherence`. Old-asset reachability is a hosting provider duty (`docs/operations/release-cache-rollback.md`); `tests/release/old-asset-reachability.test.ts` checks only the in-memory hosting fixture against `config/hosting/cache-policy.json`. An old tab of the default build (no Service Worker) whose chunk is gone after a deploy is checked in real browsers by `tests/e2e/old-tab-chunk-recovery.spec.ts`: one reload into the new build, no second reload (11-05) | Overall: **완료** — every spec §54 criterion is `완료`. diff --git a/tests/e2e/old-tab-chunk-recovery.spec.ts b/tests/e2e/old-tab-chunk-recovery.spec.ts new file mode 100644 index 00000000..73001f62 --- /dev/null +++ b/tests/e2e/old-tab-chunk-recovery.spec.ts @@ -0,0 +1,125 @@ +import { appendFile, readFile } from "node:fs/promises"; +import path from "node:path"; + +import { ROUTE_REGISTRY } from "../../src/features/installed-feature-contracts.ts"; +import { expect, test } from "../support/browser/strict-browser-test.ts"; +import { + prepareFixtureBuilds, + removeFixtureBuilds, + type FixtureBuilds, +} from "./support/fixture-builds.ts"; +import { startBuildServer } from "./support/service-worker-builds.ts"; + +/** + * 11-05. A tab opened on build A, in the default configuration (no Service + * Worker), after build B is deployed. B changes two lazy route pages, so their + * A chunks no longer exist on the server. The first missing chunk reloads the + * tab once, into B. A second missing chunk (the server alternates back to A, + * as mismatched replicas do) must not reload again: the tab shows the + * recovery failure instead. + */ + +const PLATFORM = ROUTE_REGISTRY.EXAMPLES_PLATFORM; +const UI = ROUTE_REGISTRY.EXAMPLES_UI; +const PAGES = [ + "src/presentation/examples/platform-overview-page.tsx", + "src/presentation/examples/ui-gallery-page.tsx", +] as const; + +let builds: FixtureBuilds<"a" | "b"> | undefined; + +test.beforeAll(async () => { + test.setTimeout(300_000); + builds = await prepareFixtureBuilds("chunk-recovery", [ + { name: "a" }, + { + name: "b", + edit: async (root) => { + for (const page of PAGES) { + await appendFile( + path.join(root, page), + '\n(globalThis as Record).__caFixtureBuild = "b";\n', + ); + } + }, + }, + ]); +}); + +test.afterAll(async () => { + await removeFixtureBuilds(builds); +}); + +async function routeChunk(dist: string, chunkId: string): Promise { + const manifest = JSON.parse( + await readFile(path.join(dist, "release-manifest.json"), "utf8"), + ) as { routeChunks: Record }; + return `/${manifest.routeChunks[chunkId]}`; +} + +// Each missing page chunk fails its request and the dynamic import. Chromium +// may also log the 404 itself (without its URL), and Firefox logs the error +// object React caught. Nothing else is allowed. +const MISSING_PAGE = String.raw`/assets/(?:platform-overview|ui-gallery)-page-[\w-]+\.js`; +test.use({ + allowedBrowserFailure: new RegExp( + [ + String.raw`^requestfailed:GET:${MISSING_PAGE}:`, + String.raw`^console:error:TypeError: Failed to fetch dynamically imported module: http://127\.0\.0\.1:\d+${MISSING_PAGE}$`, + String.raw`^console:error:\[JavaScript Error: "Loading module from “http://127\.0\.0\.1:\d+${MISSING_PAGE}” was blocked`, + String.raw`^console:error:Failed to load resource: the server responded with a status of 404 \(Not Found\)$`, + String.raw`^console:error:JSHandle@object$`, + ].join("|"), + "u", + ), +}); + +test("an old tab reloads once into the new build, then stops reloading", async ({ + page, +}) => { + if (!builds) throw new Error("Fixture builds were not prepared."); + const aPlatform = await routeChunk(builds.dist.a, PLATFORM.chunkId); + const bPlatform = await routeChunk(builds.dist.b, PLATFORM.chunkId); + const bUi = await routeChunk(builds.dist.b, UI.chunkId); + expect(bPlatform).not.toBe(aPlatform); + expect(bUi).not.toBe(await routeChunk(builds.dist.a, UI.chunkId)); + + const server = await startBuildServer(builds.dist); + try { + await page.goto(`${server.origin}/`); + await expect( + page.getByRole("link", { name: PLATFORM.navigationLabel!, exact: true }), + ).toBeVisible(); + let loads = 0; + page.on("load", () => { + loads += 1; + }); + + // Build B is deployed while the A tab stays open. + server.serve("b"); + await page + .getByRole("link", { name: PLATFORM.navigationLabel!, exact: true }) + .click(); + + await expect(page.getByRole("heading", { name: PLATFORM.title })).toBeVisible(); + expect(loads).toBe(1); + const served = server.served.map((entry) => entry.path); + expect(served).not.toContain(aPlatform); + expect(served).toContain(bPlatform); + await expect + .poll(() => page.evaluate(() => (globalThis as Record).__caFixtureBuild)) + .toBe("b"); + + // The replicas alternate: the B tab now meets A, which lacks B's chunk. + server.serve("a"); + await page.getByRole("link", { name: UI.navigationLabel!, exact: true }).click(); + + await expect(page.getByRole("alert")).toContainText( + "화면 자산을 복구하지 못했습니다.", + ); + expect(loads).toBe(1); + expect(page.url()).toBe(`${server.origin}${UI.path}`); + } finally { + await server.close(); + } +}); diff --git a/tests/e2e/support/fixture-builds.ts b/tests/e2e/support/fixture-builds.ts new file mode 100644 index 00000000..a29238a6 --- /dev/null +++ b/tests/e2e/support/fixture-builds.ts @@ -0,0 +1,97 @@ +import { spawnSync } from "node:child_process"; +import { cp, mkdtemp, readFile, rename, rm, writeFile } from "node:fs/promises"; +import { tmpdir } from "node:os"; +import path from "node:path"; + +import { linkFixtureNodeModules } from "../../../scripts/lib/fixture-node-modules.ts"; + +/** + * Real production builds of an edited temp copy of the repository, in the + * template's default configuration (`serviceWorker: null`). `edit` changes the + * copy right before that build runs, and edits persist into later builds. The + * working tree and its `dist` (served by the e2e preview server) are never + * touched. Serve the result with `startBuildServer` from + * `service-worker-builds.ts`. + */ + +const repoRoot = path.resolve(import.meta.dirname, "../../.."); +const skipped = new Set([ + "node_modules", + ".git", + ".claude", + ".generated", + ".tmp", + "dist", + "artifacts", + "graphify-out", +]); + +export type FixtureBuild = Readonly<{ + name: Name; + edit?: (root: string) => Promise; +}>; + +export type FixtureBuilds = Readonly<{ + root: string; + dist: Readonly>; +}>; + +/** Replaces the one occurrence of `search` in `file` of the copy. */ +export async function editOnce( + file: string, + search: string, + replacement: string, +): Promise { + const source = await readFile(file, "utf8"); + if (source.split(search).length !== 2) { + throw new Error(`Expected exactly one "${search}" in ${file}.`); + } + await writeFile(file, source.replace(search, replacement)); +} + +function run(cwd: string, script: string, buildId: string): void { + const result = spawnSync("node", [script], { + cwd, + encoding: "utf8", + env: { ...process.env, VITE_BUILD_ID: buildId, RELEASE_ID: buildId }, + }); + if (result.status !== 0) { + throw new Error( + `${script} failed for ${buildId}:\n${result.stdout}\n${result.stderr}`, + ); + } +} + +export async function prepareFixtureBuilds( + prefix: string, + builds: readonly FixtureBuild[], +): Promise> { + const root = await mkdtemp(path.join(tmpdir(), `${prefix}-`)); + try { + await cp(repoRoot, root, { + recursive: true, + filter: (source) => + !skipped.has(path.relative(repoRoot, source).split(path.sep)[0]!), + }); + await linkFixtureNodeModules(root, repoRoot); + const dist = {} as Record; + for (const build of builds) { + await build.edit?.(root); + const buildId = `${prefix}-${build.name}`; + run(root, "scripts/generate-product-feature-index.ts", buildId); + run(root, "scripts/build-frontend.ts", buildId); + dist[build.name] = path.join(root, `dist-${build.name}`); + await rename(path.join(root, "dist"), dist[build.name]); + } + return { root, dist }; + } catch (error) { + await rm(root, { recursive: true, force: true }); + throw error; + } +} + +export async function removeFixtureBuilds( + builds: Readonly<{ root: string }> | undefined, +): Promise { + if (builds) await rm(builds.root, { recursive: true, force: true }); +} diff --git a/tests/release/old-asset-reachability.test.ts b/tests/release/old-asset-reachability.test.ts index 2f6dcc62..a8852549 100644 --- a/tests/release/old-asset-reachability.test.ts +++ b/tests/release/old-asset-reachability.test.ts @@ -2,7 +2,15 @@ import { describe, expect, it } from "vitest"; import { CACHE_POLICY, createReleaseFixture } from "./release-fixture.ts"; -describe("old hashed-asset reachability", () => { +/** + * 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");