Files
clean-architecture-frontend…/tests/unit/example-feature-rules.test.ts
T
donghyeon.kang e902e657d1 test(layout): 저장소 배치 규칙 R3~R9를 검사로 두고 매뉴얼에 적는다
소유자가 2026-11-07에 지적한 것(매뉴얼이 생긴 뒤에도 남은 샘플, 역할이
겹치는 루트 폴더, 0파일 검사, 문서 속 인프라 설정)은 매뉴얼과 리뷰가
먼저 잡아야 했다. 지금은 그 규칙이 글로도 검사로도 없다. 그래서 같은
지적이 다시 나와도 게이트가 모른다.

고른 방법(design-docs repo-structure/04-frontend-layout.md 11절, 기계
검사가 「예」인 규칙을 표의 게이트 칸대로):
- R4·R5 `tests/unit/example-feature-rules.test.ts`(FE-GATE-005): 샘플
  목록은 FE-GATE-020의 `test:sample-removal`(인자 없이, 빌드와 test:all
  포함)이 증명한다. 목록 샘플의 기능 ID·라우트가 visual·e2e의 `goto`,
  gates.json 산출물 경로, `config/scale/`에 나오면 실패한다. 템플릿
  목록은 비어 있어 가짜 샘플로 판정 함수를 시험한다.
- R6·R7(문서) `verify:documentation`(FE-GATE-017): `docs/manual/`이 목록
  샘플 경로를 가리키면, 현재 문서에 ```nginx```·```hcl``` 블록이나
  `kind: Deployment` 같은 매니페스트 줄이 있으면 실패한다. 이력 폴더는
  보지 않는다. 산출물 `documentation-review.json`에
  `layoutRuleViolations`를 더했다.
- R7(파일)·R9 `tests/unit/repository-layout.test.ts`(FE-GATE-005):
  nginx·Terraform·Helm·Kustomize 파일과 Kubernetes 매니페스트 YAML이
  추적되면 실패. 옵션이 같은 tsconfig 쌍이 있으면 실패.
- R3은 `tests/unit/tracked-artifacts.test.ts`, R8은 앞 커밋의
  `check-typecheck-inputs.ts`·`check-type-fixtures.ts`가 맡는다. R10의
  기계 몫(루트 *.md 등록)은 R1이다.
- 매뉴얼 03에 E절(R1~R10 규칙과 검사, 루트 항목을 더하는 순서)과 C절
  「Web Worker를 들일 때 tsconfig 더하기」(결정 D4)를 더했다.

위험: R5는 문자열 검색이라 샘플 ID를 다르게 쓴 대상(예: 라우트 경로를
조립하는 spec)은 놓친다. R7 문서 검사는 코드 블록 언어 태그와 매니페스트
줄로만 본다. R13(리뷰 가이드)은 design-docs 몫이라 넣지 않았다.

검증(desktop): 이 커밋에서 test:unit, check:types, check:ci, lint,
verify:documentation, check:architecture를 돌렸다.

Refs: design-docs repo-structure/04-frontend-layout.md 11절, README.md 3.4절
2026-11-08 17:41:27 +09:00

127 lines
6.0 KiB
TypeScript

