diff --git a/internal/gui/assets/app.css b/internal/gui/assets/app.css index 9b9f7de6a..ea3c7f15f 100644 --- a/internal/gui/assets/app.css +++ b/internal/gui/assets/app.css @@ -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; } diff --git a/internal/gui/assets/app.js b/internal/gui/assets/app.js index e7439d1cd..133c0ef3c 100644 --- a/internal/gui/assets/app.js +++ b/internal/gui/assets/app.js @@ -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); } }; diff --git a/internal/gui/tests/provider-error-copy.test.cjs b/internal/gui/tests/provider-error-copy.test.cjs new file mode 100644 index 000000000..b53be2cb3 --- /dev/null +++ b/internal/gui/tests/provider-error-copy.test.cjs @@ -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, []); + }); + } + } +}