fix(ci): 실패한 ci:gate가 실패한 명령, 로그 경로, 로그 끝줄을 말한다
`corepack pnpm ci:gate <ID>`가 실패하면 콘솔에는 `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
This commit is contained in:
@@ -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");
|
||||
}
|
||||
+12
-1
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user