Files
tech-log-frontend/tests/unit/product-feature-selection-build.test.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

110 lines
4.7 KiB
TypeScript

import { spawnSync } from "node:child_process";
import { cp, mkdir, mkdtemp, readFile, rm } from "node:fs/promises";
import { tmpdir } from "node:os";
import path from "node:path";
import { pathToFileURL } from "node:url";
import { afterAll, describe, expect, it } from "vitest";
import { linkFixtureNodeModules } from "../../scripts/lib/fixture-node-modules.ts";
import { filesBelow } from "../../scripts/lib/removal-fixture.ts";
import { ROUTE_FEATURE_OWNER } from "../../src/features/installed-feature-contracts.ts";
import { COMPILED_PRODUCT_FEATURE_IDS } from "../../src/features/installed-product-manifest.ts";
/**
* 09-02 (D-9). `VITE_PRODUCT_FEATURES=none` has to leave every feature out of
* every consumer, not only the browser bundle: the generated context index
* (router), the installed contract contributions (Node contract-set
* generation) and the built assets. This runs the production generator and a
* Vite build over a copy of the build inputs. Written against whatever
* features the tree declares, so it holds after the sample's removal too.
*/
const BUILD_INPUTS = [
"src",
"public",
"index.html",
"package.json",
"vite.config.ts",
"tsconfig.base.json",
"tsconfig.app.json",
"scripts/lib/vite-module-inventory.ts",
] as const;
// Feature ids stay: the generated index still declares them so the platform
// overview reports NOT_INSTALLED. Their modules and route ids go.
const FEATURE_ROUTE_IDS = Object.keys(ROUTE_FEATURE_OWNER);
// Template sync (af3d8e6). TechLog is composed directly, not selected by
// VITE_PRODUCT_FEATURES (src/features/tech-log/NOT_INSTALLED), so the
// selection governs every feature but it.
const DIRECT_FEATURE_ID = "tech-log";
const FEATURE_MODULE = /^src\/(?:features\/(?!tech-log\/)[^/]+|contexts\/[^/]+)\//u;
const roots: string[] = [];
afterAll(async () => {
await Promise.all(roots.map((root) => rm(root, { recursive: true, force: true })));
});
describe("VITE_PRODUCT_FEATURES=none build (09-02)", () => {
it("leaves every feature out of the context index, the contract set and dist", async () => {
const root = await mkdtemp(path.join(tmpdir(), "product-selection-build-"));
roots.push(root);
for (const input of BUILD_INPUTS) {
await mkdir(path.dirname(path.join(root, input)), { recursive: true });
await cp(path.resolve(input), path.join(root, input), { recursive: true });
}
await linkFixtureNodeModules(root);
const env = { ...process.env, VITE_PRODUCT_FEATURES: "none" };
const generated = spawnSync(
process.execPath,
[path.resolve("scripts/generate-product-feature-index.ts"), `--root=${root}`],
{ encoding: "utf8", env },
);
expect(generated.stderr).toBe("");
expect(generated.status).toBe(0);
const contextIndex = await readFile(
path.join(root, "src/.generated/product-context-index.ts"),
"utf8",
);
expect(contextIndex).not.toContain("../features/");
const contributions = (await import(
pathToFileURL(path.join(root, "src/features/installed-contract-contributions.ts")).href
)) as typeof import("../../src/features/installed-contract-contributions.ts");
expect(
contributions.INSTALLED_CONTRACT_CONTRIBUTIONS.filter(
(contribution) => contribution.featureId !== DIRECT_FEATURE_ID,
),
).toEqual([]);
const manifest = (await import(
pathToFileURL(path.join(root, "src/features/installed-product-manifest.ts")).href
)) as typeof import("../../src/features/installed-product-manifest.ts");
expect(manifest.INSTALLED_PRODUCT_FEATURE_IDS).toEqual([]);
// Still declared, so the platform overview reports them as NOT_INSTALLED.
expect(manifest.COMPILED_PRODUCT_FEATURE_IDS).toEqual(COMPILED_PRODUCT_FEATURE_IDS);
const built = spawnSync(
path.resolve("node_modules/.bin/vite"),
["build", "--logLevel", "error"],
{ cwd: root, encoding: "utf8", env },
);
expect(built.stderr).toBe("");
expect(built.status).toBe(0);
const residue: string[] = [];
for (const file of await filesBelow(path.join(root, "dist"))) {
if (!/\.(?:js|css|html)$/u.test(file)) continue;
const content = await readFile(file, "utf8");
for (const routeId of FEATURE_ROUTE_IDS) {
if (content.includes(routeId)) residue.push(`${path.relative(root, file)}: ${routeId}`);
}
}
expect(residue).toEqual([]);
const inventory = JSON.parse(
await readFile(path.join(root, "dist/.vite/module-inventory.json"), "utf8"),
) as { chunks: { modules: string[] }[] };
const modules = inventory.chunks.flatMap((chunk) => chunk.modules);
expect(modules).toContain("src/features/installed-product-manifest.ts");
expect(modules.filter((module) => FEATURE_MODULE.test(module))).toEqual([]);
}, 120_000);
});