Files
clean-architecture-frontend…/tests/unit/documentation-readiness-checks.test.ts
DongHyeonka 5844d52d89 fix(layout): R2 면제 한 줄이 목록의 출현 한 번만 덮는다
R2 면제가 파일과 목록 글자로만 맞춰, 같은 파일에 같은 목록이 하나 더
생겨도 통과시킨다.

출현 횟수까지 대조한다. 이 규칙에 걸린 문서 준비 시험의 [docs, src]
둘은 상수 하나로 합치고 면제 이유를 바로잡는다. 면제 줄을 더하는 안은
예외 목록이 늘어 버렸다.

위험: 같은 목록을 두 번 면제받던 복사 프로젝트는 FE-GATE-005가
실패한다. 면제된 목록을 같은 글자의 진짜 목록으로 바꾸면 횟수가 같아
통과한다.

검증(노트북): 횟수 판정 시험 3개가 고치기 전 실패하고, 지금
repository-layout 18개가 통과한다. 횟수 대조를 빼거나, 목록 대조를
빼거나, 맞은 면제 대신 첫 면제를 꺼내는 변이가 실패한다.

Refs: REV-FE-0038
2026-11-23 02:45:38 +09:00

239 lines
9.9 KiB
TypeScript

import { describe, expect, it } from "vitest";
import {
checkDocumentReferences,
checkLayoutRules,
checkSourceStructure,
type ReferenceFacts,
RULES_DOCUMENT,
} from "../../scripts/lib/documentation-readiness-checks.ts";
/**
* The checks verify:documentation runs, on inputs in memory. Each check has a
* passing input and an input that only it rejects (docs-system.md 7). The
* script's wiring (which documents it reads, the facts it builds from this
* repository, the paired checkouts, the stderr) is tested by spawning it in
* tests/unit/documentation-readiness.test.ts. This file reads no document, so
* the removal drills run it too (REMOVAL_FIXTURE_DOCUMENT_TESTS in
* scripts/lib/removal-fixture.ts).
*/
describe("repository layout rules R6 and R7", () => {
const SAMPLE = ["src/features/sample-notes"];
it("passes a document with shell blocks and no infrastructure configuration", () => {
const text = "# 배포\n\n```bash\ncorepack pnpm build\n```\n\n호스트 계약은 `config/hosting/`이다.\n";
expect(checkLayoutRules("docs/operations/deploy.md", text, SAMPLE)).toEqual([]);
});
it.each(["nginx", "hcl", "terraform", "Helm"])("R7 fails a ```%s block", (language) => {
const text = `# 배포\n\n\`\`\`${language}\nserver {}\n\`\`\`\n`;
expect(checkLayoutRules("docs/operations/deploy.md", text, SAMPLE)).toEqual([
{ path: "docs/operations/deploy.md", rule: "R7", detail: `line 3: \`\`\`${language}` },
]);
});
it("R7 fails a cluster manifest inside a block, and not the same words in prose", () => {
const text = "kind: Deployment\n\n```yaml\napiVersion: apps/v1\nkind: Deployment\n```\n";
expect(checkLayoutRules("docs/operations/deploy.md", text, SAMPLE)).toEqual([
{ path: "docs/operations/deploy.md", rule: "R7", detail: "line 5: kind: Deployment" },
]);
});
it("R6 fails a manual line naming a sample feature, and only in docs/manual/", () => {
const text = "예시는 `src/features/sample-notes/feature-module.ts`를 본다.\n";
expect(checkLayoutRules("docs/manual/01-add-a-feature.md", text, SAMPLE)).toEqual([
{ path: "docs/manual/01-add-a-feature.md", rule: "R6", detail: "line 1: src/features/sample-notes" },
]);
expect(checkLayoutRules("docs/architecture/overview.md", text, SAMPLE)).toEqual([]);
expect(checkLayoutRules("docs/manual/01-add-a-feature.md", text, [])).toEqual([]);
});
});
describe("source structure (1101/14-03)", () => {
const RULES = [
"# 계층",
"",
"| 폴더 | 역할 |",
"| --- | --- |",
"| `src/platform` | 제품 중립 커널 |",
"| `src/features` | 기능 폴더 |",
"",
"규칙: `platform-is-neutral`, `features-use-barrels`.",
].join("\n");
const ENTRY = "`src/platform` — 제품 중립 커널\n`src/features` — 기능 폴더\n";
const texts = (changes: Readonly<Record<string, string>> = {}) =>
new Map(
Object.entries({
[RULES_DOCUMENT]: RULES,
"README.md": ENTRY,
"docs/architecture/overview.md": ENTRY,
"docs/architecture/frontend-application-foundation.md": ENTRY,
...changes,
}),
);
const check = (changes?: Readonly<Record<string, string>>, sourceFolders = ["features", "platform"]) =>
checkSourceStructure({
texts: texts(changes),
sourceFolders,
architectureRules: ["platform-is-neutral", "features-use-barrels"],
}).filter(
(entry) => entry.missingFolders.length + entry.unknownFolders.length + entry.missingRules.length > 0,
);
it("passes when every folder has its row and every entry document repeats it", () => {
expect(check()).toEqual([]);
});
it("fails when layers.md loses a rule name, as renaming a rule does", () => {
expect(check({ [RULES_DOCUMENT]: RULES.replace("`features-use-barrels`", "`features-barrels`") })).toEqual([
{ path: RULES_DOCUMENT, missingFolders: [], unknownFolders: [], missingRules: ["features-use-barrels"] },
]);
});
it("fails when a document names a top-level src folder that does not exist", () => {
expect(check({ "README.md": `${ENTRY}\`src/domain\`은 없다.\n` })).toEqual([
{ path: "README.md", missingFolders: [], unknownFolders: ["domain"], missingRules: [] },
]);
});
it("fails when a document describes a folder differently from layers.md", () => {
expect(check({ "docs/architecture/overview.md": ENTRY.replace("기능 폴더", "기능 묶음") })).toEqual([
{ path: "docs/architecture/overview.md", missingFolders: ["features"], unknownFolders: [], missingRules: [] },
]);
});
it("fails every document for a folder layers.md has no row for", () => {
expect(check({}, ["apps", "features", "platform"]).map((entry) => [entry.path, entry.missingFolders])).toEqual([
[RULES_DOCUMENT, ["apps"]],
["README.md", ["apps"]],
["docs/architecture/overview.md", ["apps"]],
["docs/architecture/frontend-application-foundation.md", ["apps"]],
]);
});
});
describe("document references", () => {
const FILES = new Set([
"docs",
"docs/operations",
"docs/operations/ci.md",
"docs/operations/runbooks",
"docs/README.md",
"scripts",
"scripts/check-docs.ts",
"scripts/verify.sh",
"tests",
"tests/unit",
"tests/unit/docs.test.ts",
"README.md",
]);
const facts = (overrides: Partial<ReferenceFacts> = {}): ReferenceFacts => ({
exists: (path) => FILES.has(path),
topLevelEntries: new Set(["docs", "scripts", "src", "tests", "README.md", "artifacts"]),
scripts: new Set(["verify:documentation", "lint", "drill:runbook"]),
gateIds: new Set(["FE-GATE-017"]),
pairedRepositories: new Set(["backend"]),
pairedReferenceExists: () => true,
ignorePatterns: ["artifacts/quality/"],
deletedHistory: [],
removedFeaturePaths: [],
removedFeatureScripts: new Set<string>(),
...overrides,
});
const DOCUMENT = "docs/operations/ci.md";
const check = (text: string, overrides?: Partial<ReferenceFacts>) => {
const { path, ...found } = checkDocumentReferences(DOCUMENT, text, facts(overrides));
expect(path).toBe(DOCUMENT);
return found;
};
const NONE = { missingPaths: [], unverifiedLinks: [], missingScripts: [], unknownGateIds: [] };
it("passes a document whose paths, links, scripts and gate IDs exist", () => {
const text = [
"`scripts/check-docs.ts:12`, [색인](../README.md#1), `corepack pnpm verify:documentation`, `lint`",
"FE-GATE-017이 돈다. `node scripts/…`, `scripts/verify.sh script <이름>…`, `src/adapters/web-worker`",
"```bash",
"VERIFY_SNAPSHOT=1 scripts/verify.sh exec -- node tests/unit/docs.test.ts --flag=tests/unit/docs.test.ts",
"corepack pnpm drill:runbook -- FE-RB-005 --release-root <release dir>",
"```",
].join("\n");
expect(check(text)).toEqual(NONE);
});
it("fails a path, a link target and a path beside the document that do not exist", () => {
expect(check("`scripts/check-dosc.ts` [지도](../READNE.md) `runbooks/gone.md`").missingPaths).toEqual([
"docs/READNE.md",
"docs/operations/runbooks/gone.md",
"scripts/check-dosc.ts",
]);
});
it("fails the paths an inline command, a shell block and a verify.sh exec take", () => {
const text = [
"`corepack pnpm exec vitest run tests/unit/no-such.test.ts`",
"`python3 scripts/no-such.py --history docs`",
"```bash",
"scripts/verify.sh exec -- node scripts/no-such.ts",
"```",
].join("\n");
expect(check(text).missingPaths).toEqual(["scripts/no-such.py", "scripts/no-such.ts", "tests/unit/no-such.test.ts"]);
});
it("fails a path after leading NAME=value assignments and the value of a --flag=value argument", () => {
const text = [
"`CI=true VERIFY_SNAPSHOT=1 node scripts/no-such-env.ts`",
"`node tests/unit/docs.test.ts --out=tests/unit/no-such-flag.test.ts`",
].join("\n");
expect(check(text).missingPaths).toEqual(["scripts/no-such-env.ts", "tests/unit/no-such-flag.test.ts"]);
});
it("fails package scripts and gate IDs that do not exist", () => {
const text = "`corepack pnpm verify:documentaton`, `lint:fixx `, `scripts/verify.sh script no:such -- --x`, FE-GATE-099";
expect(check(text)).toEqual({
...NONE,
missingScripts: ["lint:fixx", "no:such", "verify:documentaton"],
unknownGateIds: ["FE-GATE-099"],
});
});
it("does not ask generated output to exist", () => {
expect(check("See `artifacts/quality/not-generated-yet.json`.")).toEqual(NONE);
});
it("accepts a path under history a copy deleted or a removed sample, and only that", () => {
const text = "`docs/retired-notes/plan.md` `src/features/sample-notes/x.ts` `corepack pnpm sample:seed`";
const topLevelEntries = new Set(["docs", "src"]);
expect(
check(text, {
topLevelEntries,
deletedHistory: ["docs/retired-notes"],
removedFeaturePaths: ["src/features/sample-notes"],
removedFeatureScripts: new Set(["sample:seed"]),
}),
).toEqual(NONE);
expect(check(text, { topLevelEntries })).toEqual({
...NONE,
missingPaths: ["docs/retired-notes/plan.md", "src/features/sample-notes/x.ts"],
missingScripts: ["sample:seed"],
});
});
it("looks a paired reference up in the pinned tree, and reports one it cannot check as unverified", () => {
const text = "`backend/docs/web/http-contract.md` [계약](../../../backend/docs/gone.md)";
const lookedUp: string[] = [];
const found = check(text, {
pairedReferenceExists: (reference) => {
lookedUp.push(reference);
return reference.endsWith("http-contract.md");
},
});
expect(lookedUp.sort()).toEqual(["../backend/docs/gone.md", "../backend/docs/web/http-contract.md"]);
expect(found).toEqual({ ...NONE, missingPaths: ["../backend/docs/gone.md"] });
expect(check(text, { pairedReferenceExists: () => null })).toEqual({
...NONE,
unverifiedLinks: ["../backend/docs/gone.md", "../backend/docs/web/http-contract.md"],
});
});
});