test(cli): add zx TDD infrastructure and phase 1 tests
- Install zx as devDependency for E2E testing - Create tests/ directory with setup utilities - Add setup.ts with test context helpers: - Random port generation (never 6767) - Temp directory creation for PASEO_HOME and workDir - Daemon startup/waitForDaemon helper (WebSocket only) - Cleanup function - paseo() helper to run CLI commands against test daemon - Add Phase 1 foundation tests (01-foundation.test.mts): - Test paseo --version outputs version - Test paseo --help shows commands - Add test runner (run-all.mts) that discovers and runs all tests - Add test:e2e script to package.json
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
import { Command } from 'commander'
|
||||
import chalk from 'chalk'
|
||||
import { resolvePaseoHome } from '@paseo/server'
|
||||
import { tryConnectToDaemon, getDaemonHost } from '../../utils/client.js'
|
||||
|
||||
export function statusCommand(): Command {
|
||||
return new Command('status')
|
||||
.description('Show daemon status')
|
||||
.option('--host <host>', 'Daemon host:port (default: localhost:6767)')
|
||||
.action(async (options: { host?: string }) => {
|
||||
await runStatus(options)
|
||||
})
|
||||
}
|
||||
|
||||
async function runStatus(options: { host?: string }): Promise<void> {
|
||||
const host = getDaemonHost(options)
|
||||
const client = await tryConnectToDaemon(options)
|
||||
|
||||
if (!client) {
|
||||
console.log(chalk.red('Status:'), 'not running')
|
||||
console.log(chalk.dim(`Tried to connect to ${host}`))
|
||||
console.log()
|
||||
console.log(chalk.dim('Start the daemon with:'))
|
||||
console.log(chalk.dim(' paseo daemon start'))
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
try {
|
||||
// Request session state to get agent information
|
||||
client.requestSessionState()
|
||||
|
||||
// Wait a moment for the session state to be populated
|
||||
await new Promise(resolve => setTimeout(resolve, 500))
|
||||
|
||||
const agents = client.listAgents()
|
||||
const runningAgents = agents.filter(a => a.status === 'running')
|
||||
const idleAgents = agents.filter(a => a.status === 'idle')
|
||||
|
||||
// Get paseo home for display
|
||||
const paseoHome = resolvePaseoHome()
|
||||
|
||||
console.log(chalk.green('Status:'), 'running')
|
||||
console.log(chalk.dim('Host:'), host)
|
||||
console.log(chalk.dim('Home:'), paseoHome)
|
||||
console.log(chalk.dim('Agents:'), `${runningAgents.length} running, ${idleAgents.length} idle`)
|
||||
|
||||
await client.close()
|
||||
} catch (err) {
|
||||
await client.close().catch(() => {})
|
||||
const message = err instanceof Error ? err.message : String(err)
|
||||
console.error(chalk.red(`Failed to get status: ${message}`))
|
||||
process.exit(1)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user