fix(gateway): route watch trace spam to artifacts

This commit is contained in:
Peter Steinberger
2026-05-04 23:41:07 +01:00
parent 864b1be1b3
commit a167acee67
6 changed files with 156 additions and 2 deletions

View File

@@ -121,6 +121,13 @@ describe("gateway-watch tmux wrapper", () => {
expect(code).toBe(0);
const command = spawnSync.mock.calls[1]?.[1]?.[6] as string;
expect(command).toContain("'OPENCLAW_TRACE_SYNC_IO=1'");
expect(command).toContain(
"'OPENCLAW_RUN_NODE_OUTPUT_LOG=.artifacts/gateway-watch-profiles/gateway-watch-output.log'",
);
expect(command).toContain("'OPENCLAW_RUN_NODE_FILTER_SYNC_IO_STDERR=1'");
expect(stderr.chunks.join("")).toContain(
"gateway:watch benchmark trace output: .artifacts/gateway-watch-profiles/gateway-watch-output.log",
);
});
it("can remove --force from benchmarked watch runs", () => {

View File

@@ -448,6 +448,59 @@ describe("run-node script", () => {
});
});
it("routes sync I/O trace stderr blocks to the output log without flooding stderr", async () => {
await withTempDir({ prefix: "openclaw-run-node-" }, async (tmp) => {
await setupTrackedProject(tmp);
const outputPath = path.join(tmp, ".artifacts", "gateway-watch-profiles", "output.log");
const childStderr = [
"normal before\n",
"(node:12345) WARNING: Detected use of sync API\n",
" at statSync (node:fs:1739:25)\n",
" at loadConfig (/repo/src/config.ts:1:1)\n",
"\n",
"normal after\n",
].join("");
const spawn = (_cmd: string, args: string[]) =>
createPipedExitedProcess({
stderr: args[0] === "openclaw.mjs" ? childStderr : "",
});
const stderrChunks: string[] = [];
const stderr = {
write: (chunk: string | Buffer) => {
stderrChunks.push(String(chunk));
return true;
},
} as unknown as NodeJS.WriteStream;
const stdout = {
write: () => true,
} as unknown as NodeJS.WriteStream;
const exitCode = await runNodeMain({
cwd: tmp,
args: ["status"],
env: {
...process.env,
OPENCLAW_RUNNER_LOG: "0",
OPENCLAW_RUN_NODE_FILTER_SYNC_IO_STDERR: "1",
OPENCLAW_RUN_NODE_OUTPUT_LOG: outputPath,
},
spawn,
stderr,
stdout,
execPath: process.execPath,
platform: process.platform,
} as Parameters<typeof runNodeMain>[0] & { stdout: NodeJS.WriteStream });
expect(exitCode).toBe(0);
const terminalStderr = stderrChunks.join("");
expect(terminalStderr).toContain("normal before\n");
expect(terminalStderr).toContain("normal after\n");
expect(terminalStderr).not.toContain("Detected use of sync API");
expect(terminalStderr).not.toContain("statSync");
await expect(fs.readFile(outputPath, "utf-8")).resolves.toContain(childStderr);
});
});
it("adds Node CPU profiling flags to the launched OpenClaw child when requested", async () => {
await withTempDir({ prefix: "openclaw-run-node-" }, async (tmp) => {
await setupTrackedProject(tmp, {