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
96 lines
4.1 KiB
TypeScript
96 lines
4.1 KiB
TypeScript
import { stripVTControlCharacters } from "node:util";
|
||
|
||
/** The most lines of the first failure block the summary quotes. */
|
||
export const FIRST_FAILURE_MAX_LINES = 40;
|
||
|
||
// Where Playwright or vitest starts a failure block. Playwright numbers each
|
||
// failed test (` 1) [chromium] › tests/x.spec.ts:3:1 › title`). vitest prints
|
||
// a `Failed Suites 1` or `Failed Tests 2` rule and then a ` FAIL file > test`
|
||
// line for each, and an `Unhandled Errors` rule when an error escaped the
|
||
// tests (vitest 4.1, probed on desktop 2026-11-19).
|
||
const PLAYWRIGHT_FAILURE = /^\s*\d+\) .*:\d+:\d+ › /u;
|
||
const VITEST_FAILURES = /⎯ (Failed (Tests|Suites) \d+|Unhandled Errors) ⎯/u;
|
||
// Where that block ends: the next failure, Playwright's count lines
|
||
// (` 1 failed`, ` 68 passed (1.2m)`), vitest's `[1/6]` rule after each
|
||
// failure or the bare rule after the unhandled errors.
|
||
const PLAYWRIGHT_COUNT = /^\s*\d+ (failed|flaky|interrupted|skipped|did not run|passed)\b/u;
|
||
const VITEST_FAILURE_END = /⎯\[\d+\/\d+\]⎯|^⎯+$/u;
|
||
|
||
/**
|
||
* 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, the first
|
||
* Playwright or vitest failure block in that command's output, and the end
|
||
* of the output. The end alone lost the assertion: a reporter prints counts,
|
||
* attachments and its own stderr after the failure, and a drill runs more
|
||
* commands after the test that failed (runner runs 371 and 376).
|
||
*/
|
||
export function formatGateFailure(input: Readonly<{
|
||
gateId: string;
|
||
gateName: string;
|
||
logPath: string;
|
||
failedCommand?: string | undefined;
|
||
output: readonly string[];
|
||
tailLines?: number;
|
||
}>): string {
|
||
const lines = input.output
|
||
.flatMap((chunk) => chunk.split(/\r?\n/u))
|
||
.filter((line) => line.trim() !== "");
|
||
const tailStart = Math.max(0, lines.length - (input.tailLines ?? 20));
|
||
const failure = firstFailureBlock(lines, input.failedCommand);
|
||
// The part of the block that the last lines show anyway is not repeated.
|
||
const quoted = failure
|
||
? lines.slice(failure.start, Math.min(failure.end, tailStart))
|
||
: [];
|
||
const omitted = Math.max(0, quoted.length - FIRST_FAILURE_MAX_LINES);
|
||
return [
|
||
`${input.gateId} ${input.gateName}: FAIL`,
|
||
` failed command: ${input.failedCommand ?? "none (a check outside the commands)"}`,
|
||
` log: ${input.logPath}`,
|
||
...(quoted.length > 0
|
||
? [
|
||
" first failure in the log:",
|
||
...quoted.slice(0, FIRST_FAILURE_MAX_LINES).map((line) => ` ${line}`),
|
||
...(omitted > 0 ? [` … ${omitted} more lines of this failure in the log`] : []),
|
||
]
|
||
: []),
|
||
" last lines of the log:",
|
||
...lines.slice(tailStart).map((line) => ` ${line}`),
|
||
].join("\n");
|
||
}
|
||
|
||
/**
|
||
* Where the first reporter failure block after the failed command's own line
|
||
* starts and ends (exclusive), as indexes into `lines`. An earlier command met
|
||
* its expectation, so a failure it printed (a negative fixture) is not the
|
||
* cause. Without a failed command there is no block.
|
||
*/
|
||
function firstFailureBlock(
|
||
lines: readonly string[],
|
||
failedCommand: string | undefined,
|
||
): { start: number; end: number } | undefined {
|
||
if (failedCommand === undefined) return undefined;
|
||
const commandIndex = lines.lastIndexOf(failedCommand);
|
||
if (commandIndex === -1) return undefined;
|
||
const plain = lines.map((line) => stripVTControlCharacters(line));
|
||
const endOf = (start: number, isEnd: (line: string) => boolean) => {
|
||
let end = start + 1;
|
||
while (end < plain.length && !isEnd(plain[end] ?? "")) end += 1;
|
||
return end;
|
||
};
|
||
for (let start = commandIndex + 1; start < plain.length; start += 1) {
|
||
const line = plain[start] ?? "";
|
||
if (PLAYWRIGHT_FAILURE.test(line)) {
|
||
// The next failure or a count line is not part of this one.
|
||
return {
|
||
start,
|
||
end: endOf(start, (next) => PLAYWRIGHT_FAILURE.test(next) || PLAYWRIGHT_COUNT.test(next)),
|
||
};
|
||
}
|
||
if (VITEST_FAILURES.test(line)) {
|
||
// The closing rule is.
|
||
return { start, end: Math.min(plain.length, endOf(start, (next) => VITEST_FAILURE_END.test(next)) + 1) };
|
||
}
|
||
}
|
||
return undefined;
|
||
}
|