Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 21 additions & 43 deletions cli/src/__tests__/e2e-cli.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { spawn } from 'child_process'
import { spawn, spawnSync } from 'child_process'
import path from 'path'

import { describe, test, expect } from 'bun:test'
Expand All @@ -14,46 +14,24 @@ ensureCliTestEnv()

function runCLI(
args: string[],
): Promise<{ stdout: string; stderr: string; exitCode: number | null }> {
return new Promise((resolve, reject) => {
const proc = spawn('bun', ['run', CLI_PATH, ...args], {
cwd: path.join(__dirname, '../..'),
stdio: 'pipe',
})

let stdout = ''
let stderr = ''

proc.stdout?.on('data', (data) => {
stdout += data.toString()
})

proc.stderr?.on('data', (data) => {
stderr += data.toString()
})

const timeout = setTimeout(() => {
proc.kill('SIGTERM')
reject(new Error('Process timeout'))
}, TIMEOUT_MS)

proc.on('close', (code) => {
clearTimeout(timeout)
resolve({ stdout, stderr, exitCode: code })
})

proc.on('error', (err) => {
clearTimeout(timeout)
reject(err)
})
): { stdout: string; stderr: string; exitCode: number | null } {
const result = spawnSync('bun', ['run', CLI_PATH, ...args], {
cwd: path.join(__dirname, '../..'),
timeout: TIMEOUT_MS,
env: process.env,
})
return {
stdout: result.stdout?.toString() ?? '',
stderr: result.stderr?.toString() ?? '',
exitCode: result.status,
}
}

describe.skipIf(!sdkBuilt)('CLI End-to-End Tests', () => {
test(
'CLI shows help with --help flag',
async () => {
const { stdout, stderr, exitCode } = await runCLI(['--help'])
() => {
const { stdout, stderr, exitCode } = runCLI(['--help'])

const cleanOutput = stripAnsi(stdout + stderr)
expect(cleanOutput).toContain('--agent')
Expand All @@ -65,8 +43,8 @@ describe.skipIf(!sdkBuilt)('CLI End-to-End Tests', () => {

test(
'CLI shows help with -h flag',
async () => {
const { stdout, stderr, exitCode } = await runCLI(['-h'])
() => {
const { stdout, stderr, exitCode } = runCLI(['-h'])

const cleanOutput = stripAnsi(stdout + stderr)
expect(cleanOutput).toContain('--agent')
Expand All @@ -77,8 +55,8 @@ describe.skipIf(!sdkBuilt)('CLI End-to-End Tests', () => {

test(
'CLI shows version with --version flag',
async () => {
const { stdout, stderr, exitCode } = await runCLI(['--version'])
() => {
const { stdout, stderr, exitCode } = runCLI(['--version'])

const cleanOutput = stripAnsi(stdout + stderr)
expect(cleanOutput).toMatch(/\d+\.\d+\.\d+|dev/)
Expand All @@ -89,8 +67,8 @@ describe.skipIf(!sdkBuilt)('CLI End-to-End Tests', () => {

test(
'CLI shows version with -v flag',
async () => {
const { stdout, stderr, exitCode } = await runCLI(['-v'])
() => {
const { stdout, stderr, exitCode } = runCLI(['-v'])

const cleanOutput = stripAnsi(stdout + stderr)
expect(cleanOutput).toMatch(/\d+\.\d+\.\d+|dev/)
Expand Down Expand Up @@ -171,8 +149,8 @@ describe.skipIf(!sdkBuilt)('CLI End-to-End Tests', () => {

test(
'CLI handles invalid flags gracefully',
async () => {
const { stderr, exitCode } = await runCLI(['--invalid-flag'])
() => {
const { stderr, exitCode } = runCLI(['--invalid-flag'])

// Commander should show an error
expect(exitCode).not.toBe(0)
Expand Down
2 changes: 1 addition & 1 deletion packages/agent-runtime/src/prompt-agent-stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export const getAgentStreamFromTemplate = (params: {
includeCacheControl,
logger,
localAgentTemplates,
maxOutputTokens: 32_000,
maxOutputTokens: undefined,
maxRetries: 3,
messages,
model,
Expand Down
Loading