Files
adolf/scripts/test-live.mjs
alvis bedb527145
Some checks failed
ClawSweeper Dispatch / dispatch (push) Has been cancelled
CodeQL / Security High (actions) (push) Has been cancelled
CodeQL / Security High (channel-runtime-boundary) (push) Has been cancelled
CodeQL / Security High (core-auth-secrets) (push) Has been cancelled
CodeQL / Security High (mcp-process-tool-boundary) (push) Has been cancelled
CodeQL / Security High (network-ssrf-boundary) (push) Has been cancelled
CodeQL / Security High (plugin-trust-boundary) (push) Has been cancelled
CodeQL / Security High (process-exec-boundary) (push) Has been cancelled
Docs Sync Publish Repo / sync-publish-repo (push) Has been cancelled
Docs / docs (push) Has been cancelled
OpenClaw Stable Main Closeout / Resolve stable release closeout inputs (push) Has been cancelled
OpenClaw Stable Main Closeout / Verify stable main closeout (push) Has been cancelled
Workflow Sanity / no-tabs (push) Has been cancelled
Workflow Sanity / actionlint (push) Has been cancelled
Workflow Sanity / generated-doc-baselines (push) Has been cancelled
CI / runner-admission (push) Has been cancelled
CI / preflight (push) Has been cancelled
CI / security-fast (push) Has been cancelled
CI / pnpm-store-warmup (push) Has been cancelled
CI / build-artifacts (push) Has been cancelled
CI / native-i18n (push) Has been cancelled
CI / ${{ matrix.check_name }} (push) Has been cancelled
CI / ${{ matrix.checkName }} (push) Has been cancelled
CI / checks-node-compat-node22 (push) Has been cancelled
CI / check-bundled-channel-config-metadata (push) Has been cancelled
CI / check-dependencies (push) Has been cancelled
CI / check-guards (push) Has been cancelled
CI / check-lint (push) Has been cancelled
CI / check-prod-types (push) Has been cancelled
CI / check-shrinkwrap (push) Has been cancelled
CI / check-test-types (push) Has been cancelled
CI / check-additional-boundaries-a (push) Has been cancelled
CI / check-additional-boundaries-bcd (push) Has been cancelled
CI / check-additional-extension-bundled (push) Has been cancelled
CI / check-additional-extension-channels (push) Has been cancelled
CI / check-additional-extension-package-boundary (push) Has been cancelled
CI / check-additional-runtime-topology-architecture (push) Has been cancelled
CI / check-session-accessor-boundary (push) Has been cancelled
CI / check-session-transcript-reader-boundary (push) Has been cancelled
CI / check-docs (push) Has been cancelled
CI / skills-python (push) Has been cancelled
CI / macos-swift (push) Has been cancelled
CI / ios-build (push) Has been cancelled
CI / ci-timings-summary (push) Has been cancelled
Native App Locale Refresh / Refresh native fa (push) Has been cancelled
Native App Locale Refresh / Refresh native fr (push) Has been cancelled
Native App Locale Refresh / Refresh native hi (push) Has been cancelled
Native App Locale Refresh / Refresh native id (push) Has been cancelled
Native App Locale Refresh / Refresh native it (push) Has been cancelled
Native App Locale Refresh / Refresh native ja-JP (push) Has been cancelled
Control UI Locale Refresh / plan (push) Has been cancelled
Control UI Locale Refresh / Refresh ${{ matrix.locale }} (push) Has been cancelled
Control UI Locale Refresh / Commit control UI locale refresh (push) Has been cancelled
Live Media Runner Image / Build live media runner image (push) Has been cancelled
Native App Locale Refresh / Refresh native ar (push) Has been cancelled
Native App Locale Refresh / Refresh native de (push) Has been cancelled
Native App Locale Refresh / Refresh native es (push) Has been cancelled
Native App Locale Refresh / Refresh native ko (push) Has been cancelled
Native App Locale Refresh / Refresh native nl (push) Has been cancelled
Native App Locale Refresh / Refresh native pl (push) Has been cancelled
Native App Locale Refresh / Refresh native pt-BR (push) Has been cancelled
Native App Locale Refresh / Refresh native ru (push) Has been cancelled
Native App Locale Refresh / Refresh native sv (push) Has been cancelled
Native App Locale Refresh / Refresh native th (push) Has been cancelled
Native App Locale Refresh / Refresh native tr (push) Has been cancelled
Native App Locale Refresh / Refresh native uk (push) Has been cancelled
Native App Locale Refresh / Refresh native vi (push) Has been cancelled
Native App Locale Refresh / Refresh native zh-CN (push) Has been cancelled
Native App Locale Refresh / Refresh native zh-TW (push) Has been cancelled
Native App Locale Refresh / Commit native locale refresh (push) Has been cancelled
Plugin Init Scaffold Validation / Validate provider scaffold (push) Has been cancelled
Plugin NPM Release / preview_plugins_npm (push) Has been cancelled
Plugin NPM Release / Validate release publish approval (push) Has been cancelled
Plugin NPM Release / preview_plugin_pack (push) Has been cancelled
Plugin NPM Release / publish_plugins_npm (push) Has been cancelled
Sandbox Common Smoke / sandbox-common-smoke (push) Has been cancelled
Website Installer Sync / static (push) Has been cancelled
Website Installer Sync / linux-docker (push) Has been cancelled
Website Installer Sync / macos-installer (push) Has been cancelled
Website Installer Sync / windows-installer (push) Has been cancelled
Website Installer Sync / sync-website (push) Has been cancelled
Vendor OpenClaw source as Adolf fork baseline
Adolf is a fork/vendored clone of github.com/openclaw/openclaw (v2026.6.11),
free to diverge. Tree copied sans upstream .git; upstream remote added for
future syncs. Node pinned to 24 (.nvmrc); engines already require >=22.19.
Preserves docs/ARCHITECTURE.md.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LeqyaxJF2nbRXJtae2kNB2
2026-07-05 09:36:54 +00:00

