기능 시험 자리인 tests/features 바로 아래에 플랫폼 단위 시험 둘과, 지워진 참조 기능의 상수 이름만 보는 가드가 있다. 둘은 tests/unit으로 옮기고 가드는 지운다. 상수 이름을 바꿔 가드를 살리는 안은 참조 기능이 없는 템플릿에서 볼 대상이 없어 쓰지 않는다. 문서들이 가리키는 tests/features 폴더는 .gitkeep으로 남긴다(없으면 verify:documentation이 실패한다). 게이트 배선 시험은 옮긴 파일의 옛 경로 대신 가짜임이 보이는 probe 경로로 tests/features를 본다. REFERENCE_* 이름 금지는 없어진다. 중앙 파일의 기능 import 가운데 loaded-feature-runtimes와 type-only import는 지운 가드도 막지 않았고 지금도 막는 검사가 없다(별도 제안). 검증: 노트북 test:unit·verify:documentation이 통과한다. test:coverage 에서 tests/features를 빼면 게이트 배선 시험이 실패한다. Refs: REV-FE-0021
368 lines
16 KiB
TypeScript
368 lines
16 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 { reachablePackageScripts } from "../../scripts/lib/package-script-graph.ts";
|
|
import {
|
|
gatedPlaywrightRuns,
|
|
gatedTestPaths,
|
|
gatedTestTargets,
|
|
listTestFiles,
|
|
parseUngatedTestExclusions,
|
|
playwrightTestDirGaps,
|
|
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>;
|
|
};
|
|
const entryScripts = contract.commands.map(({ script }) => script);
|
|
const readConfig = (file: string) => readFileSync(file, "utf8");
|
|
return {
|
|
testFiles: await listTestFiles(process.cwd()),
|
|
gatedPaths: gatedTestTargets(packageDocument.scripts, entryScripts, readConfig),
|
|
exclusions: parseUngatedTestExclusions(
|
|
JSON.parse(await readFile("config/ci/ungated-tests.json", "utf8")),
|
|
),
|
|
playwrightGaps: playwrightTestDirGaps(packageDocument.scripts, entryScripts, readConfig),
|
|
};
|
|
}
|
|
|
|
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/typecheck-probe-gated/probe.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",
|
|
// 11-03: the CPU-independent scale PR tier runs in FE-GATE-005.
|
|
"tests/scale/growth-regression.test.ts",
|
|
"tests/scale/traffic/amplification-metrics.test.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("reads the Vitest paths of a scale tier the gate command runs (11-03)", () => {
|
|
expect(
|
|
gatedTestPaths({ gate: "node scripts/scale/run-scale-profile.ts pr" }, ["gate"], () => ""),
|
|
).toEqual(expect.arrayContaining(["tests/scale/growth-regression.test.ts", "tests/scale/traffic"]));
|
|
expect(
|
|
gatedTestPaths({ gate: "node scripts/scale/run-scale-profile.ts pr" }, ["gate"], () => ""),
|
|
).not.toContain("tests/scale/session");
|
|
});
|
|
|
|
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",
|
|
]);
|
|
});
|
|
|
|
// 0929/12-06. A `*.spec.ts` under a Vitest path counted as gated, but
|
|
// vitest.config.ts includes only `*.test.{ts,tsx}`: nothing ran it.
|
|
it("gates a Vitest path's test files only, and a Playwright testDir's specs", async () => {
|
|
expect(
|
|
ungatedTestFailures({ testFiles: ["tests/unit/probe.spec.ts"], gatedPaths: ["tests/unit"], exclusions: [] }),
|
|
).toEqual([
|
|
"test file is not run by any CI gate command and is not in config/ci/ungated-tests.json: tests/unit/probe.spec.ts",
|
|
]);
|
|
const inputs = await repositoryInputs();
|
|
expect(inputs.gatedPaths).toContainEqual({ path: "tests/e2e", runner: "playwright" });
|
|
expect(inputs.gatedPaths).toContainEqual({ path: "tests/unit", runner: "vitest" });
|
|
expect(
|
|
ungatedTestFailures({ ...inputs, testFiles: ["tests/unit/probe.spec.ts", "tests/e2e/probe.spec.ts"] }),
|
|
).toEqual([
|
|
"test file is not run by any CI gate command and is not in config/ci/ungated-tests.json: tests/unit/probe.spec.ts",
|
|
]);
|
|
});
|
|
|
|
// fe-ci-next-9. The parser reads `testDir:` in the text of the file
|
|
// `--config` names, not in a config that file spreads. test:a11y
|
|
// (FE-GATE-009) ran playwright.a11y.config.ts, which spread the e2e config
|
|
// without the literal, so it gated no folder; tests/e2e passed only because
|
|
// test:e2e gates it too. fe-ci-next-12: a run alone may gate no folder now
|
|
// (test:e2e's --grep-invert needs test:a11y's --grep), so this asks for the
|
|
// testDir of each run, not for a gated folder.
|
|
it("finds a Playwright testDir for every playwright test run a gate command reaches", async () => {
|
|
const contract = await loadCiGateContract(process.cwd());
|
|
const { scripts } = JSON.parse(await readFile("package.json", "utf8")) as { scripts: Record<string, string> };
|
|
const runs = reachablePackageScripts(scripts, contract.commands.map(({ script }) => script)).flatMap((name) =>
|
|
scripts[name]!
|
|
.split("&&")
|
|
.map((segment) => segment.trim())
|
|
.filter((segment) => /(?:^|\s)playwright test(?:\s|$)/u.test(segment))
|
|
.map((segment) => ({ name, segment })),
|
|
);
|
|
expect(runs.map(({ name }) => name)).toEqual(expect.arrayContaining(["test:e2e", "test:a11y"]));
|
|
|
|
const withoutTestDir = runs
|
|
.filter(({ segment }) => {
|
|
const found = gatedPlaywrightRuns({ run: segment }, ["run"], (file) => readFileSync(file, "utf8"));
|
|
return found.length !== 1 || found[0]!.testDir === undefined;
|
|
})
|
|
.map(({ name, segment }) => `${name}: ${segment}`);
|
|
expect(withoutTestDir).toEqual([]);
|
|
});
|
|
|
|
it("requires a reason for every exclusion", () => {
|
|
expect(() =>
|
|
parseUngatedTestExclusions({
|
|
schemaVersion: 1,
|
|
entries: [{ path: "tests/scale/benchmark.test.ts", reason: " " }],
|
|
}),
|
|
).toThrow(/reason/u);
|
|
});
|
|
});
|
|
|
|
/**
|
|
* fe-ci-next-12. 029 counted the testDir of every `playwright test` run a gate
|
|
* reaches and read none of its filters. With test:a11y's run taken out, it
|
|
* still passed: test:e2e runs tests/e2e with `--grep-invert @a11y`, and
|
|
* tests/e2e/accessibility.spec.ts, whose tests are all @a11y, ran in no gate.
|
|
* A testDir counts now when one gated run has no filter, or when each
|
|
* `--grep-invert P` run has a gated `--grep P` run of the same testDir.
|
|
*/
|
|
describe("Playwright runs that filter tests", () => {
|
|
const configs: Readonly<Record<string, string>> = {
|
|
"playwright.config.ts": 'export default defineConfig({ testDir: "./tests/e2e" });',
|
|
"playwright.a11y.config.ts":
|
|
'import e2eConfig from "./playwright.config.ts";\nexport default defineConfig({ ...e2eConfig, testDir: "./tests/e2e" });',
|
|
"playwright.storybook.config.ts": 'export default defineConfig({ testDir: "./tests/storybook" });',
|
|
"playwright.visual.config.ts": 'export default defineConfig({ testDir: "./tests/visual" });',
|
|
"smoke.config.ts":
|
|
'export default defineConfig({ testDir: "./tests/e2e", projects: [{ name: "smoke", grep: /@smoke/ }] });',
|
|
"smoke-spread.config.ts":
|
|
'import smoke from "./smoke.config.ts";\nexport default defineConfig({ ...smoke, testDir: "./tests/e2e" });',
|
|
};
|
|
const readConfig = (file: string) => {
|
|
const text = configs[file];
|
|
if (text === undefined) throw new Error(`no config ${file}`);
|
|
return text;
|
|
};
|
|
const playwrightDirs = (scripts: Readonly<Record<string, string>>) =>
|
|
gatedTestTargets(scripts, Object.keys(scripts), readConfig)
|
|
.filter(({ runner }) => runner === "playwright")
|
|
.map(({ path }) => path);
|
|
const gaps = (scripts: Readonly<Record<string, string>>) =>
|
|
playwrightTestDirGaps(scripts, Object.keys(scripts), readConfig);
|
|
|
|
it("reads the config a run names with -c X, --config X or --config=X", () => {
|
|
expect(
|
|
playwrightDirs({
|
|
storybook: "playwright test -c playwright.storybook.config.ts",
|
|
visual: "playwright test --config=playwright.visual.config.ts",
|
|
a11y: "playwright test --config playwright.a11y.config.ts",
|
|
}),
|
|
).toEqual(["tests/e2e", "tests/storybook", "tests/visual"]);
|
|
});
|
|
|
|
it.each([
|
|
["a run with no filter", { e2e: "playwright test" }],
|
|
[
|
|
"a --grep-invert P run and a --grep P run, through two configs",
|
|
{
|
|
e2e: "playwright test --grep-invert @a11y",
|
|
a11y: "playwright test --config playwright.a11y.config.ts --grep @a11y",
|
|
},
|
|
],
|
|
[
|
|
"the same pair with short and joined options",
|
|
{ e2e: "playwright test -G @a11y", a11y: "playwright test --config=playwright.a11y.config.ts -g @a11y" },
|
|
],
|
|
[
|
|
"two pairs",
|
|
{
|
|
e2e: "playwright test --grep-invert @a11y && playwright test --grep-invert @slow",
|
|
a11y: "playwright test --grep @a11y && playwright test --grep=@slow",
|
|
},
|
|
],
|
|
[
|
|
"a run with no filter beside an unpaired --grep-invert run",
|
|
{ all: "playwright test", fast: "playwright test --grep-invert @slow" },
|
|
],
|
|
])("counts a testDir all run by %s", (_, scripts) => {
|
|
expect(playwrightDirs(scripts)).toEqual(["tests/e2e"]);
|
|
expect(gaps(scripts)).toEqual([]);
|
|
});
|
|
|
|
it.each([
|
|
[
|
|
"a --grep-invert P run alone",
|
|
{ e2e: "playwright test --grep-invert @a11y" },
|
|
["`playwright test --grep-invert @a11y` (e2e) has no gated `--grep @a11y` run to pair with"],
|
|
],
|
|
[
|
|
"a --grep-invert P run beside a --grep run of another pattern",
|
|
{ e2e: "playwright test --grep-invert @a11y", a11y: "playwright test --grep @axe" },
|
|
["`playwright test --grep-invert @a11y` (e2e) has no gated `--grep @a11y` run to pair with"],
|
|
],
|
|
[
|
|
"one paired and one unpaired --grep-invert run",
|
|
{ e2e: "playwright test --grep-invert @a11y && playwright test --grep-invert @slow", a11y: "playwright test --grep @a11y" },
|
|
["`playwright test --grep-invert @slow` (e2e) has no gated `--grep @slow` run to pair with"],
|
|
],
|
|
[
|
|
"--grep P runs",
|
|
{ a11y: "playwright test --config playwright.a11y.config.ts --grep @a11y" },
|
|
[
|
|
"`playwright test --config playwright.a11y.config.ts --grep @a11y` (a11y) has no gated `--grep-invert @a11y` run to pair with",
|
|
],
|
|
],
|
|
[
|
|
"a --grep P run written -gP",
|
|
{ smoke: "playwright test -g@smoke" },
|
|
["`playwright test -g@smoke` (smoke) has no gated `--grep-invert @smoke` run to pair with"],
|
|
],
|
|
[
|
|
"a --grep-invert P run written -xGP",
|
|
{ e2e: "playwright test -xG@a11y" },
|
|
["`playwright test -xG@a11y` (e2e) has no gated `--grep @a11y` run to pair with"],
|
|
],
|
|
[
|
|
"a run with a file filter",
|
|
{ one: "playwright test tests/e2e/app-shell.spec.ts" },
|
|
[
|
|
"`playwright test tests/e2e/app-shell.spec.ts` (one) is a partial run FE-GATE-029 does not read: file filter tests/e2e/app-shell.spec.ts",
|
|
],
|
|
],
|
|
[
|
|
"a run with --grep and --grep-invert",
|
|
{ mixed: "playwright test --grep @a11y --grep-invert @slow" },
|
|
[
|
|
"`playwright test --grep @a11y --grep-invert @slow` (mixed) is a partial run FE-GATE-029 does not read: more than one --grep or --grep-invert",
|
|
],
|
|
],
|
|
// Playwright uses the last of two --grep-invert values, so pairing the first would count @a11y tests.
|
|
[
|
|
"a run with --grep-invert twice",
|
|
{ twice: "playwright test --grep-invert @slow --grep-invert @a11y", a11y: "playwright test --grep @slow" },
|
|
[
|
|
"`playwright test --grep-invert @slow --grep-invert @a11y` (twice) is a partial run FE-GATE-029 does not read: more than one --grep or --grep-invert",
|
|
"`playwright test --grep @slow` (a11y) has no gated `--grep-invert @slow` run to pair with",
|
|
],
|
|
],
|
|
[
|
|
"a run whose config sets grep",
|
|
{ smoke: "playwright test --config smoke.config.ts" },
|
|
[
|
|
"`playwright test --config smoke.config.ts` (smoke) is a partial run FE-GATE-029 does not read: smoke.config.ts or a config it imports sets grep or grepInvert",
|
|
],
|
|
],
|
|
[
|
|
"a run whose config imports one that sets grep",
|
|
{ smoke: "playwright test --config smoke-spread.config.ts" },
|
|
[
|
|
"`playwright test --config smoke-spread.config.ts` (smoke) is a partial run FE-GATE-029 does not read: smoke-spread.config.ts or a config it imports sets grep or grepInvert",
|
|
],
|
|
],
|
|
])("does not count a testDir run only by %s", (_, scripts, runs) => {
|
|
expect(playwrightDirs(scripts)).toEqual([]);
|
|
expect(gaps(scripts)).toEqual([{ testDir: "tests/e2e", runs }]);
|
|
});
|
|
|
|
it("does not pair runs of two testDirs", () => {
|
|
const scripts = {
|
|
e2e: "playwright test --grep-invert @a11y",
|
|
storybook: "playwright test -c playwright.storybook.config.ts --grep @a11y",
|
|
};
|
|
expect(playwrightDirs(scripts)).toEqual([]);
|
|
expect(gaps(scripts)).toEqual([
|
|
{
|
|
testDir: "tests/e2e",
|
|
runs: ["`playwright test --grep-invert @a11y` (e2e) has no gated `--grep @a11y` run to pair with"],
|
|
},
|
|
{
|
|
testDir: "tests/storybook",
|
|
runs: [
|
|
"`playwright test -c playwright.storybook.config.ts --grep @a11y` (storybook) has no gated `--grep-invert @a11y` run to pair with",
|
|
],
|
|
},
|
|
]);
|
|
});
|
|
|
|
it("names the testDir, the run and the missing pair, once for the testDir's ungated files", () => {
|
|
const scripts = { e2e: "playwright test --grep-invert @a11y" };
|
|
expect(
|
|
ungatedTestFailures({
|
|
testFiles: ["tests/e2e/accessibility.spec.ts", "tests/e2e/app-shell.spec.ts", "tests/e2e/nested/old.spec.ts", "tests/unit/a.test.ts"],
|
|
gatedPaths: [...gatedTestTargets(scripts, ["e2e"], readConfig), "tests/unit"],
|
|
exclusions: [{ path: "tests/e2e/nested/old.spec.ts", reason: "kept for a later drill" }],
|
|
playwrightGaps: gaps(scripts),
|
|
}),
|
|
).toEqual([
|
|
"Playwright testDir tests/e2e is only partly run by the CI gate commands, so none of its 2 test files counts as gated: `playwright test --grep-invert @a11y` (e2e) has no gated `--grep @a11y` run to pair with. Gate one run of it with no --grep, --grep-invert or file filter, or a `--grep P` run for each `--grep-invert P` run (package.json scripts)",
|
|
]);
|
|
});
|
|
|
|
it("does not name a testDir whose files a wider testDir gates", () => {
|
|
const scripts = { all: "playwright test", sub: "playwright test --config sub.config.ts --grep-invert @a11y" };
|
|
const read = (file: string) => (file === "sub.config.ts" ? 'testDir: "./tests/e2e/sub"' : readConfig(file));
|
|
expect(
|
|
ungatedTestFailures({
|
|
testFiles: ["tests/e2e/sub/a.spec.ts"],
|
|
gatedPaths: gatedTestTargets(scripts, ["all", "sub"], read),
|
|
exclusions: [],
|
|
playwrightGaps: playwrightTestDirGaps(scripts, ["all", "sub"], read),
|
|
}),
|
|
).toEqual([]);
|
|
});
|
|
|
|
it("fails the repository with test:a11y's playwright run taken out", async () => {
|
|
const contract = await loadCiGateContract(process.cwd());
|
|
const entryScripts = contract.commands.map(({ script }) => script);
|
|
const { scripts } = JSON.parse(await readFile("package.json", "utf8")) as { scripts: Record<string, string> };
|
|
const read = (file: string) => readFileSync(file, "utf8");
|
|
const a11yRun = " && playwright test --config playwright.a11y.config.ts --grep @a11y";
|
|
expect(scripts["test:a11y"]).toContain(a11yRun);
|
|
const mutated = { ...scripts, "test:a11y": scripts["test:a11y"]!.replace(a11yRun, "") };
|
|
expect(gatedTestTargets(scripts, entryScripts, read)).toContainEqual({ path: "tests/e2e", runner: "playwright" });
|
|
expect(gatedTestTargets(mutated, entryScripts, read)).not.toContainEqual({ path: "tests/e2e", runner: "playwright" });
|
|
|
|
expect(playwrightTestDirGaps(scripts, entryScripts, read)).toEqual([]);
|
|
expect(
|
|
ungatedTestFailures({
|
|
...(await repositoryInputs()),
|
|
gatedPaths: gatedTestTargets(mutated, entryScripts, read),
|
|
playwrightGaps: playwrightTestDirGaps(mutated, entryScripts, read),
|
|
}),
|
|
).toEqual([
|
|
expect.stringMatching(
|
|
/^Playwright testDir tests\/e2e is only partly run by the CI gate commands, so none of its \d+ test files counts as gated: `playwright test --grep-invert @a11y` \(test:e2e\) has no gated `--grep @a11y` run to pair with\. /u,
|
|
),
|
|
]);
|
|
});
|
|
});
|