From d838be543e4d897b0d951b60d5d363d1491f5766 Mon Sep 17 00:00:00 2001 From: DongHyeonka Date: Fri, 13 Nov 2026 04:59:29 +0900 Subject: [PATCH] =?UTF-8?q?fix(ci):=20gating=20=EA=B2=80=EC=82=AC=EA=B0=80?= =?UTF-8?q?=20Vitest=20=EA=B2=BD=EB=A1=9C=EC=9D=98=20*.spec=20=ED=8C=8C?= =?UTF-8?q?=EC=9D=BC=EC=9D=84=20=EA=B2=8C=EC=9D=B4=ED=8A=B8=20=EC=95=88?= =?UTF-8?q?=EC=9C=BC=EB=A1=9C=20=EC=84=B8=EC=A7=80=20=EC=95=8A=EB=8A=94?= =?UTF-8?q?=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 문제: `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 --- scripts/check-ci-gating.ts | 3 ++- scripts/lib/ungated-tests.ts | 43 +++++++++++++++++++++++++++----- tests/unit/ungated-tests.test.ts | 21 +++++++++++++++- 3 files changed, 59 insertions(+), 8 deletions(-) diff --git a/scripts/check-ci-gating.ts b/scripts/check-ci-gating.ts index cde0df88..094b2558 100644 --- a/scripts/check-ci-gating.ts +++ b/scripts/check-ci-gating.ts @@ -5,6 +5,7 @@ import { loadCiGateContract } from "./contracts/ci-gates.ts"; import { loadProductCiOverlay } from "./contracts/product-ci-overlay.ts"; import { gatedTestPaths, + gatedTestTargets, listTestFiles, parseUngatedTestExclusions, ungatedTestFailures, @@ -38,7 +39,7 @@ try { failures.push( ...ungatedTestFailures({ testFiles: await listTestFiles(process.cwd()), - gatedPaths: gatedTestPaths( + gatedPaths: gatedTestTargets( packageScripts, [...contract.commands.map(({ script }) => script), ...productGateScripts], (file) => readFileSync(file, "utf8"), diff --git a/scripts/lib/ungated-tests.ts b/scripts/lib/ungated-tests.ts index cdaeff35..b4cd322a 100644 --- a/scripts/lib/ungated-tests.ts +++ b/scripts/lib/ungated-tests.ts @@ -16,6 +16,15 @@ import { reachablePackageScripts } from "./package-script-graph.ts"; 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({ @@ -54,14 +63,26 @@ export function gatedTestPaths( entryScripts: readonly string[], readConfig: (file: string) => string, ): string[] { - const paths = new Set(); + return [...new Set(gatedTestTargets(scripts, entryScripts, readConfig).map(({ path: target }) => target))].sort(); +} + +export function gatedTestTargets( + scripts: Readonly>, + entryScripts: readonly string[], + readConfig: (file: string) => string, +): GatedTestTarget[] { + const targets = new Map(); + 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("-")) paths.add(token.replace(/\/$/u, "")); + if (!token.startsWith("-")) add(token, "vitest"); } }; for (const script of reachablePackageScripts(scripts, entryScripts)) { @@ -79,20 +100,30 @@ export function gatedTestPaths( 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) paths.add(testDir.replace(/\/$/u, "")); + if (testDir) add(testDir, "playwright"); } } } - return [...paths].sort(); + return [...targets.values()].sort( + (left, right) => left.path.localeCompare(right.path) || left.runner.localeCompare(right.runner), + ); } export function ungatedTestFailures(input: Readonly<{ testFiles: readonly string[]; - gatedPaths: 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) => - input.gatedPaths.some((gatedPath) => file === gatedPath || file.startsWith(`${gatedPath}/`)); + 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)) diff --git a/tests/unit/ungated-tests.test.ts b/tests/unit/ungated-tests.test.ts index 32a788fe..93ea3024 100644 --- a/tests/unit/ungated-tests.test.ts +++ b/tests/unit/ungated-tests.test.ts @@ -6,6 +6,7 @@ import { describe, expect, it } from "vitest"; import { loadCiGateContract } from "../../scripts/contracts/ci-gates.ts"; import { gatedTestPaths, + gatedTestTargets, listTestFiles, parseUngatedTestExclusions, ungatedTestFailures, @@ -23,7 +24,7 @@ async function repositoryInputs() { }; return { testFiles: await listTestFiles(process.cwd()), - gatedPaths: gatedTestPaths( + gatedPaths: gatedTestTargets( packageDocument.scripts, contract.commands.map(({ script }) => script), (file) => readFileSync(file, "utf8"), @@ -88,6 +89,24 @@ describe("ungated test files", () => { ]); }); + // 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", + ]); + }); + it("requires a reason for every exclusion", () => { expect(() => parseUngatedTestExclusions({