Files
clean-architecture-frontend…/tests/unit/template-contract-documents.test.ts
T
DongHyeonka 4a21bc79a1 fix(test): 새 템플릿 계약 시험이 지워도 되는 폴더 이름을 코드에 쓰지 않는다
template-contract-documents.test.ts가 README 표를 찾으려고
docs/superpowers 경로를 문자열로 적었다. deletable-history-documents.
test.ts는 코드·테스트가 지워도 되는 문서를 가리키면 실패하므로,
desktop merge 단계의 FE-GATE-005에서 이 두 줄로 실패했다.

경로를 조각으로 이어 만든다(그 시험 자신과 같은 방법). 시험이 보는
것은 그대로다.

검증: desktop FE-GATE-005(트리 ada4015c)의 실패 줄이 이 파일 15·35줄
이었다. 고친 뒤 결과는 PR 전 merge 단계에서 본다.
2026-11-08 17:53:36 +09:00

50 lines
2.4 KiB
TypeScript

import { readFile } from "node:fs/promises";
import { describe, expect, it } from "vitest";
/**
* Owner decision 2026-11-07 (docs/work/reference/decisions.md): the root
* AGENTS.md and CLAUDE.md, `.claude/` and `docs/work/` are the template's
* contract, which a copy keeps. So the README table of files a copy may delete
* must not list them, and docs/README.md section 1 links the rule book and the
* work manual, which makes verify:documentation check the paths, scripts and
* gate IDs they name.
*/
const CONTRACT = Object.freeze(["AGENTS.md", "CLAUDE.md", ".claude", "docs/work"]);
// Built from pieces: deletable-history-documents.test.ts fails on code that
// names a folder a copy may delete.
const PAST_PLANS = ["docs", "superpowers"].join("/");
/** A row only the deletable-files table has; found by content so a translated heading still finds it. */
const DELETABLE_ROW = `| \`${PAST_PLANS}/\` |`;
/** The paths in the first cells of the README table that holds DELETABLE_ROW. */
function deletablePaths(readme: string): string[] {
const lines = readme.split("\n");
const row = lines.findIndex((line) => line.startsWith(DELETABLE_ROW));
if (row === -1) throw new Error(`README.md has no table row starting with ${DELETABLE_ROW}`);
let start = row;
while (start > 0 && lines[start - 1]?.startsWith("|")) start -= 1;
let end = row;
while (lines[end + 1]?.startsWith("|")) end += 1;
return lines
.slice(start + 2, end + 1)
.flatMap((line) => [...(line.split("|")[1] ?? "").matchAll(/`([^`]+)`/gu)].map(([, entry = ""]) => entry))
.map((entry) => entry.replace(/\/$/u, ""));
}
describe("template contract documents", () => {
it("are not in the README table of files a copy may delete", async () => {
const listed = deletablePaths(await readFile("README.md", "utf8"));
expect(listed).toContain(PAST_PLANS);
expect(listed.filter((entry) => CONTRACT.some((kept) => entry === kept || entry.startsWith(`${kept}/`))))
.toEqual([]);
});
it("are linked from the current-contract section of docs/README.md", async () => {
const index = await readFile("docs/README.md", "utf8");
const section = /^## 1\.[\s\S]*?(?=^## )/mu.exec(index)?.[0] ?? "";
const links = [...section.matchAll(/\]\(([^)#\s]+)\)/gu)].map(([, target = ""]) => target);
expect(links).toEqual(expect.arrayContaining(["../AGENTS.md", "work/", "work/reference/"]));
});
});