Files
clean-architecture-frontend…/tests/unit/deletable-history-documents.test.ts
T
DongHyeonka fb446e471e Merge branch 'main' into claude/fe-b-docs-korean-645f55
하네스 PR #13(main d1b9c087)을 받는다. 충돌은 README.md와 docs/README.md
둘이다. 이 브랜치가 두 파일을 한국어로 다시 썼고, #13이 영어 판에
AGENTS.md·docs/work/·docs/ledger/를 가리키는 줄과 지워도 되는 표 행을 더했다.
이 브랜치 판을 바탕으로 #13이 더한 것을 한국어로 넣었다.
- README: 최상위 표에 AGENTS.md·.claude/, 문서 지도에 AGENTS.md·docs/work/·
  docs/vision.md·docs/problem-statement.md·docs/ledger/, 지워도 되는 표에서
  CLAUDE.md를 빼고 docs/ledger/estimates.jsonl을 더함, 새 서비스로 시작하기와
  규칙과 기여의 CLAUDE.md 줄을 AGENTS.md 기준으로
- docs/README.md: 1절 「처음 읽을 문서」에 ../AGENTS.md·work/·work/reference/
  링크(#13의 template-contract-documents 시험이 본다), 지도에 work/·ledger/
  행, 폴더 밖 문서에 AGENTS.md·vision.md·problem-statement.md, 2절 살아 있는
  문서 목록
2026-11-11 20:55:11 +09:00

101 lines
3.8 KiB
TypeScript

import { readdir, readFile } from "node:fs/promises";
import path from "node:path";
import { describe, expect, it } from "vitest";
/**
* README.md, 「복사한 뒤 지워도 되는 것」, tells a new project that
* the build and the gates read none of the history documents except
* `docs/reviews/adapters/INVENTORY.md`. The removal fixtures rely on the same
* promise: they do not copy `docs/`. A test that opens a review document broke
* all three removal checks (fix of 11-04), so the promise is checked here.
* The root instruction files left the list on 2026-11-07: they are the
* template's contract, which a copy keeps (template-contract-documents.test.ts).
*/
const CODE_ROOTS = ["src", "tests", "scripts", "config", "recipes", "schemas", ".gitea"];
const ROOT_FILES = [
"package.json",
"vite.config.ts",
"vitest.config.ts",
"eslint.config.ts",
"playwright.config.ts",
".dependency-cruiser.json",
];
// Built from pieces so that this file does not match itself.
const REVIEWS = ["docs", "reviews", ""].join("/");
const KEPT = `${REVIEWS}adapters/INVENTORY.md`;
// The 2026-09-25 round's task folder moved into the history folder on
// 2026-11-07 (docs/README.md §3), so the history pattern covers it. A pattern
// for the old root folder would now only catch a product's own route or
// folder of that name.
const DELETABLE = [
new RegExp(`${REVIEWS}(?!adapters/INVENTORY\\.md)`, "u"),
new RegExp(["docs", "superpowers"].join("/"), "u"),
new RegExp(["docs", "history"].join("/"), "u"),
new RegExp(`\\b${"SPEC"}\\.md\\b`, "u"),
];
/**
* 1101/14-01. A section number without a document name cannot be followed,
* and the scale design it meant used to live only in the history bundle a
* copy deletes. Cite it as `scale-architecture.md §N`
* (docs/architecture/scale-architecture.md, a current contract).
*/
const UNNAMED_SECTION = new RegExp(`\\b${"spec"} ?§`, "iu");
async function codeFiles(directory: string): Promise<string[]> {
const entries = await readdir(directory, { withFileTypes: true }).catch(
() => [],
);
const files = await Promise.all(
entries.map(async (entry) => {
const target = path.join(directory, entry.name);
if (entry.isDirectory())
return entry.name === "node_modules" ? [] : codeFiles(target);
return /\.(?:[cm]?[jt]sx?|json|ya?ml)$/u.test(entry.name) ? [target] : [];
}),
);
return files.flat();
}
/**
* The document checker (docs/README.md 「5. 문서 검사」) names the record
* folders to read the head block of whatever records are there and nothing
* else of them. A copy that deleted them passes it ("passes a copy that
* deleted its history" in its test), so it is not a reader this promise is
* about.
*/
const RECORD_FOLDER_CHECKERS: ReadonlySet<string> = new Set([
"scripts/lib/docs-system.ts",
"tests/unit/docs-system.test.ts",
]);
async function linesMatching(patterns: readonly RegExp[]): Promise<string[]> {
const files = [
...(await Promise.all(CODE_ROOTS.map(codeFiles))).flat().filter((file) => !RECORD_FOLDER_CHECKERS.has(file)),
...ROOT_FILES,
];
const matches: string[] = [];
for (const file of files) {
const lines = (await readFile(file, "utf8").catch(() => "")).split("\n");
lines.forEach((line, index) => {
if (patterns.some((pattern) => pattern.test(line)))
matches.push(`${file}:${index + 1}`);
});
}
return matches;
}
describe("deletable history documents", () => {
it("are read by no code, test, script or configuration", async () => {
expect(await linesMatching(DELETABLE), `only ${KEPT} may be read`).toEqual([]);
});
it("are not cited as an unnamed design section", async () => {
expect(
await linesMatching([UNNAMED_SECTION]),
"name the document: scale-architecture.md §N",
).toEqual([]);
});
});