Skip to content

Commit 2252eec

Browse files
committed
Fix for flaky e2e test
1 parent 284bc04 commit 2252eec

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

cli/src/__tests__/e2e-cli.test.ts

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,20 +80,28 @@ describe.skipIf(!sdkBuilt)('CLI End-to-End Tests', () => {
8080
test(
8181
'CLI accepts --agent flag',
8282
async () => {
83-
// Note: This will timeout and exit because we can't interact with stdin
84-
// But we can verify it starts without errors
83+
// Verify the CLI starts without errors when given --agent flag.
84+
// The CLI goes through full initialization (agent registry, skill registry,
85+
// renderer creation) before producing any piped output, so we need a
86+
// generous timeout. We also treat "process still alive" as success.
8587
const proc = spawn('bun', ['run', CLI_PATH, '--agent', 'ask'], {
8688
cwd: path.join(__dirname, '../..'),
8789
stdio: 'pipe',
8890
})
8991

9092
let started = false
93+
let exitedEarly = false
94+
proc.once('exit', () => {
95+
if (!started) exitedEarly = true
96+
})
97+
9198
await new Promise<void>((resolve) => {
9299
const timeout = setTimeout(() => {
100+
// Process is still alive after wait — it started successfully
101+
if (!exitedEarly) started = true
93102
resolve()
94-
}, 2000) // Increased timeout for CI environments
103+
}, 8000)
95104

96-
// Check both stdout and stderr - CLI may output to either
97105
proc.stdout?.once('data', () => {
98106
started = true
99107
clearTimeout(timeout)
@@ -122,12 +130,17 @@ describe.skipIf(!sdkBuilt)('CLI End-to-End Tests', () => {
122130
})
123131

124132
let started = false
133+
let exitedEarly = false
134+
proc.once('exit', () => {
135+
if (!started) exitedEarly = true
136+
})
137+
125138
await new Promise<void>((resolve) => {
126139
const timeout = setTimeout(() => {
140+
if (!exitedEarly) started = true
127141
resolve()
128-
}, 2000) // Increased timeout for CI environments
142+
}, 8000)
129143

130-
// Check both stdout and stderr - CLI may output to either
131144
proc.stdout?.once('data', () => {
132145
started = true
133146
clearTimeout(timeout)

0 commit comments

Comments
 (0)