Skip to content

Every agent's model. One place. Codex on DeepSeek, Claude Code on Kimi, from the menu bar.

gui: a gateway key list that can't be read keeps saying so in its card, and one read before stays

yetonec9c28aa58670
diff --git a/internal/gui/assets/plugins/gateway/keys.js b/internal/gui/assets/plugins/gateway/keys.js
index d34756b78..f3f22542b 100644
--- a/internal/gui/assets/plugins/gateway/keys.js
+++ b/internal/gui/assets/plugins/gateway/keys.js
@@ -7,6 +7,9 @@ let gatewayOwnDraft = "";
// #905) to how it is shown; what no provider has now is shown as it is kept
let gatewayAccountNames = {};
let gatewayKeysRead = 0;
+// gatewayKeysErr is why the list couldn't be read, said in its place until
+// a read works: a redraw of the page (the providers' poll) keeps it
+let gatewayKeysErr = "";
// gatewayLimit is the key whose limit editor is open, and its draft
// (#585): what is picked in it is sent only by its Save.
let gatewayLimit = null;
@@ -59,11 +62,15 @@ async function loadGatewayKeys() {
// A fresh list also refreshes a selected credential, which may have rotated.
connectSecret = null;
gatewayKeys = out.keys || [];
+ gatewayKeysErr = "";
renderGatewayKeys();
if (view === "gateway" && providers) selectConnectKey(connectKeyID);
} catch (e) {
if (read !== gatewayKeysRead) return;
- $("#gatewayKeys").replaceChildren(el("div", "none", t(e.message)));
+ // a list read before stays: only one never read is said unreadable
+ if (gatewayKeys !== null) return status(t(e.message), "err");
+ gatewayKeysErr = e.message;
+ renderGatewayKeys();
}
}
@@ -167,8 +174,11 @@ function renderGatewayKeys() {
$("#gatewayKeysBlock").hidden = !providers?.gateway.lan;
box.replaceChildren();
$("#addGatewayKey").onclick = () => { gatewayKeyDraft = ""; renderGatewayKeys(); };
- if (gatewayKeys === null) return;
const list = el("div", "accts");
+ if (gatewayKeys === null) {
+ if (gatewayKeysErr) list.append(el("div", "none", t(gatewayKeysErr))), box.append(list);
+ return;
+ }
for (const k of gatewayKeys) {
const row = el("div", "acc" + (k.off ? " off" : " in-use"));
row.dataset.key = k.id;
diff --git a/internal/gui/tests/README.md b/internal/gui/tests/README.md
index 7a3d4b14f..edbd40f2d 100644
--- a/internal/gui/tests/README.md
+++ b/internal/gui/tests/README.md
@@ -45,7 +45,9 @@ a live gateway.
yet, as magpie web on a 390px phone: "No gateway keys yet" sits inside the
list's card, inset from its edges, in the muted colour and size of Recent
calls' empty line, in Chromium and WebKit, light and dark, and every
-language.
+language. A list that can't be read says why in the same card, still there
+after the page is drawn again; a list read before stays when a later read
+fails, and the error goes to the status line.
`gateway-caller-keys.test.cjs` checks the named caller-key list on the
Gateway page, including creation, copying, renaming, disabling, enabling,
diff --git a/internal/gui/tests/fixtures/caller-keys.cjs b/internal/gui/tests/fixtures/caller-keys.cjs
index 64d349f7b..66f34ff1c 100644
--- a/internal/gui/tests/fixtures/caller-keys.cjs
+++ b/internal/gui/tests/fixtures/caller-keys.cjs
@@ -90,6 +90,8 @@ function fixture(lang, theme, events, options = {}) {
}
return json(lanState());
}
+ // options.keysError: the list can't be read
+ if (url.pathname === "/api/caller-keys" && options.keysError) return route.fulfill({ status: 500, json: { error: options.keysError } });
if (url.pathname === "/api/caller-keys") return json({ keys });
if (url.pathname === "/api/caller-keys/models") return json({ models: [
...(options.groups ? [
diff --git a/internal/gui/tests/gateway-keys-empty.test.cjs b/internal/gui/tests/gateway-keys-empty.test.cjs
index d9474a4ff..a1163fb76 100644
--- a/internal/gui/tests/gateway-keys-empty.test.cjs
+++ b/internal/gui/tests/gateway-keys-empty.test.cjs
@@ -6,7 +6,8 @@ const { fixture } = require("./fixtures/caller-keys.cjs");
// No gateway key yet (HarriesChen on Discord, 10-25): magpie web on a phone
// drew "No gateway keys yet" in the body's text, 14px and dark, flush
// against its card's edges. It is said in its card the way the same page's
-// Recent calls says it has none: muted, small, inset.
+// Recent calls says it has none: muted, small, inset. So is a list that
+// can't be read, and the page's next redraw keeps saying so.
const NONE = { en: "No gateway keys yet", zh: "尚无网关密钥", "zh-TW": "尚無閘道金鑰", ja: "ゲートウェイキーはまだありません", de: "Noch keine Zugangsschlüssel" };
const look = (page) => page.evaluate(() => {
@@ -54,4 +55,38 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
});
}
}
+
+ test(`${engine}: a gateway key list that can't be read says so in its card, past a redraw`, async (t) => {
+ const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
+ t.after(() => browser.close());
+ const page = await (await browser.newContext({ viewport: { width: 390, height: 844 }, reducedMotion: "reduce" })).newPage();
+ page.setDefaultTimeout(6000);
+ await page.route("**/*", fixture("en", "light", [], { lan: true, web: true, keysError: "gateway keys unreadable" }));
+ await page.goto("http://magpie.test/?view=gateway");
+ await page.locator("#gatewayKeys .none").waitFor();
+ await page.locator("#activity .none").waitFor();
+ // the page drawn again, as the providers' poll does
+ await page.evaluate(() => renderGatewayView());
+ const s = await look(page);
+ assert.equal(s.inCard, true, "said where the list goes, in its card");
+ assert.equal(s.text, "gateway keys unreadable");
+ assert.equal(s.color, s.refColor);
+ assert.equal(s.size, s.refSize);
+ assert(s.inset >= 10, `inset from the card's edges, got ${s.inset}px`);
+ });
+
+ test(`${engine}: a gateway key list read before stays when a later read fails`, async (t) => {
+ const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
+ t.after(() => browser.close());
+ const page = await (await browser.newContext({ viewport: { width: 390, height: 844 }, reducedMotion: "reduce" })).newPage();
+ page.setDefaultTimeout(6000);
+ await page.route("**/*", fixture("en", "light", [], { lan: true, web: true }));
+ await page.goto("http://magpie.test/?view=gateway");
+ await page.locator("#gatewayKeys .acc[data-key]").nth(2).waitFor();
+ await page.route("**/api/caller-keys", (route) => route.fulfill({ status: 500, json: { error: "gateway keys unreadable" } }));
+ await page.evaluate(() => loadGatewayKeys());
+ await page.waitForFunction(() => document.body.textContent.includes("gateway keys unreadable"));
+ assert.equal(await page.locator("#gatewayKeys .acc[data-key]").count(), 3, "the keys read before stay");
+ assert.equal(await page.locator("#gatewayKeys .none").count(), 0);
+ });
}