mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-03 11:40:22 +00:00
test: isolate MCP live cache probe
This commit is contained in:
@@ -24,12 +24,54 @@ const env = {
|
||||
OPENCLAW_LIVE_TEST_QUIET: quietOverride ?? process.env.OPENCLAW_LIVE_TEST_QUIET ?? "1",
|
||||
};
|
||||
|
||||
function parsePositiveInt(value, fallback) {
|
||||
if (!value) {
|
||||
return fallback;
|
||||
}
|
||||
const parsed = Number.parseInt(value, 10);
|
||||
return Number.isFinite(parsed) && parsed > 0 ? parsed : fallback;
|
||||
}
|
||||
|
||||
const heartbeatMs = parsePositiveInt(process.env.OPENCLAW_LIVE_WRAPPER_HEARTBEAT_MS, 20_000);
|
||||
const startedAt = Date.now();
|
||||
let lastOutputAt = startedAt;
|
||||
|
||||
const child = spawnPnpmRunner({
|
||||
stdio: ["inherit", "pipe", "pipe"],
|
||||
pnpmArgs: ["exec", "vitest", "run", "--config", "vitest.live.config.ts", ...forwardedArgs],
|
||||
env,
|
||||
});
|
||||
|
||||
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) => {
|
||||
clearInterval(heartbeat);
|
||||
if (signal) {
|
||||
process.kill(process.pid, signal);
|
||||
return;
|
||||
@@ -38,6 +80,7 @@ child.on("exit", (code, signal) => {
|
||||
});
|
||||
|
||||
child.on("error", (error) => {
|
||||
clearInterval(heartbeat);
|
||||
console.error(error);
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user