Files
clean-architecture-frontend…/tests/unit/product-feature-selection-build.test.ts
T
DongHyeonka 799ab7f667 fix(dev): dev manifest를 기능 생성·제거 때 다시 쓰는 커밋 파일로 둔다
문제
c15345c·db5728b·0eba082의 dev 전용 Vite 미들웨어(dev server가 설치된
기능의 contract set으로 manifest를 냄)를 넣은 뒤로, dev server를 쓰는
capability e2e가 "requestfailed:GET:/release-manifest.json:net::ERR_ABORTED"로
떨어졌다. 같은 호스트에서 번갈아 쟀다: 미들웨어 있음 5/30·2/30 실패, 없음
0/30·0/30(부하가 더 높았다). trace에서는 첫 manifest 요청이 200 헤더 뒤
끊기고 65 ms 뒤 두 번째 요청이 성공한다. 원인을 끝까지 좁히지는 못했다.
감시 이벤트(파일 쓰기)를 없애도 같았다.

고른 방법
- 미들웨어를 지운다. dev server는 커밋된 public/release-manifest.json을
  그대로 낸다.
- 그 파일의 contractSet을 설치된 기능으로 다시 쓰는 일을 명시적 단계로
  둔다: `create:feature`가 생성 뒤 scripts/write-dev-release-manifest.ts를
  돌리고, 기능 제거 드릴이 지운 뒤 돌린다. 매뉴얼의 되돌리기·기능 지우기
  절과 errors.md에 같은 명령을 적었다. 레지스트리 기준선과 같은 방식이다.
- tests/unit/dev-release-manifest.test.ts가 커밋된 파일이 설치된 기능의
  contract set과 같은지 보고, 다르면 다시 쓰는 명령을 말한다.
- 함께: vite.config.ts가 artifacts/·dist/·.tmp/를 감시하지 않는다.
  Playwright trace의 .html이 열린 페이지를 모두 다시 불러오게 했다(dev
  server 로그의 page reload).
- 버린 대안: dev 부팅에서 contract set 검사 건너뛰기. 검사하는 테스트와
  같은 조건을 dev만 따로 두게 된다.

위험·한계
- 기능을 손으로 지우고 명령을 잊으면 dev server가 부팅하지 못한다.
  test:unit이 그 상태를 이름과 명령으로 알린다.

검증
- test:unit 2,880건, dev-release-manifest·create-feature 테스트 45건,
  check:types, lint, verify:documentation 통과.
- 생성 기능을 넣은 clone의 dev capability e2e와 merge 단계 14개는 이 커밋
  뒤 깨끗한 clone에서 돈다.

Refs: docs/reviews/2026-11-03-maturity-review/README.md 14.5 14.6 X2 #3, 16-09
2026-11-05 03:30:56 +09:00

102 lines
4.4 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);
const FEATURE_MODULE = /^src\/(?:features\/[^/]+|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/loaded-feature-runtimes.ts")).href
)) as typeof import("../../src/features/loaded-feature-runtimes.ts");
expect(contributions.INSTALLED_CONTRACT_CONTRIBUTIONS).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);
});