From c38b4c3a5b08cfb0e677da5ef4d461f758f94f32 Mon Sep 17 00:00:00 2001 From: DongHyeonka Date: Thu, 12 Nov 2026 23:06:25 +0900 Subject: [PATCH 1/2] =?UTF-8?q?fix(ci):=20=EC=8B=A4=ED=8C=A8=ED=95=9C=20ci?= =?UTF-8?q?:gate=EA=B0=80=20=EC=8B=A4=ED=8C=A8=ED=95=9C=20=EB=AA=85?= =?UTF-8?q?=EB=A0=B9,=20=EB=A1=9C=EA=B7=B8=20=EA=B2=BD=EB=A1=9C,=20?= =?UTF-8?q?=EB=A1=9C=EA=B7=B8=20=EB=81=9D=EC=A4=84=EC=9D=84=20=EB=A7=90?= =?UTF-8?q?=ED=95=9C=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `corepack pnpm ci:gate `가 실패하면 콘솔에는 `FE-GATE-013 security: FAIL` 한 줄만 나온다. 어느 명령이 실패했는지, 원인이 남은 로그가 어디인지 말하지 않는다. 그래서 verify.sh의 게이트 로그도 그 세 줄뿐이고, 원인을 보려면 artifacts/quality/gates/ 아래 로그를 따로 찾아야 한다. 규칙 (.claude/rules/gates-and-budgets.md)은 실패 메시지가 넘은 항목·잰 값· 고칠 파일을 말하라고 한다. 고른 방법: scripts/lib/ci-gate-failure.ts의 formatGateFailure가 FAIL 줄, 실패한 명령(없으면 명령 밖 검사라고), 로그 경로, 로그 끝 20줄을 만든다. run-ci-gate.ts가 기대에 어긋난 명령을 기억해 넘긴다. 버린 대안: 명령의 출력을 그대로 흘리기(PASS일 때도 콘솔이 길어진다). 위험·한계: 끝 20줄에 원인이 없을 수 있다. 로그 경로가 있으니 거기서 본다. 검증: tests/unit/ci-gate-failure.test.ts 셋이 고치기 전에는 모듈이 없어 실패하고 고친 뒤 통과한다. desktop의 FE-GATE-013(호스트 제약으로 실패)이 새 출력을 낸다(PR 본문). Refs: 1112/08-13 --- scripts/lib/ci-gate-failure.ts | 25 ++++++++++++ scripts/run-ci-gate.ts | 13 ++++++- tests/unit/ci-gate-failure.test.ts | 62 ++++++++++++++++++++++++++++++ 3 files changed, 99 insertions(+), 1 deletion(-) create mode 100644 scripts/lib/ci-gate-failure.ts create mode 100644 tests/unit/ci-gate-failure.test.ts diff --git a/scripts/lib/ci-gate-failure.ts b/scripts/lib/ci-gate-failure.ts new file mode 100644 index 00000000..e795dec1 --- /dev/null +++ b/scripts/lib/ci-gate-failure.ts @@ -0,0 +1,25 @@ +/** + * 1112/08-13. What a failed `ci:gate` prints to stderr: the gate, the command + * that failed (or that none did), the log with the whole output, and the end + * of that output, where the cause usually is. + */ +export function formatGateFailure(input: Readonly<{ + gateId: string; + gateName: string; + logPath: string; + failedCommand?: string | undefined; + output: readonly string[]; + tailLines?: number; +}>): string { + const tail = input.output + .flatMap((chunk) => chunk.split(/\r?\n/u)) + .filter((line) => line.trim() !== "") + .slice(-(input.tailLines ?? 20)); + return [ + `${input.gateId} ${input.gateName}: FAIL`, + ` failed command: ${input.failedCommand ?? "none (a check outside the commands)"}`, + ` log: ${input.logPath}`, + " last lines of the log:", + ...tail.map((line) => ` ${line}`), + ].join("\n"); +} diff --git a/scripts/run-ci-gate.ts b/scripts/run-ci-gate.ts index d1167601..92957f43 100644 --- a/scripts/run-ci-gate.ts +++ b/scripts/run-ci-gate.ts @@ -11,6 +11,7 @@ import { import { classifyGateStepResult } from "./lib/ci-step-result.ts"; import { withCiGatePreflight } from "./contracts/ci-gates.ts"; import { validateCiArtifact } from "./lib/ci-artifact-validator.ts"; +import { formatGateFailure } from "./lib/ci-gate-failure.ts"; import { writeCiGateLogAtomic } from "./lib/ci-gate-log.ts"; const requestedGateId = process.argv @@ -111,6 +112,7 @@ for (const variable of gate.requiresEnvironment ?? []) { } } +let failedCommand: string | undefined; if (passed) { for (const commandId of gate.commandIds) { const step = contractIndex.commands.get(commandId); @@ -174,6 +176,7 @@ if (passed) { }); if (!appendOutput(`classification: ${classification.kind}`)) passed = false; if (!classification.expectationMet) { + failedCommand = commandLine; appendOutput( `expectation failed: expected ${step.expect}, exit=${result.status}, signal=${result.signal ?? "none"}`, ...(step.expect === "fail" @@ -241,7 +244,15 @@ if (passed) { } if (!passed) { - process.stderr.write(`${gateId} ${gate.name}: FAIL\n`); + process.stderr.write( + `${formatGateFailure({ + gateId, + gateName: gate.name, + logPath: logArtifact.path, + failedCommand, + output, + })}\n`, + ); process.exit(1); } process.stdout.write( diff --git a/tests/unit/ci-gate-failure.test.ts b/tests/unit/ci-gate-failure.test.ts new file mode 100644 index 00000000..db66d294 --- /dev/null +++ b/tests/unit/ci-gate-failure.test.ts @@ -0,0 +1,62 @@ +import { describe, expect, it } from "vitest"; + +import { formatGateFailure } from "../../scripts/lib/ci-gate-failure.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"); + }); +}); From 36f8c00fd793338ed94f174d9f7c9a475d4ec3e0 Mon Sep 17 00:00:00 2001 From: DongHyeonka Date: Fri, 13 Nov 2026 00:13:25 +0900 Subject: [PATCH 2/2] =?UTF-8?q?test(ci):=20ci:gate=20=EC=8B=A4=ED=8C=A8=20?= =?UTF-8?q?=EC=B6=9C=EB=A0=A5=EC=9D=B4=20=EC=8B=A4=ED=8C=A8=ED=95=9C=20?= =?UTF-8?q?=EB=AA=85=EB=A0=B9=EC=9D=84=20=EB=B0=9B=EB=8A=94=20=EC=97=B0?= =?UTF-8?q?=EA=B2=B0=EC=9D=84=20=EC=8B=A4=ED=96=89=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EC=A7=80=ED=82=A8=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 앞 커밋의 시험은 출력 문구를 만드는 순수 함수(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 --- tests/unit/ci-gate-failure.test.ts | 48 ++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/tests/unit/ci-gate-failure.test.ts b/tests/unit/ci-gate-failure.test.ts index db66d294..f3db4bb7 100644 --- a/tests/unit/ci-gate-failure.test.ts +++ b/tests/unit/ci-gate-failure.test.ts @@ -1,6 +1,14 @@ +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: @@ -60,3 +68,43 @@ describe("formatGateFailure", () => { 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; + }; + 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 }); + } + }); +});