Merge remote-tracking branch 'origin/main' into fix/r9-gate-failure-output
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 / 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
frontend-quality-gates / external-vulnerability-provider (pull_request) Canceled after 0s
frontend-quality-gates / external-provenance-provider (pull_request) Canceled after 0s

This commit is contained in:
DongHyeonka
2026-11-13 04:29:34 +09:00
67 changed files with 1437 additions and 701 deletions
+1 -1
View File
@@ -4,7 +4,7 @@ export const ciContractReportSchema = z
.object({
schemaVersion: z.literal(2),
nodeVersion: z.string().regex(/^\d+\.\d+\.\d+$/u),
gateCount: z.literal(28),
gateCount: z.literal(29),
commandDefinitionCount: z.number().int().positive(),
commandReferenceCount: z.number().int().positive(),
artifactCount: z.number().int().positive(),
+41
View File
@@ -0,0 +1,41 @@
import path from "node:path";
/**
* Vitest matches `coverage.include` and `coverage.exclude` against each
* module's absolute path with picomatch `contains: true`, so a relative
* pattern may match anywhere in that path. `src/**` also matched
* `<checkout>/vite.config.ts` when the checkout sat in a folder whose name
* ends in `src` (`~/work/app-src/`), and risk coverage then failed on rows
* outside the repository inventory. A pattern that starts with the root
* matches only inside it.
*
* The root is escaped with the expression Vitest's glob library (tinyglobby
* 0.2) uses for a cwd, so a root with glob characters still matches itself
* literally and the untested-file glob resolves the pattern back to
* `src/...` under that cwd. A Windows root is turned into forward slashes
* first; for a valid Windows path that escape equals tinyglobby's Windows one.
*/
const UNESCAPED_GLOB_SYMBOLS =
/(?<!\\)([()[\]{}*?|]|^!|[!+@](?=\()|\\(?![()[\]{}!*+?@|]))/gu;
export function rootAnchoredGlobs(
root: string,
patterns: readonly string[],
): string[] {
const normalizedRoot = path.resolve(root).split(path.sep).join("/");
const escapedRoot = normalizedRoot.replace(UNESCAPED_GLOB_SYMBOLS, "\\$&");
return patterns.map((pattern) => {
if (
pattern.length === 0 ||
pattern.startsWith("/") ||
pattern.startsWith("!") ||
pattern.includes("\\") ||
pattern.split("/").includes("..")
) {
throw new TypeError(
`coverage pattern must be a forward-slash path inside the root: ${pattern}`,
);
}
return `${escapedRoot.replace(/\/$/u, "")}/${pattern}`;
});
}
+33 -4
View File
@@ -22,6 +22,29 @@ const BROWSER =
const DRILL =
"a removal drill copies the repository again. The drill runs the generated " +
"feature's own removal instead (feature-removal).";
/**
* The drill runs FE-GATE-005's test:coverage in the same copy, and its paths
* hold every path of these suites (tests/unit/removal-drill-test-paths.test.ts).
* Running them plain as well found nothing more and cost about 80 s a drill.
*/
const COVERED =
"test:coverage runs the same test files in this copy " +
"(tests/unit/removal-drill-test-paths.test.ts checks the paths).";
export const SCAFFOLD_DRILL_COVERED_SUITES: readonly string[] = Object.freeze([
"test:runtime-schema",
"test:unit",
"test:contract",
"test:component",
"test:integration",
]);
/**
* What a removal drill runs next to test:coverage so that every test:all path
* still runs once in the copy (scripts/test-sample-removal.ts). The rest of
* test:all, check:release-coherence included, is inside coverage's paths.
*/
export const REMOVAL_DRILL_SUITES_OUTSIDE_COVERAGE: readonly string[] = Object.freeze([
"test:recipes",
]);
export const SCAFFOLD_DRILL_EXCLUDED_SCRIPTS: Readonly<Record<string, string>> = Object.freeze({
"verify:lockfile":
@@ -38,11 +61,9 @@ export const SCAFFOLD_DRILL_EXCLUDED_SCRIPTS: Readonly<Record<string, string>> =
"needs the CI runner's bubblewrap, systemd and cgroup v2 " +
"(scripts/check-system-test-prerequisites.ts). It tests the provider " +
"sandbox, which a feature does not reach.",
...Object.fromEntries(SCAFFOLD_DRILL_COVERED_SUITES.map((script) => [script, COVERED])),
"test:sample-removal": DRILL,
"test:feature-scaffold": "is this drill.",
"test:optional-recipe-removal": DRILL,
"test:browser-file-storage-removal": DRILL,
"test:realtime-removal": DRILL,
});
export type ScaffoldDrillCommand = Readonly<{
@@ -65,6 +86,14 @@ export function scaffoldDrillCommands(
const mergeScripts = new Set<string>();
const seen = new Set<string>();
const selected: ScaffoldDrillCommand[] = [];
// A covered suite is left out only while the drill runs test:coverage. A
// copy whose merge stage lost it runs the suites plain again.
const runsCoverage = !Object.hasOwn(excluded, "test:coverage") && merge.gateIds.some((gateId) =>
contract.gates.find(({ id }) => id === gateId)?.commandIds.some((commandId) =>
commands.get(commandId)?.script === "test:coverage"));
const leftOut = (script: string) =>
Object.hasOwn(excluded, script) &&
(runsCoverage || !SCAFFOLD_DRILL_COVERED_SUITES.includes(script) || excluded[script] !== COVERED);
for (const gateId of merge.gateIds) {
const gate = contract.gates.find(({ id }) => id === gateId);
if (!gate) throw new TypeError(`the merge stage names an undefined gate: ${gateId}`);
@@ -72,7 +101,7 @@ export function scaffoldDrillCommands(
const command = commands.get(commandId);
if (!command) throw new TypeError(`${gateId} names an undefined command: ${commandId}`);
mergeScripts.add(command.script);
if (seen.has(commandId) || Object.hasOwn(excluded, command.script)) continue;
if (seen.has(commandId) || leftOut(command.script)) continue;
seen.add(commandId);
selected.push(Object.freeze({
name: `${gateId}:${commandId}`,
+4 -1
View File
@@ -43,7 +43,10 @@ export const PROMOTION_FORMULA = Object.freeze({
// F2 (design-docs repo-structure/03-ci.md 7.3). The checkers' negative
// fixtures and the gating coverage check run after a merge to main. They
// test the checkers, not the change, so they hold no promotion.
MAIN_READY: Object.freeze(["FE-GATE-029"]),
// FE-GATE-030 (owner decision 2026-11-12 p): the optional runtime removal
// drills moved here from FE-GATE-020. A failure turns main red, and the next
// pull request fixes it before it merges.
MAIN_READY: Object.freeze(["FE-GATE-029", "FE-GATE-030"]),
});
export type GateResult = "PASS" | "FAIL" | "UNVERIFIED";
+64 -23
View File
@@ -1,12 +1,17 @@
import { constants, type Dirent, type Stats } from "node:fs";
import {
lstat,
open,
readdir,
realpath,
} from "node:fs/promises";
closeSync,
constants,
type Dirent,
fstatSync,
lstatSync,
openSync,
readdirSync,
readFileSync,
realpathSync,
type Stats,
} from "node:fs";
import path from "node:path";
import babelParser from "@babel/eslint-parser";
import { parseSync } from "@babel/core";
import {
COVERAGE_SUMMARY_METRICS as coverageMetrics,
@@ -422,23 +427,35 @@ 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,
): boolean {
// Babel's own parser and AST. @babel/eslint-parser ran the same parser and
// then converted the whole tree and its tokens to ESTree, about 2.8 times
// the cost over the repository, and the top-level statement types and
// flags read here are the same in both trees. Every production module is
// parsed once per inventory, and the inventory is built in the gate and in
// its tests.
let parsed: unknown;
try {
parsed = babelParser.parse(source, {
parsed = parseSync(source, {
filename: relativePath,
babelrc: false,
configFile: false,
sourceType: "module",
requireConfigFile: false,
filePath: relativePath,
babelOptions: {
parserOpts: {
plugins: [
"typescript",
...(relativePath.endsWith(".tsx") ? ["jsx"] : []),
],
},
parserOpts: {
plugins: [
"typescript",
...(relativePath.endsWith(".tsx") ? (["jsx"] as const) : []),
],
},
});
} catch (error) {
@@ -446,10 +463,21 @@ export function hasCoverageCounterBearingStatements(
cause: error,
});
}
if (!isRecord(parsed) || !Array.isArray(parsed.body)) {
const program = isRecord(parsed) ? parsed.program : undefined;
if (
!isRecord(program) ||
!Array.isArray(program.body) ||
!Array.isArray(program.directives)
) {
throw new TypeError("TypeScript parser returned an invalid program");
}
return parsed.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(
@@ -457,12 +485,25 @@ export async function buildProductionModuleInventory(
): Promise<ProductionModuleInventory> {
const repositoryRoot = path.resolve(options.repositoryRoot ?? process.cwd());
const sourceRoot = path.join(repositoryRoot, "src");
// The default file system makes the same calls in the same order as the
// fs/promises one, synchronously. The walk awaits about six calls per
// module one after another; through the thread pool each waited for an
// event-loop turn, and on a loaded CI machine that wait, not the work, made
// the inventory take seconds. Injected file systems keep the async shape.
const readDirectory = options.readDirectory ??
((target: string) => readdir(target, { withFileTypes: true }));
const lstatPath = options.lstatPath ?? lstat;
const realpathPath = options.realpathPath ?? realpath;
(async (target: string) => readdirSync(target, { withFileTypes: true }));
const lstatPath = options.lstatPath ?? (async (target: string) => lstatSync(target));
const realpathPath = options.realpathPath ??
(async (target: string) => realpathSync.native(target));
const openFile = options.openFile ??
((target: string, flags: number) => open(target, flags));
(async (target: string, flags: number): Promise<ReadableFileHandle> => {
const descriptor = openSync(target, flags);
return {
stat: async () => fstatSync(descriptor),
readFile: async (encoding) => readFileSync(descriptor, encoding),
close: async () => closeSync(descriptor),
};
});
const generatedPaths = uniquePaths(options.generatedPaths ?? [], "generatedPaths");
const generated = new Set(generatedPaths);
const repositoryRealpath = await realpathPath(repositoryRoot);
+34 -14
View File
@@ -10,6 +10,8 @@ import { tmpdir } from "node:os";
import path from "node:path";
import { promisify } from "node:util";
import { rootAnchoredGlobs } from "./coverage-scope.ts";
const execFileAsync = promisify(execFile);
const coverageMetrics = [
"lines",
@@ -17,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",
@@ -27,15 +34,25 @@ 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;
/**
* The fixture is copied into a folder whose name ends in `src` and has glob
* characters. Vitest matches coverage patterns anywhere in an absolute path,
* so an unanchored `src/**` also counts the fixture's root-level
* `outside-src.ts`, which the row-set check then reports as additional. The
* repository's own coverage patterns are anchored the same way
* (vitest.config.ts, scripts/lib/coverage-scope.ts).
*/
const fixtureCheckoutName = "checkout (copy)-src";
type ChildOutput = Readonly<{ stdout: string; stderr: string }>;
type ChildInput = Readonly<{
repositoryRoot: string;
ownedRoot: string;
fixtureRoot: string;
configPath: string;
}>;
type CheckerOptions = Readonly<{
@@ -144,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)!;
@@ -166,7 +185,7 @@ export function assertV8CoverageCounterSemantics(
}
}
return Object.freeze({
counterBearingModules: Object.freeze([runtimeModule]),
counterBearingModules: Object.freeze([...counterBearingModules]),
counterlessModules: Object.freeze([...counterlessModules]),
});
}
@@ -195,7 +214,7 @@ async function defaultRunVitest(input: ChildInput): Promise<ChildOutput> {
"--no-color",
],
{
cwd: input.ownedRoot,
cwd: input.fixtureRoot,
encoding: "utf8",
timeout: 30_000,
maxBuffer: 256 * 1024,
@@ -232,15 +251,16 @@ export async function checkV8CoverageCounterSemantics(
repositoryRoot,
"tests/fixtures/v8-coverage-counter-semantics",
);
const configPath = path.join(ownedRoot, "vitest.config.mjs");
const fixtureRoot = path.join(ownedRoot, fixtureCheckoutName);
const configPath = path.join(fixtureRoot, "vitest.config.mjs");
const reportsDirectory = path.join(ownedRoot, "coverage");
try {
await cp(fixtureSource, ownedRoot, { recursive: true });
await cp(fixtureSource, fixtureRoot, { recursive: true });
await writeFile(
configPath,
`export default ${JSON.stringify(
{
root: ownedRoot,
root: fixtureRoot,
test: {
globals: true,
include: ["counter-semantics.fixture.ts"],
@@ -249,7 +269,7 @@ export async function checkV8CoverageCounterSemantics(
provider: "v8",
reportsDirectory,
reporter: ["json-summary"],
include: ["src/**/*.ts"],
include: rootAnchoredGlobs(fixtureRoot, ["src/**/*.ts"]),
},
},
},
@@ -259,7 +279,7 @@ export async function checkV8CoverageCounterSemantics(
"utf8",
);
try {
await runVitest({ repositoryRoot, ownedRoot, configPath });
await runVitest({ repositoryRoot, ownedRoot, fixtureRoot, configPath });
} catch (error) {
const record = isRecord(error) ? error : {};
throw new Error(
@@ -287,7 +307,7 @@ export async function checkV8CoverageCounterSemantics(
cause: error,
});
}
return assertV8CoverageCounterSemantics(summary, ownedRoot);
return assertV8CoverageCounterSemantics(summary, fixtureRoot);
} finally {
await rm(ownedRoot, { recursive: true, force: true });
}