#!/usr/bin/env npx tsx import assert from "node:assert"; import { runLocalPaseo } from "./helpers/local-cli.ts"; import { startTestDaemon } from "./helpers/test-daemon.ts"; console.log("=== Daemon Auth Command Errors ===\n"); const daemon = await startTestDaemon({ env: { PASEO_PASSWORD: "shared-secret" }, }); async function lsError(password: string, remoteClient = false) { const result = await runLocalPaseo(["ls", "--json"], { PASEO_HOME: remoteClient ? "" : daemon.paseoHome, PASEO_HOST: remoteClient ? `127.0.0.1:${daemon.port}` : "", PASEO_PASSWORD: password, }); assert.notStrictEqual(result.exitCode, 0, "ls should fail without a valid password"); return JSON.parse(result.stderr).error as { code: string; message: string; details: string; }; } try { { console.log("Test 1: a client outside the daemon home needs PASEO_PASSWORD"); const error = await lsError("", true); assert.strictEqual(error.code, "AUTH_REQUIRED"); assert.match(error.message, /Password required/); assert.match(error.details, /PASEO_PASSWORD/); assert.doesNotMatch(error.details, /daemon start/); console.log("✓ client without the local credential is asked for PASEO_PASSWORD\n"); } { console.log("Test 2: wrong password asks for PASEO_PASSWORD, not a daemon start"); const error = await lsError("wrong-secret"); assert.strictEqual(error.code, "AUTH_FAILED"); assert.match(error.message, /Incorrect password/); assert.match(error.details, /PASEO_PASSWORD/); assert.doesNotMatch(error.details, /daemon start/); console.log("✓ wrong password points at PASEO_PASSWORD\n"); } } finally { await daemon.stop(); } console.log("=== Daemon Auth Command Errors Tests Passed ===");