mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-09 03:22:40 +00:00
fix(qa): reject malformed kitchen-sink CPU samples
This commit is contained in:
@@ -1740,7 +1740,7 @@ function parsePosixProcessRows(stdout) {
|
||||
const processId = Number.parseInt(pidRaw, 10);
|
||||
const parentProcessId = Number.parseInt(ppidRaw, 10);
|
||||
const rssKb = Number.parseInt(rssKbRaw, 10);
|
||||
const cpuPercent = Number.parseFloat(cpuRaw);
|
||||
const cpuPercent = parsePosixCpuPercent(cpuRaw);
|
||||
if (
|
||||
!Number.isInteger(processId) ||
|
||||
!Number.isInteger(parentProcessId) ||
|
||||
@@ -1752,13 +1752,22 @@ function parsePosixProcessRows(stdout) {
|
||||
processId,
|
||||
parentProcessId,
|
||||
rssKb,
|
||||
cpuPercent: Number.isFinite(cpuPercent) ? cpuPercent : null,
|
||||
cpuPercent,
|
||||
command: command ?? "",
|
||||
};
|
||||
})
|
||||
.filter(Boolean);
|
||||
}
|
||||
|
||||
function parsePosixCpuPercent(raw) {
|
||||
const text = String(raw ?? "").trim();
|
||||
if (!/^(?:0|[1-9]\d*)(?:\.\d+)?$/u.test(text)) {
|
||||
return null;
|
||||
}
|
||||
const parsed = Number(text);
|
||||
return Number.isFinite(parsed) ? parsed : null;
|
||||
}
|
||||
|
||||
function collectPosixProcessTree(rows, rootPid) {
|
||||
const byParent = new Map();
|
||||
for (const row of rows) {
|
||||
|
||||
@@ -1412,6 +1412,23 @@ describe("kitchen-sink RPC process sampling", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("does not truncate malformed POSIX CPU samples", async () => {
|
||||
const sample = await sampleProcess(4321, {
|
||||
platform: "linux",
|
||||
runCommand: async () => ({
|
||||
stdout: " 4321 1 262144 12.5.6 node dist/index.js gateway --port 19080",
|
||||
stderr: "",
|
||||
}),
|
||||
});
|
||||
|
||||
expect(sample).toEqual({
|
||||
aggregateRssMiB: 256,
|
||||
cpuPercent: null,
|
||||
processId: 4321,
|
||||
rssMiB: 256,
|
||||
});
|
||||
});
|
||||
|
||||
it("samples the POSIX gateway child instead of the pnpm launcher", async () => {
|
||||
const sample = await sampleProcess(4321, {
|
||||
platform: "linux",
|
||||
|
||||
Reference in New Issue
Block a user