Files
paseo/packages/cli/tests/42-agent-open.test.ts
T
paseo-bot[bot] 5599f9e567 fix(cli): fail agent open for an agent the daemon does not have (#5727)
paseo agent open launched Desktop with whatever string it was given,
printed "opened" and exited 0, so a bad ID moved the user to a broken
"Agent not found" tab and the calling script saw success. Look the agent
up on the daemon first, the way inspect and mode do, and open Desktop on
the ID the daemon resolved.

Closes #5721

Co-authored-by: paseo-bot[bot] <266920839+paseo-bot[bot]@users.noreply.github.com>
2026-09-30 02:55:44 +02:00

53 lines
1.9 KiB
TypeScript

#!/usr/bin/env npx tsx
import assert from "node:assert";
import { chmod, mkdir, readFile, writeFile } from "node:fs/promises";
import { existsSync } from "node:fs";
import { join } from "node:path";
import { runPaseoCli, startTestDaemon } from "./helpers/test-daemon.ts";
console.log("=== Agent Open Command Tests ===\n");
if (process.platform !== "linux") {
console.log("Skipped: the fake Desktop app is a Linux AppImage path.");
process.exit(0);
}
const daemon = await startTestDaemon();
// runPaseoCli sets HOME to the daemon's home, where the CLI looks for
// ~/Applications/Paseo.AppImage on Linux. The fake app records its launch.
const launchRecord = join(daemon.paseoHome, "desktop-launches.txt");
const fakeDesktop = join(daemon.paseoHome, "Applications", "Paseo.AppImage");
await mkdir(join(daemon.paseoHome, "Applications"), { recursive: true });
await writeFile(fakeDesktop, `#!/bin/sh\necho "$@" >> "${launchRecord}"\n`);
await chmod(fakeDesktop, 0o755);
try {
{
console.log("Test 1: an unknown agent ID fails without opening Desktop");
const result = await runPaseoCli(daemon, [
"agent",
"open",
"does-not-exist",
"--host",
`127.0.0.1:${daemon.port}`,
"--json",
]);
assert.notStrictEqual(result.exitCode, 0, "open should fail for an unknown agent");
assert.match(JSON.parse(result.stderr).error.message, /Agent not found: does-not-exist/);
// Give a wrongly spawned detached app time to write its record.
await new Promise((resolve) => setTimeout(resolve, 500));
assert.ok(
!existsSync(launchRecord),
`Desktop should not open, but was launched with: ${existsSync(launchRecord) ? await readFile(launchRecord, "utf8") : ""}`,
);
console.log("✓ unknown agent ID fails without opening Desktop\n");
}
} finally {
await daemon.stop();
}
console.log("=== All agent open tests passed ===");