mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-04 13:50:23 +00:00
fix(ci): fail on fatal test runner output
This commit is contained in:
35
scripts/test-parallel-utils.mjs
Normal file
35
scripts/test-parallel-utils.mjs
Normal file
@@ -0,0 +1,35 @@
|
||||
const DEFAULT_OUTPUT_CAPTURE_LIMIT = 200_000;
|
||||
|
||||
const fatalOutputPatterns = [
|
||||
/FATAL ERROR:.*heap out of memory/i,
|
||||
/Allocation failed - JavaScript heap out of memory/i,
|
||||
/node::OOMErrorHandler/i,
|
||||
];
|
||||
|
||||
export function appendCapturedOutput(current, chunk, limit = DEFAULT_OUTPUT_CAPTURE_LIMIT) {
|
||||
if (!chunk) {
|
||||
return current;
|
||||
}
|
||||
const next = `${current}${chunk}`;
|
||||
if (next.length <= limit) {
|
||||
return next;
|
||||
}
|
||||
return next.slice(-limit);
|
||||
}
|
||||
|
||||
export function hasFatalTestRunOutput(output) {
|
||||
return fatalOutputPatterns.some((pattern) => pattern.test(output));
|
||||
}
|
||||
|
||||
export function resolveTestRunExitCode({ code, signal, output }) {
|
||||
if (typeof code === "number" && code !== 0) {
|
||||
return code;
|
||||
}
|
||||
if (signal) {
|
||||
return 1;
|
||||
}
|
||||
if (hasFatalTestRunOutput(output)) {
|
||||
return 1;
|
||||
}
|
||||
return code ?? 0;
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { channelTestPrefixes } from "../vitest.channel-paths.mjs";
|
||||
import { isUnitConfigTestFile } from "../vitest.unit-paths.mjs";
|
||||
import { appendCapturedOutput, resolveTestRunExitCode } from "./test-parallel-utils.mjs";
|
||||
import {
|
||||
loadTestRunnerBehavior,
|
||||
loadUnitTimingManifest,
|
||||
@@ -740,10 +741,11 @@ const runOnce = (entry, extraArgs = []) =>
|
||||
const resolvedNodeOptions = heapFlag
|
||||
? `${nextNodeOptions} ${heapFlag}`.trim()
|
||||
: nextNodeOptions;
|
||||
let output = "";
|
||||
let child;
|
||||
try {
|
||||
child = spawn(pnpm, args, {
|
||||
stdio: "inherit",
|
||||
stdio: ["inherit", "pipe", "pipe"],
|
||||
env: { ...process.env, VITEST_GROUP: entry.name, NODE_OPTIONS: resolvedNodeOptions },
|
||||
shell: isWindows,
|
||||
});
|
||||
@@ -753,17 +755,26 @@ const runOnce = (entry, extraArgs = []) =>
|
||||
return;
|
||||
}
|
||||
children.add(child);
|
||||
child.stdout?.on("data", (chunk) => {
|
||||
const text = chunk.toString();
|
||||
output = appendCapturedOutput(output, text);
|
||||
process.stdout.write(chunk);
|
||||
});
|
||||
child.stderr?.on("data", (chunk) => {
|
||||
const text = chunk.toString();
|
||||
output = appendCapturedOutput(output, text);
|
||||
process.stderr.write(chunk);
|
||||
});
|
||||
child.on("error", (err) => {
|
||||
console.error(`[test-parallel] child error: ${String(err)}`);
|
||||
});
|
||||
child.on("exit", (code, signal) => {
|
||||
child.on("close", (code, signal) => {
|
||||
children.delete(child);
|
||||
const resolvedCode = resolveTestRunExitCode({ code, signal, output });
|
||||
console.log(
|
||||
`[test-parallel] done ${entry.name} code=${String(code ?? (signal ? 1 : 0))} elapsed=${formatElapsedMs(
|
||||
Date.now() - startedAt,
|
||||
)}`,
|
||||
`[test-parallel] done ${entry.name} code=${String(resolvedCode)} elapsed=${formatElapsedMs(Date.now() - startedAt)}`,
|
||||
);
|
||||
resolve(code ?? (signal ? 1 : 0));
|
||||
resolve(resolvedCode);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user