소유자 결정(2026-11-07, design-docs repo-structure/README.md 3.4절)으로 템플릿 샘플을 지운다. 샘플이 맡던 시험 대상은 앞 커밋들이 옮겼다. 참조 기능과 예제 화면, 두 context, 그 시험, e2e 3개, 수동 접근성 기록 7개, 런타임 프로필 키, test:reference-feature(명령, 산출물, 게이트 참조), 커버리지 정책 행을 지웠다. removable-template-features 목록은 비우고 장치는 남겼다: test:sample-removal은 인자가 없으면 목록을 하나씩 지우고, 비면 SKIP을 출력하고 보고서에 건너뛴 사례를 남긴다. 기능 스위치 시험과 홈 시작 링크 스위치 시험은 시험 전용 fixture 기능으로 옮겼다. browser soak은 생성 기능을 넣은 빌드에서 돈다. 문서의 샘플 경로를 고쳤다. 날짜가 붙은 설계·리뷰 기록의 본문은 그대로 두었다. 레지스트리 기준선(update:registry-baseline, OWNER DongHyeonka), CI 계약 기준선과 workflow, 초기 JS 기록(194,354B, 17파일, 첫 기능 6,327B, 기능 539B, context 4B)을 다시 받았다. 위험: 레지스트리 행 삭제는 breaking이다. 샘플을 고쳐 쓰는 다운스트림은 수정/삭제 충돌을 만난다. 성능 lab의 기능 라우트 측정은 템플릿에 공개 기능 라우트가 없어 measured:false다. TEMPLATE_FIXTURE 출처는 플랫폼 코드에 남았다. 검증(desktop): check:types, lint, check:architecture, check:registries, check:ci, verify:documentation, test:unit, test:component, test:contract, test:integration, test:recipes, test:coverage(Risk coverage PASS 378/378, 문턱 68개), test:e2e 183, test:a11y, test:visual, test:storybook, test:browser-capabilities, test:feature-scaffold PASS(76 checks), test:sample-removal SKIP, build, check:bundle.
262 lines
9.8 KiB
TypeScript
262 lines
9.8 KiB
TypeScript
import { appendFile, readFile } from "node:fs/promises";
|
|
import path from "node:path";
|
|
|
|
import type { RouteDefinition } from "../../src/contracts/routes.ts";
|
|
import {
|
|
ROUTE_REGISTRY,
|
|
ROUTE_RUNTIME_CONTRACT,
|
|
} 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 {
|
|
addGeneratedFeature,
|
|
generatedFeature,
|
|
} from "../../scripts/lib/generated-feature.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.
|
|
*/
|
|
|
|
// 1103/09-04. The platform overview is a platform route; a feature route is
|
|
// reached through its context gateway. The template has no feature, so both
|
|
// builds carry the one `create:feature` writes (scripts/lib/generated-feature.ts)
|
|
// and the second page is its list. The page sources are read from build A's
|
|
// Vite manifest, so this spec names no feature folder.
|
|
const installedRoutes: Readonly<Record<string, RouteDefinition>> = ROUTE_REGISTRY;
|
|
const runtimeContracts: Readonly<Record<string, { moduleId: string }>> =
|
|
ROUTE_RUNTIME_CONTRACT;
|
|
function installedRoute(routeId: string): RouteDefinition {
|
|
const definition = installedRoutes[routeId];
|
|
if (!definition) throw new Error(`${routeId} is not installed.`);
|
|
return definition;
|
|
}
|
|
type ChunkRoute = Readonly<{
|
|
path: string;
|
|
chunkId: string;
|
|
moduleId: string;
|
|
navigationLabel: string;
|
|
title: string;
|
|
}>;
|
|
const platformRoute = installedRoute("EXAMPLES_PLATFORM");
|
|
const PLATFORM: ChunkRoute = Object.freeze({
|
|
path: platformRoute.path,
|
|
chunkId: platformRoute.chunkId,
|
|
moduleId: runtimeContracts[platformRoute.routeId]!.moduleId,
|
|
navigationLabel: platformRoute.navigationLabel!,
|
|
title: platformRoute.title,
|
|
});
|
|
/** The generated feature's list, read from build A's copy. */
|
|
let featureList: ChunkRoute | undefined;
|
|
function FEATURE(): ChunkRoute {
|
|
if (!featureList) throw new Error("Fixture builds were not prepared.");
|
|
return featureList;
|
|
}
|
|
|
|
type ViteManifest = Record<
|
|
string,
|
|
{
|
|
file: string;
|
|
name?: string;
|
|
isDynamicEntry?: boolean;
|
|
imports?: string[];
|
|
dynamicImports?: string[];
|
|
}
|
|
>;
|
|
|
|
async function viteManifest(dist: string): Promise<ViteManifest> {
|
|
return JSON.parse(
|
|
await readFile(path.join(dist, ".vite/manifest.json"), "utf8"),
|
|
) as ViteManifest;
|
|
}
|
|
|
|
/** The source of a route's page: the dynamic entry named by its module id. */
|
|
function pageSource(manifest: ViteManifest, route: ChunkRoute): string {
|
|
const sources = Object.entries(manifest)
|
|
.filter(([, entry]) => entry.isDynamicEntry && entry.name === route.moduleId)
|
|
.map(([source]) => source);
|
|
if (sources.length !== 1) {
|
|
throw new Error(`Expected one page chunk for ${route.moduleId}: ${sources.join(", ")}`);
|
|
}
|
|
return sources[0]!;
|
|
}
|
|
|
|
/** The context routes module that lazy-loads `page`. */
|
|
function routesSource(manifest: ViteManifest, page: string): string {
|
|
const sources = Object.entries(manifest)
|
|
.filter(([, entry]) => entry.isDynamicEntry && entry.dynamicImports?.includes(page))
|
|
.map(([source]) => source);
|
|
if (sources.length !== 1) {
|
|
throw new Error(`Expected one routes module for ${page}: ${sources.join(", ")}`);
|
|
}
|
|
return sources[0]!;
|
|
}
|
|
|
|
let builds: FixtureBuilds<"a" | "b"> | undefined;
|
|
|
|
test.beforeAll(async () => {
|
|
test.setTimeout(300_000);
|
|
builds = await prepareFixtureBuilds("chunk-recovery", [
|
|
{
|
|
name: "a",
|
|
edit: async (root) => {
|
|
await addGeneratedFeature(root);
|
|
const { list, messages } = generatedFeature(root);
|
|
featureList = Object.freeze({
|
|
...list,
|
|
navigationLabel: messages["ko-KR"][`route.${list.routeId}.navigation`]!,
|
|
title: messages["ko-KR"][`route.${list.routeId}.title`]!,
|
|
});
|
|
},
|
|
},
|
|
{
|
|
name: "b",
|
|
edit: async (root) => {
|
|
const manifest = await viteManifest(path.join(root, "dist-a"));
|
|
for (const route of [PLATFORM, FEATURE()]) {
|
|
await appendFile(
|
|
path.join(root, pageSource(manifest, route)),
|
|
'\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 chunk fails its request and the dynamic import. Chromium may
|
|
// also log the 404 itself (without its URL), Firefox logs the error object
|
|
// React caught, and WebKit logs its own import error without the URL. Nothing
|
|
// else is allowed, but for the WebKit warning below. 1103/09-04: the B tab
|
|
// misses the feature's context routes module before its page: that module
|
|
// names B's new page chunk, so its hash changed too.
|
|
function missingPageFailures(): string[] {
|
|
const missingPage = String.raw`/assets/(?:${PLATFORM.moduleId}|${FEATURE().moduleId}|context-routes)-[\w-]+\.js`;
|
|
return [
|
|
String.raw`^requestfailed:GET:${missingPage}:`,
|
|
String.raw`^console:error:TypeError: Failed to fetch dynamically imported module: http://127\.0\.0\.1:\d+${missingPage}$`,
|
|
String.raw`^console:error:\[JavaScript Error: "Loading module from “http://127\.0\.0\.1:\d+${missingPage}” 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$`,
|
|
String.raw`^console:error:TypeError: Importing a module script failed\.$`,
|
|
String.raw`^preloadunused:${missingPage}$`,
|
|
];
|
|
}
|
|
|
|
/** The chunks Vite preloads with `page`: its static imports in `dist`. */
|
|
async function preloadedWith(dist: string, page: string): Promise<string[]> {
|
|
const manifest = await viteManifest(dist);
|
|
if (!manifest[page]) throw new Error(`${page} is not in ${dist}'s manifest.`);
|
|
const files = new Set<string>();
|
|
const pending = [...(manifest[page].imports ?? [])];
|
|
for (let key = pending.pop(); key !== undefined; key = pending.pop()) {
|
|
const entry = manifest[key];
|
|
if (!entry || files.has(entry.file)) continue;
|
|
files.add(entry.file);
|
|
pending.push(...(entry.imports ?? []));
|
|
}
|
|
return [...files];
|
|
}
|
|
|
|
// 1103/11-09. Vite preloads a chunk together with the chunks it imports, so a
|
|
// missing chunk leaves itself and the chunks preloaded with it unused: in the
|
|
// A tab those of A's platform page (the tab is still on A while recovery
|
|
// reads the release manifest), in the B tab those of B's context routes
|
|
// module for the feature's list page. The fixture's preload check reports them in every
|
|
// engine (WebKit's own three-second warning only did when its timer ran
|
|
// before the test ended). They are the provoked failure's own effect; only
|
|
// those chunks are allowed.
|
|
test.use({
|
|
allowedBrowserFailure: async ({ browserName: _engine }, provide) => {
|
|
if (!builds) throw new Error("Fixture builds were not prepared.");
|
|
const aManifest = await viteManifest(builds.dist.a);
|
|
const bManifest = await viteManifest(builds.dist.b);
|
|
const files = [
|
|
...(await preloadedWith(builds.dist.a, pageSource(aManifest, PLATFORM))),
|
|
...(await preloadedWith(
|
|
builds.dist.b,
|
|
routesSource(bManifest, pageSource(bManifest, FEATURE())),
|
|
)),
|
|
].map((file) => file.replaceAll(".", String.raw`\.`));
|
|
await provide(
|
|
new RegExp(
|
|
[
|
|
...missingPageFailures(),
|
|
String.raw`^preloadunused:/(?:${files.join("|")})$`,
|
|
].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 bFeature = await routeChunk(builds.dist.b, FEATURE().chunkId);
|
|
expect(bPlatform).not.toBe(aPlatform);
|
|
expect(bFeature).not.toBe(await routeChunk(builds.dist.a, FEATURE().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: FEATURE().navigationLabel, exact: true }).click();
|
|
|
|
await expect(page.getByRole("alert")).toContainText(
|
|
"화면 자산을 복구하지 못했습니다.",
|
|
);
|
|
expect(loads).toBe(1);
|
|
expect(page.url()).toBe(`${server.origin}${FEATURE().path}`);
|
|
} finally {
|
|
await server.close();
|
|
}
|
|
});
|