test: stabilize full-suite flakes

This commit is contained in:
Peter Steinberger
2026-04-23 18:47:25 +01:00
parent d0303e2a97
commit 310b1eea4a
7 changed files with 72 additions and 15 deletions

View File

@@ -145,9 +145,9 @@ export async function runChangedCheck(result, options = {}) {
}
} else if (plan.runChangedTestsBroad) {
const testArgs = options.explicitPaths
? ["scripts/test-projects.mjs"]
: ["scripts/test-projects.mjs", "--changed", options.base ?? "origin/main"];
const status = await runNode(
? ["test"]
: ["test", "--changed", options.base ?? "origin/main"];
const status = await runPnpm(
{
name: options.explicitPaths ? "tests all" : "tests changed broad",
args: testArgs,
@@ -159,10 +159,10 @@ export async function runChangedCheck(result, options = {}) {
return status;
}
} else if (plan.testTargets.length > 0) {
const status = await runNode(
const status = await runPnpm(
{
name: "tests changed",
args: ["scripts/test-projects.mjs", ...plan.testTargets],
args: ["test", ...plan.testTargets],
},
timings,
);
@@ -209,10 +209,6 @@ async function runPnpm(command, timings) {
return await runCommand({ ...command, bin: "pnpm" }, timings);
}
async function runNode(command, timings) {
return await runCommand({ ...command, bin: process.execPath }, timings);
}
async function runCommand(command, timings) {
const startedAt = performance.now();
console.error(`\n[check:changed] ${command.name}`);

View File

@@ -180,7 +180,13 @@ export function forwardVitestOutput(stream, target, shouldSuppressLine = () => f
});
}
export function spawnWatchedVitestProcess({ pnpmArgs, spawnParams, env, label }) {
export function spawnWatchedVitestProcess({
pnpmArgs,
spawnParams,
env,
label,
onNoOutputTimeout,
}) {
const child = spawnVitestProcess({
pnpmArgs,
spawnParams,
@@ -194,6 +200,7 @@ export function spawnWatchedVitestProcess({ pnpmArgs, spawnParams, env, label })
console.error(message);
},
onTimeout: () => {
onNoOutputTimeout?.();
forwardSignalToVitestProcessGroup({
child,
signal: "SIGTERM",

View File

@@ -189,11 +189,15 @@ function runVitestSpec(spec) {
if (spec.includeFilePath && spec.includePatterns) {
writeVitestIncludeFile(spec.includeFilePath, spec.includePatterns);
}
let noOutputTimedOut = false;
return new Promise((resolve, reject) => {
const { child, teardown } = spawnWatchedVitestProcess({
pnpmArgs: spec.pnpmArgs,
env: spec.env,
label: spec.config,
onNoOutputTimeout: () => {
noOutputTimedOut = true;
},
spawnParams: {
cwd: process.cwd(),
...resolveVitestSpawnParams(spec.env),
@@ -203,7 +207,7 @@ function runVitestSpec(spec) {
child.on("exit", (code, signal) => {
teardown();
cleanupVitestRunSpec(spec);
resolve({ code: code ?? 1, signal });
resolve({ code: code ?? (signal ? 143 : 1), noOutputTimedOut, signal });
});
child.on("error", (error) => {
@@ -231,8 +235,21 @@ function applyDefaultParallelVitestWorkerBudget(specs, env) {
async function runLoggedVitestSpec(spec) {
console.error(`[test] starting ${spec.config}`);
const startedAt = performance.now();
const result = await runVitestSpec(spec);
let result = await runVitestSpec(spec);
if (result.noOutputTimedOut && !spec.watchMode) {
console.error(`[test] retrying ${spec.config} after no-output timeout`);
result = await runVitestSpec(spec);
}
const durationMs = performance.now() - startedAt;
if (result.noOutputTimedOut && result.signal) {
console.error(`[test] ${spec.config} exceeded no-output timeout`);
return {
...result,
code: result.code || 143,
signal: null,
timing: null,
};
}
if (result.signal) {
console.error(`[test] ${spec.config} exited by signal ${result.signal}`);
releaseLockOnce();

View File

@@ -1,4 +1,6 @@
import { describe, expect, it } from "vitest";
import path from "node:path";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { clearBundledProviderPolicySurfaceCache } from "../plugins/provider-public-artifacts.js";
import type { OpenClawConfig } from "./config.js";
import { applyProviderConfigDefaultsForConfig } from "./provider-policy.js";
@@ -13,6 +15,19 @@ function applyAnthropicDefaultsForTest(config: OpenClawConfig) {
}
describe("config pruning defaults", () => {
beforeEach(() => {
clearBundledProviderPolicySurfaceCache();
vi.stubEnv(
"OPENCLAW_BUNDLED_PLUGINS_DIR",
path.resolve(import.meta.dirname, "../../extensions"),
);
});
afterEach(() => {
vi.unstubAllEnvs();
clearBundledProviderPolicySurfaceCache();
});
it("does not enable contextPruning by default", () => {
const cfg = applyAnthropicDefaultsForTest({ agents: { defaults: {} } });

View File

@@ -1,9 +1,24 @@
import { describe, expect, it } from "vitest";
import path from "node:path";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { DEFAULT_CONTEXT_TOKENS } from "../agents/defaults.js";
import { clearBundledProviderPolicySurfaceCache } from "../plugins/provider-public-artifacts.js";
import { applyModelDefaults } from "./defaults.js";
import type { OpenClawConfig } from "./types.js";
describe("applyModelDefaults", () => {
beforeEach(() => {
clearBundledProviderPolicySurfaceCache();
vi.stubEnv(
"OPENCLAW_BUNDLED_PLUGINS_DIR",
path.resolve(import.meta.dirname, "../../extensions"),
);
});
afterEach(() => {
vi.unstubAllEnvs();
clearBundledProviderPolicySurfaceCache();
});
function buildProxyProviderConfig(overrides?: { contextWindow?: number; maxTokens?: number }) {
return {
models: {

View File

@@ -8,6 +8,8 @@ const repoRoot = path.resolve(import.meta.dirname, "..");
const ALLOWED_EXTENSION_PUBLIC_SURFACE_BASENAMES = new Set(
GUARDED_EXTENSION_PUBLIC_SURFACE_BASENAMES,
);
const ROOTDIR_BOUNDARY_CANARY_RE =
/(^|\/)__rootdir_boundary_canary__\.(?:[cm]?ts|[cm]?js|tsx|jsx)$/u;
function walk(dir: string, entries: string[] = []): string[] {
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
@@ -40,7 +42,11 @@ function walkCode(dir: string, entries: string[] = []): string[] {
if (!entry.name.endsWith(".ts") && !entry.name.endsWith(".tsx")) {
continue;
}
entries.push(path.relative(repoRoot, fullPath).replaceAll(path.sep, "/"));
const relativePath = path.relative(repoRoot, fullPath).replaceAll(path.sep, "/");
if (ROOTDIR_BOUNDARY_CANARY_RE.test(relativePath)) {
continue;
}
entries.push(relativePath);
}
return entries;
}

View File

@@ -17,6 +17,7 @@ export function createExtensionTelegramVitestConfig(
{
dir: "extensions",
env,
fileParallelism: false,
name: "extension-telegram",
passWithNoTests: true,
setupFiles: ["test/setup.extensions.ts"],