fix(tests): iteration 20
This commit is contained in:
@@ -15,12 +15,10 @@
|
||||
*/
|
||||
|
||||
import assert from 'node:assert'
|
||||
import { $ } from 'zx'
|
||||
import { mkdtemp, rm } from 'fs/promises'
|
||||
import { tmpdir } from 'os'
|
||||
import { join } from 'path'
|
||||
|
||||
$.verbose = false
|
||||
import { runLocalPaseo } from './helpers/local-cli.ts'
|
||||
|
||||
console.log('=== Daemon Commands ===\n')
|
||||
|
||||
@@ -28,11 +26,15 @@ console.log('=== Daemon Commands ===\n')
|
||||
const port = 10000 + Math.floor(Math.random() * 50000)
|
||||
const paseoHome = await mkdtemp(join(tmpdir(), 'paseo-test-home-'))
|
||||
|
||||
function daemonCommand(args: string[]) {
|
||||
return runLocalPaseo(['daemon', ...args], { PASEO_HOME: paseoHome })
|
||||
}
|
||||
|
||||
try {
|
||||
// Test 1: daemon --help shows subcommands
|
||||
{
|
||||
console.log('Test 1: daemon --help shows subcommands')
|
||||
const result = await $`npx paseo daemon --help`.nothrow()
|
||||
const result = await runLocalPaseo(['daemon', '--help'])
|
||||
assert.strictEqual(result.exitCode, 0, 'daemon --help should exit 0')
|
||||
assert(result.stdout.includes('start'), 'help should mention start')
|
||||
assert(result.stdout.includes('status'), 'help should mention status')
|
||||
@@ -45,8 +47,7 @@ try {
|
||||
// Test 2: daemon pair works without daemon process
|
||||
{
|
||||
console.log('Test 2: daemon pair prints local pairing URL')
|
||||
const result =
|
||||
await $`PASEO_HOME=${paseoHome} npx paseo daemon pair`.nothrow()
|
||||
const result = await daemonCommand(['pair'])
|
||||
assert.strictEqual(result.exitCode, 0, 'daemon pair should succeed')
|
||||
assert(result.stdout.includes('Scan to pair:'), 'output should include scan header')
|
||||
assert(result.stdout.includes('#offer='), 'output should include pairing offer fragment')
|
||||
@@ -56,8 +57,7 @@ try {
|
||||
// Test 3: daemon status reports stopped when daemon not running
|
||||
{
|
||||
console.log('Test 3: daemon status reports stopped when not running')
|
||||
const result =
|
||||
await $`PASEO_HOME=${paseoHome} npx paseo daemon status`.nothrow()
|
||||
const result = await daemonCommand(['status'])
|
||||
assert.strictEqual(result.exitCode, 0, 'status should succeed when daemon is stopped')
|
||||
const output = result.stdout.toLowerCase()
|
||||
assert(output.includes('status'), 'status table should include Status row')
|
||||
@@ -68,8 +68,7 @@ try {
|
||||
// Test 4: daemon pair --json outputs valid JSON
|
||||
{
|
||||
console.log('Test 4: daemon pair --json outputs JSON')
|
||||
const result =
|
||||
await $`PASEO_HOME=${paseoHome} npx paseo daemon pair --json`.nothrow()
|
||||
const result = await daemonCommand(['pair', '--json'])
|
||||
assert.strictEqual(result.exitCode, 0, 'daemon pair --json should succeed')
|
||||
const pairing = JSON.parse(result.stdout)
|
||||
assert.strictEqual(pairing.relayEnabled, true, 'pairing should report relay enabled')
|
||||
@@ -81,8 +80,7 @@ try {
|
||||
// Test 5: daemon status --json outputs valid JSON
|
||||
{
|
||||
console.log('Test 5: daemon status --json outputs JSON')
|
||||
const result =
|
||||
await $`PASEO_HOME=${paseoHome} npx paseo daemon status --json`.nothrow()
|
||||
const result = await daemonCommand(['status', '--json'])
|
||||
assert.strictEqual(result.exitCode, 0, '--json status should succeed')
|
||||
const status = JSON.parse(result.stdout)
|
||||
assert.strictEqual(typeof status.serverId, 'string', 'json status should include serverId')
|
||||
@@ -95,8 +93,7 @@ try {
|
||||
// Test 6: daemon stop handles daemon not running gracefully
|
||||
{
|
||||
console.log('Test 6: daemon stop handles daemon not running')
|
||||
const result =
|
||||
await $`PASEO_HOME=${paseoHome} npx paseo daemon stop`.nothrow()
|
||||
const result = await daemonCommand(['stop'])
|
||||
// Stop should succeed even if daemon is not running (idempotent).
|
||||
assert.strictEqual(result.exitCode, 0, 'stop should succeed when daemon not running')
|
||||
const output = result.stdout + result.stderr
|
||||
@@ -110,18 +107,17 @@ try {
|
||||
// Test 7: daemon restart starts daemon and can be stopped
|
||||
{
|
||||
console.log('Test 7: daemon restart starts daemon and can be stopped')
|
||||
const result =
|
||||
await $`PASEO_HOME=${paseoHome} npx paseo daemon restart --port ${String(port)}`.nothrow()
|
||||
const result = await daemonCommand(['restart', '--port', String(port)])
|
||||
assert.strictEqual(result.exitCode, 0, 'restart should succeed even when previously stopped')
|
||||
assert(result.stdout.toLowerCase().includes('restarted'), 'output should report restart')
|
||||
|
||||
const cleanup = await $`PASEO_HOME=${paseoHome} npx paseo daemon stop --force`.nothrow()
|
||||
const cleanup = await daemonCommand(['stop', '--force'])
|
||||
assert.strictEqual(cleanup.exitCode, 0, 'cleanup stop should succeed after restart')
|
||||
console.log('✓ daemon restart starts and stop cleanup succeeds\n')
|
||||
}
|
||||
} finally {
|
||||
// Best-effort daemon cleanup in case assertions fail before explicit stop.
|
||||
await $`PASEO_HOME=${paseoHome} npx paseo daemon stop --force`.nothrow()
|
||||
await daemonCommand(['stop', '--force'])
|
||||
// Clean up temp directory
|
||||
await rm(paseoHome, { recursive: true, force: true })
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user