1+ import { spawnSync } from "node:child_process" ;
12import fs from "node:fs" ;
23import os from "node:os" ;
34import path from "node:path" ;
@@ -17,6 +18,18 @@ function writeJson(filePath: string, value: unknown) {
1718 fs . writeFileSync ( filePath , JSON . stringify ( value ) , "utf8" ) ;
1819}
1920
21+ function runCli ( ...args : string [ ] ) {
22+ return spawnSync ( process . execPath , [ "scripts/openclaw-performance-source-summary.mjs" , ...args ] , {
23+ cwd : path . resolve ( "." ) ,
24+ encoding : "utf8" ,
25+ } ) ;
26+ }
27+
28+ function expectNoNodeStack ( stderr : string ) {
29+ expect ( stderr ) . not . toContain ( "Node.js" ) ;
30+ expect ( stderr ) . not . toContain ( "\n at " ) ;
31+ }
32+
2033function writeSourceFixture ( sourceDir : string ) {
2134 writeJson ( path . join ( sourceDir , "gateway-cpu" , "gateway-startup-bench.json" ) , {
2235 results : [
@@ -126,6 +139,20 @@ describe("parseArgs", () => {
126139 ) ;
127140 }
128141 } ) ;
142+
143+ it ( "reports CLI argument errors without a Node stack trace" , ( ) => {
144+ const missingSource = runCli ( ) ;
145+ expect ( missingSource . status ) . toBe ( 1 ) ;
146+ expect ( missingSource . stdout ) . toBe ( "" ) ;
147+ expect ( missingSource . stderr . trim ( ) ) . toBe ( "--source-dir is required" ) ;
148+ expectNoNodeStack ( missingSource . stderr ) ;
149+
150+ const unknownArg = runCli ( "--wat" ) ;
151+ expect ( unknownArg . status ) . toBe ( 1 ) ;
152+ expect ( unknownArg . stdout ) . toBe ( "" ) ;
153+ expect ( unknownArg . stderr . trim ( ) ) . toBe ( "Unknown argument: --wat" ) ;
154+ expectNoNodeStack ( unknownArg . stderr ) ;
155+ } ) ;
129156} ) ;
130157
131158describe ( "buildMarkdown" , ( ) => {
0 commit comments