225 lines
5.7 KiB
JavaScript

// Runs the full live Vitest suite with live-test env and heartbeat output.
import { spawnPnpmRunner } from "./pnpm-runner.mjs";
import {
forwardSignalToVitestProcessGroup,
installVitestProcessGroupCleanup,
shouldUseDetachedVitestProcessGroup,
} from "./vitest-process-group.mjs";
/**
* Renders CLI usage for the live-test wrapper.
*/
export function testLiveUsage() {
return [
"Usage: node scripts/test-live.mjs [options] [--] [vitest targets/args...]",
"",
"Runs live Vitest suites with OPENCLAW_LIVE_TEST=1.",
"",
"Options:",
" --codex-harness Enable the live Codex harness.",
" --quiet, --quiet-live Keep live test output quiet.",
" --no-quiet, --no-quiet-live",
" Show live test output.",
" -h, --help Show this help without starting live tests.",
].join("\n");
}
/**
* Parses live-test wrapper flags and forwarded Vitest args.
*/
export function parseTestLiveArgs(argv) {
const forwardedArgs = [];
let quietOverride;
let forceCodexHarness = false;
let help = false;
let passthrough = false;
for (const arg of argv) {
if (passthrough) {
forwardedArgs.push(arg);
continue;
}
if (arg === "--") {
passthrough = true;
continue;
}
if (arg === "--help" || arg === "-h") {
help = true;
continue;
}
if (arg === "--codex-harness") {
forceCodexHarness = true;
continue;
}
if (arg === "--quiet" || arg === "--quiet-live") {
quietOverride = "1";
continue;
}
if (arg === "--no-quiet" || arg === "--no-quiet-live") {
quietOverride = "0";
continue;
}
forwardedArgs.push(arg);
}
return {
forceCodexHarness,
forwardedArgs,
help,
quietOverride,
};
}
/**
* Builds env for live tests, including quiet mode and Codex harness opt-in.
*/
export function buildTestLiveEnv(args, baseEnv = process.env) {
return {
...baseEnv,
CI: baseEnv.CI || "1",
PNPM_CONFIG_VERIFY_DEPS_BEFORE_RUN: baseEnv.PNPM_CONFIG_VERIFY_DEPS_BEFORE_RUN || "false",
pnpm_config_verify_deps_before_run: baseEnv.pnpm_config_verify_deps_before_run || "false",
OPENCLAW_LIVE_TEST: baseEnv.OPENCLAW_LIVE_TEST || "1",
OPENCLAW_LIVE_TEST_QUIET: args.quietOverride ?? baseEnv.OPENCLAW_LIVE_TEST_QUIET ?? "1",
...(args.forceCodexHarness ? { OPENCLAW_LIVE_CODEX_HARNESS: "1" } : {}),
};
}
/**
* Reads the live-test heartbeat interval.
*/
export function resolveTestLiveHeartbeatMs(baseEnv = process.env) {
const value = baseEnv.OPENCLAW_LIVE_WRAPPER_HEARTBEAT_MS;
if (value === undefined || value === "") {
return 20_000;
}
const text = value.trim();
if (!/^\d+$/u.test(text)) {
throw new Error(`invalid OPENCLAW_LIVE_WRAPPER_HEARTBEAT_MS: ${text}`);
}
const parsed = Number(text);
if (!Number.isSafeInteger(parsed) || parsed <= 0) {
throw new Error(`invalid OPENCLAW_LIVE_WRAPPER_HEARTBEAT_MS: ${text}`);
}
return parsed;
}
/**
* Builds pnpm/vitest args for full live test execution.
*/
export function buildTestLivePnpmArgs(args) {
return [
"exec",
"vitest",
"run",
"--config",
"test/vitest/vitest.live.config.ts",
...args.forwardedArgs,
];
}
/**
* Builds spawn options for the live-test Vitest child.
*/
export function buildTestLiveSpawnParams(env, platform = process.platform) {
return {
detached: shouldUseDetachedVitestProcessGroup(platform),
env,
stdio: ["inherit", "pipe", "pipe"],
};
}
/**
* Runs the live-test wrapper process.
*/
export function main(argv = process.argv.slice(2), baseEnv = process.env) {
const args = parseTestLiveArgs(argv);
if (args.help) {
console.log(testLiveUsage());
process.exit(0);
}
const env = buildTestLiveEnv(args, baseEnv);
const heartbeatMs = resolveTestLiveHeartbeatMs(baseEnv);
const startedAt = Date.now();
let lastOutputAt = startedAt;
const child = spawnPnpmRunner({
pnpmArgs: buildTestLivePnpmArgs(args),
...buildTestLiveSpawnParams(env),
});
let forwardedSignal = null;
const teardownChildCleanup = installVitestProcessGroupCleanup({
child,
forceSignal: "SIGKILL",
forceSignalDelayMs: 100,
onSignal: (signal) => {
forwardedSignal ??= signal;
},
});
const teardown = () => {
clearInterval(heartbeat);
teardownChildCleanup();
};
const noteOutput = () => {
lastOutputAt = Date.now();
};
child.stdout?.on("data", (chunk) => {
noteOutput();
process.stdout.write(chunk);
});
child.stderr?.on("data", (chunk) => {
noteOutput();
process.stderr.write(chunk);
});
const heartbeat = setInterval(() => {
const now = Date.now();
if (now - lastOutputAt < heartbeatMs) {
return;
}
const elapsedSec = Math.max(1, Math.round((now - startedAt) / 1_000));
const quietSec = Math.max(1, Math.round((now - lastOutputAt) / 1_000));
process.stderr.write(
`[test:live] still running (${elapsedSec}s elapsed, ${quietSec}s since last output)\n`,
);
lastOutputAt = now;
}, heartbeatMs);
heartbeat.unref?.();
child.on("exit", (code, signal) => {
teardown();
if (forwardedSignal) {
forwardSignalToVitestProcessGroup({
child,
kill: process.kill.bind(process),
signal: "SIGKILL",
});
process.kill(process.pid, forwardedSignal);
return;
}
if (signal) {
process.stderr.write(`[test:live] vitest exited via signal=${signal}\n`);
process.kill(process.pid, signal);
return;
}
if ((code ?? 1) !== 0) {
process.stderr.write(`[test:live] vitest exited code=${code ?? 1}\n`);
}
process.exit(code ?? 1);
});
child.on("error", (error) => {
teardown();
console.error(error);
process.exit(1);
});
}
if (import.meta.main) {
main();
}