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:
Mohamed Boudra
2026-01-28 22:47:08 +07:00
parent 6781c1b888
commit 6fd4214466
14 changed files with 664 additions and 12 deletions
+53
View File
@@ -0,0 +1,53 @@
import { Command } from 'commander'
import chalk from 'chalk'
import { connectToDaemon, getDaemonHost } from '../../utils/client.js'
export function stopCommand(): Command {
return new Command('stop')
.description('Stop the daemon')
.option('--host <host>', 'Daemon host:port (default: localhost:6767)')
.action(async (options: { host?: string }) => {
await runStop(options)
})
}
async function runStop(options: { host?: string }): Promise<void> {
const host = getDaemonHost(options)
let client
try {
client = await connectToDaemon(options)
} catch {
console.log(chalk.yellow('Daemon is not running'))
console.log(chalk.dim(`Tried to connect to ${host}`))
process.exit(0)
}
try {
console.log(chalk.dim('Stopping daemon...'))
// Request server restart with "shutdown" reason
// This signals the daemon to shut down gracefully
await client.restartServer('cli_shutdown')
// Give the daemon a moment to acknowledge
await new Promise(resolve => setTimeout(resolve, 500))
console.log(chalk.green('Daemon stop requested'))
console.log(chalk.dim('The daemon will shut down gracefully'))
await client.close()
} catch (err) {
await client.close().catch(() => {})
const message = err instanceof Error ? err.message : String(err)
// If connection was closed, the daemon is stopping
if (message.includes('closed') || message.includes('disconnected')) {
console.log(chalk.green('Daemon is stopping'))
process.exit(0)
}
console.error(chalk.red(`Failed to stop daemon: ${message}`))
process.exit(1)
}
}