/** * 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"); }