mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 13:50:49 +00:00
fix: fail fast on silent changed-test hangs
This commit is contained in:
@@ -10,6 +10,20 @@ import { printTimingSummary } from "./lib/check-timing-summary.mjs";
|
||||
import { runManagedCommand } from "./lib/managed-child-process.mjs";
|
||||
import { resolveChangedTestTargetPlan } from "./test-projects.test-support.mjs";
|
||||
|
||||
export const CHANGED_CHECK_VITEST_NO_OUTPUT_TIMEOUT_MS = "60000";
|
||||
const VITEST_NO_OUTPUT_TIMEOUT_ENV_KEY = "OPENCLAW_VITEST_NO_OUTPUT_TIMEOUT_MS";
|
||||
const VITEST_NO_OUTPUT_RETRY_ENV_KEY = "OPENCLAW_VITEST_NO_OUTPUT_RETRY";
|
||||
|
||||
export function createChangedCheckVitestEnv(baseEnv = process.env) {
|
||||
return {
|
||||
...baseEnv,
|
||||
[VITEST_NO_OUTPUT_TIMEOUT_ENV_KEY]:
|
||||
baseEnv[VITEST_NO_OUTPUT_TIMEOUT_ENV_KEY]?.trim() ||
|
||||
CHANGED_CHECK_VITEST_NO_OUTPUT_TIMEOUT_MS,
|
||||
[VITEST_NO_OUTPUT_RETRY_ENV_KEY]: baseEnv[VITEST_NO_OUTPUT_RETRY_ENV_KEY]?.trim() || "0",
|
||||
};
|
||||
}
|
||||
|
||||
export function createChangedCheckPlan(result, options = {}) {
|
||||
const commands = [];
|
||||
const add = (name, args) => {
|
||||
@@ -138,7 +152,10 @@ export async function runChangedCheck(result, options = {}) {
|
||||
}
|
||||
|
||||
if (plan.runFullTests) {
|
||||
const status = await runPnpm({ name: "tests all", args: ["test"] }, timings);
|
||||
const status = await runPnpm(
|
||||
{ name: "tests all", args: ["test"], env: createChangedCheckVitestEnv() },
|
||||
timings,
|
||||
);
|
||||
if (status !== 0) {
|
||||
printSummary(timings, options);
|
||||
return status;
|
||||
@@ -151,6 +168,7 @@ export async function runChangedCheck(result, options = {}) {
|
||||
{
|
||||
name: options.explicitPaths ? "tests all" : "tests changed broad",
|
||||
args: testArgs,
|
||||
env: createChangedCheckVitestEnv(),
|
||||
},
|
||||
timings,
|
||||
);
|
||||
@@ -163,6 +181,7 @@ export async function runChangedCheck(result, options = {}) {
|
||||
{
|
||||
name: "tests changed",
|
||||
args: ["test", ...plan.testTargets],
|
||||
env: createChangedCheckVitestEnv(),
|
||||
},
|
||||
timings,
|
||||
);
|
||||
@@ -173,7 +192,14 @@ export async function runChangedCheck(result, options = {}) {
|
||||
}
|
||||
|
||||
if (plan.runExtensionTests) {
|
||||
const status = await runPnpm({ name: "tests extensions", args: ["test:extensions"] }, timings);
|
||||
const status = await runPnpm(
|
||||
{
|
||||
name: "tests extensions",
|
||||
args: ["test:extensions"],
|
||||
env: createChangedCheckVitestEnv(),
|
||||
},
|
||||
timings,
|
||||
);
|
||||
if (status !== 0) {
|
||||
printSummary(timings, options);
|
||||
return status;
|
||||
@@ -217,6 +243,7 @@ async function runCommand(command, timings) {
|
||||
status = await runManagedCommand({
|
||||
bin: command.bin,
|
||||
args: command.args,
|
||||
env: command.env,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
|
||||
@@ -20,6 +20,7 @@ import {
|
||||
resolveParallelFullSuiteConcurrency,
|
||||
resolveChangedTargetArgs,
|
||||
shouldAcquireLocalHeavyCheckLock,
|
||||
shouldRetryVitestNoOutputTimeout,
|
||||
writeVitestIncludeFile,
|
||||
} from "./test-projects.test-support.mjs";
|
||||
|
||||
@@ -236,7 +237,7 @@ async function runLoggedVitestSpec(spec) {
|
||||
console.error(`[test] starting ${spec.config}`);
|
||||
const startedAt = performance.now();
|
||||
let result = await runVitestSpec(spec);
|
||||
if (result.noOutputTimedOut && !spec.watchMode) {
|
||||
if (result.noOutputTimedOut && !spec.watchMode && shouldRetryVitestNoOutputTimeout(spec.env)) {
|
||||
console.error(`[test] retrying ${spec.config} after no-output timeout`);
|
||||
result = await runVitestSpec(spec);
|
||||
}
|
||||
|
||||
@@ -243,6 +243,7 @@ const GENERATED_CHANGED_TEST_TARGETS = new Set([
|
||||
"src/canvas-host/a2ui/a2ui.bundle.js",
|
||||
]);
|
||||
const VITEST_NO_OUTPUT_TIMEOUT_ENV_KEY = "OPENCLAW_VITEST_NO_OUTPUT_TIMEOUT_MS";
|
||||
const VITEST_NO_OUTPUT_RETRY_ENV_KEY = "OPENCLAW_VITEST_NO_OUTPUT_RETRY";
|
||||
export const DEFAULT_TEST_PROJECTS_VITEST_NO_OUTPUT_TIMEOUT_MS = "180000";
|
||||
const VITEST_CONFIG_TARGET_KIND_BY_PATH = new Map(
|
||||
Object.entries(VITEST_CONFIG_BY_KIND).map(([kind, config]) => [config, kind]),
|
||||
@@ -1098,6 +1099,11 @@ export function applyDefaultVitestNoOutputTimeout(specs, params = {}) {
|
||||
});
|
||||
}
|
||||
|
||||
export function shouldRetryVitestNoOutputTimeout(env = process.env) {
|
||||
const value = env[VITEST_NO_OUTPUT_RETRY_ENV_KEY]?.trim().toLowerCase();
|
||||
return !["0", "false", "no", "off"].includes(value ?? "");
|
||||
}
|
||||
|
||||
export function createVitestRunSpecs(args, params = {}) {
|
||||
const cwd = params.cwd ?? process.cwd();
|
||||
const baseEnv = params.baseEnv ?? process.env;
|
||||
|
||||
Reference in New Issue
Block a user