From 2c2d2a5e51b543d7f4cbdbffad282faa1c194740 Mon Sep 17 00:00:00 2001 From: yetone Date: Tue, 3 Nov 2026 09:59:24 +0800 Subject: [PATCH] gui: Test models says which key a test goes out with, when several are ticked (water5433) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit water5433 (cduyzh) on Discord asked for Test models to say which account a test uses. Their patch added "Tests use the preferred account/key by default." to the button's tooltip for every provider, in en, zh and zh-TW. Taken reworded, because it didn't say what the code does: - There is no "preferred" key and no other choice of one: TestModels (keySeeing in internal/provider/test.go) sends each model with the first ticked key that serves it, made for its endpoint first, so a key that doesn't see the model is skipped. "By default" promised a choice the editor doesn't have. - A subscription account is a provider of its own, so "account" only confused it; and with one key, or none, there is nothing to say. So the line, "Each model is tested with the first ticked key that can serve it", shows only when more than one key is ticked, in en, zh, zh-TW, ja and de (theirs had no ja or de, and zh-TW said 默認 where zh-TW says 預設; it now follows the key list's own 勾選/金鑰 words). app.js stays in the core budget without a raise: the line's comment and two comments beside it (modelTestWhy, modelTests, testOne) were cut down. Test: test-models-key-hint.test.cjs, every language, Chromium and WebKit, 900 and 390 wide: with two keys ticked the tooltip has the line, and still has it after a test run puts the title back; with one of two ticked, and with no key list, it doesn't. Run (mote-run, at this commit on origin/main 12599e9cd): - test-models-key-hint: 20/20; with status-long, model-test-one, account-models, key-plan and i18n-keys: 114/114 in both engines. - go test -tags nogui ./internal/gui: ok (TestCoreScriptBudget: core 1,533,793 of 1,533,802). - Broken by hand in Chromium: no line 0/10; the line on whatever keys are ticked red ("One on: no key to choose, no hint"). Not tried: the real app with a real multi-key provider. Co-authored-by: cduyzh --- internal/gui/assets/app.js | 16 ++- internal/gui/assets/i18n.js | 4 + .../gui/tests/test-models-key-hint.test.cjs | 107 ++++++++++++++++++ 3 files changed, 118 insertions(+), 9 deletions(-) create mode 100644 internal/gui/tests/test-models-key-hint.test.cjs diff --git a/internal/gui/assets/app.js b/internal/gui/assets/app.js index 966327aa3..be50c168a 100644 --- a/internal/gui/assets/app.js +++ b/internal/gui/assets/app.js @@ -10949,16 +10949,14 @@ function detectAPIs(p, base, use) { return box; } -// modelTestWhy: why a provider's models can't each be sent a test request -// (the server's providerJSON.modelTest), in words, or "" when they can +// modelTestWhy: why p's models can't be tested one by one (providerJSON.modelTest), or "" function modelTestWhy(p) { if (p.modelTest === "decide") return t("A classifier's models aren't sent test requests: Test under Endpoints asks Jev's endpoint for them."); if (p.modelTest === "own-api") return t("{name} is reached through its own API, which magpie translates each agent request for, so a test request can't be sent to it on its own. Ask the model from an agent to try it.", { name: p.name }); return ""; } -// modelTests: what each provider's models answered Test models, by id; a -// model still being asked is null +// modelTests: each provider's Test models answers by id, null while asked const modelTests = {}; // testsOn: a provider's tests under way, by run; Stop ends them on the server too (RIck) @@ -11797,9 +11795,10 @@ function renderModels(p) { await loadProviders(); } catch (e) { statusErr(e); refresh.classList.remove("busy"); } }; - // each model the agents see gets a tiny request of its own: a vendor - // that answers can still have a model that doesn't - const testAll = testButton(p, t("Test models"), t("Send a tiny request to each model agents see, to find the ones that don't answer") + "\n" + t("Right-click a model to test just it"), async () => { + // a tiny request to each model agents see (a vendor that answers can have one that doesn't), + // with the first ticked key that serves it (keySeeing, water5433) + const byKey = p.keyList?.filter((k) => k.on)[1] ? "\n" + t("Each model is tested with the first ticked key that can serve it") : ""; + const testAll = testButton(p, t("Test models"), t("Send a tiny request to each model agents see, to find the ones that don't answer") + byKey + "\n" + t("Right-click a model to test just it"), async () => { const ids = servedIds(p).filter((id) => p.decideTest || !decidesModel(p, id)); if (!ids.length) { status(t("Pick a model first."), "err"); return; } const got = modelTests[p.id] = {}; @@ -11813,8 +11812,7 @@ function renderModels(p) { } catch (e) { delete modelTests[p.id]; testErr(e); } draw(); }); - // one model, its dot and title as Test models leaves them, the others' - // results kept + // one model, the others' results kept const testOne = async (id, as) => { const got = modelTests[p.id] = modelTests[p.id] || {}; got[id] = null; diff --git a/internal/gui/assets/i18n.js b/internal/gui/assets/i18n.js index ffb820a79..718f5edaa 100644 --- a/internal/gui/assets/i18n.js +++ b/internal/gui/assets/i18n.js @@ -2526,6 +2526,7 @@ const I18N = { "All {n} models answered": "{n} 个模型全部可用", "Right-click to test just this model": "右键可单独测试这个模型", "Right-click a model to test just it": "右键点击某个模型可单独测试它", + "Each model is tested with the first ticked key that can serve it": "每个模型用第一个已勾选、能提供它的密钥测试", "Test this model": "测试此模型", "Test as Codex": "以 Codex 身份测试", "Test as Claude Code": "以 Claude Code 身份测试", @@ -6943,6 +6944,7 @@ const I18N = { "All {n} models answered": "{n} 個模型全部可用", "Right-click to test just this model": "右鍵可單獨測試這個模型", "Right-click a model to test just it": "右鍵點選某個模型可單獨測試它", + "Each model is tested with the first ticked key that can serve it": "每個模型用第一個已勾選、能提供它的金鑰測試", "Test this model": "測試此模型", "Test as Codex": "以 Codex 身分測試", "Test as Claude Code": "以 Claude Code 身分測試", @@ -11378,6 +11380,7 @@ const I18N = { "All {n} models answered": "{n} 個のモデルすべてが応答しました", "Right-click to test just this model": "右クリックでこのモデルだけをテスト", "Right-click a model to test just it": "モデルを右クリックするとそのモデルだけをテストできます", + "Each model is tested with the first ticked key that can serve it": "各モデルは、それを提供できる最初のチェック済みキーでテストされます", "Test this model": "このモデルをテスト", "Test as Codex": "Codex としてテスト", "Test as Claude Code": "Claude Code としてテスト", @@ -15824,6 +15827,7 @@ const I18N = { "All {n} models answered": "Alle {n} Modelle haben geantwortet", "Right-click to test just this model": "Rechtsklick, um nur dieses Modell zu testen", "Right-click a model to test just it": "Rechtsklick auf ein Modell testet nur dieses", + "Each model is tested with the first ticked key that can serve it": "Jedes Modell wird mit dem ersten angehakten Schlüssel getestet, der es bereitstellen kann", "Test this model": "Dieses Modell testen", "Test as Codex": "Als Codex testen", "Test as Claude Code": "Als Claude Code testen", diff --git a/internal/gui/tests/test-models-key-hint.test.cjs b/internal/gui/tests/test-models-key-hint.test.cjs new file mode 100644 index 000000000..ed94982a6 --- /dev/null +++ b/internal/gui/tests/test-models-key-hint.test.cjs @@ -0,0 +1,107 @@ +// Run with Node's test runner and Playwright on the module path; see README.md. +// Which key Test models goes out with (water5433 on Discord): with more +// than one key ticked, its tooltip says each model is tested with the +// first ticked key that can serve it (keySeeing in internal/provider), and +// it still says so after a test has run. With one key ticked, or none +// listed, it doesn't. In every language, Chromium and WebKit, 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 models = ["gpt-5.1", "model-b"].map((id) => ({ id, name: id, on: true })); +const base = { + icon: "generic", chat: "https://relay.example.com/v1", responses: "", anthropic: "", catalog: "", + models, agents: [], fallback: [], headers: {}, key: { set: true, masked: "sk-…one" }, + balanceToken: { takes: false, set: false }, proxy: "", +}; +const keys = (second) => [ + { id: "aaaaaaaaa1", name: "Personal", masked: "sk-…a1", on: true, active: true }, + { id: "aaaaaaaaa2", name: "Team", masked: "sk-…a2", on: second }, +]; +const providers = [ + { ...base, id: "two", name: "Two keys", keyList: keys(true) }, + { ...base, id: "oneon", name: "One on", keyList: keys(false) }, + { ...base, id: "single", name: "Single", keyList: [] }, +]; + +function serve(lang) { + const list = { providers, presets: [], excluded: [], gateway: { running: true, window: true } }; + 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(list); + if (url.pathname === "/api/groups") return json({ groups: [] }); + if (url.pathname === "/api/plugins") return json({ plugins: [] }); + if (url.pathname === "/api/provider/test") { + const body = route.request().postDataJSON(); + return json({ results: (body.test || []).map((model) => ({ ok: true, ms: 120, model })) }); + } + 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 }); + }; +} + +// the hint and the button, as each language words them +const words = { + en: ["Test models", "Each model is tested with the first ticked key that can serve it"], + zh: ["测试模型", "每个模型用第一个已勾选、能提供它的密钥测试"], + "zh-TW": ["測試模型", "每個模型用第一個已勾選、能提供它的金鑰測試"], + ja: [null, "各モデルは、それを提供できる最初のチェック済みキーでテストされます"], + de: [null, "Jedes Modell wird mit dem ersten angehakten Schlüssel getestet, der es bereitstellen kann"], +}; + +for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) { + for (const [lang, [label, hint]] of Object.entries(words)) { + for (const width of [900, 390]) { + test(`${engine} ${lang} ${width}: Test models says which key a test goes out with`, async (t) => { + const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" })); + const page = await (await browser.newContext({ viewport: { width, height: 760 }, reducedMotion: "reduce" })).newPage(); + t.after(async () => { + if (process.env.ARTIFACT_DIR) { + await fs.mkdir(process.env.ARTIFACT_DIR, { recursive: true }); + await page.screenshot({ path: path.join(process.env.ARTIFACT_DIR, `${engine}-${lang}-${width}-test-models-key-hint.png`) }); + } + await browser.close(); + }); + page.setDefaultTimeout(5000); + page.setDefaultNavigationTimeout(60000); + const errors = []; + page.on("pageerror", (e) => errors.push(e.message)); + await page.route("**/*", serve(lang)); + let name = label; + const tip = async (row) => { + // each editor opened from a fresh list + await page.goto("http://magpie.test/?view=providers"); + name ||= await page.evaluate(() => t("Test models")); + await page.locator(".row.provider", { hasText: row }).first().click(); + await page.locator(".editor .mchips .mchip").first().waitFor(); + const b = page.locator(".editor .mfoot").getByRole("button", { name, exact: true }); + return { b, title: await b.getAttribute("title") }; + }; + + const two = await tip("Two keys"); + assert(two.title.includes(hint), `two keys ticked: the tooltip names the key (${two.title})`); + // a test's end puts the tooltip back whole + await two.b.click(); + await page.waitForFunction((n) => [...document.querySelectorAll(".editor .mfoot button")].some((b) => b.textContent === n && b.title), name); + assert((await two.b.getAttribute("title")).includes(hint), "still said after a test"); + + for (const row of ["One on", "Single"]) { + const { title } = await tip(row); + assert(title && !title.includes(hint), `${row}: no key to choose, no hint (${title})`); + } + assert.deepEqual(errors, []); + }); + } + } +}