Skip to content

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

test(settings): verify legacy protocol fallback by behavior

hui4552db48b0b8ba4
diff --git a/apps/desktop/test/provider-model-config.test.mjs b/apps/desktop/test/provider-model-config.test.mjs
index c33a86796..7638f027e 100644
--- a/apps/desktop/test/provider-model-config.test.mjs
+++ b/apps/desktop/test/provider-model-config.test.mjs
@@ -8,10 +8,15 @@
* came back, and the user picks from that live list.
*/
import assert from "node:assert/strict";
+import { register } from "node:module";
import { readFile } from "node:fs/promises";
import test from "node:test";
import { loadStyles } from "./helpers/styles.mjs";
+register(new URL("./helpers/ts-import-hooks.mjs", import.meta.url));
+const { normalizeApiStyle } = await import("@pi-desktop/shared");
+const { normalizeBaseUrlInput } = await import("../src/components/settings/provider-endpoint-guidance.ts");
+
const read = (rel) => readFile(new URL(rel, import.meta.url), "utf8");
const setupSource = await read("../src/components/settings/ProviderSetupDialog.tsx");
@@ -98,7 +103,12 @@ test("custom API format is a common-path choice, named services skip it", () =>
test("editing a provider with an unknown persisted API style stays renderable", () => {
assert.match(setupSource, /normalizeApiStyle\(provider\?\.apiStyle\)/);
- assert.match(setupSource, /default:\s*return \["\/chat\/completions", "\/models"\]/);
+ const style = normalizeApiStyle("future_api_format");
+ assert.equal(style, "chat_completions");
+ assert.equal(
+ normalizeBaseUrlInput("https://relay.example/v1/chat/completions", style),
+ "https://relay.example/v1",
+ );
});
test("both credential kinds share one live list and one binding shape", () => {
diff --git a/scripts/e2e/provider-api-style.tsx b/scripts/e2e/provider-api-style.tsx
index 04854e64e..55c5df2aa 100644
--- a/scripts/e2e/provider-api-style.tsx
+++ b/scripts/e2e/provider-api-style.tsx
@@ -289,6 +289,19 @@ globalThis.providerApiStyleProbe = async () => {
assert(apiStyleTrigger()?.textContent?.includes(apiStyleLabel("chat_completions")), "named host overwrote manual format");
results.push(`${locale}:saved-protocol-wins-over-preset`);
+ const legacyUnknown = { ...fixture("future_api_format"),
+ baseUrl: "https://relay.example/v1/chat/completions" };
+ render({ provider: legacyUnknown });
+ assert(apiStyleTrigger()?.textContent?.includes(apiStyleLabel("chat_completions")),
+ "unknown stored API format did not render with the compatible fallback");
+ const beforeUnknownSave = updates.length;
+ click(control("settings.saveProvider"));
+ await until(() => updates.length === beforeUnknownSave + 1, "save legacy unknown API format");
+ assert(updates.at(-1)?.apiStyle === "chat_completions" &&
+ updates.at(-1)?.baseUrl === "https://relay.example/v1",
+ "unknown stored format did not save the normalized compatible endpoint");
+ results.push(`${locale}:unknown-stored-api-format-open-save`);
+
const codexAccount = { ...fixture("openai_codex_responses"), id: "codex-account", name: "OpenAI OAuth", vendorKey: "openai-codex", type: "native", protocol: "openai", authKind: "oauth" } satisfies ProviderPublic;
let savedCodexAccount: VendorAccountForm | undefined;
flushSync(() => root.render(<I18nextProvider i18n={i18n}><VendorAccountDialog provider={codexAccount} initialName={codexAccount.name} onClose={() => { closes++; }} onSave={(form) => { savedCodexAccount = structuredClone(form); }} saving={false} /></I18nextProvider>));