Files
tech-log-frontend/tests/e2e/service-worker-recovery.spec.ts
T
DongHyeonka c80320dfc7 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 at 8210d48.

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 at
8210d48 first 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)
2026-11-12 08:28:54 +09:00

152 lines
4.9 KiB
TypeScript

import path from "node:path";
import { expect, test, type Page } from "../support/browser/strict-browser-test.ts";
import {
ACTIVE_SELECTION,
prepareServiceWorkerBuilds,
removeServiceWorkerBuilds,
replaceOnce,
startBuildServer,
type ServiceWorkerBuilds,
} from "./support/service-worker-builds.ts";
/**
* 06-03 (D-5). The emergency exit for a worker that stops the page from
* booting. Page code cannot help then: the page never runs. Build A is the
* ACTIVE worker with its fetch handler broken (every intercepted request is a
* network error, the entry script included). Build B is a
* `REMOVE_REGISTRATION` release, which ships the self-unregistering
* `service-worker.js` (`scripts/lib/self-unregistering-service-worker.ts`).
* The browser's update check alone replaces A with it, and the next load boots
* B from the network.
*/
type Probe = typeof globalThis & {
__caServiceWorkerTest?: { events: string[] };
};
let builds: ServiceWorkerBuilds | undefined;
test.beforeAll(async () => {
test.setTimeout(180_000);
builds = await prepareServiceWorkerBuilds({
async beforeBuild(name, root) {
if (name === "a") {
await replaceOnce(
path.join(root, "src/adapters/service-worker/service-worker-entry.ts"),
"runtime.onFetch(described).then((cached) => cached ?? fetch(request)),",
"Promise.resolve(Response.error()),",
);
return;
}
await replaceOnce(
path.join(root, "src/features/installed-runtime-capabilities.ts"),
ACTIVE_SELECTION,
`const SERVICE_WORKER: InstalledServiceWorkerSelection | null = {
mode: "REMOVE_REGISTRATION",
scriptPath: "service-worker.js",
};`,
);
},
});
});
test.afterAll(async () => {
await removeServiceWorkerBuilds(builds);
});
async function startOutcome(page: Page): Promise<unknown> {
await page.waitForFunction(
() =>
(globalThis as Probe).__caServiceWorkerTest?.events.some((event) =>
event.startsWith("start:"),
) === true,
undefined,
{ timeout: 60_000 },
);
const event = await page.evaluate(() =>
(globalThis as Probe).__caServiceWorkerTest!.events.find((entry) =>
entry.startsWith("start:"),
)!,
);
return JSON.parse(event.slice("start:".length));
}
test("a REMOVE_REGISTRATION release unregisters a worker that blocks boot", async ({
browser,
browserName,
}) => {
// Same quarantine as service-worker-update.spec.ts.
// quarantine(owner=frontend-platform, defect=playwright-firefox-no-sw-control, expires=2027-03-31)
test.skip(
browserName === "firefox",
"Playwright Firefox pages are never controlled by a service worker.",
);
if (!builds) throw new Error("Service Worker builds were not prepared.");
const server = await startBuildServer(builds.dist);
// The broken phase fails requests on purpose, so this test drives its own
// context instead of the strict `page` fixture and checks the recovered
// load for browser errors itself.
const context = await browser.newContext();
try {
const page = await context.newPage();
await page.goto(`${server.origin}/`);
expect(await startOutcome(page)).toEqual({ kind: "RELOAD_TO_ENABLE" });
await page.evaluate(async () => {
await navigator.serviceWorker.ready;
});
// Worker A controls the next load and fails the entry script.
await page.goto(`${server.origin}/`);
const blocked = await page.evaluate(async () => {
const entry = document.querySelector<HTMLScriptElement>(
'script[type="module"][src]',
);
if (!entry) return "no entry script";
try {
await fetch(entry.src);
return "loaded";
} catch {
return navigator.serviceWorker.controller ? "blocked" : "uncontrolled";
}
});
expect(blocked).toBe("blocked");
// Release B. Only the browser's update check runs; no code of B does.
server.serve("b");
await page.evaluate(async () => {
await (await navigator.serviceWorker.getRegistration())?.update();
});
await expect
.poll(
() =>
page.evaluate(
async () =>
(await navigator.serviceWorker.getRegistration()) === undefined,
),
{ timeout: 30_000 },
)
.toBe(true);
const failures: string[] = [];
page.on("console", (message) => {
if (["error", "warning"].includes(message.type())) {
failures.push(`console:${message.type()}:${message.text()}`);
}
});
page.on("pageerror", (error) => failures.push(`pageerror:${error.name}`));
page.on("requestfailed", (request) =>
failures.push(`requestfailed:${new URL(request.url()).pathname}`),
);
await page.goto(`${server.origin}/`);
expect(await startOutcome(page)).toEqual({ kind: "DISABLED" });
expect(
await page.evaluate(() => navigator.serviceWorker.controller === null),
).toBe(true);
expect(failures).toEqual([]);
} finally {
await context.close();
await server.close();
}
});