Files
clean-architecture-frontend…/tests/unit/ungated-scripts.test.ts
donghyeon-kaandClaude Opus 5.5 15a946fc46 ci(gates): require every verification package script to run in a gate or name why not (12-04)
check-ci-contract only caught test files outside the gates; check:* scripts
such as check:request-fanout and check:remediation-ledger ran nowhere. The
new check reads config/ci/ungated-scripts.json; three checks are now wired
into FE-GATE-010 and FE-GATE-012 and the rest carry a reason.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-27 14:14:42 +09:00

104 lines
3.8 KiB
TypeScript

import { readFileSync } from "node:fs";
import { readFile } from "node:fs/promises";
import { describe, expect, it } from "vitest";
import { loadCiGateContract } from "../../scripts/contracts/ci-gates.ts";
import {
parseUngatedScriptExclusions,
ungatedScriptFailures,
UNGATED_SCRIPTS_PATH,
} from "../../scripts/lib/ungated-scripts.ts";
import { gatedTestPaths } from "../../scripts/lib/ungated-tests.ts";
/**
* 12-04. Test files had an orphan check; package scripts did not. A `check:*`
* script that no gate reaches (check:remediation-ledger, and the checks only
* verify:extreme-scale ran) could break without anyone noticing.
*/
async function repositoryInputs() {
const contract = await loadCiGateContract(process.cwd());
const packageDocument = JSON.parse(await readFile("package.json", "utf8")) as {
scripts: Record<string, string>;
};
const entryScripts = contract.commands.map(({ script }) => script);
return {
scripts: packageDocument.scripts,
entryScripts,
gatedTestPaths: gatedTestPaths(packageDocument.scripts, entryScripts, (file) =>
readFileSync(file, "utf8"),
),
exclusions: parseUngatedScriptExclusions(
JSON.parse(await readFile(UNGATED_SCRIPTS_PATH, "utf8")),
),
};
}
const fixture = {
scripts: {
gate: "corepack pnpm check:wired && node scripts/run-vitest.ts run tests/unit",
"check:wired": "node scripts/wired.ts",
"check:orphan": "node scripts/orphan.ts",
"check:subset": "node scripts/run-vitest.ts run tests/unit/one.test.ts --reporter=default",
"check:outside": "node scripts/run-vitest.ts run tests/scale/heavy.test.ts",
"lint:fix": "eslint . --fix",
},
entryScripts: ["gate"],
gatedTestPaths: ["tests/unit"],
exclusions: [],
};
describe("ungated verification scripts", () => {
it("reaches every verification script from a CI gate or names why not", async () => {
expect(ungatedScriptFailures(await repositoryInputs())).toEqual([]);
});
it.each(["check:request-fanout", "check:app-build-input", "check:app-build-input:bundle"])(
"gates %s",
async (script) => {
const inputs = await repositoryInputs();
expect(inputs.exclusions.some((entry) => entry.script === script)).toBe(false);
expect(
ungatedScriptFailures({ ...inputs, scripts: { ...inputs.scripts }, exclusions: [] }),
).not.toContainEqual(expect.stringContaining(`: ${script}`));
},
);
it("rejects a check script that no gate reaches", () => {
expect(ungatedScriptFailures(fixture)).toEqual([
`verification script is not reached by any CI gate command and is not in ${UNGATED_SCRIPTS_PATH}: check:orphan`,
`verification script is not reached by any CI gate command and is not in ${UNGATED_SCRIPTS_PATH}: check:outside`,
]);
});
it("counts a Vitest subset as gated only when a gate runs every path", () => {
const failures = ungatedScriptFailures(fixture);
expect(failures.join("\n")).not.toContain("check:subset");
expect(failures.join("\n")).toContain("check:outside");
});
it("accepts a reasoned exclusion and rejects a stale one", () => {
expect(
ungatedScriptFailures({
...fixture,
exclusions: [
{ script: "check:orphan", reason: "local only" },
{ script: "check:outside", reason: "heavy" },
{ script: "check:wired", reason: "stale" },
// A removal may delete the script; its entry is harmless.
{ script: "check:removed", reason: "gone" },
],
}),
).toEqual([`ungated script exclusion is stale; a CI gate reaches it: check:wired`]);
});
it("requires a reason for every exclusion", () => {
expect(() =>
parseUngatedScriptExclusions({
schemaVersion: 1,
entries: [{ script: "check:orphan", reason: " " }],
}),
).toThrow(/reason/u);
});
});