fix(scripts): run RPC RTT probe without pnpm

This commit is contained in:
Vincent Koc
2026-06-04 01:22:33 +02:00
parent 25f3d2d714
commit 009d7335b5
2 changed files with 45 additions and 4 deletions

View File

@@ -1,5 +1,6 @@
import { spawn } from "node:child_process";
import { randomUUID } from "node:crypto";
import { existsSync } from "node:fs";
import fs from "node:fs/promises";
import { createRequire } from "node:module";
import net from "node:net";
@@ -156,6 +157,14 @@ async function defaultOpen(filePath, flags) {
return await fs.open(filePath, flags);
}
function resolveOpenClawLaunchArgs(repoRoot, sourceEntryExists = existsSync) {
const sourceEntry = path.join(repoRoot, "src", "entry.ts");
if (sourceEntryExists(sourceEntry)) {
return ["--import", "tsx", sourceEntry];
}
return [path.join(repoRoot, "openclaw.mjs")];
}
export function signalGatewayProcess(child, signal, killProcess = defaultKillProcess) {
if (process.platform !== "win32" && typeof child.pid === "number") {
try {
@@ -272,6 +281,7 @@ export async function startGateway({
openImpl = defaultOpen,
port,
repoRoot,
sourceEntryExists = existsSync,
spawnImpl = spawn,
stderrPath,
stdoutPath,
@@ -290,11 +300,12 @@ export async function startGateway({
}
let child;
const launcherArgs = resolveOpenClawLaunchArgs(repoRoot, sourceEntryExists);
try {
child = spawnImpl(
"pnpm",
process.execPath,
[
"openclaw",
...launcherArgs,
"gateway",
"run",
"--port",
@@ -353,6 +364,25 @@ export async function cleanupTempRoot(tempRoot, { rmImpl = fs.rm } = {}) {
}
}
async function copyLogIfPresent(source, target) {
try {
await fs.copyFile(source, target);
} catch (error) {
if (error && typeof error === "object" && error.code === "ENOENT") {
return;
}
throw error;
}
}
async function copyGatewayLogs({ outputDir, stderrPath, stdoutPath }) {
await fs.mkdir(outputDir, { recursive: true });
await Promise.all([
copyLogIfPresent(stdoutPath, path.join(outputDir, "gateway.stdout.log")),
copyLogIfPresent(stderrPath, path.join(outputDir, "gateway.stderr.log")),
]);
}
function quantile(sorted, q) {
return sorted[Math.min(sorted.length - 1, Math.max(0, Math.ceil(sorted.length * q) - 1))];
}
@@ -642,6 +672,14 @@ async function main() {
} finally {
removeGatewayParentCleanup();
}
try {
await copyGatewayLogs({ outputDir, stderrPath, stdoutPath });
} catch (error) {
const message = formatErrorMessage(error);
details = details
? `${details}\nwarning: failed to copy gateway logs: ${message}`
: `warning: failed to copy gateway logs: ${message}`;
}
try {
await cleanupTempRoot(tempRoot);
} catch (error) {

View File

@@ -29,6 +29,7 @@ describe("scripts/measure-rpc-rtt.mjs", () => {
openImpl,
port: 23456,
repoRoot: "/repo",
sourceEntryExists: () => true,
spawnImpl,
stderrPath: "/tmp/stderr.log",
stdoutPath: "/tmp/stdout.log",
@@ -40,9 +41,11 @@ describe("scripts/measure-rpc-rtt.mjs", () => {
expect(openImpl).toHaveBeenNthCalledWith(1, "/tmp/stdout.log", "w");
expect(openImpl).toHaveBeenNthCalledWith(2, "/tmp/stderr.log", "w");
expect(spawnImpl).toHaveBeenCalledWith(
"pnpm",
process.execPath,
[
"openclaw",
"--import",
"tsx",
"/repo/src/entry.ts",
"gateway",
"run",
"--port",