gui: a gateway key list that can't be read keeps saying so in its card, and one read before stays
Found beside HarriesChen's report: when /api/caller-keys failed,
loadGatewayKeys put the error straight into #gatewayKeys, and the page's
next redraw (renderGatewayKeys from renderGatewayView, the providers'
poll) wiped it, since it returns early while no list was read. A failed
re-read also replaced a list already shown with the error.
gatewayKeysErr now holds why a never-read list failed, and
renderGatewayKeys says it in the list's card (styled like the empty line
by the previous commit). A list read before stays, and the error goes to
the status line. A read that works clears it.
Run:
- gateway-keys-empty.test.cjs: the unreadable case (past a
renderGatewayView redraw) and the read-before case, both engines: green;
with keys.js from main both red (".none" never visible; the 3 keys gone).
All 22+2 of the file green with the change.
- The whole GUI suite was still running at push time (see the previous
commit); not in this record.
Not tried: a real failing gateway (only the fixture's 500).
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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,
|
||||
|
||||
+2
@@ -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 ? [
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user