From 20d3eccf00ff8a4ad22b649330764fdff533f3aa Mon Sep 17 00:00:00 2001 From: Vincent Koc Date: Fri, 19 Jun 2026 19:50:02 +0200 Subject: [PATCH] fix(test): sample direct POSIX gateway process --- scripts/e2e/kitchen-sink-rpc-walk.mjs | 12 ++++++++---- test/scripts/kitchen-sink-rpc-walk.test.ts | 19 +++++++++++++++++++ 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/scripts/e2e/kitchen-sink-rpc-walk.mjs b/scripts/e2e/kitchen-sink-rpc-walk.mjs index 9685cafaedcb..37190651820f 100644 --- a/scripts/e2e/kitchen-sink-rpc-walk.mjs +++ b/scripts/e2e/kitchen-sink-rpc-walk.mjs @@ -1873,12 +1873,14 @@ async function samplePosixProcessTree(pid, run, commandLineNeedles) { if (hasMalformedProcessTreeRows(malformedRows, rootTreeRows)) { return null; } + const rootRow = rootTreeRows.find((row) => row.processId === safePid) ?? null; const descendants = rootTreeRows.filter((row) => row.processId !== safePid); - const commandMatches = descendants.filter((row) => + const matchesCommandNeedles = (row) => commandLineNeedles.every((needle) => row.command.toLowerCase().includes(needle.toLowerCase()), - ), - ); + ); + const commandMatches = descendants.filter(matchesCommandNeedles); + const rootCommandMatches = rootRow && matchesCommandNeedles(rootRow) ? [rootRow] : []; const gatewayTitleMatches = descendants.filter((row) => row.command.toLowerCase().includes("openclaw-gateway"), ); @@ -1887,7 +1889,9 @@ async function samplePosixProcessTree(pid, run, commandLineNeedles) { ? commandMatches : gatewayTitleMatches.length > 0 ? gatewayTitleMatches - : descendants, + : descendants.length > 0 + ? descendants + : rootCommandMatches, ); if (!selected) { return null; diff --git a/test/scripts/kitchen-sink-rpc-walk.test.ts b/test/scripts/kitchen-sink-rpc-walk.test.ts index 17f9439fe1de..17d6ec3f16d2 100644 --- a/test/scripts/kitchen-sink-rpc-walk.test.ts +++ b/test/scripts/kitchen-sink-rpc-walk.test.ts @@ -1739,6 +1739,25 @@ describe("kitchen-sink RPC process sampling", () => { }); }); + it("samples the POSIX gateway root when command-line needles match", async () => { + const sample = await sampleProcess(4321, { + platform: "darwin", + posixCommandLineNeedles: ["gateway", "--port", "19080"], + runCommand: async () => ({ + stdout: + " 4321 1 262144 12.5 node dist/index.js gateway --port 19080 --bind loopback\n", + stderr: "", + }), + }); + + expect(sample).toEqual({ + aggregateRssMiB: 256, + cpuPercent: 12.5, + processId: 4321, + rssMiB: 256, + }); + }); + it("falls back to the POSIX gateway process title when the port arg is rewritten", async () => { const sample = await sampleProcess(4321, { platform: "darwin",