mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-29 21:33:35 +00:00
fix(e2e): reject loose docker stats CPU samples
This commit is contained in:
@@ -57,7 +57,12 @@ function parseMemoryMiB(raw) {
|
||||
}
|
||||
|
||||
function parseCpuPercent(raw) {
|
||||
const parsed = Number(String(raw || "").replace(/%$/u, ""));
|
||||
const text = String(raw ?? "").trim();
|
||||
const valueText = text.endsWith("%") ? text.slice(0, -1).trim() : text;
|
||||
if (!NON_NEGATIVE_DECIMAL_PATTERN.test(valueText)) {
|
||||
return undefined;
|
||||
}
|
||||
const parsed = Number(valueText);
|
||||
return Number.isFinite(parsed) ? parsed : undefined;
|
||||
}
|
||||
|
||||
|
||||
@@ -77,6 +77,11 @@ describe("scripts/e2e/lib/docker-stats/assert-resource-ceiling.mjs", () => {
|
||||
|
||||
expect(malformed.status).not.toBe(0);
|
||||
expect(malformed.stderr).toContain("had invalid MemUsage");
|
||||
|
||||
const looseCpu = runAssert(writeStats('{"MemUsage":"128MiB / 2GiB","CPUPerc":"1e3%"}\n'));
|
||||
|
||||
expect(looseCpu.status).not.toBe(0);
|
||||
expect(looseCpu.stderr).toContain("had invalid CPUPerc");
|
||||
});
|
||||
|
||||
it("reports and enforces parsed Docker resource peaks", () => {
|
||||
|
||||
Reference in New Issue
Block a user