In WebKit (the macOS app's WKWebView, and Playwright's WebKit) the Routing page stopped well short of its bottom (wizzy-yang on #1213). Each time the page was drawn again while it was scrolled near its end, WebKit cut its scrollTop back to a shorter range. The page has query containers in it (.rt, .rt-accts, .rt-more, .rt-col), and the cut happens during a redraw. Seen at 440x620: 575 of 585, and up to a whole screen short when a part was redrawn. Chromium is unaffected. With container-type set to normal on those boxes the page reaches its end, and the cut goes away. Replacing a container with its clone at the end reproduces it in WKWebView too. Each box's width now sets a class, the same way container queries would have chosen a layout: - routing.js sets the classes from a ResizeObserver: max560 on .rt and .rt-accts, max460 on .rt-accts, max520/min1150 on .rt-more, and max440/max760 on each .rt-col. - context.js does the same for each .ctx-card: max520 and max420. - A rule that names the box goes through :where(), so it keeps the specificity it had inside its query. - The class is set on the next frame, as quotaFit does: set in the observer's own call, it changes the box's height, and WebKit reports that as a ResizeObserver loop. - A redrawn ctx-card starts with the width the last card in its place had (routing or session). It doesn't lay out wide for a frame and then narrow, which would itself pull the page up. - The Safari 15 @supports fallbacks are dropped. They chose a layout by the window's width, and ResizeObserver covers that Safari. Sibling: Usage → Context, with a session open, has the same bug. Each timed read redraws the card, and WebKit pulled the page up by up to 946px at 420 wide (682px at 1100). It is fixed the same way. The other query containers were checked at their end with a synthetic redraw and were not affected: Library's .lib-row.with-agents and Agents' .row.agent .who. Sessions (.sess-pane) also jumps in WebKit as it refreshes, but it still does with its container removed, so the cause is something else. It is left alone here. Run: - routing-scroll-end.test.cjs (new): 440x620, 600x700, 900x500, 1200x600 and 1400x700, en and zh, Chromium and WebKit, with the trace redrawing the page. It also checks the stage, request and column layouts. On the old CSS all 10 WebKit cases fail (twice); with the fix it passes 22/22 (four runs). - context-scroll-end.test.cjs (new): 420, 700 and 1100 wide, en and zh, across a timed read. On the old CSS the WebKit cases fail ("958 of 1891"…); with the fix it passes 14/14. - Layout compared with the old CSS: every element's rect on the Routing page (group editor closed and open) and in the Context card. Widths 360–1700, en/zh/zh-TW/ja/de, Chromium and WebKit: 220 + 100 configurations, none differ, and there are no page errors. - The macOS WKWebView: a part redrawn at the end left the page 200–238px short before the fix and 0 after, at 440 and 1100. - gui-ja, gui-de, gui-zh-tw and i18n-keys pass. - Full GUI suite (concurrency 4): 3719/3733. - Pass alone: azure-endpoint, remote-magpie, signin-again and routing-sessions. - mobile-web compares with origin/main, which had moved on; against this commit's parent it passes. - panel-arrange fails the same way on the parent. - context-window's chromium 1100px hover flakes under load on the parent too: 5 of 16 parallel runs, against 1 of 16 here. - go test ./internal/gui; GOOS=linux and GOOS=windows go vet ./internal/gui. Not run: the reporter's own machine, or an old Safari 15 WebKit.
100 lines
6.2 KiB
JavaScript
100 lines
6.2 KiB
JavaScript
// Run with Node's test runner and Playwright on the module path; see README.md.
|
|
// The Routing page scrolls to its end (#1249, wizzy-yang on #1213): in
|
|
// WebKit the page stopped well short of its bottom, a frame after each
|
|
// scroll pulled back by the container queries its narrow and wide layouts
|
|
// went by. Wheeled down to the end, at a phone's width, the tray's, and a
|
|
// desk's, the view's scrollTop reaches its scroll range, in Chromium and
|
|
// WebKit, in English and Chinese — and the narrow and wide layouts still
|
|
// follow each box's own width.
|
|
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 now = new Date();
|
|
const day = [now.getFullYear(), now.getMonth() + 1, now.getDate()].map((n) => String(n).padStart(2, "0")).join("-");
|
|
const at = (i) => new Date(now.getTime() - (i + 1) * 60e3).toISOString();
|
|
const who = { id: "fixture-key", provider: "fixture", name: "Fixture", who: "key-1", kind: "key", model: "model-a", routing: "", used: 0 };
|
|
const routes = Array.from({ length: 12 }, (_, i) => ({ id: 100 - i, seq: 100 - i, time: at(i), agent: "fixture", model: "model-a", provider: "fixture", order: [who],
|
|
tries: [{ id: who.id, model: "model-a", start: at(i), done: true, status: 200, ms: 1200 }], done: true, status: 200, ms: 1200, tokens: 3000 }));
|
|
const agents = Array.from({ length: 14 }, (_, i) => ({ id: "a" + i, name: "Agent " + i, path: "/t/a" + i + ".json", icon: "generic", wired: true,
|
|
fields: [{ key: "model", label: "model", value: "m", options: [{ value: "m", label: "M", ref: "a/m" }] }] }));
|
|
|
|
function serve(lang) {
|
|
return async (r) => {
|
|
const url = new URL(r.request().url());
|
|
const json = (data) => r.fulfill({ 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 (url.pathname === "/api/state") return json({ agents, profiles: [], settings: { lang, theme: "light" } });
|
|
if (url.pathname === "/api/gateway/trace") {
|
|
// the trace asked again: the page is redrawn with each answer
|
|
if (url.searchParams.get("wait")) await new Promise((ok) => setTimeout(ok, 100));
|
|
return json({ mine: true, now: now.toISOString(), seq: 1, totals: { requests: routes.length, rerouted: 0, errors: 0 }, routes });
|
|
}
|
|
if (url.pathname === "/api/gateway/history") return json({ cut: false, days: [{ day, requests: routes.length }], routes: url.searchParams.get("day") ? routes : [] });
|
|
if (url.pathname === "/api/groups") return json({ groups: [] });
|
|
if (url.pathname === "/api/providers") return json({ providers: [], gateway: { running: true, window: true } });
|
|
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 });
|
|
};
|
|
}
|
|
|
|
// the number of columns a grid lays out
|
|
const tracks = (page, sel) => page.locator(sel).first().evaluate((e) => getComputedStyle(e).gridTemplateColumns.split(" ").length);
|
|
|
|
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
|
test(`${engine}: the Routing page scrolls to its end`, async (t) => {
|
|
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
|
const errors = [];
|
|
t.after(async () => {
|
|
if (errors.length) console.log(errors);
|
|
await browser.close();
|
|
});
|
|
for (const lang of ["en", "zh"]) for (const [width, height] of [[440, 620], [600, 700], [900, 500], [1200, 600], [1400, 700]]) {
|
|
await t.test(`${lang}, ${width}x${height}`, async () => {
|
|
const ctx = await browser.newContext({ viewport: { width, height }, reducedMotion: "reduce" });
|
|
const page = await ctx.newPage();
|
|
page.setDefaultTimeout(5000);
|
|
page.on("pageerror", (e) => errors.push(e.message));
|
|
await page.route("**/*", serve(lang));
|
|
await page.goto("http://magpie.test/?view=routing");
|
|
const view = page.locator("#view-routing");
|
|
await page.locator("#view-routing .rt-req").nth(11).waitFor();
|
|
await page.waitForTimeout(500);
|
|
|
|
// the layouts by width: magpie and the agent side by side over the
|
|
// accounts when the stage is narrow, each request on three lines in
|
|
// a narrow list, the accounts beside the requests on a wide page
|
|
const narrow = width <= 600;
|
|
assert.equal(await tracks(page, ".rt-stage"), narrow ? 2 : 3, "the stage's columns");
|
|
assert.equal(await tracks(page, ".rt-reqs"), width < 800 ? 2 : 4, "the requests' columns");
|
|
assert.equal(await tracks(page, ".rt-cols"), width >= 1200 ? 2 : 1, "the requests and the accounts, side by side or one under the other");
|
|
|
|
// down to the end, by the wheel
|
|
const box = await view.boundingBox();
|
|
await page.mouse.move(box.x + box.width / 2, box.y + box.height / 2);
|
|
for (let i = 0; i < 20; i++) { await page.mouse.wheel(0, 300); await page.waitForTimeout(40); }
|
|
await page.waitForTimeout(300);
|
|
// and on at the end, as the page is redrawn: each turn of the wheel
|
|
// there leaves it at its end, not pulled back from it
|
|
const short = [];
|
|
for (let i = 0; i < 10; i++) {
|
|
await page.mouse.wheel(0, 300);
|
|
await page.waitForTimeout(120);
|
|
const { range, top } = await view.evaluate((v) => ({ range: v.scrollHeight - v.clientHeight, top: v.scrollTop }));
|
|
assert(range > 0, "the page is taller than the window here");
|
|
if (top < range - 1) short.push(`${top} of ${range}`);
|
|
}
|
|
assert.deepEqual(short, [], "scrolled to");
|
|
await ctx.close();
|
|
});
|
|
}
|
|
assert.deepEqual(errors, []);
|
|
});
|
|
}
|