fix(test): harden startup benchmark harness

This commit is contained in:
Vincent Koc
2026-05-28 06:40:30 +02:00
parent 4f26cc9090
commit d10d30c5fa
4 changed files with 139 additions and 8 deletions

View File

@@ -65,6 +65,78 @@ describe("bench-cli-startup", () => {
]);
});
it("allows declared nonzero exit codes for clean-state probes", () => {
const sample = {
ms: 10,
firstOutputMs: 5,
maxRssMb: 50,
exitCode: 1,
signal: null,
stderrTail: "Health check failed: gateway closed\n Gateway target: ws://127.0.0.1:18789",
};
expect(
testing.collectFailedSamples({
entry: "openclaw.mjs",
cases: [
{
id: "health",
name: "health",
args: ["health"],
expectedExitCodes: [0, 1],
expectedNonzeroOutputIncludes: ["Gateway target:"],
contract: null,
samples: [sample],
summary: {
sampleCount: 1,
durationMs: { avg: 10, p50: 10, p95: 10, min: 10, max: 10 },
firstOutputMs: { avg: 5, p50: 5, p95: 5, min: 5, max: 5 },
maxRssMb: { avg: 50, p50: 50, p95: 50, min: 50, max: 50 },
exitSummary: "code:1x1",
},
},
],
}),
).toEqual([]);
});
it("rejects allowed nonzero exits without their expected clean-state output", () => {
const sample = {
ms: 10,
firstOutputMs: 5,
maxRssMb: 50,
exitCode: 1,
signal: null,
stderrTail: "TypeError: crashed before output",
};
expect(
testing.collectFailedSamples({
entry: "openclaw.mjs",
cases: [
{
id: "health",
name: "health",
args: ["health"],
expectedExitCodes: [0, 1],
expectedNonzeroOutputIncludes: ["Gateway target:"],
contract: null,
samples: [sample],
summary: {
sampleCount: 1,
durationMs: { avg: 10, p50: 10, p95: 10, min: 10, max: 10 },
firstOutputMs: { avg: 5, p50: 5, p95: 5, min: 5, max: 5 },
maxRssMb: { avg: 50, p50: 50, p95: 50, min: 50, max: 50 },
exitSummary: "code:1x1",
},
},
],
}),
).toEqual([
"openclaw.mjs health sample 1: exited with expected code 1 but output did not match expected clean-state markers (Gateway target:)",
]);
});
it("rejects invalid measured run counts", () => {
expect(() => testing.parsePositiveInt("0", 5, "--runs")).toThrow(
"--runs must be an integer >= 1",

View File

@@ -19,6 +19,20 @@ describe("CLI startup benchmark script spawners", () => {
}
});
it("builds the source CLI before generating a startup budget report", () => {
const source = fs.readFileSync(
path.resolve(process.cwd(), "scripts/test-cli-startup-bench-budget.mjs"),
"utf8",
);
expect(source).toContain(
'spawnSync(process.execPath, ["scripts/ensure-cli-startup-build.mjs"]',
);
expect(source.indexOf("scripts/ensure-cli-startup-build.mjs")).toBeLessThan(
source.indexOf("scripts/bench-cli-startup.ts"),
);
});
it("does not require unrelated fixture cases for a narrowed preset", () => {
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-bench-budget-test-"));
try {