The add sheet drew "+ Custom provider" only under every preset section (vendors, relays, local, remote), and only while the search was empty, so it was hard to find. It is now a text button in the sheet's head, right after "Find a vendor…", there as the sheet opens and kept while searching; its old hint is its title. A search that finds nothing still offers "Add it as a custom provider" in its line. Below 760px the head wraps: the title, Import… and Close on the first line, the search and Custom provider on a line of their own, so no language clips them. The foot line and its styles are gone; app.js is 248 bytes smaller. Run (WSL magpie-desktop, Playwright 1.62.0, Chromium + WebKit): - add-sheet-custom.test.cjs (new): en, zh, zh-TW, ja, de at 980, 761 and 420px, 32/32 pass. Against origin/main's assets (MAGPIE_ASSETS) 0/32: no button in the head. - add-sheet, provider-detect-draft, provider-add-gemini, model-id-space, provider-curl-paste, system-one, provider-add-models, provider-url-each-api, provider-retrieval-only, i18n-keys (selectors moved from .custom-foot to .row-head) pass, but for reds that are red the same at origin/mainb46f23ffain the same run (below). - 72 GUI files that reach the add sheet, concurrency 3: the reds are the same files as origin/mainb46f23ffarun alone: vertex-editor (#4720, #4721), tencent-cloud (#4321, #4399), remote-magpie (#4398), plugin-moved-signin (#2900, #4218), plugin-signin-no-url (#5938, filed now), plugin-pick-sub webkit ja 420 (#5937, filed now), plus page.goto timeouts under the run's load (load ~70). - plugins-more-discover, zcode-site-layout, provider-retrieval-only, twice each at this change and atb46f23ffa: here 43/43 then 39/43, there 41/43 twice; webkit "More in Plugins opens Discover" (#5559) and "ZCode's site step" (#4727) are red on both. - At9c39edb92+ this: add-sheet-custom, add-sheet, i18n-keys 42/42. Rebased onto4eeee5215(no add-sheet code); TestCoreScriptBudget ok there. - TestCoreScriptBudget (Windows box): ok. Not tried: macOS WebKit and the real app (mote refused SSH all session); the tray panel's narrow sheet in the real app.
83 lines
5.2 KiB
JavaScript
83 lines
5.2 KiB
JavaScript
// Run with Node's test runner and Playwright on the module path; see README.md.
|
|
// A vendor that lists only embedding and rerank models (heatonz on Discord,
|
|
// 11-05): there is nothing for an agent to chat with, and nothing to pick,
|
|
// as they are served on /v1/embeddings and /v1/rerank as listed. The add
|
|
// form's Fetch models, and a saved provider's editor, say so rather than
|
|
// that the list is empty; a list that is empty still says it is. Every
|
|
// language; no backend, the API is faked here.
|
|
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 { I18N } = require("./strings.cjs").strings();
|
|
const ONLY = "Only embedding and rerank models are listed. They need no pick: ask them on /v1/embeddings and /v1/rerank.";
|
|
const ADD_EMPTY = "The vendor's list is empty. Type the model ids instead.";
|
|
const SAVED_EMPTY = "The vendor's list is empty. Fetch models again, or type a model id.";
|
|
const say = (lang, k) => lang === "en" ? k : I18N[lang][k];
|
|
|
|
const relay = (retrieval) => ({ id: "relay", name: "Embed Relay", icon: "openai", models: [], agents: [], key: { set: true, masked: "sk-…ab12" }, chat: "http://embed.test/v1", ...(retrieval ? { retrieval } : {}) });
|
|
|
|
function server(lang, list, retrieval) {
|
|
const providers = { providers: list, presets: [], excluded: [], gateway: { running: true, window: true } };
|
|
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:${JSON.stringify(lang)},theme:"light",web:false};` });
|
|
if (url.pathname === "/wails/runtime.js") return route.fulfill({ contentType: "text/javascript", body: "export const Window = {};" });
|
|
if (url.pathname === "/api/state") return json({ agents: [], profiles: [], settings: { lang, theme: "light" } });
|
|
if (url.pathname === "/api/providers") return json(providers);
|
|
if (url.pathname === "/api/groups") return json({ groups: [], pools: [] });
|
|
if (url.pathname === "/api/provider/list") return json({ models: [], ...(retrieval ? { retrieval } : {}) });
|
|
if (url.pathname.startsWith("/api/")) return json({});
|
|
const file = path.join(assets, url.pathname === "/" ? "index.html" : url.pathname);
|
|
try { await route.fulfill({ body: await fs.readFile(file), contentType: { ".html": "text/html", ".js": "text/javascript", ".css": "text/css", ".svg": "image/svg+xml", ".png": "image/png" }[path.extname(file)] }); } catch { await route.fulfill({ status: 404, body: "" }); }
|
|
};
|
|
}
|
|
|
|
test("each language says it", () => {
|
|
for (const lang of ["zh", "zh-TW", "ja", "de"]) assert(I18N[lang][ONLY], lang);
|
|
});
|
|
|
|
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
|
test(engine + ": a list of embedding and rerank models alone", async (t) => {
|
|
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: process.env.PLAYWRIGHT_CHANNEL || "chromium" }));
|
|
t.after(() => browser.close());
|
|
for (const lang of ["en", "zh", "zh-TW", "ja", "de"]) for (const retrieval of [2, 0]) {
|
|
await t.test(`${lang}, ${retrieval} retrieval`, async () => {
|
|
const page = await (await browser.newContext({ viewport: { width: 900, height: 760 }, reducedMotion: "reduce" })).newPage();
|
|
page.setDefaultTimeout(5000);
|
|
const errors = [];
|
|
page.on("pageerror", (e) => errors.push(e.message));
|
|
await page.route("**/*", server(lang, [relay(retrieval)], retrieval));
|
|
await page.goto("http://magpie.test/?view=providers");
|
|
|
|
// the add form's Fetch models
|
|
await page.locator("#addProvider").click();
|
|
await page.locator("#addSheet .row-head .custom").click();
|
|
const ed = page.locator(".editor.new");
|
|
await ed.locator(".add-models").waitFor();
|
|
await ed.locator('input[type="url"][placeholder="https://…/v1"]').first().fill("http://embed.test/v1");
|
|
await ed.locator(".add-models .detect-row button").click();
|
|
// past "Asking the vendor…", the one hint the answer leaves
|
|
const hint = ed.locator(".add-models-list .hint");
|
|
await page.waitForFunction(() => !/…$/.test(document.querySelector(".editor.new .add-models-list .hint")?.textContent ?? "…"));
|
|
assert.deepEqual(await hint.allTextContents(), [say(lang, retrieval ? ONLY : ADD_EMPTY)]);
|
|
|
|
// the saved provider's editor
|
|
await page.goto("http://magpie.test/?view=providers");
|
|
await page.locator(".row.provider", { hasText: "Embed Relay" }).first().click();
|
|
await page.locator(".editor .ehead b", { hasText: "Embed Relay" }).waitFor();
|
|
const all = await page.locator(".editor .hint").allTextContents();
|
|
const want = say(lang, retrieval ? ONLY : SAVED_EMPTY), not = say(lang, retrieval ? SAVED_EMPTY : ONLY);
|
|
assert(all.includes(want), `no ${JSON.stringify(want)} among ${JSON.stringify(all)}`);
|
|
assert(!all.includes(not), "also " + not);
|
|
assert.deepEqual(errors, []);
|
|
await page.context().close();
|
|
});
|
|
}
|
|
});
|
|
}
|