fix(qa): reject malformed kitchen-sink CPU samples · openclaw/openclaw@b816dfb
vincentkoc
·
2026-06-17
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -1740,7 +1740,7 @@ function parsePosixProcessRows(stdout) {
|
1740 | 1740 | const processId = Number.parseInt(pidRaw, 10); |
1741 | 1741 | const parentProcessId = Number.parseInt(ppidRaw, 10); |
1742 | 1742 | const rssKb = Number.parseInt(rssKbRaw, 10); |
1743 | | -const cpuPercent = Number.parseFloat(cpuRaw); |
| 1743 | +const cpuPercent = parsePosixCpuPercent(cpuRaw); |
1744 | 1744 | if ( |
1745 | 1745 | !Number.isInteger(processId) || |
1746 | 1746 | !Number.isInteger(parentProcessId) || |
@@ -1752,13 +1752,22 @@ function parsePosixProcessRows(stdout) {
|
1752 | 1752 | processId, |
1753 | 1753 | parentProcessId, |
1754 | 1754 | rssKb, |
1755 | | -cpuPercent: Number.isFinite(cpuPercent) ? cpuPercent : null, |
| 1755 | + cpuPercent, |
1756 | 1756 | command: command ?? "", |
1757 | 1757 | }; |
1758 | 1758 | }) |
1759 | 1759 | .filter(Boolean); |
1760 | 1760 | } |
1761 | 1761 | |
| 1762 | +function parsePosixCpuPercent(raw) { |
| 1763 | +const text = String(raw ?? "").trim(); |
| 1764 | +if (!/^(?:0|[1-9]\d*)(?:\.\d+)?$/u.test(text)) { |
| 1765 | +return null; |
| 1766 | +} |
| 1767 | +const parsed = Number(text); |
| 1768 | +return Number.isFinite(parsed) ? parsed : null; |
| 1769 | +} |
| 1770 | + |
1762 | 1771 | function collectPosixProcessTree(rows, rootPid) { |
1763 | 1772 | const byParent = new Map(); |
1764 | 1773 | for (const row of rows) { |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -1412,6 +1412,23 @@ describe("kitchen-sink RPC process sampling", () => {
|
1412 | 1412 | }); |
1413 | 1413 | }); |
1414 | 1414 | |
| 1415 | +it("does not truncate malformed POSIX CPU samples", async () => { |
| 1416 | +const sample = await sampleProcess(4321, { |
| 1417 | +platform: "linux", |
| 1418 | +runCommand: async () => ({ |
| 1419 | +stdout: " 4321 1 262144 12.5.6 node dist/index.js gateway --port 19080", |
| 1420 | +stderr: "", |
| 1421 | +}), |
| 1422 | +}); |
| 1423 | + |
| 1424 | +expect(sample).toEqual({ |
| 1425 | +aggregateRssMiB: 256, |
| 1426 | +cpuPercent: null, |
| 1427 | +processId: 4321, |
| 1428 | +rssMiB: 256, |
| 1429 | +}); |
| 1430 | +}); |
| 1431 | + |
1415 | 1432 | it("samples the POSIX gateway child instead of the pnpm launcher", async () => { |
1416 | 1433 | const sample = await sampleProcess(4321, { |
1417 | 1434 | platform: "linux", |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。