nav-timeout.test.cjs was red on main since #5425 was filed (11-06),
first for four files and now for 24: each new GUI test copied
page.setDefaultTimeout(5000) without a navigation timeout, and nothing
caught it because CI runs no GUI file. Each short default now sits
beside page.setDefaultNavigationTimeout(60000); clicks and waits keep
their 5s/6s/8s/30s bar. skygunner's 10275d5a6 did the same for the nine
files listed on 11-08, and was never taken; this covers those and the 15
added since.
The class: nav-timeout, i18n-keys and i18n-en-no-cjk read the sources
and need no browser, and LESSONS.md records each of them red on main
after a push that ran chosen GUI files. test.yml's Linux cli job, which
already sets up Node 22, now runs them, so the push that adds the next
offender goes red on CI.
Run (mica; mote was at load 26):
- node --test nav-timeout, i18n-keys, i18n-en-no-cjk at this tree on
origin/main b2b3d488c: 9/9 ok.
- usage-drag, form-align, accounts-switch-alone (changed files, both
engines, every language): 34/34 ok.
- Broken by hand: origin/main's usage-drag copied in beside the fix,
nav-timeout red, naming it.
Not run: the other 21 changed files in a browser (one added line each)
and the whole GUI suite; both machines were running other sessions'
GUI runs.
Co-authored-by: vincent <webmaster@palmit.com.au>
84 lines
5.3 KiB
JavaScript
84 lines
5.3 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);
|
|
page.setDefaultNavigationTimeout(60000);
|
|
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();
|
|
});
|
|
}
|
|
});
|
|
}
|