From a67f809b3320eae96d553dd7c03b0ac03338186c Mon Sep 17 00:00:00 2001 From: Vincent Koc Date: Sat, 20 Jun 2026 02:00:34 +0200 Subject: [PATCH] fix(test): clean perf summary cli errors --- .../openclaw-performance-source-summary.mjs | 2 +- ...penclaw-performance-source-summary.test.ts | 27 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/scripts/openclaw-performance-source-summary.mjs b/scripts/openclaw-performance-source-summary.mjs index 5b038331ee61..5cb772fb1d37 100644 --- a/scripts/openclaw-performance-source-summary.mjs +++ b/scripts/openclaw-performance-source-summary.mjs @@ -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; }, ); diff --git a/test/scripts/openclaw-performance-source-summary.test.ts b/test/scripts/openclaw-performance-source-summary.test.ts index fe649b2c3bf0..c8de48d5df49 100644 --- a/test/scripts/openclaw-performance-source-summary.test.ts +++ b/test/scripts/openclaw-performance-source-summary.test.ts @@ -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", () => {