test: make gateway sigterm e2e node25-compatible

This commit is contained in:
Peter Steinberger
2026-02-22 11:51:43 +00:00
parent 9f80ac47ee
commit 5636e6257c

View File

@@ -2,13 +2,8 @@ import { spawn } from "node:child_process";
import fs from "node:fs"; import fs from "node:fs";
import os from "node:os"; import os from "node:os";
import path from "node:path"; import path from "node:path";
import { pathToFileURL } from "node:url";
import { afterEach, describe, expect, it } from "vitest"; import { afterEach, describe, expect, it } from "vitest";
const nodeMajor = Number.parseInt(process.versions.node.split(".")[0] ?? "0", 10);
// tsx currently crashes with "__name is not a function" on Node 25 in child bootstrap mode.
const runSigtermTest = nodeMajor >= 25 ? it.skip : it;
const waitForReady = async ( const waitForReady = async (
proc: ReturnType<typeof spawn>, proc: ReturnType<typeof spawn>,
chunksOut: string[], chunksOut: string[],
@@ -82,7 +77,7 @@ describe("gateway SIGTERM", () => {
child = null; child = null;
}); });
runSigtermTest("exits 0 on SIGTERM", { timeout: 180_000 }, async () => { it("exits 0 on SIGTERM", { timeout: 180_000 }, async () => {
const stateDir = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-gateway-test-")); const stateDir = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-gateway-test-"));
const out: string[] = []; const out: string[] = [];
const err: string[] = []; const err: string[] = [];
@@ -98,30 +93,34 @@ describe("gateway SIGTERM", () => {
OPENCLAW_SKIP_BROWSER_CONTROL_SERVER: "1", OPENCLAW_SKIP_BROWSER_CONTROL_SERVER: "1",
OPENCLAW_SKIP_CANVAS_HOST: "1", OPENCLAW_SKIP_CANVAS_HOST: "1",
}; };
const bootstrapPath = path.join(stateDir, "openclaw-entry-bootstrap.mjs"); const bootstrapPath = path.join(stateDir, "openclaw-entry-bootstrap.cjs");
const runLoopPath = path.resolve("src/cli/gateway-cli/run-loop.ts"); const runLoopPath = path.resolve("src/cli/gateway-cli/run-loop.ts");
const runtimePath = path.resolve("src/runtime.ts"); const runtimePath = path.resolve("src/runtime.ts");
const jitiPath = require.resolve("jiti");
fs.writeFileSync( fs.writeFileSync(
bootstrapPath, bootstrapPath,
[ [
'import { pathToFileURL } from "node:url";', `const jiti = require(${JSON.stringify(jitiPath)})(__filename);`,
`const runLoopUrl = ${JSON.stringify(pathToFileURL(runLoopPath).href)};`, `const { runGatewayLoop } = jiti(${JSON.stringify(runLoopPath)});`,
`const runtimeUrl = ${JSON.stringify(pathToFileURL(runtimePath).href)};`, `const { defaultRuntime } = jiti(${JSON.stringify(runtimePath)});`,
"const { runGatewayLoop } = await import(runLoopUrl);", "(async () => {",
"const { defaultRuntime } = await import(runtimeUrl);", " await runGatewayLoop({",
"await runGatewayLoop({", " start: async () => {",
" start: async () => {", ' process.stdout.write("READY\\\\n");',
' process.stdout.write("READY\\\\n");', " if (process.send) process.send({ ready: true });",
" if (process.send) process.send({ ready: true });", " const keepAlive = setInterval(() => {}, 1000);",
" const keepAlive = setInterval(() => {}, 1000);", " return { close: async () => clearInterval(keepAlive) };",
" return { close: async () => clearInterval(keepAlive) };", " },",
" },", " runtime: defaultRuntime,",
" runtime: defaultRuntime,", " });",
"})().catch((err) => {",
" console.error(err);",
" process.exitCode = 1;",
"});", "});",
].join("\n"), ].join("\n"),
"utf8", "utf8",
); );
const childArgs = ["--import", "tsx", bootstrapPath]; const childArgs = [bootstrapPath];
child = spawn(nodeBin, childArgs, { child = spawn(nodeBin, childArgs, {
cwd: process.cwd(), cwd: process.cwd(),