mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-12 21:53:00 -06:00
c70aee247e
* refactor(scripts): migrate JavaScript tools to TypeScript * fix(ci): keep changed-scope preflight zero-install * fix(ci): preserve zero-install script owners * fix(ci): complete script migration follow-through * fix(release): keep stable closeout zero-install * fix(scripts): preserve standalone execution boundaries * fix(scripts): repair standalone loader boundaries * fix(scripts): normalize gateway observation ids * fix(scripts): keep Docker packager standalone * test(scripts): preserve rebase cleanup helpers * test(sessions): use tracked temp directory
46 lines
1.6 KiB
TypeScript
46 lines
1.6 KiB
TypeScript
// Vitest child-process environment and native worker budget policy.
|
|
import { resolveLocalVitestEnv } from "./vitest-local-scheduling.mts";
|
|
|
|
function parseExplicitVitestWorkerBudget(value: string | undefined): number | null {
|
|
const text = value?.trim();
|
|
if (!text || !/^\d+$/u.test(text)) {
|
|
return null;
|
|
}
|
|
const parsed = Number(text);
|
|
return Number.isSafeInteger(parsed) && parsed > 0 ? parsed : null;
|
|
}
|
|
|
|
function resolveExplicitVitestWorkerBudget(env: NodeJS.ProcessEnv): number | null {
|
|
return parseExplicitVitestWorkerBudget(
|
|
env.OPENCLAW_VITEST_MAX_WORKERS ?? env.OPENCLAW_TEST_WORKERS,
|
|
);
|
|
}
|
|
|
|
function shouldApplyNativeWorkerBudget(env: NodeJS.ProcessEnv): boolean {
|
|
if (env.RAYON_NUM_THREADS?.trim() && env.TOKIO_WORKER_THREADS?.trim()) {
|
|
return false;
|
|
}
|
|
return (
|
|
env.OPENCLAW_TEST_PROJECTS_SERIAL === "1" || resolveExplicitVitestWorkerBudget(env) !== null
|
|
);
|
|
}
|
|
|
|
function resolveNativeWorkerCount(env: NodeJS.ProcessEnv): number {
|
|
return Math.min(resolveExplicitVitestWorkerBudget(env) ?? 1, 4);
|
|
}
|
|
|
|
/** Applies local Vitest scheduling and native worker budget env. */
|
|
export function resolveVitestProcessEnv(env: NodeJS.ProcessEnv = process.env): NodeJS.ProcessEnv {
|
|
const baseEnv = resolveLocalVitestEnv(env);
|
|
if (!shouldApplyNativeWorkerBudget(baseEnv)) {
|
|
return baseEnv;
|
|
}
|
|
|
|
const nativeWorkerCount = String(resolveNativeWorkerCount(baseEnv));
|
|
return {
|
|
...baseEnv,
|
|
RAYON_NUM_THREADS: baseEnv.RAYON_NUM_THREADS?.trim() || nativeWorkerCount,
|
|
TOKIO_WORKER_THREADS: baseEnv.TOKIO_WORKER_THREADS?.trim() || nativeWorkerCount,
|
|
};
|
|
}
|