frontend-quality-gates / merge / static checks (pull_request) Successful in 1m26s
frontend-quality-gates / merge / tests (pull_request) Successful in 17m2s
frontend-quality-gates / merge / browser tests (pull_request) Successful in 5m42s
frontend-quality-gates / FE-GATE-017 / diagram-review (pull_request) Skipped
frontend-quality-gates / main / self-tests and removal drills (pull_request) Skipped
frontend-quality-gates / FE-GATE-014 / config-compatibility (pull_request) Skipped
frontend-quality-gates / FE-GATE-028 / manual-accessibility-review (pull_request) Skipped
frontend-quality-gates / FE-GATE-026 / lab-performance (pull_request) Skipped
frontend-quality-gates / FE-GATE-015 / immutable-release-candidate (pull_request) Skipped
frontend-quality-gates / external-vulnerability-provider (pull_request) Skipped
frontend-quality-gates / external-provenance-provider (pull_request) Skipped
frontend-quality-gates / promote-verified-immutable-candidate (pull_request) Skipped
frontend-quality-gates / deploy-promoted-release (pull_request) Skipped
frontend-quality-gates / FE-GATE-019 / hosting-header (pull_request) Skipped
frontend-quality-gates / FE-GATE-021 / runbook-boot-config (pull_request) Skipped
frontend-quality-gates / FE-GATE-022 / runbook-chunk-mismatch (pull_request) Skipped
frontend-quality-gates / FE-GATE-023 / runbook-api-degradation (pull_request) Skipped
frontend-quality-gates / FE-GATE-024 / runbook-telemetry (pull_request) Skipped
frontend-quality-gates / FE-GATE-025 / runbook-release-rollback (pull_request) Skipped
frontend-quality-gates / FE-GATE-018 / field-web-vitals (pull_request) Skipped
문제: `ci:gate`가 실패하면 job 로그에는 게이트 출력의 끝 20줄만
남는다. Playwright는 실패 블록 뒤에 첨부·개수 줄·자기 stderr를 찍고,
제거 드릴은 실패한 vitest 뒤에 다른 명령 줄을 찍는다. 그래서 단언
(기대·받은 값)이 20줄 밖으로 밀린다. runner run 371의 FE-GATE-008은
`expect.poll(...).toEqual(...)`의 코드 틀만, run 376의 FE-GATE-030은
vitest 코드 틀만 남기고 `FAIL` 줄과 ENOENT를 잃었다. 원인을 보려면
artifact를 받아야 했다.
고른 방법: 실패한 명령의 줄 뒤에서 Playwright나 vitest가 찍은 첫 실패
블록을 찾아 「first failure in the log」로 끝 줄 앞에 둔다.
- Playwright: `1) [project] › file:line:col › 제목`부터 다음 실패나
개수 줄(`1 failed`, `68 passed`) 앞까지.
- vitest: `Failed Suites N`·`Failed Tests N`·`Unhandled Errors` 줄부터
닫는 구분선(`[1/N]` 또는 맨 줄)까지. 모양은 desktop에서 vitest 4.1을
돌려 확인했다.
앞 명령은 기대를 채웠으니(음성 fixture가 일부러 낸 실패) 보지 않는다.
블록은 40줄까지 싣고 넘는 줄 수를 적는다. 끝 줄이 이미 보이는 부분은
다시 싣지 않는다. 색 코드는 판정할 때만 떼고 줄은 그대로 싣는다.
버린 것: 끝 줄 수만 늘리기(드릴처럼 뒤 출력이 길면 또 밀리고 job
로그만 길어진다), `Error:` 낱말 찾기(통과한 시험의 stderr에도 나온다,
run 376 FE-GATE-030 로그의 chunk-recovery-boundary 줄).
위험·한계: reporter 형식(Playwright 번호 줄, vitest 구분선)에 기댄다.
형식이 바뀌어 블록을 못 찾으면 지금처럼 끝 줄만 보인다. 실패한 명령
안에서 다른 실패가 먼저 찍히면(드릴 안의 음성 fixture 출력) 그 블록을
고른다. 실행기는 명령의 stdout 다음에 stderr를 붙이므로 「첫」은 로그
안의 순서다. 끝 줄은 늘 그대로 있다. fixture 셋 중 둘은 두 run의 게이트
로그(artifacts/quality/gates/)를 줄이고 checkout 경로를 줄인 것, 하나는
vitest 4.1 탐침 출력이다.
검증(desktop, `scripts/verify.sh`, 깨끗한 worktree):
- RED: 기준 2b9a7715 + 새 시험 → 새 시험 4건 실패(rc=1).
- GREEN: `tests/unit/ci-gate-failure.test.ts` 13개 통과, lint·
check:types rc=0. 변이 8건(끝 조건 넷, Unhandled 머리, 명령 영역,
상한, 겹침 제거) 모두 새 시험이 잡음.
- `scripts/verify.sh merge` 14개 rc=0, `gate FE-GATE-029 FE-GATE-030`
rc=0(제거 드릴이 tests/를 사본에 복사해 이 시험을 돌린다).
Refs: fe-ci-next (1), runner run 371 FE-GATE-008, run 376 FE-GATE-030
311 lines
13 KiB
TypeScript
311 lines
13 KiB
TypeScript
import { spawnSync } from "node:child_process";
|
||
import { mkdir, mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
|
||
import { tmpdir } from "node:os";
|
||
import path from "node:path";
|
||
import { stripVTControlCharacters } from "node:util";
|
||
|
||
import { describe, expect, it } from "vitest";
|
||
|
||
import { loadCiGateContract } from "../../scripts/contracts/ci-gates.ts";
|
||
import { FIRST_FAILURE_MAX_LINES, formatGateFailure } from "../../scripts/lib/ci-gate-failure.ts";
|
||
import { FIXTURE_PNPM_ENVIRONMENT } from "../../scripts/lib/fixture-node-modules.ts";
|
||
import { PR_BASE_REF_VARIABLE } from "../../scripts/lib/pr-gate-selection.ts";
|
||
import { childProcessTimeout } from "../helpers/child-process-timeout.ts";
|
||
|
||
/**
|
||
* 1112/08-13. A failed `ci:gate` printed one line, `FE-GATE-013 security:
|
||
* FAIL`: neither the command that failed nor the log that holds the cause
|
||
* (.claude/rules/gates-and-budgets.md: a failure names what it crossed and
|
||
* where to look).
|
||
*/
|
||
describe("formatGateFailure", () => {
|
||
const output = [
|
||
"$ corepack pnpm verify:lockfile",
|
||
"lockfile ok",
|
||
"classification: PASS",
|
||
"$ corepack pnpm test:system",
|
||
"System test prerequisites: FAIL\n - this host does not allow unprivileged user namespaces\n",
|
||
"classification: COMMAND_FAILURE",
|
||
"expectation failed: expected pass, exit=1, signal=none",
|
||
];
|
||
|
||
it("names the gate, the failed command and the log", () => {
|
||
const text = formatGateFailure({
|
||
gateId: "FE-GATE-013",
|
||
gateName: "security",
|
||
logPath: "artifacts/quality/gates/FE-GATE-013.txt",
|
||
failedCommand: "$ corepack pnpm test:system",
|
||
output,
|
||
});
|
||
|
||
expect(text.split("\n")[0]).toBe("FE-GATE-013 security: FAIL");
|
||
expect(text).toContain("failed command: $ corepack pnpm test:system");
|
||
expect(text).toContain("log: artifacts/quality/gates/FE-GATE-013.txt");
|
||
});
|
||
|
||
it("quotes the end of the log, where the cause is", () => {
|
||
const text = formatGateFailure({
|
||
gateId: "FE-GATE-013",
|
||
gateName: "security",
|
||
logPath: "artifacts/quality/gates/FE-GATE-013.txt",
|
||
failedCommand: "$ corepack pnpm test:system",
|
||
output,
|
||
tailLines: 4,
|
||
});
|
||
|
||
expect(text).toContain("this host does not allow unprivileged user namespaces");
|
||
expect(text).toContain("expectation failed: expected pass, exit=1");
|
||
expect(text).not.toContain("lockfile ok");
|
||
});
|
||
|
||
it("says when no command failed (a check before or after the commands)", () => {
|
||
const text = formatGateFailure({
|
||
gateId: "FE-GATE-005",
|
||
gateName: "unit",
|
||
logPath: "artifacts/quality/gates/FE-GATE-005.txt",
|
||
output: ["missing required environment: CI_RUNNER_IMAGE"],
|
||
});
|
||
|
||
expect(text).toContain("failed command: none (a check outside the commands)");
|
||
expect(text).toContain("missing required environment: CI_RUNNER_IMAGE");
|
||
});
|
||
});
|
||
|
||
// Runner runs 371 and 376. The last 20 lines held the reporter's summary, the
|
||
// pnpm stderr and the classification, not the assertion: run 371's FE-GATE-008
|
||
// job log showed the code frame of a failed `expect.poll(...).toEqual(...)`
|
||
// but neither the expected nor the received value, and run 376's FE-GATE-030
|
||
// lost the vitest `FAIL` line and its ENOENT to the removal drill's later
|
||
// commands. Two fixtures are those gate logs (artifacts/quality/gates/), cut
|
||
// down, with the checkout path shortened; the third is vitest 4.1's own output
|
||
// for a suite that fails to load, two failed tests and an unhandled rejection
|
||
// (probed on desktop 2026-11-19).
|
||
describe("formatGateFailure with a reporter's failure block", () => {
|
||
const fixture = (name: string) =>
|
||
readFile(path.join("tests/fixtures/ci-gate-failure", name), "utf8");
|
||
// The reporters color their output; the assertions read the text.
|
||
const plain = (text: string) => stripVTControlCharacters(text);
|
||
/** The quoted first failure, without its four-space indent. */
|
||
const firstFailure = (text: string) => {
|
||
const lines = plain(text).split("\n");
|
||
const from = lines.indexOf(" first failure in the log:");
|
||
const to = lines.indexOf(" last lines of the log:");
|
||
return from === -1 ? [] : lines.slice(from + 1, to).map((line) => line.slice(4));
|
||
};
|
||
// Lines a reporter prints after the failures, enough to push them out of
|
||
// the last 20 lines.
|
||
const laterOutput = Array.from({ length: 25 }, (_, index) => `[WebServer] request ${index + 1}`);
|
||
const passedCommand = [
|
||
"$ corepack pnpm test:e2e",
|
||
" 189 passed (1.8m)",
|
||
"classification: EXPECTED_PASS",
|
||
];
|
||
const failing = (command: string, output: readonly string[]) =>
|
||
formatGateFailure({
|
||
gateId: "FE-GATE-008",
|
||
gateName: "e2e",
|
||
logPath: "artifacts/quality/gates/FE-GATE-008.txt",
|
||
failedCommand: command,
|
||
output: [command, ...output],
|
||
});
|
||
|
||
it("quotes the first Playwright failure with its expected and received values", async () => {
|
||
const text = formatGateFailure({
|
||
gateId: "FE-GATE-008",
|
||
gateName: "e2e",
|
||
logPath: "artifacts/quality/gates/FE-GATE-008.txt",
|
||
failedCommand: "$ corepack pnpm test:browser-capabilities",
|
||
output: [...passedCommand, await fixture("playwright-assertion.txt")],
|
||
});
|
||
|
||
expect(text).toContain(
|
||
"1) [chromium] › tests/browser-capabilities/cross-context-invalidation.spec.ts:223:1",
|
||
);
|
||
expect(text).toContain("Error: expect(received).toEqual(expected) // deep equality");
|
||
expect(text).toContain("- Expected - 8");
|
||
expect(text).toContain("+ Received + 1");
|
||
expect(text).toContain('- "sequence": 1,');
|
||
expect(text).toContain("+ Array []");
|
||
// The end of the log is still there.
|
||
expect(text).toContain("expectation failed: expected pass, exit=1, signal=none");
|
||
});
|
||
|
||
it("quotes the first vitest failure that a drill printed before its later commands", async () => {
|
||
const text = plain(formatGateFailure({
|
||
gateId: "FE-GATE-030",
|
||
gateName: "optional-removability",
|
||
logPath: "artifacts/quality/gates/FE-GATE-030.txt",
|
||
failedCommand: "$ corepack pnpm test:browser-file-storage-removal",
|
||
output: [await fixture("vitest-in-removal-drill.txt")],
|
||
}));
|
||
|
||
expect(text).toContain(
|
||
"FAIL tests/unit/test-evidence-source-rules.test.ts > test evidence source rules > rejects a focused test",
|
||
);
|
||
expect(text).toContain("AssertionError: expected 'node:internal/fs/promises:637");
|
||
expect(text).toContain("to contain 'focused test'");
|
||
expect(text).toContain(
|
||
"Error: ENOENT: no such file or directory, open 'playwright.capabilities.config.ts'",
|
||
);
|
||
expect(text).toContain("Browser file/storage runtime removal failed: test");
|
||
});
|
||
|
||
it("ends a Playwright failure where the next one starts", () => {
|
||
const quoted = firstFailure(failing("$ corepack pnpm test:e2e", [
|
||
" 1) [chromium] › tests/e2e/first.spec.ts:3:1 › fails first",
|
||
" Error: the first failure",
|
||
" 2) [firefox] › tests/e2e/second.spec.ts:5:1 › fails second",
|
||
" Error: the second failure",
|
||
" 2 failed",
|
||
...laterOutput,
|
||
]));
|
||
|
||
expect(quoted).toEqual([
|
||
" 1) [chromium] › tests/e2e/first.spec.ts:3:1 › fails first",
|
||
" Error: the first failure",
|
||
]);
|
||
});
|
||
|
||
it("ends a Playwright failure before the count lines", () => {
|
||
const quoted = firstFailure(failing("$ corepack pnpm test:e2e", [
|
||
" 1) [chromium] › tests/e2e/only.spec.ts:3:1 › fails",
|
||
" Error: the only failure",
|
||
" 1 failed",
|
||
" [chromium] › tests/e2e/only.spec.ts:3:1 › fails",
|
||
" 68 passed (1.2m)",
|
||
...laterOutput,
|
||
]));
|
||
|
||
expect(quoted).toEqual([
|
||
" 1) [chromium] › tests/e2e/only.spec.ts:3:1 › fails",
|
||
" Error: the only failure",
|
||
]);
|
||
});
|
||
|
||
it("ends a vitest failure with its closing rule", async () => {
|
||
const quoted = firstFailure(formatGateFailure({
|
||
gateId: "FE-GATE-005",
|
||
gateName: "unit",
|
||
logPath: "artifacts/quality/gates/FE-GATE-005.txt",
|
||
failedCommand: "$ corepack pnpm test:unit",
|
||
output: [await fixture("vitest-suites-tests-unhandled.txt"), ...laterOutput],
|
||
}));
|
||
|
||
expect(quoted[0]).toMatch(/⎯ Failed Suites 1 ⎯/u);
|
||
expect(quoted).toContain("Error: probe suite failure at import");
|
||
expect(quoted.at(-1)).toMatch(/⎯\[1\/3\]⎯$/u);
|
||
expect(quoted.join("\n")).not.toContain("fails one");
|
||
});
|
||
|
||
it("quotes vitest's unhandled errors when every test passed", async () => {
|
||
const probe = (await fixture("vitest-suites-tests-unhandled.txt")).split("\n");
|
||
const unhandled = probe.findIndex((line) => plain(line).includes("⎯ Unhandled Errors ⎯"));
|
||
expect(unhandled).toBeGreaterThan(0);
|
||
const quoted = firstFailure(failing("$ corepack pnpm test:unit", [
|
||
" ✓ tests/unit/passes.test.ts (1 test) 13ms",
|
||
...probe.slice(unhandled),
|
||
...laterOutput,
|
||
]));
|
||
|
||
expect(quoted[0]).toMatch(/⎯ Unhandled Errors ⎯/u);
|
||
expect(quoted).toContain("Error: probe unhandled rejection");
|
||
expect(quoted.at(-1)).toMatch(/^⎯+$/u);
|
||
expect(quoted.join("\n")).not.toContain("Test Files");
|
||
});
|
||
|
||
it("looks only in the output of the command that failed", async () => {
|
||
const text = formatGateFailure({
|
||
gateId: "FE-GATE-008",
|
||
gateName: "e2e",
|
||
logPath: "artifacts/quality/gates/FE-GATE-008.txt",
|
||
failedCommand: "$ corepack pnpm test:browser-capabilities",
|
||
output: [
|
||
// A negative fixture fails on purpose and meets its expectation.
|
||
"$ corepack pnpm check:fails-on-purpose",
|
||
" 1) [chromium] › tests/e2e/negative.spec.ts:3:1 › fails on purpose",
|
||
" Error: a failure this command was expected to print",
|
||
" 1 failed",
|
||
"classification: EXPECTED_FAILURE",
|
||
await fixture("playwright-assertion.txt"),
|
||
],
|
||
});
|
||
|
||
expect(text).not.toContain("a failure this command was expected to print");
|
||
expect(text).toContain("Error: expect(received).toEqual(expected) // deep equality");
|
||
});
|
||
|
||
it("bounds a long failure and says how much more the log holds", () => {
|
||
const diff = Array.from({ length: 120 }, (_, index) => ` + line ${index + 1}`);
|
||
const block = [
|
||
" 1) [chromium] › tests/e2e/long.spec.ts:3:1 › prints a long diff",
|
||
" Error: expect(received).toEqual(expected) // deep equality",
|
||
...diff,
|
||
];
|
||
const text = failing("$ corepack pnpm test:e2e", [...block, " 1 failed", ...laterOutput]);
|
||
const quoted = firstFailure(text);
|
||
|
||
expect(quoted).toEqual([
|
||
...block.slice(0, FIRST_FAILURE_MAX_LINES),
|
||
`… ${block.length - FIRST_FAILURE_MAX_LINES} more lines of this failure in the log`,
|
||
]);
|
||
// Three heading lines, the quoted failure, the end of the log.
|
||
expect(text.split("\n")).toHaveLength(3 + 1 + FIRST_FAILURE_MAX_LINES + 1 + 1 + 20);
|
||
});
|
||
|
||
it("does not repeat a failure that the last lines already show", () => {
|
||
const text = failing("$ corepack pnpm test:e2e", [
|
||
" 1) [chromium] › tests/e2e/short.spec.ts:3:1 › fails",
|
||
" Error: the one failure",
|
||
" 1 failed",
|
||
"classification: UNEXPECTED_EXIT",
|
||
]);
|
||
|
||
expect(firstFailure(text)).toEqual([]);
|
||
expect(text.split("Error: the one failure").length - 1).toBe(1);
|
||
});
|
||
});
|
||
|
||
// round9 confirm review. The runner itself hands the failed command to that
|
||
// text: a gate whose one command fails names it, its log and its last line.
|
||
// Same temp-root runner as tests/system/ci-runner/ci-evidence-freshness.test.ts,
|
||
// whose measured run this reuses.
|
||
describe("run-ci-gate on a failing command", { timeout: childProcessTimeout(871) }, () => {
|
||
it("names the command, the log and the cause", async () => {
|
||
const root = await mkdtemp(path.join(tmpdir(), "ci-gate-failure-output-"));
|
||
try {
|
||
await mkdir(path.join(root, "config/ci"), { recursive: true });
|
||
const contract = JSON.parse(
|
||
JSON.stringify(await loadCiGateContract(process.cwd())),
|
||
) as { commands: { id: string; script: string }[] };
|
||
const command = contract.commands.find((entry) => entry.id === "test-runtime-schema");
|
||
if (!command) throw new Error("expected the runtime-schema command");
|
||
command.script = "test:fails-on-purpose";
|
||
const packageDocument = JSON.parse(await readFile("package.json", "utf8")) as {
|
||
scripts: Record<string, string>;
|
||
};
|
||
packageDocument.scripts[command.script] =
|
||
"node -e \"console.error('the cause of this failure'); process.exit(3)\"";
|
||
await writeFile(path.join(root, "config/ci/gates.json"), `${JSON.stringify(contract)}\n`);
|
||
await writeFile(path.join(root, "package.json"), `${JSON.stringify(packageDocument)}\n`);
|
||
|
||
// The job environment of a PR run: its merge jobs set the PR's base
|
||
// branch (runner run 291). The fixture environment turns the selection
|
||
// off, so this gate runs here whatever run this test is in.
|
||
const prRunEnvironment = { ...process.env, [PR_BASE_REF_VARIABLE]: "main" };
|
||
const result = spawnSync(
|
||
process.execPath,
|
||
[path.resolve("scripts/run-ci-gate.ts"), "FE-GATE-004"],
|
||
{ cwd: root, encoding: "utf8", env: { ...prRunEnvironment, ...FIXTURE_PNPM_ENVIRONMENT, CI: "false" } },
|
||
);
|
||
|
||
expect(result.status).toBe(1);
|
||
expect(result.stderr).toContain("FE-GATE-004 runtime-schema: FAIL");
|
||
expect(result.stderr).toContain("failed command: $ corepack pnpm test:fails-on-purpose");
|
||
expect(result.stderr).toContain("log: artifacts/quality/gates/FE-GATE-004.txt");
|
||
expect(result.stderr).toContain("the cause of this failure");
|
||
} finally {
|
||
await rm(root, { recursive: true, force: true });
|
||
}
|
||
});
|
||
});
|