1- import { spawn } from 'child_process'
1+ import { spawn , spawnSync } from 'child_process'
22import path from 'path'
33
44import { describe , test , expect } from 'bun:test'
@@ -14,46 +14,24 @@ ensureCliTestEnv()
1414
1515function runCLI (
1616 args : string [ ] ,
17- ) : Promise < { stdout : string ; stderr : string ; exitCode : number | null } > {
18- return new Promise ( ( resolve , reject ) => {
19- const proc = spawn ( 'bun' , [ 'run' , CLI_PATH , ...args ] , {
20- cwd : path . join ( __dirname , '../..' ) ,
21- stdio : 'pipe' ,
22- } )
23-
24- let stdout = ''
25- let stderr = ''
26-
27- proc . stdout ?. on ( 'data' , ( data ) => {
28- stdout += data . toString ( )
29- } )
30-
31- proc . stderr ?. on ( 'data' , ( data ) => {
32- stderr += data . toString ( )
33- } )
34-
35- const timeout = setTimeout ( ( ) => {
36- proc . kill ( 'SIGTERM' )
37- reject ( new Error ( 'Process timeout' ) )
38- } , TIMEOUT_MS )
39-
40- proc . on ( 'close' , ( code ) => {
41- clearTimeout ( timeout )
42- resolve ( { stdout, stderr, exitCode : code } )
43- } )
44-
45- proc . on ( 'error' , ( err ) => {
46- clearTimeout ( timeout )
47- reject ( err )
48- } )
17+ ) : { stdout : string ; stderr : string ; exitCode : number | null } {
18+ const result = spawnSync ( 'bun' , [ 'run' , CLI_PATH , ...args ] , {
19+ cwd : path . join ( __dirname , '../..' ) ,
20+ timeout : TIMEOUT_MS ,
21+ env : process . env ,
4922 } )
23+ return {
24+ stdout : result . stdout ?. toString ( ) ?? '' ,
25+ stderr : result . stderr ?. toString ( ) ?? '' ,
26+ exitCode : result . status ,
27+ }
5028}
5129
5230describe . skipIf ( ! sdkBuilt ) ( 'CLI End-to-End Tests' , ( ) => {
5331 test (
5432 'CLI shows help with --help flag' ,
55- async ( ) => {
56- const { stdout, stderr, exitCode } = await runCLI ( [ '--help' ] )
33+ ( ) => {
34+ const { stdout, stderr, exitCode } = runCLI ( [ '--help' ] )
5735
5836 const cleanOutput = stripAnsi ( stdout + stderr )
5937 expect ( cleanOutput ) . toContain ( '--agent' )
@@ -65,8 +43,8 @@ describe.skipIf(!sdkBuilt)('CLI End-to-End Tests', () => {
6543
6644 test (
6745 'CLI shows help with -h flag' ,
68- async ( ) => {
69- const { stdout, stderr, exitCode } = await runCLI ( [ '-h' ] )
46+ ( ) => {
47+ const { stdout, stderr, exitCode } = runCLI ( [ '-h' ] )
7048
7149 const cleanOutput = stripAnsi ( stdout + stderr )
7250 expect ( cleanOutput ) . toContain ( '--agent' )
@@ -77,8 +55,8 @@ describe.skipIf(!sdkBuilt)('CLI End-to-End Tests', () => {
7755
7856 test (
7957 'CLI shows version with --version flag' ,
80- async ( ) => {
81- const { stdout, stderr, exitCode } = await runCLI ( [ '--version' ] )
58+ ( ) => {
59+ const { stdout, stderr, exitCode } = runCLI ( [ '--version' ] )
8260
8361 const cleanOutput = stripAnsi ( stdout + stderr )
8462 expect ( cleanOutput ) . toMatch ( / \d + \. \d + \. \d + | d e v / )
@@ -89,8 +67,8 @@ describe.skipIf(!sdkBuilt)('CLI End-to-End Tests', () => {
8967
9068 test (
9169 'CLI shows version with -v flag' ,
92- async ( ) => {
93- const { stdout, stderr, exitCode } = await runCLI ( [ '-v' ] )
70+ ( ) => {
71+ const { stdout, stderr, exitCode } = runCLI ( [ '-v' ] )
9472
9573 const cleanOutput = stripAnsi ( stdout + stderr )
9674 expect ( cleanOutput ) . toMatch ( / \d + \. \d + \. \d + | d e v / )
@@ -171,8 +149,8 @@ describe.skipIf(!sdkBuilt)('CLI End-to-End Tests', () => {
171149
172150 test (
173151 'CLI handles invalid flags gracefully' ,
174- async ( ) => {
175- const { stderr, exitCode } = await runCLI ( [ '--invalid-flag' ] )
152+ ( ) => {
153+ const { stderr, exitCode } = runCLI ( [ '--invalid-flag' ] )
176154
177155 // Commander should show an error
178156 expect ( exitCode ) . not . toBe ( 0 )
0 commit comments