Files
clean-architecture-frontend…/tests/unit/ungated-tests.test.ts
T
DongHyeonkaandClaude Opus 5.5 840de45ee7 ci: run every test file in a gate or name why not (12-04, 09-11)
tests/architecture, tests/release, tests/scripts, the top-level
tests/features files and the browser-soak contract now run in
test:coverage (FE-GATE-005); check:adapter-inventory joins FE-GATE-010
and the image resolve-signal type fixture joins FE-GATE-003 (baseline
updated). check:ci fails on a test file no gate command reaches unless
config/ci/ungated-tests.json gives a reason; only the tests/scale suite
is listed, pending 11-03. defineFeatureModule's id mismatch is tested.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-25 21:47:10 +09:00

88 lines
2.9 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 {
gatedTestPaths,
listTestFiles,
parseUngatedTestExclusions,
ungatedTestFailures,
} from "../../scripts/lib/ungated-tests.ts";
/**
* 12-04 / 09-11. A test file only protects anything if a CI gate runs it.
* Several directories were reachable only from local scripts, and nothing
* noticed a new one.
*/
async function repositoryInputs() {
const contract = await loadCiGateContract(process.cwd());
const packageDocument = JSON.parse(await readFile("package.json", "utf8")) as {
scripts: Record<string, string>;
};
return {
testFiles: await listTestFiles(process.cwd()),
gatedPaths: gatedTestPaths(
packageDocument.scripts,
contract.commands.map(({ script }) => script),
(file) => readFileSync(file, "utf8"),
),
exclusions: parseUngatedTestExclusions(
JSON.parse(await readFile("config/ci/ungated-tests.json", "utf8")),
),
};
}
describe("ungated test files", () => {
it("runs every test file in a CI gate or names why it does not", async () => {
expect(ungatedTestFailures(await repositoryInputs())).toEqual([]);
});
it.each([
"tests/features/feature-module.test.ts",
"tests/architecture/observability-boundaries.test.ts",
"tests/release/old-asset-reachability.test.ts",
"tests/scripts/verify-extreme-scale.test.ts",
"tests/scale/browser-soak.contract.test.ts",
"tests/e2e/app-shell.spec.ts",
])("gates %s", async (file) => {
const inputs = await repositoryInputs();
expect(ungatedTestFailures({ ...inputs, testFiles: [file] })).toEqual([]);
expect(inputs.exclusions.some(({ path }) => path === file)).toBe(false);
});
it("rejects a new test directory that no gate runs", async () => {
const inputs = await repositoryInputs();
expect(
ungatedTestFailures({
...inputs,
testFiles: [...inputs.testFiles, "tests/new-area/new-area.test.ts"],
}),
).toEqual([
"test file is not run by any CI gate command and is not in config/ci/ungated-tests.json: tests/new-area/new-area.test.ts",
]);
});
it("rejects an exclusion that a gate already runs", async () => {
const inputs = await repositoryInputs();
expect(
ungatedTestFailures({
...inputs,
exclusions: [...inputs.exclusions, { path: "tests/unit/ungated-tests.test.ts", reason: "stale" }],
}),
).toEqual([
"ungated test exclusion is stale; a CI gate runs it: tests/unit/ungated-tests.test.ts",
]);
});
it("requires a reason for every exclusion", () => {
expect(() =>
parseUngatedTestExclusions({
schemaVersion: 1,
entries: [{ path: "tests/scale/benchmark.test.ts", reason: " " }],
}),
).toThrow(/reason/u);
});
});