P2 of docs/subsystems/plugin-runtime.md, the third page after Sessions and Library. - routing.js and routing.css move to assets/plugins/routing/ (client.js, routing.css). Its part's html is the page's head and boxes that were index.html's <main id="view-routing">; the rest is drawn by routingPage, run at mount since it builds on app.js. It keeps itself after that as it did (its own hidden, the language, focus), so its hooks are dirty and discard, a routing group being edited, which show() and the window's close ask through magpie.call: window.routingDirty and discardRouting are gone. - plugins/routing: Essential, Requires window and gateway, in use while the user has a routing group (not Auto, not Hidden), since the page is where it is edited. The gateway routes the same with it off. - With it off, what leads to the page goes too: the nav and panel tabs and the panel's section (data-feature="routing"), the guide's Open Routing, Providers' "Make a routing group of …", the Usage list's View routing and its time as a link, the context card's Latest request. A panel left on its Routing tab shows Agents. - What other pages use of it stays on window: openRoute (context.js), kindName, swapWhy, routedWhy (Usage's Requests), newGroupWith (Providers), panelRoutingShown (the panel). - The 505 strings only Routing says move from i18n.js to plugins/routing/i18n.js (4 languages); i18n.js 17048 → 15032 lines. The plugin's own name and line stay in i18n.js: the Plugins page says them with the plugin off (TestBuiltinsTranslated). - Tests and comments that named routing.js name the new path (gateway's antigravity_rest and loop_guard, codeassist.go, usage.go, web_compress, group_member_info, assets_revalidate, font-cascade, win-fonts, three routing-*.test.cjs). builtins.test.cjs and builtins_test.go count seven built-ins and switch Routing off: its tabs go, the page shown stays. - docs: plugin-runtime.md, gui-shell.md, gateway-routing.md. Run, first on origin/main3ec45e715, then after rebasing ontoaf27b70b4(main's routing.js, css, app.js and i18n.js changes since were carried into the moved files; its new Routing words, as the rules' conditions, are in the plugin's i18n.js): - gofmt -l clean; go vet darwin, GOOS=linux -tags nogui, GOOS=windows. - go test -count=1 ./internal/gui ./internal/gateway ./internal/usage ./internal/pluginrt ./plugins/...: ok (gateway 1800s under load, -timeout 45m; gui with -skip TestMainWindowCorners, #1936). - All 193 GUI test files, 3 at a time at load ~250, Chromium and WebKit, at the Usage commit on743fcc035: 185 and 186 green. Every red run alone here and on a just-fetched origin/mainc524bc018: - the same on main: routing-model-rest (#2115), routing-wb-restricted (#1905), usage-agents-hide (11 of 16 in both, #2211), usage-fold (#2163: 12 of 14 here, 9 of 14 on main over 7 runs, the same 4px), quota-count-wrap and quota-name-translated in WebKit (#2228); - red only under load, green alone on both: routing-flood (#2215), routing-log-icons, usage-ledger (#2211), and three plugin-* files whose tree was rebased under them mid-run. - days-fit, failed-open, side-calls and burst-speed, red on main aftercf455ebd5, are fixed before this commit (#2134,d692b2548).
164 lines
9.9 KiB
JavaScript
164 lines
9.9 KiB
JavaScript
// Run with Node's test runner and Playwright on the module path; see README.md.
|
|
// A routing group made from a model is added (悠悠哥 on Discord: in a small
|
|
// window, the new group "Hy4 preview" of its one model, Hy4 preview from
|
|
// WorkBuddy, did nothing on Add). A group opened from a model — by the
|
|
// picker's or the provider editor's "Make a routing group of it", or the
|
|
// tray panel's ?newgroup= — had no fast members in its draft, so Add threw
|
|
// and posted nothing; and a hidden classifier left an empty cell in the
|
|
// editor's grid, so Levels' label sat at the right and its choices under
|
|
// the labels. Now each label is beside its field, Add posts the group, and
|
|
// what goes wrong is said where it is seen:
|
|
// a save the server refuses shows its error in the window, in sight, the
|
|
// editor stays, and Add takes another press (it stayed busy, deaf to
|
|
// clicks). In Chromium and WebKit, English and Chinese, in a
|
|
// small window and a large one.
|
|
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 MODEL = "workbuddy/hy4-preview";
|
|
|
|
function serve(lang, posts, refuse) {
|
|
const state = { agents: [], profiles: [], settings: { lang, theme: "light" } };
|
|
const groups = { groups: [], pools: [], deciders: [], models: [{ id: MODEL, name: "Hy4 preview", provider: "workbuddy", providerName: "WorkBuddy", icon: "generic" }] };
|
|
return async (r) => {
|
|
const req = r.request(), url = new URL(req.url());
|
|
const json = (data, status = 200) => r.fulfill({ status, json: data });
|
|
if (url.pathname === "/boot.js") return r.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"${lang}",theme:"light",web:true};` });
|
|
if (url.pathname === "/wails/runtime.js") return r.fulfill({ contentType: "text/javascript", body: "export const Window = {};" });
|
|
if (req.method() === "POST" && url.pathname.startsWith("/api/")) posts.push({ path: url.pathname, body: JSON.parse(req.postData() || "{}") });
|
|
if (url.pathname === "/api/state") return json(state);
|
|
if (url.pathname === "/api/plugins") return json({ plugins: [] });
|
|
if (url.pathname === "/api/usage/quotas") return json([]);
|
|
if (url.pathname === "/api/agents/cli") return json({ agents: {}, pending: false });
|
|
if (url.pathname === "/api/gateway/trace") {
|
|
if (url.searchParams.get("wait")) return new Promise(() => {});
|
|
return json({ mine: true, now: new Date().toISOString(), seq: 1, totals: { requests: 0, rerouted: 0, errors: 0 }, routes: [] });
|
|
}
|
|
if (url.pathname === "/api/gateway/history") return json({ cut: false, days: [], routes: [] });
|
|
if (url.pathname === "/api/groups/save" && refuse) return r.fulfill({ status: 400, contentType: "text/plain", body: "group hy4-preview: no such model" });
|
|
if (url.pathname === "/api/groups" || url.pathname.startsWith("/api/groups/")) return json(groups);
|
|
if (url.pathname === "/api/providers") return json({ providers: [], presets: [], excluded: [], gateway: { running: true, window: true, url: "http://127.0.0.1:3999", groups: [] } });
|
|
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 r.fulfill({ body: await fs.readFile(file), contentType });
|
|
};
|
|
}
|
|
|
|
const words = { en: { add: "Add", addModel: "Add another model" }, zh: { add: "添加", addModel: "再加一个模型" } };
|
|
|
|
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
|
for (const lang of ["en", "zh"]) {
|
|
for (const [width, height] of [[600, 420], [1000, 700]]) {
|
|
test(`${engine} ${lang} ${width}x${height}: a routing group made from a model is added`, async (t) => {
|
|
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
|
t.after(() => browser.close());
|
|
const open = async (posts, refuse) => {
|
|
const page = await (await browser.newContext({ viewport: { width, height }, reducedMotion: "reduce" })).newPage();
|
|
page.setDefaultTimeout(5000);
|
|
page.setDefaultNavigationTimeout(20000); // the page's first load, slow on a busy machine
|
|
const errors = [];
|
|
page.on("pageerror", (e) => errors.push(e.message));
|
|
await page.route("**/*", serve(lang, posts, refuse));
|
|
await page.goto(`http://magpie.test/?view=routing&newgroup=${encodeURIComponent(MODEL)}`);
|
|
const ed = page.locator("#view-routing:not([hidden]) .rt-gedit");
|
|
await ed.waitFor();
|
|
await ed.locator("input").first().fill("Hy4 preview");
|
|
// the reader wheels down until Add itself is under the pointer's
|
|
// reach, and it has settled, as the page moves for no one else
|
|
const add = ed.getByRole("button", { name: words[lang].add, exact: true });
|
|
const seen = () => add.evaluate((btn) => {
|
|
const r = btn.getBoundingClientRect(), x = r.left + r.width / 2, y = r.top + r.height / 2;
|
|
return document.elementFromPoint(x, y)?.closest("button") === btn ? { x, y } : null;
|
|
});
|
|
await page.mouse.move(width / 2, height / 2);
|
|
let at = null;
|
|
for (let i = 0; i < 60; i++) {
|
|
const now = await seen();
|
|
if (now && at && Math.abs(now.y - at.y) < 0.5) break;
|
|
at = now;
|
|
if (!now) await page.mouse.wheel(0, 120);
|
|
await page.waitForTimeout(80);
|
|
}
|
|
assert.ok(at, "the wheel reaches Add, and nothing covers it");
|
|
// Add is clicked where it is, and what is under it is checked: the
|
|
// error it answers with comes in at the foot of the page and, in a
|
|
// one column editor (under 760px), covers Add itself until the view
|
|
// is scrolled to its end. The reader wheels down to the end of the
|
|
// page here, so that the press lands whatever the error does.
|
|
const clickAdd = async () => {
|
|
for (let i = 0; i < 80; i++) {
|
|
const done = await page.evaluate(() => {
|
|
const v = document.querySelector("#view-routing");
|
|
return v.scrollTop + v.clientHeight >= v.scrollHeight - 1;
|
|
});
|
|
if (done) break;
|
|
await page.mouse.wheel(0, 120);
|
|
await page.waitForTimeout(60);
|
|
}
|
|
let now = await seen();
|
|
for (let i = 0; i < 80 && !now; i++) {
|
|
await page.mouse.wheel(0, -120);
|
|
await page.waitForTimeout(60);
|
|
now = await seen();
|
|
}
|
|
assert.ok(now, "Add is under the pointer's reach to be clicked");
|
|
await page.mouse.click(now.x, now.y);
|
|
};
|
|
return { page, ed, errors, clickAdd };
|
|
};
|
|
|
|
// Add posts the group of its one model
|
|
let posts = [];
|
|
let { page, ed, errors, clickAdd } = await open(posts, false);
|
|
// every label beside its own field, or over it where the editor is one
|
|
// column: a hidden classifier left its cell behind, and Levels' label
|
|
// sat at the right, its choices below. Under 760px the editor is one
|
|
// column on purpose (plugins/routing/routing.css), so the label is above its field
|
|
// there — beside is only what a wide window can ask for.
|
|
const oneColumn = width <= 760;
|
|
const rows = await ed.evaluate((e, oneColumn) => [...e.children].filter((c) => c.matches("label") && !c.hidden && c.offsetParent).map((l) => {
|
|
const f = l.nextElementSibling, a = l.getBoundingClientRect(), b = f.getBoundingClientRect();
|
|
const beside = a.right <= b.left + 1 && Math.abs(a.top - b.top) < 12;
|
|
const above = a.bottom <= b.top + 1 && a.left <= b.left + 1;
|
|
return { label: l.textContent, beside, above };
|
|
}), oneColumn);
|
|
assert.ok(rows.length >= 6, JSON.stringify(rows));
|
|
assert.deepEqual(rows.filter((r) => !(oneColumn ? r.above : r.beside)), [],
|
|
oneColumn ? "each label over its field, the editor in one column" : "each label beside its field");
|
|
await clickAdd();
|
|
for (let i = 0; i < 40 && !posts.some((p) => p.path === "/api/groups/save"); i++) await page.waitForTimeout(50);
|
|
const saved = posts.find((p) => p.path === "/api/groups/save")?.body;
|
|
assert.deepEqual(saved?.members, [MODEL], "the group is posted with its model");
|
|
assert.deepEqual(saved.fast, [], "no member sent fast");
|
|
assert.equal(saved.name, "Hy4 preview");
|
|
assert.deepEqual(errors, [], "nothing throws");
|
|
await page.context().close();
|
|
|
|
// refused, the error is said in sight and the editor stays
|
|
posts = [];
|
|
({ page, ed, errors, clickAdd } = await open(posts, true));
|
|
await clickAdd();
|
|
const st = page.locator("#status.err");
|
|
await st.waitFor();
|
|
assert.match(await st.textContent(), /no such model/);
|
|
const box = await st.boundingBox();
|
|
assert.ok(box && box.width > 0 && box.y >= 0 && box.y + box.height <= height + 1, `the error is in sight: ${JSON.stringify(box)}`);
|
|
assert.equal(await ed.isVisible(), true, "the editor stays open");
|
|
// and Add takes a second press, where it stayed busy and took none
|
|
const saves = () => posts.filter((p) => p.path === "/api/groups/save").length;
|
|
assert.equal(saves(), 1);
|
|
for (let i = 0; i < 40 && await ed.locator(".bar .primary.busy").count(); i++) await page.waitForTimeout(50);
|
|
await clickAdd();
|
|
for (let i = 0; i < 40 && saves() < 2; i++) await page.waitForTimeout(50);
|
|
assert.equal(saves(), 2, "a second Add is posted");
|
|
assert.deepEqual(errors, [], "nothing throws");
|
|
});
|
|
}
|
|
}
|
|
}
|