fix(test): clean perf summary cli errors

This commit is contained in:
Vincent Koc
2026-06-20 02:00:34 +02:00
parent 1f1c434ede
commit a67f809b33
2 changed files with 28 additions and 1 deletions
@@ -669,7 +669,7 @@ function isCliEntry() {
if (isCliEntry()) {
main().catch(
/** @param {unknown} error */ (error) => {
console.error(error instanceof Error ? error.stack : String(error));
console.error(error instanceof Error ? error.message : String(error));
process.exitCode = 1;
},
);
@@ -1,3 +1,4 @@
import { spawnSync } from "node:child_process";
import fs from "node:fs";
import os from "node:os";
import path from "node:path";
@@ -17,6 +18,18 @@ function writeJson(filePath: string, value: unknown) {
fs.writeFileSync(filePath, JSON.stringify(value), "utf8");
}
function runCli(...args: string[]) {
return spawnSync(process.execPath, ["scripts/openclaw-performance-source-summary.mjs", ...args], {
cwd: path.resolve("."),
encoding: "utf8",
});
}
function expectNoNodeStack(stderr: string) {
expect(stderr).not.toContain("Node.js");
expect(stderr).not.toContain("\n at ");
}
function writeSourceFixture(sourceDir: string) {
writeJson(path.join(sourceDir, "gateway-cpu", "gateway-startup-bench.json"), {
results: [
@@ -126,6 +139,20 @@ describe("parseArgs", () => {
);
}
});
it("reports CLI argument errors without a Node stack trace", () => {
const missingSource = runCli();
expect(missingSource.status).toBe(1);
expect(missingSource.stdout).toBe("");
expect(missingSource.stderr.trim()).toBe("--source-dir is required");
expectNoNodeStack(missingSource.stderr);
const unknownArg = runCli("--wat");
expect(unknownArg.status).toBe(1);
expect(unknownArg.stdout).toBe("");
expect(unknownArg.stderr.trim()).toBe("Unknown argument: --wat");
expectNoNodeStack(unknownArg.stderr);
});
});
describe("buildMarkdown", () => {