fix(coverage): 위험 커버리지가 "use strict" 밖의 지시문을 문장으로 센다
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-028 / manual-accessibility-review (pull_request) Canceled after 0s
frontend-quality-gates / FE-GATE-026 / lab-performance (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 / checker self-tests (pull_request) Canceled after 0s

문제: 0bb1f0af에서 모듈을 Babel AST로 읽게 바꾼 뒤, 파일 맨 위의
지시문(`"use client";`)을 세지 않는다. Babel은 지시문을
`program.directives`에 두고 `body`에 넣지 않는다(ESTree 변환은 body에
넣었다). V8 coverage는 `"use client"`를 문장 1개로 세고 `"use strict"`는
세지 않는다(desktop에서 실제 V8 실행으로 확인). 그래서 지시문과 타입만
있는 모듈이 counterless로 분류되고 coverage에는 문장이 잡혀, 파생
프로젝트에서 risk-coverage가 거짓으로 실패한다. 지금 `src/`에는
지시문이 없어 375개 대조에서 보이지 않았다. 새 눈 리뷰(fe-testing
렌즈)가 찾았다.

고른 방법: `"use strict"`가 아닌 지시문이 있으면 counter-bearing이다.
check:v8-coverage-counter-semantics의 fixture에 지시문 모듈 둘
(`use client`는 counter-bearing, `use strict`는 counterless)을 더해,
분류기가 기대는 V8 동작을 실제 실행으로 고정한다. risk-coverage 시험도
같은 두 모듈을 분류한다.

위험·한계: 예전 분류(ESTree)는 `"use strict"`만 있는 모듈을
counter-bearing으로 봤다. 이제 V8과 같이 counterless다.

검증(desktop): risk-coverage·risk-coverage-files·counter-semantics 시험
통과, check:v8-coverage-counter-semantics PASS(2 counter-bearing,
8 counterless), check:types·eslint rc=0. 변이: 지시문 규칙을 빼면
「matches the observed V8 counterless …」가 `directive-use-client.ts`를
counterless로 받아 실패. 로그 /tmp/claude-gates/w2fe2-dir1·2·4/.

Fixes: 0bb1f0afc0 ("perf(coverage): 위험 커버리지 모듈 목록을 Babel 파서와 동기 fs로 만든다")
This commit is contained in:
DongHyeonka
2026-11-12 22:45:48 +09:00
parent e2bf08e9ea
commit 0c3c9d3351
7 changed files with 65 additions and 14 deletions
+19 -2
View File
@@ -427,6 +427,13 @@ function statementIsCoverageCounterBearing(value: unknown): boolean {
return true;
}
function directiveIsCoverageCounterBearing(value: unknown): boolean {
if (!isRecord(value) || !isRecord(value.value) || typeof value.value.value !== "string") {
throw new TypeError("TypeScript parser returned an invalid directive");
}
return value.value.value !== "use strict";
}
export function hasCoverageCounterBearingStatements(
source: string,
relativePath: string,
@@ -457,10 +464,20 @@ export function hasCoverageCounterBearingStatements(
});
}
const program = isRecord(parsed) ? parsed.program : undefined;
if (!isRecord(program) || !Array.isArray(program.body)) {
if (
!isRecord(program) ||
!Array.isArray(program.body) ||
!Array.isArray(program.directives)
) {
throw new TypeError("TypeScript parser returned an invalid program");
}
return program.body.some(statementIsCoverageCounterBearing);
// Babel keeps the directive prologue in `directives`, not `body` (ESTree
// put it in `body`). V8 coverage counts a directive as a statement, all but
// "use strict" (check:v8-coverage-counter-semantics runs both).
return (
program.directives.some(directiveIsCoverageCounterBearing) ||
program.body.some(statementIsCoverageCounterBearing)
);
}
export async function buildProductionModuleInventory(
+14 -7
View File
@@ -19,8 +19,13 @@ const coverageMetrics = [
"functions",
"branches",
] as const;
const runtimeModule = "src/runtime.ts";
/** Modules V8 gives at least one counter: code, and a directive prologue. */
const counterBearingModules = Object.freeze([
"src/directive-use-client.ts",
"src/runtime.ts",
] as const);
const counterlessModules = Object.freeze([
"src/directive-use-strict.ts",
"src/import-empty.ts",
"src/import-side-effect.ts",
"src/import-type-empty.ts",
@@ -29,8 +34,8 @@ const counterlessModules = Object.freeze([
"src/reexport-star.ts",
"src/type-only.ts",
] as const);
const expectedModules = Object.freeze(
[runtimeModule, ...counterlessModules].sort(),
const expectedModules: readonly string[] = Object.freeze(
[...counterBearingModules, ...counterlessModules].sort(),
);
const childOutputLimit = 1_800;
/**
@@ -156,9 +161,11 @@ export function assertV8CoverageCounterSemantics(
`V8 coverage row set mismatch; missing: ${missing.join(", ") || "none"}; additional: ${additional.join(", ") || "none"}`,
);
}
const runtimeRow = rows.get(runtimeModule)!;
if (!coverageMetrics.some((metric) => runtimeRow[metric].total > 0)) {
throw new Error(`V8 runtime module is not counter-bearing: ${runtimeModule}`);
for (const modulePath of counterBearingModules) {
const row = rows.get(modulePath)!;
if (!coverageMetrics.some((metric) => row[metric].total > 0)) {
throw new Error(`V8 module is not counter-bearing: ${modulePath}`);
}
}
for (const modulePath of counterlessModules) {
const row = rows.get(modulePath)!;
@@ -178,7 +185,7 @@ export function assertV8CoverageCounterSemantics(
}
}
return Object.freeze({
counterBearingModules: Object.freeze([runtimeModule]),
counterBearingModules: Object.freeze([...counterBearingModules]),
counterlessModules: Object.freeze([...counterlessModules]),
});
}
@@ -1,5 +1,7 @@
/// <reference types="vitest/globals" />
import "./src/directive-use-client.ts";
import "./src/directive-use-strict.ts";
import "./src/import-empty.ts";
import "./src/import-side-effect.ts";
import "./src/import-type-empty.ts";
@@ -0,0 +1,4 @@
"use client";
// A directive prologue and types only. V8 counts the directive as a statement.
export type ClientOnly = 1;
@@ -0,0 +1,4 @@
"use strict";
// "use strict" and types only. V8 does not count "use strict".
export type StrictOnly = 1;
+10
View File
@@ -699,6 +699,14 @@ describe("repository-aware risk coverage", () => {
path.join(repositoryRoot, "src/reexport-star.ts"),
"export * from './a.ts';\n",
),
writeFile(
path.join(repositoryRoot, "src/directive-use-client.ts"),
"'use client';\nexport type ClientOnly = 1;\n",
),
writeFile(
path.join(repositoryRoot, "src/directive-use-strict.ts"),
'"use strict";\nexport type StrictOnly = 1;\n',
),
]);
const productionInventory = await buildProductionModuleInventory({
@@ -708,6 +716,7 @@ describe("repository-aware risk coverage", () => {
expect(productionInventory.counterlessModules).toEqual([
"src/barrel.ts",
"src/directive-use-strict.ts",
"src/import-side-effect.ts",
"src/import-type-empty.ts",
"src/import-value-empty.ts",
@@ -718,6 +727,7 @@ describe("repository-aware risk coverage", () => {
]);
expect(productionInventory.counterBearingModules).toEqual([
"src/a.ts",
"src/directive-use-client.ts",
"src/nested/b.tsx",
"src/runtime-export.ts",
"src/side-effect.ts",
@@ -33,6 +33,7 @@ const zeroMetrics = Object.freeze({
branches: zeroCounter,
});
const counterlessPaths = Object.freeze([
"src/directive-use-strict.ts",
"src/import-empty.ts",
"src/import-side-effect.ts",
"src/import-type-empty.ts",
@@ -53,15 +54,15 @@ function fixtureSummary(root: string): Record<string, unknown> {
branches: zeroCounter,
},
],
[
path.join(root, "src/runtime.ts"),
...["src/directive-use-client.ts", "src/runtime.ts"].map((modulePath) => [
path.join(root, modulePath),
{
lines: { total: 1, covered: 1, skipped: 0, pct: 100 },
statements: { total: 1, covered: 1, skipped: 0, pct: 100 },
functions: zeroCounter,
branches: zeroCounter,
},
],
]),
...counterlessPaths.map((modulePath) => [path.join(root, modulePath), zeroMetrics]),
]);
}
@@ -87,7 +88,7 @@ describe("V8 coverage counter semantics", () => {
const root = "/owned-fixture";
expect(assertV8CoverageCounterSemantics(fixtureSummary(root), root)).toEqual({
counterBearingModules: ["src/runtime.ts"],
counterBearingModules: ["src/directive-use-client.ts", "src/runtime.ts"],
counterlessModules: counterlessPaths,
});
});
@@ -121,7 +122,13 @@ describe("V8 coverage counter semantics", () => {
const runtimeDrift = fixtureSummary(root);
runtimeDrift[path.join(root, "src/runtime.ts")] = zeroMetrics;
expect(() => assertV8CoverageCounterSemantics(runtimeDrift, root)).toThrow(
/runtime.*counter-bearing/u,
/not counter-bearing: src\/runtime\.ts/u,
);
const directiveDrift = fixtureSummary(root);
directiveDrift[path.join(root, "src/directive-use-client.ts")] = zeroMetrics;
expect(() => assertV8CoverageCounterSemantics(directiveDrift, root)).toThrow(
/not counter-bearing: src\/directive-use-client\.ts/u,
);
});