gui: a failed endpoint test's error can be selected and copied (imwritingbugs on X)

The provider editor's endpoint Test result (.res.bad) was ellipsized under
body's user-select: none, so a vendor's error could not be picked up to hand
to an agent. The selectable :where() list in app.css now takes the error and
warning classes (.bad, .warn, .warnbox, *-warn, *-bad, *-fail, .res,
.bal-res), so those texts select; controls keep none. A failed endpoint row
and a failed Detect APIs row get the small copyBtn other values have; a
passing row has none, and a new Test clears the old button.

Run (mote): provider-error-copy.test.cjs, 16 of 16 green in chromium and
webkit, en/zh/ja/de, 1000 and 420 px; 16 of 16 red with app.js and app.css
at the merge-base. go test ./internal/gui ok; gofmt -l clean;
GOOS=linux go vet -tags nogui and GOOS=windows go vet of internal/gui ok.
GUI files the change reaches (provider*, i18n*, model-test*, *select*,
*copy*, balance*): 70 fail, and the same 10 files fail with the same counts
with app.js and app.css at the merge-base (group-editor-selected 2,
model-copy-id 4, provider-fetch-again 14, provider-many-keys 6,
provider-max-output 20, provider-models-rest 4, provider-picks-stay 4,
provider-proxy 4, provider-remove 4, provider-typed 4), so they are on main
already; filed separately.
Not run: the whole GUI suite and the full Go suite (both Macs were busy with
other sessions' full suites). Not tried: the reporter's screenshot was never
seen; the endpoint Test result is the likeliest error they meant. Siblings
are covered through the class list, not each page.
This commit is contained in:
yetone
2026-11-20 01:23:51 +08:00
parent f534245f1c
commit 99cc8fa5d5
3 changed files with 85 additions and 2 deletions
+1 -1
View File
@@ -164,7 +164,7 @@ body {
specificity, so a view's own rule (a list being sorted, a blurred value)
still decides; a field typed into stays a field. An account's or a key's
name is text, though a click renames it (`.acc .rename`). */
:where(p, pre, code, kbd, samp, dd, td, .hint, .note, .why, .err, .error, [class*="-err "], [class$="-err"], [class*="-error"], .empty-state, .sess-talk, .rt-log, .rt-steps, .rt-time) { user-select: text; -webkit-user-select: text; }
:where(p, pre, code, kbd, samp, dd, td, .hint, .note, .why, .err, .error, [class*="-err "], [class$="-err"], [class*="-error"], .bad, .warn, .warnbox, [class*="-warn"], [class*="-bad"], [class*="-fail"], .res, .bal-res, .empty-state, .sess-talk, .rt-log, .rt-steps, .rt-time) { user-select: text; -webkit-user-select: text; }
:where(button, label, summary, select, nav, menu, [role="tab"], [role="menu"], [role="menuitem"], [role="option"], [role="switch"], [draggable="true"], .pop, .seg, .opt, .grip),
:where(button, label, summary, select, nav, menu, [role="tab"], [role="menu"], [role="menuitem"], [role="option"], [role="switch"], [draggable="true"], .pop, .seg, .opt, .grip) * { user-select: none; -webkit-user-select: none; }
:where(input, textarea, [contenteditable="true"], [contenteditable=""]) { user-select: text; -webkit-user-select: text; }
+6 -1
View File
@@ -11123,7 +11123,7 @@ function renderEndpoints(p, src) {
}
if (p) {
const test = testButton(p, t("Test"), t("Send a tiny request through each endpoint"), async () => {
for (const s of Object.values(slots)) { s.className = "res wait"; s.textContent = "…"; }
for (const s of Object.values(slots)) { s.className = "res wait"; s.textContent = "…"; if (s.nextElementSibling?.classList.contains("copy")) s.nextElementSibling.remove(); }
try {
const r = await provTest(p.id, asTyped());
for (const x of r.results) {
@@ -11135,6 +11135,10 @@ function renderEndpoints(p, src) {
const result = x.ok ? ledTook(x.ms) : x.status ? `${x.status} · ${x.error}` : x.error;
s.append(el("span", "", x.account ? t("Tested {user}: {result}", { user: x.account, result }) : result));
s.title = x.ok ? t("model {model}", { model: x.model }) : x.error;
// a failed test's words can be copied whole, to hand to an agent
// (imwritingbugs on X)
s.nextElementSibling?.classList.contains("copy") && s.nextElementSibling.remove();
if (!x.ok) s.after(copyBtn(x.status ? `${x.status} · ${x.error}` : x.error, t("Error")));
}
} catch (e) { for (const s of Object.values(slots)) { s.className = "res"; s.textContent = ""; } testErr(e); }
});
@@ -11261,6 +11265,7 @@ function detectAPIs(p, base, use) {
res.append(el("span", "", x.ok ? ledTook(x.ms) : why));
res.title = (x.model ? t("model {model}", { model: x.model }) : "") + (x.ok ? "" : "\n" + why);
e.append(pl, el("code", "", x.base || "—"), res);
if (!x.ok) e.append(copyBtn(why, t("Error")));
out.append(e);
}
};
@@ -0,0 +1,78 @@
// Run with Node's test runner and Playwright on the module path; see README.md.
// A provider's endpoint test that fails says why under its settings, and the
// words can be selected and copied, to hand to an agent or send in a report
// (imwritingbugs on X: 建议供应商设置这里的报错信息可以复制). The failed
// row has the small copy button other values have; a passing one has none.
// Its controls stay controls. In both engines, every language, wide and narrow.
const assert = require("node:assert/strict");
const fs = require("node:fs/promises");
const path = require("node:path");
const { test } = require("node:test");
const { chromium, webkit } = require("playwright");
const assets = path.resolve(__dirname, "../assets");
const why = "model_not_found: The model `claude-opus-9` does not exist or you do not have access to it";
const provider = {
icon: "generic", id: "relay", preset: "relay", name: "Relay", chat: "https://relay.example/v1", responses: "", anthropic: "https://relay.example", catalog: "",
agents: [], fallback: [], headers: {}, keyList: [], balanceToken: { takes: false, set: false }, proxy: "", key: { set: true, masked: "sk-…one" },
models: [{ id: "claude-opus-9", name: "", on: true }],
};
function serve(lang, copied) {
const state = { agents: [], profiles: [], settings: { lang, theme: "light" } };
return async (route) => {
const url = new URL(route.request().url());
const json = (data) => route.fulfill({ json: data });
if (url.pathname === "/boot.js") return route.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"${lang}",theme:"light",web:true};` });
if (url.pathname === "/wails/runtime.js") return route.fulfill({ contentType: "text/javascript", body: "export const Window = {};" });
if (url.pathname === "/api/state") return json(state);
if (url.pathname === "/api/providers") return json({ providers: [provider], presets: [{ id: "relay", name: "Relay", icon: "generic", chat: provider.chat, added: true }], excluded: [], gateway: { running: true, window: true } });
if (url.pathname === "/api/groups") return json({ groups: [] });
if (url.pathname === "/api/plugins") return json({ plugins: [] });
if (url.pathname === "/api/provider/test") {
return json({ results: [{ protocol: "chat", ok: false, status: 404, error: why }, { protocol: "anthropic", ok: true, ms: 120, model: "claude-opus-9" }] });
}
if (url.pathname === "/api/copy") { copied.push(route.request().postDataJSON().text); return json({ ok: true }); }
if (url.pathname.startsWith("/api/")) return json({});
const file = path.join(assets, url.pathname === "/" ? "index.html" : url.pathname);
const contentType = { ".html": "text/html", ".js": "text/javascript", ".css": "text/css", ".svg": "image/svg+xml", ".png": "image/png" }[path.extname(file)];
await route.fulfill({ body: await fs.readFile(file), contentType });
};
}
const selectOf = (loc) => loc.evaluate((e) => { const s = getComputedStyle(e); return s.userSelect || s.webkitUserSelect; });
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
for (const lang of ["en", "zh", "ja", "de"]) {
for (const width of [1000, 420]) {
test(`${engine} ${lang} ${width}: a failed endpoint test can be selected and copied`, async (t) => {
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
const page = await (await browser.newContext({ viewport: { width, height: 800 }, reducedMotion: "reduce" })).newPage();
t.after(() => browser.close());
page.setDefaultTimeout(5000);
page.setDefaultNavigationTimeout(60000);
const errors = [], copied = [];
page.on("pageerror", (e) => errors.push(e.message));
await page.route("**/*", serve(lang, copied));
await page.goto("http://magpie.test/?view=providers");
await page.locator(".row.provider", { hasText: "Relay" }).first().click();
await page.locator(".editor .mchips .mchip").first().waitFor();
await page.locator(".editor .eps:not(.detect-out) .ep").first().waitFor();
await page.waitForTimeout(300);
await page.locator(".editor .eps button[data-tests]").click();
const bad = page.locator(".editor .eps:not(.detect-out) .ep .res.bad span");
await bad.waitFor();
assert.equal(await selectOf(bad), "text");
assert.equal(await bad.textContent(), "404 · " + why);
// the copy button is on the failed row alone, and a control
assert.equal(await page.locator(".editor .eps:not(.detect-out) .ep .copy").count(), 1);
const cp = page.locator(".editor .eps:not(.detect-out) .ep .copy");
assert.equal(await selectOf(cp), "none");
await cp.click();
await page.waitForFunction(() => document.querySelector(".editor .eps:not(.detect-out) .ep .copy.done"));
assert.deepEqual(copied, ["404 · " + why]);
assert.deepEqual(errors, []);
});
}
}
}