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 <cduyzh@users.noreply.github.com>
108 lines
5.8 KiB
JavaScript
108 lines
5.8 KiB
JavaScript
// 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, []);
|
|
});
|
|
}
|
|
}
|
|
}
|