refactor(cli): rename ps to ls and add top-level agent commands

This commit is contained in:
Mohamed Boudra
2026-01-29 10:41:19 +07:00
parent 7d4636ecff
commit dfda6daeed
46 changed files with 4473 additions and 542 deletions
+48 -48
View File
@@ -1,20 +1,20 @@
#!/usr/bin/env npx tsx
/**
* Phase 7: Agent Logs Command Tests
* Phase 7: Logs Command Tests
*
* Tests the agent logs command - viewing agent activity/timeline.
* Tests the logs command - viewing agent activity/timeline (top-level command).
* Since daemon may not be running, we test both:
* - Help and argument parsing
* - Graceful error handling when daemon not running
* - All flags are accepted
*
* Tests:
* - agent logs --help shows options
* - agent logs requires ID argument
* - agent logs handles daemon not running
* - agent logs -f (follow) flag is accepted
* - agent logs --tail flag is accepted
* - logs --help shows options
* - logs requires ID argument
* - logs handles daemon not running
* - logs -f (follow) flag is accepted
* - logs --tail flag is accepted
*/
import assert from 'node:assert'
@@ -25,30 +25,30 @@ import { join } from 'path'
$.verbose = false
console.log('=== Agent Logs Command Tests ===\n')
console.log('=== Logs Command Tests ===\n')
// Get random port that's definitely not in use (never 6767)
const port = 10000 + Math.floor(Math.random() * 50000)
const paseoHome = await mkdtemp(join(tmpdir(), 'paseo-test-home-'))
try {
// Test 1: agent logs --help shows options
// Test 1: logs --help shows options
{
console.log('Test 1: agent logs --help shows options')
const result = await $`npx paseo agent logs --help`.nothrow()
assert.strictEqual(result.exitCode, 0, 'agent logs --help should exit 0')
console.log('Test 1: logs --help shows options')
const result = await $`npx paseo logs --help`.nothrow()
assert.strictEqual(result.exitCode, 0, 'logs --help should exit 0')
assert(result.stdout.includes('-f') || result.stdout.includes('--follow'), 'help should mention -f/--follow flag')
assert(result.stdout.includes('--tail'), 'help should mention --tail option')
assert(result.stdout.includes('--host'), 'help should mention --host option')
assert(result.stdout.includes('<id>'), 'help should mention required id argument')
console.log('✓ agent logs --help shows options\n')
console.log('✓ logs --help shows options\n')
}
// Test 2: agent logs requires ID argument
// Test 2: logs requires ID argument
{
console.log('Test 2: agent logs requires ID argument')
console.log('Test 2: logs requires ID argument')
const result =
await $`PASEO_HOST=localhost:${port} PASEO_HOME=${paseoHome} npx paseo agent logs`.nothrow()
await $`PASEO_HOST=localhost:${port} PASEO_HOME=${paseoHome} npx paseo logs`.nothrow()
assert.notStrictEqual(result.exitCode, 0, 'should fail without id')
const output = result.stdout + result.stderr
const hasError =
@@ -57,14 +57,14 @@ try {
output.toLowerCase().includes('argument') ||
output.toLowerCase().includes('id')
assert(hasError, 'error should mention missing argument')
console.log('✓ agent logs requires ID argument\n')
console.log('✓ logs requires ID argument\n')
}
// Test 3: agent logs handles daemon not running
// Test 3: logs handles daemon not running
{
console.log('Test 3: agent logs handles daemon not running')
console.log('Test 3: logs handles daemon not running')
const result =
await $`PASEO_HOST=localhost:${port} PASEO_HOME=${paseoHome} npx paseo agent logs abc123`.nothrow()
await $`PASEO_HOST=localhost:${port} PASEO_HOME=${paseoHome} npx paseo logs abc123`.nothrow()
// Should fail because daemon not running
assert.notStrictEqual(result.exitCode, 0, 'should fail when daemon not running')
const output = result.stdout + result.stderr
@@ -73,76 +73,76 @@ try {
output.toLowerCase().includes('connect') ||
output.toLowerCase().includes('cannot')
assert(hasError, 'error message should mention connection issue')
console.log('✓ agent logs handles daemon not running\n')
console.log('✓ logs handles daemon not running\n')
}
// Test 4: agent logs -f (follow) flag is accepted
// Test 4: logs -f (follow) flag is accepted
{
console.log('Test 4: agent logs -f (follow) flag is accepted')
console.log('Test 4: logs -f (follow) flag is accepted')
// Use timeout to avoid hanging on follow mode
const result =
await $`timeout 1 bash -c 'PASEO_HOST=localhost:${port} PASEO_HOME=${paseoHome} npx paseo agent logs -f abc123' || true`.nothrow()
await $`timeout 1 bash -c 'PASEO_HOST=localhost:${port} PASEO_HOME=${paseoHome} npx paseo logs -f abc123' || true`.nothrow()
const output = result.stdout + result.stderr
assert(!output.includes('unknown option'), 'should accept -f flag')
assert(!output.includes('error: option'), 'should not have option parsing error')
console.log('✓ agent logs -f (follow) flag is accepted\n')
console.log('✓ logs -f (follow) flag is accepted\n')
}
// Test 5: agent logs --follow flag is accepted
// Test 5: logs --follow flag is accepted
{
console.log('Test 5: agent logs --follow flag is accepted')
console.log('Test 5: logs --follow flag is accepted')
const result =
await $`timeout 1 bash -c 'PASEO_HOST=localhost:${port} PASEO_HOME=${paseoHome} npx paseo agent logs --follow abc123' || true`.nothrow()
await $`timeout 1 bash -c 'PASEO_HOST=localhost:${port} PASEO_HOME=${paseoHome} npx paseo logs --follow abc123' || true`.nothrow()
const output = result.stdout + result.stderr
assert(!output.includes('unknown option'), 'should accept --follow flag')
assert(!output.includes('error: option'), 'should not have option parsing error')
console.log('✓ agent logs --follow flag is accepted\n')
console.log('✓ logs --follow flag is accepted\n')
}
// Test 6: agent logs --tail flag is accepted
// Test 6: logs --tail flag is accepted
{
console.log('Test 6: agent logs --tail flag is accepted')
console.log('Test 6: logs --tail flag is accepted')
const result =
await $`PASEO_HOST=localhost:${port} PASEO_HOME=${paseoHome} npx paseo agent logs --tail 50 abc123`.nothrow()
await $`PASEO_HOST=localhost:${port} PASEO_HOME=${paseoHome} npx paseo logs --tail 50 abc123`.nothrow()
const output = result.stdout + result.stderr
assert(!output.includes('unknown option'), 'should accept --tail flag')
assert(!output.includes('error: option'), 'should not have option parsing error')
console.log('✓ agent logs --tail flag is accepted\n')
console.log('✓ logs --tail flag is accepted\n')
}
// Test 7: agent logs with ID and --host flag is accepted
// Test 7: logs with ID and --host flag is accepted
{
console.log('Test 7: agent logs with ID and --host flag is accepted')
console.log('Test 7: logs with ID and --host flag is accepted')
const result =
await $`PASEO_HOST=localhost:${port} PASEO_HOME=${paseoHome} npx paseo agent logs abc123 --host localhost:${port}`.nothrow()
await $`PASEO_HOST=localhost:${port} PASEO_HOME=${paseoHome} npx paseo logs abc123 --host localhost:${port}`.nothrow()
const output = result.stdout + result.stderr
assert(!output.includes('unknown option'), 'should accept --host flag')
assert(!output.includes('error: option'), 'should not have option parsing error')
console.log('✓ agent logs with ID and --host flag is accepted\n')
console.log('✓ logs with ID and --host flag is accepted\n')
}
// Test 8: agent shows logs in subcommands
// Test 8: paseo --help shows logs command
{
console.log('Test 8: agent --help shows logs subcommand')
const result = await $`npx paseo agent --help`.nothrow()
assert.strictEqual(result.exitCode, 0, 'agent --help should exit 0')
assert(result.stdout.includes('logs'), 'help should mention logs subcommand')
console.log('✓ agent --help shows logs subcommand\n')
console.log('Test 8: paseo --help shows logs command')
const result = await $`npx paseo --help`.nothrow()
assert.strictEqual(result.exitCode, 0, 'paseo --help should exit 0')
assert(result.stdout.includes('logs'), 'help should mention logs command')
console.log('✓ paseo --help shows logs command\n')
}
// Test 9: -q (quiet) flag is accepted with agent logs
// Test 9: -q (quiet) flag is accepted with logs
{
console.log('Test 9: -q (quiet) flag is accepted with agent logs')
console.log('Test 9: -q (quiet) flag is accepted with logs')
const result =
await $`PASEO_HOST=localhost:${port} PASEO_HOME=${paseoHome} npx paseo -q agent logs abc123`.nothrow()
await $`PASEO_HOST=localhost:${port} PASEO_HOME=${paseoHome} npx paseo -q logs abc123`.nothrow()
const output = result.stdout + result.stderr
assert(!output.includes('unknown option'), 'should accept -q flag')
assert(!output.includes('error: option'), 'should not have option parsing error')
console.log('✓ -q (quiet) flag is accepted with agent logs\n')
console.log('✓ -q (quiet) flag is accepted with logs\n')
}
} finally {
// Clean up temp directory
await rm(paseoHome, { recursive: true, force: true })
}
console.log('=== All agent logs tests passed ===')
console.log('=== All logs tests passed ===')