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)
This commit is contained in:
DongHyeonka
2026-11-12 08:28:54 +09:00
parent 585c62431a
commit c80320dfc7
738 changed files with 55027 additions and 13567 deletions
+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 });
}
+252
View File
@@ -0,0 +1,252 @@
import { spawnSync } from "node:child_process";
import {
cp,
mkdtemp,
readFile,
rename,
rm,
writeFile,
} from "node:fs/promises";
import { createServer, type Server } from "node:http";
import type { AddressInfo } from "node:net";
import { tmpdir } from "node:os";
import path from "node:path";
import { gzipSync } from "node:zlib";
import { linkFixtureNodeModules } from "../../../scripts/lib/fixture-node-modules.ts";
/**
* R3-6 test helper: two real production builds with the Service Worker on,
* and a static server that can switch which one it serves.
*
* The template ships with `serviceWorker: null`. The supported way to turn the
* worker on is the static capability selection in
* `src/features/installed-runtime-capabilities.ts` (`mode: "ACTIVE"` with the
* `PWA_STATIC_ASSETS` handler); `scripts/build-frontend.ts` then runs the
* two-pass worker build. Runtime Config can only disable it. So the helper
* copies the repo to a temp dir, edits the selection there, and runs the
* repo's own build scripts twice with different `VITE_BUILD_ID`s. The working
* tree and its `dist` (served by the e2e preview server) are never touched.
*
* The app composes the worker host but nothing subscribes to it yet, and it is
* not reachable from outside. The copy therefore also wraps
* `createServiceWorkerRuntimeHost` so the page records the host's own
* `onUpdateWaiting` / `onReloadRequired` callbacks and `start()` outcome on
* `globalThis.__caServiceWorkerTest`. Only the temp copy is edited.
*/
const repoRoot = path.resolve(import.meta.dirname, "../../..");
const skipped = new Set([
"node_modules",
".git",
".claude",
".generated",
"dist",
"artifacts",
"graphify-out",
]);
export type BuildName = "a" | "b";
export type ServiceWorkerBuilds = Readonly<{
root: string;
dist: Readonly<Record<BuildName, string>>;
}>;
export const ACTIVE_SELECTION = `const SERVICE_WORKER: InstalledServiceWorkerSelection | null = {
mode: "ACTIVE",
scriptPath: "service-worker.js",
handlers: ["PWA_STATIC_ASSETS"],
};`;
const HOST_PROBE = `
export function createServiceWorkerRuntimeHost(
input: ServiceWorkerHostInput,
): ServiceWorkerRuntimeHost | null {
const host = createServiceWorkerRuntimeHostUnobserved(input);
if (!host) return host;
const events: string[] = [];
host.onUpdateWaiting(() => events.push("update-waiting"));
host.onReloadRequired(() => events.push("reload-required"));
const observed: ServiceWorkerRuntimeHost = Object.freeze({
...host,
start: async () => {
const outcome = await host.start();
events.push("start:" + JSON.stringify(outcome));
return outcome;
},
});
Object.assign(globalThis, { __caServiceWorkerTest: { host: observed, events } });
return observed;
}
`;
export async function replaceOnce(
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}`,
);
}
}
/**
* `beforeBuild` edits the temp copy right before build `name` (06-03: a
* broken worker A, then a `REMOVE_REGISTRATION` release B). Edits persist
* into the later build.
*/
export async function prepareServiceWorkerBuilds(
options: Readonly<{
beforeBuild?: (name: BuildName, root: string) => Promise<void>;
}> = {},
): Promise<ServiceWorkerBuilds> {
const root = await mkdtemp(path.join(tmpdir(), "ca-sw-builds-"));
await cp(repoRoot, root, {
recursive: true,
filter: (source) =>
!skipped.has(path.relative(repoRoot, source).split(path.sep)[0]!),
});
await linkFixtureNodeModules(root, repoRoot);
await replaceOnce(
path.join(root, "src/features/installed-runtime-capabilities.ts"),
"const SERVICE_WORKER: InstalledServiceWorkerSelection | null = null;",
ACTIVE_SELECTION,
);
const hostFile = path.join(root, "src/bootstrap/register-service-worker.ts");
await replaceOnce(
hostFile,
"export function createServiceWorkerRuntimeHost(",
"function createServiceWorkerRuntimeHostUnobserved(",
);
await writeFile(hostFile, (await readFile(hostFile, "utf8")) + HOST_PROBE);
const dist = { a: path.join(root, "dist-a"), b: path.join(root, "dist-b") };
for (const name of ["a", "b"] as const) {
await options.beforeBuild?.(name, root);
run(root, "scripts/generate-product-feature-index.ts", `sw-e2e-${name}`);
run(root, "scripts/build-frontend.ts", `sw-e2e-${name}`);
await rename(path.join(root, "dist"), dist[name]);
}
return { root, dist };
}
export async function removeServiceWorkerBuilds(
builds: ServiceWorkerBuilds | undefined,
): Promise<void> {
if (builds) await rm(builds.root, { recursive: true, force: true });
}
export type AssetHeaders = Readonly<{
/** Sent for every `.js` file, the worker script included. */
javascriptContentType: string;
/** gzip every `/assets/*` body; Content-Length is the compressed size. */
gzip: boolean;
}>;
export type ServedResponse = Readonly<{
path: string;
contentType: string;
contentEncoding: string | null;
contentLength: number;
decodedLength: number;
}>;
const CONTENT_TYPES: Readonly<Record<string, string>> = {
".html": "text/html; charset=utf-8",
".css": "text/css",
".json": "application/json",
".svg": "image/svg+xml",
".png": "image/png",
".webp": "image/webp",
".woff2": "font/woff2",
};
/**
* Serves one dist directory at a time from an ephemeral 127.0.0.1 port, so
* every test gets its own origin (and its own Service Worker registration).
* Paths without an extension get `index.html`; a missing file is a plain 404,
* never the SPA fallback, so a chunk that the served build lacks really 404s.
*/
export async function startBuildServer(
dist: Readonly<Record<BuildName, string>>,
headers: AssetHeaders = {
javascriptContentType: "text/javascript",
gzip: false,
},
) {
let current: BuildName = "a";
const served: ServedResponse[] = [];
const server: Server = createServer((request, response) => {
void (async () => {
const pathname = decodeURIComponent(
new URL(request.url ?? "/", "http://127.0.0.1").pathname,
);
const root = dist[current];
const file = path.extname(pathname)
? path.join(root, path.normalize(pathname))
: path.join(root, "index.html");
let body: Buffer;
try {
if (!file.startsWith(root + path.sep)) throw new Error("outside root");
body = await readFile(file);
} catch {
response.writeHead(404, { "cache-control": "no-store" }).end();
return;
}
const extension = path.extname(file);
const contentType =
extension === ".js"
? headers.javascriptContentType
: (CONTENT_TYPES[extension] ?? "application/octet-stream");
const encoded = headers.gzip && pathname.startsWith("/assets/");
const payload = encoded ? gzipSync(body) : body;
served.push({
path: pathname,
contentType,
contentEncoding: encoded ? "gzip" : null,
contentLength: payload.byteLength,
decodedLength: body.byteLength,
});
response
.writeHead(200, {
"content-type": contentType,
"content-length": String(payload.byteLength),
"cache-control": "no-cache",
...(encoded
? { "content-encoding": "gzip", vary: "Accept-Encoding" }
: {}),
})
.end(request.method === "HEAD" ? undefined : payload);
})();
});
await new Promise<void>((resolve) =>
server.listen(0, "127.0.0.1", () => resolve()),
);
const { port } = server.address() as AddressInfo;
return {
origin: `http://127.0.0.1:${port}`,
served,
serve(name: BuildName) {
current = name;
},
async close() {
server.closeAllConnections();
await new Promise<void>((resolve) => server.close(() => resolve()));
},
};
}