import { readdir, readFile } from "node:fs/promises";
import path from "node:path";
import { describe, expect, it } from "vitest";
import { loadCiGateContract } from "../../scripts/contracts/ci-gates.ts";
import {
REMOVABLE_TEMPLATE_FEATURES,
type RemovableTemplateFeature,
} from "../../scripts/lib/removable-template-features.ts";
import { INSTALLED_FEATURE_CONTRACTS } from "../../src/features/installed-feature-contracts.ts";
/**
* R4 and R5 of docs/manual/03-outside-feature-folder.md. A sample feature
* that the template or a project ships is listed in
* scripts/lib/removable-template-features.ts, and the list is proven by a
* drill that builds and tests a copy without it (R4). The gates' own targets
* (visual goldens, e2e routes, the gate evidence list, scale measurements)
* are platform screens, test fixtures and generator output, never a sample a
* copy is meant to delete (R5): the template's reference sample was the
* target of nine gates when it was deleted on 2026-11-07.
*/
type ExampleFeature = Readonly<{ featureId: string; routeIds: readonly string[]; routePaths: readonly string[] }>;
type GateTargets = Readonly<{
gotoTargets: readonly Readonly<{ file: string; target: string }>[];
artifactPaths: readonly string[];
scaleFiles: readonly Readonly<{ file: string; text: string }>[];
}>;
function exampleFeatures(features: readonly RemovableTemplateFeature[]): ExampleFeature[] {
return features.map(({ featureId }) => {
// The template installs no feature, so the composed list's type is empty.
const contracts = INSTALLED_FEATURE_CONTRACTS as readonly Readonly<{ featureId: string; routes: object }>[];
const routes = contracts.filter((contract) => contract.featureId === featureId).flatMap(
(contract) => Object.values(contract.routes as Record<string, { routeId: string; path: string }>),
);
return {
featureId,
routeIds: routes.map(({ routeId }) => routeId),
routePaths: routes.map(({ path: routePath }) => routePath).filter((routePath) => routePath !== "/"),
};
});
}
function gateTargetsNamingExamples(examples: readonly ExampleFeature[], targets: GateTargets): string[] {
return examples.flatMap(({ featureId, routeIds, routePaths }) => [
...targets.gotoTargets
.filter(({ target }) => target.includes(featureId) || routePaths.some((routePath) => target === routePath || target.startsWith(`${routePath}/`) || target.startsWith(`${routePath}?`)))
.map(({ file, target }) => `${file}: goto ${target}`),
...targets.artifactPaths
.filter((artifact) => artifact.includes(featureId) || routeIds.some((routeId) => artifact.includes(`/${routeId}.`)))
.map((artifact) => `config/ci/gates.json: ${artifact}`),
...targets.scaleFiles.filter(({ text }) => text.includes(featureId)).map(({ file }) => `${file}: ${featureId}`),
]);
}
async function specFiles(directory: string): Promise<string[]> {
return ((await readdir(directory, { recursive: true })) as string[])
.filter((name) => /\.ts$/u.test(name))
.map((name) => path.join(directory, name));
}
async function repositoryGateTargets(): Promise<GateTargets> {
const gotoTargets: { file: string; target: string }[] = [];
for (const file of [...(await specFiles("tests/visual")), ...(await specFiles("tests/e2e"))]) {
const source = await readFile(file, "utf8");
for (const [, target = ""] of source.matchAll(/\.goto\(\s*["'`]([^"'`]+)["'`]/gu)) gotoTargets.push({ file, target });
}
const contract = await loadCiGateContract(process.cwd());
const scaleFiles = await Promise.all(
(await readdir("config/scale")).map(async (name) => ({
file: `config/scale/${name}`,
text: await readFile(`config/scale/${name}`, "utf8"),
})),
);
return { gotoTargets, artifactPaths: contract.artifacts.map(({ path: artifact }) => artifact), scaleFiles };
}
describe("sample features (R4)", () => {
it("are all proven by the removal drill in FE-GATE-020", async () => {
const contract = await loadCiGateContract(process.cwd());
const removability = contract.gates.find(({ id }) => id === "FE-GATE-020");
const scripts = new Set(
contract.commands
.filter(({ id }) => removability?.commandIds.includes(id))
.map(({ script }) => script),
);
expect(scripts).toContain("test:sample-removal");
// Without `--feature` the drill deletes every listed sample.
const packageScripts = (JSON.parse(await readFile("package.json", "utf8")) as { scripts: Record<string, string> })
.scripts;
expect(packageScripts["test:sample-removal"]).not.toMatch(/--feature/u);
// It builds and tests the copy; a documents-only check does not prove removal.
const drill = await readFile("scripts/test-sample-removal.ts", "utf8");
expect(drill).toMatch(/check\(`\$\{prefix\}build`, "build"\)/u);
expect(drill).toMatch(/check\(`\$\{prefix\}unit-integration`, "test:all"\)/u);
});
});
describe("gate targets (R5)", () => {
it("name no sample feature", async () => {
expect(gateTargetsNamingExamples(exampleFeatures(REMOVABLE_TEMPLATE_FEATURES), await repositoryGateTargets())).toEqual(
[],
);
});
it("finds a sample's route in a visual spec, the evidence list and a scale record", () => {
const sample = { featureId: "order-feature", routeIds: ["ORDER_LIST"], routePaths: ["/orders"] };
expect(
gateTargetsNamingExamples([sample], {
gotoTargets: [
{ file: "tests/visual/a.visual.spec.ts", target: "/orders?page=2" },
{ file: "tests/visual/a.visual.spec.ts", target: "/examples/platform" },
],
artifactPaths: ["docs/accessibility/route-reviews/ORDER_LIST.md", "artifacts/quality/bundle.json"],
scaleFiles: [{ file: "config/scale/feature-shape-growth.json", text: '{"sourceFeature":"order-feature"}' }],
}),
).toEqual([
"tests/visual/a.visual.spec.ts: goto /orders?page=2",
"config/ci/gates.json: docs/accessibility/route-reviews/ORDER_LIST.md",
"config/scale/feature-shape-growth.json: order-feature",
]);
});
});