Skip to content

Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins

fix(providers): probe the resolved endpoint in the connection test (#1690)

Liu Zixiang195c52361eca
diff --git a/apps/desktop/electron/main/ipc/provider-ipc.ts b/apps/desktop/electron/main/ipc/provider-ipc.ts
index d3c741a61..1bfd6a88a 100644
--- a/apps/desktop/electron/main/ipc/provider-ipc.ts
+++ b/apps/desktop/electron/main/ipc/provider-ipc.ts
@@ -252,25 +252,24 @@ export function registerProviderIpc({
const timer = setTimeout(() => controller.abort(), 8000);
try {
/*
- The same request builder discovery uses, so "the list loaded" and "the
- connection test passed" can never describe two different endpoints: one
- URL rule, one auth rule, one wire style, for a real at-least-once check.
+ The same request builder and the same resolved endpoint discovery
+ uses, so "the list loaded" and "the connection test passed" can never
+ describe two different endpoints: one URL rule, one auth rule, one
+ wire style, for a real at-least-once check. The URL is probed after
+ effective-base-URL resolution (#1687) — a saved operation suffix like
+ `/messages` must not send the test to `<endpoint>/messages/models`
+ while the list on the same page loads from `<endpoint>/models`.
*/
- const probe = await probeProviderEndpoint({
+ const profile = inferEndpointProfile({
baseUrl,
+ apiStyle: normalizeApiStyle(detail.provider?.apiStyle),
+ explicitApiStyle: true,
+ });
+ const probe = await probeProviderEndpoint({
+ baseUrl: profile?.effectiveBaseUrl ?? baseUrl,
apiKey: secret.value,
apiStyle: detail.provider?.apiStyle,
- /*
- Resolved the same way the model list is resolved, so a service that
- publishes its model list in another style than it generates in (a
- subscription plan on Anthropic Messages) is tested with the
- credentials that actually answer.
- */
- discoveryStyle: inferEndpointProfile({
- baseUrl,
- apiStyle: normalizeApiStyle(detail.provider?.apiStyle),
- explicitApiStyle: true,
- })?.discoveryStyle,
+ discoveryStyle: profile?.discoveryStyle,
headers: detail.provider?.headers,
signal: controller.signal,
});
diff --git a/apps/desktop/test/provider-stepfun-plan-discovery.test.mjs b/apps/desktop/test/provider-stepfun-plan-discovery.test.mjs
index 0dc3c84aa..ee7c9db72 100644
--- a/apps/desktop/test/provider-stepfun-plan-discovery.test.mjs
+++ b/apps/desktop/test/provider-stepfun-plan-discovery.test.mjs
@@ -124,3 +124,39 @@ test("the connection test of that row uses the same credentials as its model lis
"a valid key must not be reported as rejected",
);
});
+
+test("the connection test probes the effective endpoint when a row has an operation suffix", async (t) => {
+ const row = {
+ ...stepfunPlanRow,
+ baseUrl: "https://api.stepfun.com/step_plan/v1/messages",
+ };
+ const { calls, handlers } = await handlersFor(t, row);
+
+ const result = await handlers.get(IPC.invoke.providersTest)(row.id);
+
+ assert.deepEqual(calls.map((call) => call.url), [
+ "https://api.stepfun.com/step_plan/v1/models",
+ ]);
+ assert.equal(calls[0].headers.Authorization, "Bearer sk-secret");
+ assert.equal(calls[0].headers["x-api-key"], undefined);
+ assert.deepEqual(
+ { ok: result.ok, network: result.network },
+ { ok: true, network: "ok" },
+ "a valid key must not be rejected because the operation suffix was appended",
+ );
+});
+
+test("the connection test probes the resolved effective endpoint, matching model discovery", async () => {
+ const { readMainSource } = await import("./helpers/source-contracts.mjs");
+ const source = await readMainSource("ipc/provider-ipc.ts");
+
+ // Contract (#1687): the probe's baseUrl is the profile's effectiveBaseUrl —
+ // operation suffixes like a saved `/messages` must not send the connection
+ // test to `<endpoint>/messages/models` while the model list on the same
+ // page loads from `<endpoint>/models`.
+ assert.match(
+ source,
+ /const\s+profile\s*=\s*inferEndpointProfile\(\{[\s\S]*?baseUrl,[\s\S]*?explicitApiStyle:\s*true,\s*\}\);[\s\S]*?probeProviderEndpoint\(\{[\s\S]*?baseUrl:\s*profile\?\.effectiveBaseUrl\s*\?\?\s*baseUrl,[\s\S]*?discoveryStyle:\s*profile\?\.discoveryStyle,/,
+ "the connection test must resolve the endpoint profile once and probe its effectiveBaseUrl",
+ );
+});