Skip to content

Commit c945118

Browse files
committed
Refine CLI E2E helpers and auth env handling
1 parent 4031c96 commit c945118

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

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

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import {
1212

1313
const CLI_PATH = path.join(__dirname, '../../index.tsx')
1414
const TIMEOUT_MS = 25000
15+
const RENDER_WAIT_MS = 3000
16+
const SHORT_WAIT_MS = 500
1517
const sdkBuilt = isSDKBuilt()
1618
type TerminalSession = Awaited<ReturnType<typeof launchTerminal>>
1719

@@ -30,7 +32,7 @@ beforeAll(() => {
3032

3133
function attachReliableTyping(session: TerminalSession, keyDelayMs = 40): TerminalSession {
3234
const originalPress = session.press.bind(session)
33-
session.type = async (text: string) => {
35+
const reliableType = async (text: string) => {
3436
for (const char of text) {
3537
if (char === ' ') {
3638
await originalPress('space')
@@ -41,7 +43,11 @@ function attachReliableTyping(session: TerminalSession, keyDelayMs = 40): Termin
4143
await sleep(keyDelayMs)
4244
}
4345
}
44-
return session
46+
47+
// Avoid mutating the original session; return a thin wrapper
48+
return Object.assign(Object.create(session), {
49+
type: reliableType,
50+
})
4551
}
4652

4753
function logSnapshot(label: string, text: string): void {
@@ -78,9 +84,10 @@ async function launchCLIWithoutAuth(options: {
7884
}): Promise<Awaited<ReturnType<typeof launchTerminal>>> {
7985
const { args = [], cols = 120, rows = 30 } = options
8086
// Remove authentication-related env vars to trigger login flow
81-
const envWithoutAuth = { ...process.env, ...cliEnv }
82-
delete envWithoutAuth.CODEBUFF_API_KEY
83-
delete envWithoutAuth.CODEBUFF_TOKEN
87+
const { CODEBUFF_API_KEY, CODEBUFF_TOKEN, ...envWithoutAuth } = {
88+
...process.env,
89+
...cliEnv,
90+
}
8491

8592
const session = await launchTerminal({
8693
command: 'bun',
@@ -286,11 +293,11 @@ describe('CLI UI Tests', () => {
286293

287294
try {
288295
// Wait for CLI to render
289-
await sleep(3000)
296+
await sleep(RENDER_WAIT_MS)
290297

291298
// Type some text
292299
await session.type('hello world')
293-
await sleep(500)
300+
await sleep(SHORT_WAIT_MS)
294301

295302
const text = await session.text()
296303
// The typed text should appear in the terminal
@@ -314,7 +321,7 @@ describe('CLI UI Tests', () => {
314321

315322
try {
316323
// Wait for CLI to render
317-
await sleep(3000)
324+
await sleep(RENDER_WAIT_MS)
318325

319326
// Type a message and press enter
320327
await session.type('test message')
@@ -348,7 +355,7 @@ describe('CLI UI Tests', () => {
348355

349356
try {
350357
// Wait for CLI to render
351-
await sleep(3000)
358+
await sleep(RENDER_WAIT_MS)
352359

353360
// Press Ctrl+C once
354361
await session.press(['ctrl', 'c'])

0 commit comments

Comments
 (0)