frontend-quality-gates / merge / static checks (pull_request) Canceled after 0s
frontend-quality-gates / merge / tests (pull_request) Canceled after 0s
frontend-quality-gates / merge / browser tests (pull_request) Canceled after 0s
frontend-quality-gates / FE-GATE-014 / config-compatibility (pull_request) Canceled after 0s
frontend-quality-gates / FE-GATE-026 / lab-performance (pull_request) Canceled after 0s
frontend-quality-gates / FE-GATE-028 / manual-accessibility-review (pull_request) Canceled after 0s
frontend-quality-gates / FE-GATE-015 / immutable-release-candidate (pull_request) Canceled after 0s
frontend-quality-gates / external-vulnerability-provider (pull_request) Canceled after 0s
frontend-quality-gates / external-provenance-provider (pull_request) Canceled after 0s
frontend-quality-gates / promote-verified-immutable-candidate (pull_request) Canceled after 0s
frontend-quality-gates / deploy-promoted-release (pull_request) Canceled after 0s
frontend-quality-gates / FE-GATE-019 / hosting-header (pull_request) Canceled after 0s
frontend-quality-gates / FE-GATE-021 / runbook-boot-config (pull_request) Canceled after 0s
frontend-quality-gates / FE-GATE-022 / runbook-chunk-mismatch (pull_request) Canceled after 0s
frontend-quality-gates / FE-GATE-023 / runbook-api-degradation (pull_request) Canceled after 0s
frontend-quality-gates / FE-GATE-024 / runbook-telemetry (pull_request) Canceled after 0s
frontend-quality-gates / FE-GATE-025 / runbook-release-rollback (pull_request) Canceled after 0s
frontend-quality-gates / FE-GATE-018 / field-web-vitals (pull_request) Canceled after 0s
frontend-quality-gates / FE-GATE-017 / diagram-review (pull_request) Canceled after 0s
frontend-quality-gates / main / self-tests and removal drills (pull_request) Canceled after 0s
문제: `check:ci:gating`(FE-GATE-029)은 `*.test.*`와 `*.spec.*`를 모두 모은 뒤
게이트 명령이 닿는 경로 접두어만 본다. 그래서 `tests/unit/x.spec.ts`는
「게이트 안」으로 세지만 vitest.config.ts는 `*.test.{ts,tsx}`만 모아 아무
게이트도 그 파일을 돌리지 않는다.
고른 방법: 경로마다 그 경로를 돌리는 runner를 함께 적는다
(`gatedTestTargets`: Vitest 경로와 Playwright `testDir`). Vitest 경로는
`*.test.*`만, Playwright `testDir`는 기본 testMatch처럼 `*.spec.*`와
`*.test.*`를 게이트 안으로 본다. 판정(`ungatedTestFailures`)은 이 목록을
받고, 문자열만 주면 Vitest 경로로 본다. `gatedTestPaths`(경로만)는 다른
호출자를 위해 그대로 둔다.
위험·한계: Playwright 설정이 testMatch를 좁혀도 그 testDir의 두 꼴을 모두
게이트 안으로 본다(예전과 같다).
검증(desktop): 새 시험이 판정 규칙을 빼는 변이에서 실패(RED), 고친 뒤
ungated-tests·ungated-scripts·test-all-paths·removal-drill-test-paths 29개
통과, 실제 `check:ci:gating` PASS, `tests/unit/probe.spec.ts`를 두면 그
파일 이름으로 rc=1, eslint·check:types rc=0. 로그
/tmp/claude-gates/w2fe2-ung3/.
Refs: 0929/12-06
140 lines
5.5 KiB
TypeScript
140 lines
5.5 KiB
TypeScript
import { readdir } from "node:fs/promises";
|
|
import path from "node:path";
|
|
|
|
import { z } from "zod";
|
|
|
|
import { SCALE_TIERS, type ScaleTier } from "../scale/run-scale-profile.ts";
|
|
import { reachablePackageScripts } from "./package-script-graph.ts";
|
|
|
|
/**
|
|
* 12-04. A test file protects nothing unless a CI gate runs it. The gated set
|
|
* is read from the package scripts the CI contract's commands reach: Vitest
|
|
* path filters (`run-vitest.ts run <paths>`), the Vitest steps of a scale tier
|
|
* (`run-scale-profile.ts <tier>`) and Playwright config `testDir`s.
|
|
* A test outside that set needs a reasoned entry in config/ci/ungated-tests.json.
|
|
*/
|
|
export const UNGATED_TESTS_PATH = "config/ci/ungated-tests.json";
|
|
|
|
const TEST_FILE = /\.(?:test|spec)\.tsx?$/u;
|
|
// vitest.config.ts includes only the `*.test.ts` and `*.test.tsx` files below tests.
|
|
const VITEST_TEST_FILE = /\.test\.tsx?$/u;
|
|
|
|
/**
|
|
* 0929/12-06. A gated path and the runner that reaches it. A Vitest path
|
|
* runs its `*.test.*` files only; a Playwright `testDir` runs what the
|
|
* Playwright default `testMatch` takes, `*.spec.*` and `*.test.*`.
|
|
*/
|
|
export type GatedTestTarget = Readonly<{ path: string; runner: "vitest" | "playwright" }>;
|
|
|
|
const ungatedTestsSchema = z
|
|
.object({
|
|
schemaVersion: z.literal(1),
|
|
entries: z.array(
|
|
z
|
|
.object({
|
|
path: z.string().regex(/^tests\/\S+$/u),
|
|
reason: z.string().trim().min(1, "exclusion reason is required"),
|
|
})
|
|
.strict(),
|
|
),
|
|
})
|
|
.strict();
|
|
|
|
export type UngatedTestExclusion = Readonly<{ path: string; reason: string }>;
|
|
|
|
export function parseUngatedTestExclusions(value: unknown): readonly UngatedTestExclusion[] {
|
|
return ungatedTestsSchema.parse(value).entries;
|
|
}
|
|
|
|
/** Repository-relative test files below tests/, fixtures excluded. */
|
|
export async function listTestFiles(root: string): Promise<string[]> {
|
|
const entries = await readdir(path.join(root, "tests"), { recursive: true, withFileTypes: true });
|
|
return entries
|
|
.filter((entry) => entry.isFile() && TEST_FILE.test(entry.name))
|
|
.map((entry) =>
|
|
path.relative(root, path.join(entry.parentPath, entry.name)).split(path.sep).join("/"),
|
|
)
|
|
.filter((file) => !file.startsWith("tests/fixtures/"))
|
|
.sort();
|
|
}
|
|
|
|
export function gatedTestPaths(
|
|
scripts: Readonly<Record<string, string>>,
|
|
entryScripts: readonly string[],
|
|
readConfig: (file: string) => string,
|
|
): string[] {
|
|
return [...new Set(gatedTestTargets(scripts, entryScripts, readConfig).map(({ path: target }) => target))].sort();
|
|
}
|
|
|
|
export function gatedTestTargets(
|
|
scripts: Readonly<Record<string, string>>,
|
|
entryScripts: readonly string[],
|
|
readConfig: (file: string) => string,
|
|
): GatedTestTarget[] {
|
|
const targets = new Map<string, GatedTestTarget>();
|
|
const add = (target: string, runner: GatedTestTarget["runner"]) => {
|
|
const normalized = target.replace(/\/$/u, "");
|
|
targets.set(`${runner} ${normalized}`, { path: normalized, runner });
|
|
};
|
|
const addVitestPaths = (tokens: readonly string[]) => {
|
|
const vitestRun = tokens.findIndex(
|
|
(token, index) => token === "run" && /(?:run-vitest\.ts|vitest)$/u.test(tokens[index - 1] ?? ""),
|
|
);
|
|
if (vitestRun < 0) return;
|
|
for (const token of tokens.slice(vitestRun + 1)) {
|
|
if (!token.startsWith("-")) add(token, "vitest");
|
|
}
|
|
};
|
|
for (const script of reachablePackageScripts(scripts, entryScripts)) {
|
|
for (const segment of scripts[script]!.split("&&")) {
|
|
const tokens = segment.trim().split(/\s+/u);
|
|
addVitestPaths(tokens);
|
|
const scaleProfile = tokens.findIndex((token) => /run-scale-profile\.ts$/u.test(token));
|
|
if (scaleProfile >= 0) {
|
|
for (const step of SCALE_TIERS[tokens[scaleProfile + 1] as ScaleTier] ?? []) addVitestPaths(step.command);
|
|
}
|
|
const playwrightTest = tokens.findIndex(
|
|
(token, index) => token === "test" && tokens[index - 1] === "playwright",
|
|
);
|
|
if (playwrightTest >= 0) {
|
|
const configFlag = tokens.indexOf("--config");
|
|
const config = configFlag >= 0 ? tokens[configFlag + 1]! : "playwright.config.ts";
|
|
const testDir = /testDir:\s*["']\.?\/?([^"']+)["']/u.exec(readConfig(config))?.[1];
|
|
if (testDir) add(testDir, "playwright");
|
|
}
|
|
}
|
|
}
|
|
return [...targets.values()].sort(
|
|
(left, right) => left.path.localeCompare(right.path) || left.runner.localeCompare(right.runner),
|
|
);
|
|
}
|
|
|
|
export function ungatedTestFailures(input: Readonly<{
|
|
testFiles: readonly string[];
|
|
/** A bare string is a Vitest path. */
|
|
gatedPaths: readonly (string | GatedTestTarget)[];
|
|
exclusions: readonly UngatedTestExclusion[];
|
|
}>): string[] {
|
|
const targets = input.gatedPaths.map((target): GatedTestTarget =>
|
|
typeof target === "string" ? { path: target, runner: "vitest" } : target,
|
|
);
|
|
const gated = (file: string) =>
|
|
targets.some(
|
|
({ path: gatedPath, runner }) =>
|
|
(file === gatedPath || file.startsWith(`${gatedPath}/`)) &&
|
|
(runner === "playwright" || VITEST_TEST_FILE.test(file)),
|
|
);
|
|
const excluded = new Set(input.exclusions.map(({ path: file }) => file));
|
|
const failures = input.testFiles
|
|
.filter((file) => !gated(file) && !excluded.has(file))
|
|
.map((file) =>
|
|
`test file is not run by any CI gate command and is not in ${UNGATED_TESTS_PATH}: ${file}`
|
|
);
|
|
// An entry for a file a removal deleted is harmless; one for a file a gate
|
|
// now runs would hide the next regression, so it has to go.
|
|
for (const { path: file } of input.exclusions) {
|
|
if (gated(file)) failures.push(`ungated test exclusion is stale; a CI gate runs it: ${file}`);
|
|
}
|
|
return failures;
|
|
}
|