Files
adolf/test/scripts/test-live.test.ts
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

234 lines
7.7 KiB
TypeScript

// Test Live tests cover test live script behavior.
import { spawn, spawnSync } from "node:child_process";
import { chmodSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { setTimeout as delay } from "node:timers/promises";
import { describe, expect, it } from "vitest";
import {
buildTestLiveEnv,
buildTestLivePnpmArgs,
buildTestLiveSpawnParams,
parseTestLiveArgs,
resolveTestLiveHeartbeatMs,
} from "../../scripts/test-live.mjs";
const posixIt = process.platform === "win32" ? it.skip : it;
describe("scripts/test-live", () => {
it("parses wrapper flags before live test spawn", () => {
const args = parseTestLiveArgs([
"--codex-harness",
"--no-quiet",
"--",
"src/gateway/gateway-codex-harness.live.test.ts",
"--reporter=verbose",
]);
expect(args).toEqual({
forceCodexHarness: true,
forwardedArgs: ["src/gateway/gateway-codex-harness.live.test.ts", "--reporter=verbose"],
help: false,
quietOverride: "0",
});
expect(buildTestLivePnpmArgs(args)).toEqual([
"exec",
"vitest",
"run",
"--config",
"test/vitest/vitest.live.config.ts",
"src/gateway/gateway-codex-harness.live.test.ts",
"--reporter=verbose",
]);
});
it("preserves vitest flags after the passthrough separator", () => {
const args = parseTestLiveArgs(["--quiet", "--", "--help", "--no-quiet", "--codex-harness"]);
expect(args).toEqual({
forceCodexHarness: false,
forwardedArgs: ["--help", "--no-quiet", "--codex-harness"],
help: false,
quietOverride: "1",
});
});
it("builds live env without mutating caller env", () => {
const env = buildTestLiveEnv(
{ forceCodexHarness: true, forwardedArgs: [], help: false, quietOverride: undefined },
{},
);
expect(env).toMatchObject({
CI: "1",
OPENCLAW_LIVE_CODEX_HARNESS: "1",
OPENCLAW_LIVE_TEST: "1",
OPENCLAW_LIVE_TEST_QUIET: "1",
PNPM_CONFIG_VERIFY_DEPS_BEFORE_RUN: "false",
pnpm_config_verify_deps_before_run: "false",
});
});
it("spawns live test children in a cleanup-friendly process group", () => {
expect(buildTestLiveSpawnParams({ PATH: "/usr/bin" }, "darwin")).toEqual({
detached: true,
env: { PATH: "/usr/bin" },
stdio: ["inherit", "pipe", "pipe"],
});
expect(buildTestLiveSpawnParams({ PATH: "/usr/bin" }, "win32")).toEqual({
detached: false,
env: { PATH: "/usr/bin" },
stdio: ["inherit", "pipe", "pipe"],
});
});
posixIt("signals the live pnpm child when the wrapper is terminated", async () => {
const root = mkdtempSync(join(tmpdir(), "openclaw-test-live-signal-"));
const fakePnpmPath = join(root, "pnpm");
const childPidPath = join(root, "child.pid");
const descendantPidPath = join(root, "descendant.pid");
const signaledPath = join(root, "signaled");
writeFakePnpm(fakePnpmPath);
const runner = spawn(process.execPath, ["scripts/test-live.mjs", "--", "fake.live.test.ts"], {
env: {
...process.env,
OPENCLAW_FAKE_PNPM_PID_PATH: childPidPath,
OPENCLAW_FAKE_PNPM_DESCENDANT_PID_PATH: descendantPidPath,
OPENCLAW_FAKE_PNPM_SIGNALED_PATH: signaledPath,
npm_execpath: fakePnpmPath,
},
stdio: "ignore",
});
let childPid = 0;
let descendantPid = 0;
try {
await waitFor(() => fileExists(childPidPath), 5_000);
await waitFor(() => fileExists(descendantPidPath), 5_000);
childPid = Number(readFileSync(childPidPath, "utf8"));
descendantPid = Number(readFileSync(descendantPidPath, "utf8"));
expect(Number.isInteger(childPid)).toBe(true);
expect(Number.isInteger(descendantPid)).toBe(true);
expect(runner.pid).toBeGreaterThan(0);
process.kill(runner.pid!, "SIGTERM");
const result = await waitForClose(runner);
expect(result).toEqual({ code: null, signal: "SIGTERM" });
await waitFor(() => fileExists(signaledPath), 5_000);
expect(readFileSync(signaledPath, "utf8")).toBe("SIGTERM");
await waitFor(() => !isProcessAlive(childPid), 5_000);
await waitFor(() => !isProcessAlive(descendantPid), 5_000);
} finally {
if (runner.pid && isProcessAlive(runner.pid)) {
process.kill(runner.pid, "SIGKILL");
}
if (childPid && isProcessAlive(childPid)) {
process.kill(childPid, "SIGKILL");
}
if (descendantPid && isProcessAlive(descendantPid)) {
process.kill(descendantPid, "SIGKILL");
}
rmSync(root, { force: true, recursive: true });
}
});
it("rejects loose heartbeat intervals instead of parsing prefixes", () => {
expect(resolveTestLiveHeartbeatMs({})).toBe(20_000);
expect(resolveTestLiveHeartbeatMs({ OPENCLAW_LIVE_WRAPPER_HEARTBEAT_MS: "2500" })).toBe(2500);
expect(() => resolveTestLiveHeartbeatMs({ OPENCLAW_LIVE_WRAPPER_HEARTBEAT_MS: "1e3" })).toThrow(
"invalid OPENCLAW_LIVE_WRAPPER_HEARTBEAT_MS: 1e3",
);
expect(() =>
resolveTestLiveHeartbeatMs({ OPENCLAW_LIVE_WRAPPER_HEARTBEAT_MS: "1000ms" }),
).toThrow("invalid OPENCLAW_LIVE_WRAPPER_HEARTBEAT_MS: 1000ms");
expect(() => resolveTestLiveHeartbeatMs({ OPENCLAW_LIVE_WRAPPER_HEARTBEAT_MS: "0" })).toThrow(
"invalid OPENCLAW_LIVE_WRAPPER_HEARTBEAT_MS: 0",
);
});
it("prints help without spawning live Vitest", () => {
const result = spawnSync(process.execPath, ["scripts/test-live.mjs", "--help"], {
cwd: process.cwd(),
encoding: "utf8",
});
expect(result.status).toBe(0);
expect(result.stderr).toBe("");
expect(result.stdout).toContain("Usage: node scripts/test-live.mjs");
expect(result.stdout).not.toContain("Scope:");
expect(result.stdout).not.toContain("pnpm");
expect(result.stdout).not.toContain("[test:live]");
});
});
function writeFakePnpm(filePath: string): void {
writeFileSync(
filePath,
[
"#!/usr/bin/env node",
'const { spawn } = require("node:child_process");',
'const fs = require("node:fs");',
"if (process.env.OPENCLAW_FAKE_PNPM_DESCENDANT_PID_PATH) {",
" const child = spawn(process.execPath, [",
' "-e",',
" \"process.on('SIGTERM', () => {}); setInterval(() => {}, 1000);\",",
" ], { stdio: 'ignore' });",
" fs.writeFileSync(process.env.OPENCLAW_FAKE_PNPM_DESCENDANT_PID_PATH, String(child.pid));",
"}",
"fs.writeFileSync(process.env.OPENCLAW_FAKE_PNPM_PID_PATH, String(process.pid));",
'process.on("SIGTERM", () => {',
' fs.writeFileSync(process.env.OPENCLAW_FAKE_PNPM_SIGNALED_PATH, "SIGTERM");',
" process.exit(0);",
"});",
"setInterval(() => {}, 1000);",
"",
].join("\n"),
);
chmodExecutable(filePath);
}
function chmodExecutable(filePath: string): void {
chmodSync(filePath, 0o755);
}
async function waitFor(condition: () => boolean, timeoutMs = 3_000) {
const startedAt = Date.now();
while (!condition()) {
if (Date.now() - startedAt > timeoutMs) {
throw new Error("timed out waiting for condition");
}
await delay(25);
}
}
async function waitForClose(child: ReturnType<typeof spawn>, timeoutMs = 5_000) {
return await Promise.race([
new Promise<{ code: number | null; signal: NodeJS.Signals | null }>((resolve) => {
child.once("close", (code, signal) => resolve({ code, signal }));
}),
delay(timeoutMs).then(() => {
throw new Error("timed out waiting for child close");
}),
]);
}
function fileExists(filePath: string): boolean {
try {
readFileSync(filePath);
return true;
} catch {
return false;
}
}
function isProcessAlive(pid: number): boolean {
try {
process.kill(pid, 0);
return true;
} catch {
return false;
}
}