Merge lane/J: test system (10-02, 10-04~10-07, 11-04~11-08, F-2, F-4, F-12, 00-03)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
donghyeon-ka
2026-09-27 13:28:55 +09:00
co-authored by Claude Opus 5.5
43 changed files with 1908 additions and 172 deletions
+59
View File
@@ -0,0 +1,59 @@
import path from "node:path";
import { expect, test } from "../support/browser/strict-browser-test.ts";
import {
editOnce,
prepareFixtureBuilds,
removeFixtureBuilds,
type FixtureBuilds,
} from "./support/fixture-builds.ts";
import { startBuildServer } from "./support/service-worker-builds.ts";
/**
* 09-03 (F-2). A production build whose application graph throws while its
* modules evaluate: the installed features are composed twice, so
* `installed-feature-messages.ts` meets every message key a second time and
* throws at module top level. The static "loading" shell used to stay up
* forever; the boot error shell has to replace it.
*/
let builds: FixtureBuilds<"broken"> | undefined;
test.beforeAll(async () => {
test.setTimeout(300_000);
builds = await prepareFixtureBuilds("boot-module-failure", [
{
name: "broken",
edit: (root) =>
editOnce(
path.join(root, "src/features/installed-feature-messages.ts"),
"composeInstalledMessageCatalogs(\n INSTALLED_PRODUCT_FEATURE_MODULES,\n)",
"composeInstalledMessageCatalogs([\n ...INSTALLED_PRODUCT_FEATURE_MODULES,\n ...INSTALLED_PRODUCT_FEATURE_MODULES,\n])",
),
},
]);
});
test.afterAll(async () => {
await removeFixtureBuilds(builds);
});
test("shows the boot error shell when a module throws while it evaluates", async ({
page,
}) => {
if (!builds) throw new Error("Fixture build was not prepared.");
const broken = builds.dist.broken;
const server = await startBuildServer({ a: broken, b: broken });
try {
await page.goto(`${server.origin}/`);
const shell = page.getByRole("alert");
await expect(shell).toContainText("애플리케이션을 시작할 수 없습니다.");
await expect(shell).toContainText("BOOT_UNEXPECTED_FAILURE");
await expect(shell).toContainText("TypeError");
await expect(shell).toContainText("boot-module-failure-broken");
await expect(page.locator("[data-boot-shell]")).toHaveCount(0);
} finally {
await server.close();
}
});
+125
View File
@@ -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<string, unknown>).__caFixtureBuild = "b";\n',
);
}
},
},
]);
});
test.afterAll(async () => {
await removeFixtureBuilds(builds);
});
async function routeChunk(dist: string, chunkId: string): Promise<string> {
const manifest = JSON.parse(
await readFile(path.join(dist, "release-manifest.json"), "utf8"),
) as { routeChunks: Record<string, string> };
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<string, unknown>).__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();
}
});
+2
View File
@@ -29,4 +29,6 @@ test("opens the protected integration route through the local demo seam", async
page.getByRole("heading", { name: protectedRoute.title }),
).toBeVisible();
await expect(page.getByText("인증됨")).toBeVisible();
// The mocked row went through the production codec, mapper and query cache.
await expect(page.getByText("Browser reference")).toBeVisible();
});
+100
View File
@@ -0,0 +1,100 @@
import type { Page, Route } from "@playwright/test";
import { expect, test } from "../support/browser/strict-browser-test.ts";
const CREATE_URL = "http://localhost:8080/api/reference-resources";
type CreateCall = Readonly<{ name: unknown; idempotencyKey: string | null }>;
async function openForm(page: Page) {
await page.route(`${CREATE_URL}?*`, (route) => route.fulfill({ json: [] }));
await page.goto("/examples/reference-resources/new");
await page.getByRole("button", { name: "로그인 시작" }).click();
await expect(
page.getByRole("heading", { name: "Reference resource 만들기" }),
).toBeVisible();
}
/** Answers each POST with the next responder and records what was sent. */
async function routeCreate(
page: Page,
responders: readonly ((route: Route) => Promise<void>)[],
): Promise<CreateCall[]> {
const calls: CreateCall[] = [];
await page.route(CREATE_URL, async (route) => {
const request = route.request();
if (request.method() !== "POST") return route.fallback();
calls.push({
name: (request.postDataJSON() as { name?: unknown }).name,
idempotencyKey: await request.headerValue("idempotency-key"),
});
const respond = responders[calls.length - 1];
if (!respond) throw new Error(`unexpected create call ${calls.length}`);
await respond(route);
});
return calls;
}
const created = (route: Route) =>
route.fulfill({
status: 201,
json: {
id: "browser-created",
name: "Saved in the browser",
createdAt: "2026-07-26T00:00:00.000Z",
},
});
test("saves a new reference resource through the production command path", async ({
page,
}) => {
await openForm(page);
const calls = await routeCreate(page, [created]);
await page
.getByRole("textbox", { name: /새 항목 이름/ })
.fill("Saved in the browser");
await page.getByRole("button", { name: "저장" }).click();
await expect(page.getByRole("status")).toHaveText("저장했습니다.");
expect(calls).toHaveLength(1);
expect(calls[0]?.name).toBe("Saved in the browser");
expect(calls[0]?.idempotencyKey).toBeTruthy();
});
test.describe("after a rate-limited save", () => {
// Chromium and WebKit log a 4xx fetch response to the console, and the
// client cancels the 429 body unread, which Chromium reports as aborted.
test.use({
allowedBrowserFailure:
/^console:error:.*status of 429|^requestfailed:POST:\/api\/reference-resources:net::ERR_ABORTED$/u,
});
test("keeps the input and saves on retry", async ({ page }) => {
await openForm(page);
const calls = await routeCreate(page, [
(route) =>
route.fulfill({
status: 429,
headers: { "retry-after": "1" },
json: { title: "Too many requests" },
}),
created,
]);
const name = page.getByRole("textbox", { name: /새 항목 이름/ });
await name.fill("Saved in the browser");
await page.getByRole("button", { name: "저장" }).click();
await expect(
page.getByText("요청이 많습니다. 잠시 후 다시 시도해 주세요."),
).toBeVisible();
await expect(name).toHaveValue("Saved in the browser");
await page.getByRole("button", { name: "다시 시도" }).click();
await expect(page.getByRole("status")).toHaveText("저장했습니다.");
expect(calls.map((call) => call.name)).toEqual([
"Saved in the browser",
"Saved in the browser",
]);
});
});
+97
View File
@@ -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<Name extends string> = Readonly<{
name: Name;
edit?: (root: string) => Promise<void>;
}>;
export type FixtureBuilds<Name extends string> = Readonly<{
root: string;
dist: Readonly<Record<Name, string>>;
}>;
/** Replaces the one occurrence of `search` in `file` of the copy. */
export async function editOnce(
file: string,
search: string,
replacement: string,
): Promise<void> {
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<Name extends string>(
prefix: string,
builds: readonly FixtureBuild<Name>[],
): Promise<FixtureBuilds<Name>> {
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<Name, string>;
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<void> {
if (builds) await rm(builds.root, { recursive: true, force: true });
}