Files
clean-architecture-frontend…/tests/unit/ci-gate-failure.test.ts
T
DongHyeonka 36f8c00fd7
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 / merge / static checks (pull_request) Successful in 3m54s
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
frontend-quality-gates / merge / tests (pull_request) Canceled after 10m30s
test(ci): ci:gate 실패 출력이 실패한 명령을 받는 연결을 실행으로 지킨다
앞 커밋의 시험은 출력 문구를 만드는 순수 함수(formatGateFailure)만 본다.
run-ci-gate.ts에서 실패한 명령을 기억하는 줄(failedCommand = commandLine)을
지워도 그 시험은 통과한다(확인 리뷰, fe-testing 함정 1).

고른 방법: tests/system/ci-runner의 임시 root 방식 그대로, FE-GATE-004의 명령
하나를 일부러 실패하는 script로 바꾼 계약으로 run-ci-gate.ts를 돌린다. stderr가
게이트, 실패한 명령, 로그 경로, 원인 줄을 말하는지 본다. timeout은 같은 방식의
그 시험에서 잰 값을 쓴다.

검증: 실패한 명령을 기억하는 줄을 지운 변이에서 새 시험이 실패하고 원래
코드에서 통과한다(desktop, PR 본문).

Refs: 1112/08-13
2026-11-13 00:13:25 +09:00

111 lines
4.7 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 { describe, expect, it } from "vitest";
import { loadCiGateContract } from "../../scripts/contracts/ci-gates.ts";
import { formatGateFailure } from "../../scripts/lib/ci-gate-failure.ts";
import { FIXTURE_PNPM_ENVIRONMENT } from "../../scripts/lib/fixture-node-modules.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");
});
});
// 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`);
const result = spawnSync(
process.execPath,
[path.resolve("scripts/run-ci-gate.ts"), "FE-GATE-004"],
{ cwd: root, encoding: "utf8", env: { ...process.env, ...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 });
}
});
});