The growth test read docs/reviews/, which the removal fixtures do not copy and README lets a project delete, so three removal checks failed with ENOENT. The rationale now lives in config/scale/feature-shape-ceilings.json and a guard test keeps code from reading the deletable history documents. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
66 lines
2.2 KiB
TypeScript
66 lines
2.2 KiB
TypeScript
import { readdir, readFile } from "node:fs/promises";
|
|
import path from "node:path";
|
|
|
|
import { describe, expect, it } from "vitest";
|
|
|
|
/**
|
|
* README.md, "Files you can delete after copying", 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.
|
|
*/
|
|
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",
|
|
];
|
|
|
|
// Built from pieces so that this file does not match itself.
|
|
const REVIEWS = ["docs", "reviews", ""].join("/");
|
|
const KEPT = `${REVIEWS}adapters/INVENTORY.md`;
|
|
const DELETABLE = [
|
|
new RegExp(`${REVIEWS}(?!adapters/INVENTORY\\.md)`, "u"),
|
|
new RegExp(["docs", "superpowers"].join("/"), "u"),
|
|
new RegExp(`\\b${"SPEC"}\\.md\\b`, "u"),
|
|
new RegExp(`\\b${"CLAUDE"}\\.md\\b`, "u"),
|
|
new RegExp(`(^|["'\`(\\s])${"tasks"}/`, "u"),
|
|
];
|
|
|
|
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();
|
|
}
|
|
|
|
describe("deletable history documents", () => {
|
|
it("are read by no code, test, script or configuration", async () => {
|
|
const files = [
|
|
...(await Promise.all(CODE_ROOTS.map(codeFiles))).flat(),
|
|
...ROOT_FILES,
|
|
];
|
|
const readers: string[] = [];
|
|
for (const file of files) {
|
|
const lines = (await readFile(file, "utf8").catch(() => "")).split("\n");
|
|
lines.forEach((line, index) => {
|
|
if (DELETABLE.some((pattern) => pattern.test(line)))
|
|
readers.push(`${file}:${index + 1}`);
|
|
});
|
|
}
|
|
|
|
expect(readers, `only ${KEPT} may be read`).toEqual([]);
|
|
});
|
|
});
|