mirror of
https://github.com/getpaseo/paseo.git
synced 2026-10-26 11:12:53 +00:00
* fix(daemon): keep lifecycle operations on the selected instance Restart reconstructed launch inputs and address fallback could redirect a home-selected shutdown to another daemon. Let supervisors publish bound endpoints, retain their worker restart contract, and share captured local lifecycle ownership between CLI and Desktop. * test(daemon): verify bounded desktop readiness and cancellable artifacts * test(cli): verify reload target hints and durable offline pairing * test(daemon): align lifecycle fixtures with ownership and targeting * fix(daemon): preserve reachability when status details time out Provider discovery can outlast a status request after authentication succeeds. Keep local connection facts separate from unavailable details, while explicit remote queries retain their error outcome. Migrate CLI and packaged Desktop fixtures to persistent managed configuration and explicit targets. Isolate generic Git observation from forge discovery and reuse disposable CLI homes on Windows. * test(daemon): observe restart through the worker status RPC The bounded CLI status observation may omit worker details while an authenticated connection remains healthy. Exercise the app-style restart through its full RPC and retain the replacement observation, with a real slow provider probe covering the distinction.
177 lines
7.8 KiB
TypeScript
177 lines
7.8 KiB
TypeScript
#!/usr/bin/env npx tsx
|
|
|
|
/**
|
|
* Permit Allow/Deny Command Tests
|
|
*
|
|
* Tests the permit allow and deny commands.
|
|
* Since daemon may not be running, we test:
|
|
* - Help and argument parsing
|
|
* - Graceful error handling when daemon not running
|
|
* - Flag acceptance
|
|
*
|
|
* Tests:
|
|
* - permit allow --help shows options
|
|
* - permit deny --help shows options
|
|
* - permit allow handles daemon not running
|
|
* - permit deny handles daemon not running
|
|
* - permit allow --all flag is accepted
|
|
* - permit deny --all flag is accepted
|
|
* - permit deny --message flag is accepted
|
|
* - permit deny --interrupt flag is accepted
|
|
* - permit allow --input flag is accepted
|
|
*/
|
|
|
|
import assert from "node:assert";
|
|
import { getAvailablePort } from "./helpers/network.ts";
|
|
import { $ } from "zx";
|
|
import { mkdtemp, rm } from "fs/promises";
|
|
import { tmpdir } from "os";
|
|
import { join } from "path";
|
|
|
|
$.verbose = false;
|
|
|
|
console.log("=== Permit Allow/Deny Command Tests ===\n");
|
|
|
|
// Allocate an unused endpoint for connection-error and argument-validation checks.
|
|
const port = await getAvailablePort();
|
|
const paseoHome = await mkdtemp(join(tmpdir(), "paseo-test-home-"));
|
|
|
|
try {
|
|
// Test 1: permit allow --help shows options
|
|
{
|
|
console.log("Test 1: permit allow --help shows options");
|
|
const result = await $`npx paseo permit allow --help`.nothrow();
|
|
assert.strictEqual(result.exitCode, 0, "permit allow --help should exit 0");
|
|
assert(result.stdout.includes("--all"), "help should mention --all flag");
|
|
assert(result.stdout.includes("--input"), "help should mention --input option");
|
|
assert(result.stdout.includes("--host"), "help should mention --host option");
|
|
assert(result.stdout.includes("<agent>"), "help should mention agent argument");
|
|
console.log("✓ permit allow --help shows options\n");
|
|
}
|
|
|
|
// Test 2: permit deny --help shows options
|
|
{
|
|
console.log("Test 2: permit deny --help shows options");
|
|
const result = await $`npx paseo permit deny --help`.nothrow();
|
|
assert.strictEqual(result.exitCode, 0, "permit deny --help should exit 0");
|
|
assert(result.stdout.includes("--all"), "help should mention --all flag");
|
|
assert(result.stdout.includes("--message"), "help should mention --message option");
|
|
assert(result.stdout.includes("--interrupt"), "help should mention --interrupt flag");
|
|
assert(result.stdout.includes("--host"), "help should mention --host option");
|
|
assert(result.stdout.includes("<agent>"), "help should mention agent argument");
|
|
console.log("✓ permit deny --help shows options\n");
|
|
}
|
|
|
|
// Test 3: permit allow handles daemon not running
|
|
{
|
|
console.log("Test 3: permit allow handles daemon not running");
|
|
const result =
|
|
await $`PASEO_HOME=${paseoHome} npx paseo --host localhost:${port} permit allow abc123 req456`.nothrow();
|
|
// Should fail because daemon not running
|
|
assert.notStrictEqual(result.exitCode, 0, "should fail when daemon not running");
|
|
const output = result.stdout + result.stderr;
|
|
const hasError =
|
|
output.toLowerCase().includes("daemon") ||
|
|
output.toLowerCase().includes("connect") ||
|
|
output.toLowerCase().includes("cannot");
|
|
assert(hasError, "error message should mention connection issue");
|
|
console.log("✓ permit allow handles daemon not running\n");
|
|
}
|
|
|
|
// Test 4: permit deny handles daemon not running
|
|
{
|
|
console.log("Test 4: permit deny handles daemon not running");
|
|
const result =
|
|
await $`PASEO_HOME=${paseoHome} npx paseo --host localhost:${port} permit deny abc123 req456`.nothrow();
|
|
// Should fail because daemon not running
|
|
assert.notStrictEqual(result.exitCode, 0, "should fail when daemon not running");
|
|
const output = result.stdout + result.stderr;
|
|
const hasError =
|
|
output.toLowerCase().includes("daemon") ||
|
|
output.toLowerCase().includes("connect") ||
|
|
output.toLowerCase().includes("cannot");
|
|
assert(hasError, "error message should mention connection issue");
|
|
console.log("✓ permit deny handles daemon not running\n");
|
|
}
|
|
|
|
// Test 5: permit allow --all flag is accepted
|
|
{
|
|
console.log("Test 5: permit allow --all flag is accepted");
|
|
const result =
|
|
await $`PASEO_HOME=${paseoHome} npx paseo --host localhost:${port} permit allow abc123 --all`.nothrow();
|
|
const output = result.stdout + result.stderr;
|
|
assert(!output.includes("unknown option"), "should accept --all flag");
|
|
assert(!output.includes("error: option"), "should not have option parsing error");
|
|
console.log("✓ permit allow --all flag is accepted\n");
|
|
}
|
|
|
|
// Test 6: permit deny --all flag is accepted
|
|
{
|
|
console.log("Test 6: permit deny --all flag is accepted");
|
|
const result =
|
|
await $`PASEO_HOME=${paseoHome} npx paseo --host localhost:${port} permit deny abc123 --all`.nothrow();
|
|
const output = result.stdout + result.stderr;
|
|
assert(!output.includes("unknown option"), "should accept --all flag");
|
|
assert(!output.includes("error: option"), "should not have option parsing error");
|
|
console.log("✓ permit deny --all flag is accepted\n");
|
|
}
|
|
|
|
// Test 7: permit deny --message flag is accepted
|
|
{
|
|
console.log("Test 7: permit deny --message flag is accepted");
|
|
const result =
|
|
await $`PASEO_HOME=${paseoHome} npx paseo --host localhost:${port} permit deny abc123 req456 --message "Not allowed"`.nothrow();
|
|
const output = result.stdout + result.stderr;
|
|
assert(!output.includes("unknown option"), "should accept --message flag");
|
|
assert(!output.includes("error: option"), "should not have option parsing error");
|
|
console.log("✓ permit deny --message flag is accepted\n");
|
|
}
|
|
|
|
// Test 8: permit deny --interrupt flag is accepted
|
|
{
|
|
console.log("Test 8: permit deny --interrupt flag is accepted");
|
|
const result =
|
|
await $`PASEO_HOME=${paseoHome} npx paseo --host localhost:${port} permit deny abc123 req456 --interrupt`.nothrow();
|
|
const output = result.stdout + result.stderr;
|
|
assert(!output.includes("unknown option"), "should accept --interrupt flag");
|
|
assert(!output.includes("error: option"), "should not have option parsing error");
|
|
console.log("✓ permit deny --interrupt flag is accepted\n");
|
|
}
|
|
|
|
// Test 9: permit allow --input flag is accepted
|
|
{
|
|
console.log("Test 9: permit allow --input flag is accepted");
|
|
const result =
|
|
await $`PASEO_HOME=${paseoHome} npx paseo --host localhost:${port} permit allow abc123 req456 --input '{"key":"value"}'`.nothrow();
|
|
const output = result.stdout + result.stderr;
|
|
assert(!output.includes("unknown option"), "should accept --input flag");
|
|
assert(!output.includes("error: option"), "should not have option parsing error");
|
|
console.log("✓ permit allow --input flag is accepted\n");
|
|
}
|
|
|
|
// Test 10: permit allow without req_id and without --all fails gracefully
|
|
{
|
|
console.log("Test 10: permit allow requires req_id or --all");
|
|
const result =
|
|
await $`PASEO_HOME=${paseoHome} npx paseo --host localhost:${port} permit allow abc123`.nothrow();
|
|
// This might fail due to daemon not running first, or due to missing argument
|
|
// The important thing is it doesn't crash with an unhandled error
|
|
assert.notStrictEqual(result.exitCode, 0, "should fail without req_id or --all");
|
|
console.log("✓ permit allow requires req_id or --all\n");
|
|
}
|
|
|
|
// Test 11: permit deny without req_id and without --all fails gracefully
|
|
{
|
|
console.log("Test 11: permit deny requires req_id or --all");
|
|
const result =
|
|
await $`PASEO_HOME=${paseoHome} npx paseo --host localhost:${port} permit deny abc123`.nothrow();
|
|
assert.notStrictEqual(result.exitCode, 0, "should fail without req_id or --all");
|
|
console.log("✓ permit deny requires req_id or --all\n");
|
|
}
|
|
} finally {
|
|
// Clean up temp directory
|
|
await rm(paseoHome, { recursive: true, force: true });
|
|
}
|
|
|
|
console.log("=== All permit allow/deny tests passed ===");
|