mirror of
https://github.com/getpaseo/paseo.git
synced 2026-11-03 07:03:18 +00:00
fix(cli): wait for daemon feature flags
Provider and pairing gates now wait for the daemon's server_info message instead of reading the cache immediately after connect. This removes a startup race where slower CLI cold starts could treat a supported daemon as missing the feature.
This commit is contained in:
@@ -33,10 +33,9 @@ export async function runPairCommand(options: PairOptions): Promise<void> {
|
||||
if (host) {
|
||||
const client = await tryConnectToDaemon({ host, timeout: 1500 });
|
||||
if (client) {
|
||||
const supportsDaemonStatusRpc =
|
||||
client.getLastServerInfoMessage()?.features?.daemonStatusRpc === true;
|
||||
if (supportsDaemonStatusRpc) {
|
||||
try {
|
||||
try {
|
||||
const serverInfo = await client.waitForServerInfo(PAIRING_DAEMON_RPC_TIMEOUT_MS);
|
||||
if (serverInfo.features?.daemonStatusRpc === true) {
|
||||
const offer = await client.getDaemonPairingOffer({
|
||||
timeout: PAIRING_DAEMON_RPC_TIMEOUT_MS,
|
||||
});
|
||||
@@ -46,11 +45,11 @@ export async function runPairCommand(options: PairOptions): Promise<void> {
|
||||
options,
|
||||
);
|
||||
return;
|
||||
} catch {
|
||||
// COMPAT(daemon-rpc-rollout): fall back to CLI-side pairing generation while
|
||||
// old daemons lack daemonStatusRpc. Remove once the daemon floor is past
|
||||
// v0.1.76; pairing should come from daemon.get_pairing_offer.
|
||||
}
|
||||
} catch {
|
||||
// COMPAT(daemon-rpc-rollout): fall back to CLI-side pairing generation while
|
||||
// old daemons lack daemonStatusRpc. Remove once the daemon floor is past
|
||||
// v0.1.76; pairing should come from daemon.get_pairing_offer.
|
||||
}
|
||||
await client.close().catch(() => {});
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ interface RecordingClientInput {
|
||||
|
||||
function createClient(input: RecordingClientInput) {
|
||||
return {
|
||||
getLastServerInfoMessage: () => ({
|
||||
waitForServerInfo: async () => ({
|
||||
status: "server_info",
|
||||
serverId: "test-daemon",
|
||||
features: input.features ?? { paseoAgentCatalog: true },
|
||||
@@ -619,7 +619,7 @@ describe("provider add", () => {
|
||||
},
|
||||
write: () => {},
|
||||
connectDaemon: async () => ({
|
||||
getLastServerInfoMessage: () => ({
|
||||
waitForServerInfo: async () => ({
|
||||
status: "server_info",
|
||||
serverId: "test-daemon",
|
||||
features: {},
|
||||
|
||||
@@ -48,7 +48,7 @@ interface ProviderConfiguredItem {
|
||||
|
||||
interface ProviderAddClient extends Pick<
|
||||
DaemonClient,
|
||||
| "getLastServerInfoMessage"
|
||||
| "waitForServerInfo"
|
||||
| "getPaseoAgentCatalog"
|
||||
| "setPaseoAgentProvider"
|
||||
| "startPaseoAgentOAuth"
|
||||
@@ -462,7 +462,7 @@ export async function runAddCommand(
|
||||
const deps = { ...defaultDependencies, ...dependencies };
|
||||
const client = await deps.connectDaemon({ host: options.host });
|
||||
try {
|
||||
requirePaseoAgentCatalogFeature(client);
|
||||
await requirePaseoAgentCatalogFeature(client);
|
||||
const catalogResult = await client.getPaseoAgentCatalog();
|
||||
if (catalogResult.error) {
|
||||
throw {
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import type { ServerInfoStatusPayload } from "@getpaseo/protocol/messages";
|
||||
|
||||
import { requirePaseoAgentCatalogFeature } from "./feature.js";
|
||||
|
||||
function createServerInfo(features: ServerInfoStatusPayload["features"]): ServerInfoStatusPayload {
|
||||
return {
|
||||
status: "server_info",
|
||||
serverId: "test-daemon",
|
||||
features,
|
||||
};
|
||||
}
|
||||
|
||||
describe("provider feature gate", () => {
|
||||
it("waits for delayed server_info before allowing catalog commands", async () => {
|
||||
let resolveServerInfo: ((serverInfo: ServerInfoStatusPayload) => void) | null = null;
|
||||
|
||||
const allowed = requirePaseoAgentCatalogFeature({
|
||||
waitForServerInfo: async () =>
|
||||
new Promise<ServerInfoStatusPayload>((resolve) => {
|
||||
resolveServerInfo = resolve;
|
||||
}),
|
||||
});
|
||||
|
||||
expect(resolveServerInfo).not.toBeNull();
|
||||
resolveServerInfo?.(createServerInfo({ paseoAgentCatalog: true }));
|
||||
|
||||
await expect(allowed).resolves.toBeUndefined();
|
||||
});
|
||||
|
||||
it("surfaces the server_info wait timeout", async () => {
|
||||
const timeoutError = new Error("Timed out waiting for server_info status message (5ms)");
|
||||
|
||||
await expect(
|
||||
requirePaseoAgentCatalogFeature({
|
||||
waitForServerInfo: async () => {
|
||||
throw timeoutError;
|
||||
},
|
||||
}),
|
||||
).rejects.toThrow("Timed out waiting for server_info status message (5ms)");
|
||||
});
|
||||
|
||||
it("requires the catalog feature when server_info arrives without it", async () => {
|
||||
await expect(
|
||||
requirePaseoAgentCatalogFeature({
|
||||
waitForServerInfo: async () => createServerInfo({ paseoAgentCatalog: false }),
|
||||
}),
|
||||
).rejects.toMatchObject({
|
||||
code: "HOST_UPDATE_REQUIRED",
|
||||
message: "Update the Paseo daemon to use this command.",
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,13 +1,13 @@
|
||||
import type { DaemonClient } from "@getpaseo/client/internal/daemon-client";
|
||||
import type { CommandError } from "../../output/index.js";
|
||||
|
||||
export interface PaseoAgentCatalogFeatureClient extends Pick<
|
||||
DaemonClient,
|
||||
"getLastServerInfoMessage"
|
||||
> {}
|
||||
export interface PaseoAgentCatalogFeatureClient extends Pick<DaemonClient, "waitForServerInfo"> {}
|
||||
|
||||
export function requirePaseoAgentCatalogFeature(client: PaseoAgentCatalogFeatureClient): void {
|
||||
if (client.getLastServerInfoMessage()?.features?.paseoAgentCatalog === true) {
|
||||
export async function requirePaseoAgentCatalogFeature(
|
||||
client: PaseoAgentCatalogFeatureClient,
|
||||
): Promise<void> {
|
||||
const serverInfo = await client.waitForServerInfo();
|
||||
if (serverInfo.features?.paseoAgentCatalog === true) {
|
||||
return;
|
||||
}
|
||||
throw {
|
||||
|
||||
@@ -16,7 +16,7 @@ describe("provider ls", () => {
|
||||
it("renders an empty configured-provider table with headers", async () => {
|
||||
const result = await runLsCommand({ host: "localhost:7777" }, {} as never, {
|
||||
connectDaemon: async () => ({
|
||||
getLastServerInfoMessage: createServerInfo,
|
||||
waitForServerInfo: async () => createServerInfo(),
|
||||
getPaseoAgentCatalog: async () => ({
|
||||
requestId: "catalog-1",
|
||||
catalog: [],
|
||||
@@ -42,7 +42,7 @@ describe("provider ls", () => {
|
||||
connectDaemon: async (options) => {
|
||||
expect(options.host).toBe("localhost:7777");
|
||||
return {
|
||||
getLastServerInfoMessage: createServerInfo,
|
||||
waitForServerInfo: async () => createServerInfo(),
|
||||
getPaseoAgentCatalog: async () => ({
|
||||
requestId: "catalog-1",
|
||||
catalog: [
|
||||
@@ -142,7 +142,7 @@ describe("provider rm", () => {
|
||||
connectDaemon: async (options) => {
|
||||
expect(options.host).toBe("localhost:7777");
|
||||
return {
|
||||
getLastServerInfoMessage: createServerInfo,
|
||||
waitForServerInfo: async () => createServerInfo(),
|
||||
removePaseoAgentProvider: async (name: string) => {
|
||||
removedNames.push(name);
|
||||
return {
|
||||
|
||||
@@ -25,7 +25,7 @@ export interface ProviderListItem {
|
||||
|
||||
interface ProviderLsClient extends Pick<
|
||||
DaemonClient,
|
||||
"getLastServerInfoMessage" | "getPaseoAgentCatalog" | "getPaseoAgentProviders" | "close"
|
||||
"waitForServerInfo" | "getPaseoAgentCatalog" | "getPaseoAgentProviders" | "close"
|
||||
> {}
|
||||
|
||||
export interface ProviderLsDependencies {
|
||||
@@ -80,7 +80,7 @@ export async function runLsCommand(
|
||||
const client = await deps.connectDaemon({ host: options.host });
|
||||
|
||||
try {
|
||||
requirePaseoAgentCatalogFeature(client);
|
||||
await requirePaseoAgentCatalogFeature(client);
|
||||
const catalogResult = await client.getPaseoAgentCatalog();
|
||||
if (catalogResult.error) {
|
||||
throw {
|
||||
|
||||
@@ -21,7 +21,7 @@ interface ProviderRemoveItem {
|
||||
|
||||
interface ProviderRmClient extends Pick<
|
||||
DaemonClient,
|
||||
"getLastServerInfoMessage" | "removePaseoAgentProvider" | "close"
|
||||
"waitForServerInfo" | "removePaseoAgentProvider" | "close"
|
||||
> {}
|
||||
|
||||
export interface ProviderRmDependencies {
|
||||
@@ -49,7 +49,7 @@ export async function runRmCommand(
|
||||
const deps = { ...defaultDependencies, ...dependencies };
|
||||
const client = await deps.connectDaemon({ host: options.host });
|
||||
try {
|
||||
requirePaseoAgentCatalogFeature(client);
|
||||
await requirePaseoAgentCatalogFeature(client);
|
||||
const result = await client.removePaseoAgentProvider(name);
|
||||
if (!result.success) {
|
||||
throw {
|
||||
|
||||
Reference in New Issue
Block a user