diff --git a/packages/cli/src/commands/hub/login-flow.test.ts b/packages/cli/src/commands/hub/login-flow.test.ts index 2b3561dda3..75bf33ed89 100644 --- a/packages/cli/src/commands/hub/login-flow.test.ts +++ b/packages/cli/src/commands/hub/login-flow.test.ts @@ -38,7 +38,9 @@ describe("Hub CLI login browser flow", () => { assert.equal(credential, "paseo_cli_prefix_durable-secret-value"); assert.deepEqual(journey.waits, [5_000, 5_000, 10_000]); assert.deepEqual(journey.opened, ["https://hub.test/cli-login?code=ABCD-EFGH"]); - assert.deepEqual(journey.instructions, ["https://hub.test/cli-login ABCD-EFGH"]); + assert.deepEqual(journey.instructions, [ + "Open https://hub.test/cli-login?code=ABCD-EFGH to approve CLI login (code: ABCD-EFGH)", + ]); }); it("does not open a browser in noninteractive mode", async () => { @@ -57,7 +59,9 @@ describe("Hub CLI login browser flow", () => { await journey.authorize(); assert.deepEqual(journey.opened, []); - assert.equal(journey.instructions.length, 1); + assert.deepEqual(journey.instructions, [ + "Open https://hub.test/cli-login?code=ABCD-EFGH to approve CLI login (code: ABCD-EFGH)", + ]); }); }); @@ -95,7 +99,7 @@ class LoginJourney { now: () => this.now, }, browser: { open: async (url) => void this.opened.push(url) }, - instructions: (url, code) => void this.instructions.push(`${url} ${code}`), + instructions: (message) => void this.instructions.push(message), openBrowser, }); } diff --git a/packages/cli/src/commands/hub/login-flow.ts b/packages/cli/src/commands/hub/login-flow.ts index 64b37fe990..49c8fdd0a1 100644 --- a/packages/cli/src/commands/hub/login-flow.ts +++ b/packages/cli/src/commands/hub/login-flow.ts @@ -40,7 +40,7 @@ interface CliLoginFlowOptions { hub: Pick; waiter: LoginWaiter; browser: BrowserOpener; - instructions(verificationUri: string, userCode: string): void; + instructions(message: string): void; openBrowser: boolean; } @@ -49,7 +49,9 @@ export class CliLoginFlow { async authorize(origin: string): Promise { const authorization = await this.options.hub.startCliAuthorization(origin); - this.options.instructions(authorization.verificationUri, authorization.userCode); + this.options.instructions( + `Open ${authorization.verificationUriComplete} to approve CLI login (code: ${authorization.userCode})`, + ); if (this.options.openBrowser) { await this.options.browser.open(authorization.verificationUriComplete).catch(() => undefined); } @@ -84,8 +86,8 @@ export function createCliLoginFlow(hub: HubHttpClient): CliLoginFlow { now: Date.now, }, browser: new SystemBrowser(), - instructions(verificationUri, userCode) { - process.stderr.write(`Open ${verificationUri} and enter code ${userCode}\n`); + instructions(message) { + process.stderr.write(`${message}\n`); }, openBrowser: process.stderr.isTTY === true, }); diff --git a/packages/server/src/server/agent/plugin-provider.ts b/packages/server/src/server/agent/plugin-provider.ts index bdd824d400..5e52f66032 100644 --- a/packages/server/src/server/agent/plugin-provider.ts +++ b/packages/server/src/server/agent/plugin-provider.ts @@ -150,6 +150,10 @@ function describeVersion(inspection: ProviderInstallationInspection): string { return inspection.version?.trim() || "unknown"; } +function toProviderLaunch(launch: ProviderInstallationLaunch): ProviderLaunch { + return { command: launch.command, args: launch.args, env: launch.env }; +} + class ProviderRuntime { private connection: ProviderConnection | null = null; connectedLaunch: ProviderLaunch | undefined; @@ -212,13 +216,13 @@ class ProviderRuntime { const launch = await this.resolveEffectiveLaunch(); if (!launch) return undefined; if (!launch.resolved) throw new Error(`${launch.command} not found on PATH`); - return { command: launch.command, args: launch.args, env: launch.env }; + return toProviderLaunch(launch); } async resolveUsageLaunch(): Promise { const launch = await this.resolveEffectiveLaunch(); if (!launch?.resolved) return undefined; - return { command: launch.command, args: launch.args, env: launch.env }; + return toProviderLaunch(launch); } async inspectInstallation(signal: AbortSignal): Promise { @@ -281,7 +285,11 @@ class ProviderRuntime { async catalogCacheKey(options: FetchCatalogOptions): Promise { const callback = this.registration.getCatalogCacheKey; if (!callback) return undefined; - return callback({ ...options, launch: await this.resolveLaunch() }); + const launch = await this.resolveEffectiveLaunch(); + // A missing executable gets its own catalogue, so refresh reports it unavailable instead of + // failing the key or reusing a catalogue cached while it was installed. + if (launch && !launch.resolved) return JSON.stringify(["unresolved", launch.command]); + return callback({ ...options, launch: launch && toProviderLaunch(launch) }); } get negotiatedCapabilities(): readonly string[] { diff --git a/packages/server/src/server/agent/provider-snapshot-manager.test.ts b/packages/server/src/server/agent/provider-snapshot-manager.test.ts index 04ba1f7f46..b8c2ed7df7 100644 --- a/packages/server/src/server/agent/provider-snapshot-manager.test.ts +++ b/packages/server/src/server/agent/provider-snapshot-manager.test.ts @@ -1,6 +1,7 @@ import pino from "pino"; -import { homedir } from "node:os"; -import { resolve } from "node:path"; +import { chmodSync, mkdtempSync, rmSync, writeFileSync } from "node:fs"; +import { homedir, tmpdir } from "node:os"; +import { join, resolve } from "node:path"; import { describe, expect, test, vi } from "vitest"; import type { ProviderEvent, @@ -8,6 +9,7 @@ import type { ProviderLaunch, } from "@getpaseo/plugin/server/provider"; +import { isPlatform } from "../../test-utils/platform.js"; import { createTestLogger } from "../../test-utils/test-logger.js"; import type { AgentClient, @@ -217,6 +219,97 @@ describe("ProviderSnapshotManager public surface", () => { } }); + test("reports a plugin provider whose command is not installed as unavailable", async () => { + const manager = new ProviderSnapshotManager({ logger: createTestLogger() }); + manager.replacePluginProviders([ + { + id: "uninstalled-plugin", + label: "Uninstalled plugin", + command: ["paseo-test-command-that-is-not-installed"], + async getCatalogCacheKey({ launch }) { + if (!launch) throw new Error("requires a daemon-resolved executable"); + return launch.command; + }, + async status({ launch }) { + return launch ? { available: true } : { available: false, diagnostic: "Install it" }; + }, + async connect() { + throw new Error("an uninstalled provider is never connected"); + }, + }, + ]); + try { + const entry = await manager.getProvider({ + provider: "uninstalled-plugin", + cwd: "/tmp/project", + wait: true, + }); + expect(entry).toMatchObject({ status: "unavailable" }); + expect(entry.error).toBeUndefined(); + } finally { + manager.destroy(); + } + }); + + test.skipIf(isPlatform("win32"))( + "reports a workspace-cached plugin provider as unavailable after its executable is removed", + async () => { + const directory = mkdtempSync(join(tmpdir(), "paseo-removed-plugin-")); + const executable = join(directory, "removed-plugin"); + writeFileSync(executable, "#!/bin/sh\necho 1.0.0\n"); + chmodSync(executable, 0o755); + const manager = new ProviderSnapshotManager({ logger: createTestLogger() }); + manager.replacePluginProviders([ + { + id: "removed-plugin", + label: "Removed plugin", + command: [executable], + // undefined asks the snapshot manager to cache the catalogue per workspace. + async getCatalogCacheKey() { + return undefined; + }, + async status({ launch }) { + return launch ? { available: true } : { available: false, diagnostic: "Install it" }; + }, + async connect() { + let listener: ((event: ProviderEvent) => void) | undefined; + return { + version: 1, + capabilities: [], + async send(input) { + if (input.type === "catalog") + listener?.({ + type: "catalog", + requestId: input.requestId, + catalog: { models: [{ id: "model", label: "Model" }], modes: [] }, + }); + }, + onEvent(next) { + listener = next; + return () => { + listener = undefined; + }; + }, + async close() {}, + }; + }, + }, + ]); + try { + const read = () => + manager.getProvider({ provider: "removed-plugin", cwd: "/tmp/project", wait: true }); + expect(await read()).toMatchObject({ status: "ready" }); + + rmSync(directory, { recursive: true, force: true }); + + expect(await read()).toMatchObject({ status: "unavailable" }); + } finally { + manager.destroy(); + rmSync(directory, { recursive: true, force: true }); + } + }, + ); + test("carries a plugin provider icon and docs link in snapshot metadata", () => { const iconSvg = ''; const docsUrl = "https://example.com/docs";