From 95a4180c0b0a9d3453259853a93dd504d2d8560b Mon Sep 17 00:00:00 2001 From: yetone Date: Mon, 26 Oct 2026 03:40:44 +0800 Subject: [PATCH] gui tests: the sidebar lists expect Masking's tab, and Built-in wheels to rows it can reach (#3498) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit e698a688 gave Insights › Masking a sidebar tab (data-view="masking", between Usage and Plugins, shown while the redact built-in is on, as it is in the fixtures). builtins, gateway-mode and sidebar kept the old lists. ggbdpq's patch on #3498 (5db37861) adds masking where the nav puts it; ported as written, with the deepEquals left exact. With the lists fixed, builtins was still red, in its scrolling. Its wheelTo moved the mouse to the list's top corner. After the first turn that corner had scrolled out of view, so the second turn scrolled nothing. At 420 the rows wrap and Usage's row sat at 884px under a 672px fold, with view-plugins at scrollTop 400 of 747 (measured). In WebKit, Observability's row is below the fold, and a click's own scroll is put back (scrollOnPurpose), so the click never landed. wheelTo now turns the wheel over the visible part of the list until the row is in view, five turns at most, and asserts the row was reached. Observability is reached the same way before its click. Run at this head (origin/main 9fc382e66): - builtins.test.cjs, chromium and webkit: 4 of 4, twice. With the list patch alone: 2 of 4 (wheelTo timeouts). - gateway-mode.test.cjs: 6 of 6. sidebar.test.cjs: 18 of 18. Not run: the whole GUI suite. Co-authored-by: ggbdpq --- internal/gui/tests/builtins.test.cjs | 30 ++++++++++++++++-------- internal/gui/tests/gateway-mode.test.cjs | 6 ++--- internal/gui/tests/sidebar.test.cjs | 2 +- 3 files changed, 24 insertions(+), 14 deletions(-) diff --git a/internal/gui/tests/builtins.test.cjs b/internal/gui/tests/builtins.test.cjs index 3f89c1abb..76dbd25ca 100644 --- a/internal/gui/tests/builtins.test.cjs +++ b/internal/gui/tests/builtins.test.cjs @@ -111,7 +111,8 @@ function server(lang, posts, broken) { // the pages' tabs shown, the page shown const tabs = (page) => page.evaluate(() => [...document.querySelectorAll("#nav button[data-view]")].filter((b) => !b.hidden && b.offsetParent && getComputedStyle(b).display !== "none").map((b) => b.dataset.view)); const viewShown = (page) => page.evaluate(() => [...document.querySelectorAll("main.view")].filter((v) => !v.hidden).map((v) => v.id)); -const KEPT = ["agents", "providers", "routing", "gateway", "usage", "plugins"]; +// the tabs with Sessions and Library off, the preset's masking on +const KEPT = ["agents", "providers", "routing", "gateway", "usage", "masking", "plugins"]; const rowsOf = (page) => page.evaluate(() => [...document.querySelectorAll("#builtinList .feat-row")].map((r) => { const b = r.querySelector('[role="switch"]'); return { id: r.dataset.id, name: r.querySelector(".name").textContent, on: b.getAttribute("aria-checked"), disabled: b.disabled, why: r.querySelector(".feat-why")?.textContent || "" }; @@ -206,20 +207,29 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", assert.deepEqual(posts, [["library", true]], where); if (width >= 800) assert.deepEqual(await tabs(page), ["agents", "library", ...KEPT.slice(1)], `${where}: Library back`); assert.deepEqual(await viewShown(page), ["view-plugins"], `${where}: Plugins stays`); + // Observability's, Routing's and Usage's rows can be below the fold: + // the reader scrolls to them with the wheel, since the page puts back + // a scroll that isn't the reader's (scrollOnPurpose), a click's own + // too. The wheel turns over what shows of the list (its top may have + // scrolled away, and a wheel there scrolls nothing), as often as the + // row needs: at 420 the rows wrap and Usage's is more than one turn + // down + const below = (id) => page.evaluate((id) => { const r = document.querySelector(`#builtinList [data-id="${id}"] [role="switch"]`).getBoundingClientRect(), foot = document.querySelector("footer.foot"); return r.bottom > Math.min(document.getElementById("view-plugins").getBoundingClientRect().bottom, foot && foot.offsetParent ? foot.getBoundingClientRect().top : Infinity); }, id); + const wheelTo = async (id) => { + for (let i = 0; i < 5 && await below(id); i++) { + const at = await page.evaluate(() => { const l = document.getElementById("builtinList").getBoundingClientRect(), v = document.getElementById("view-plugins").getBoundingClientRect(); return { x: l.x + 20, y: (Math.max(l.top, v.top) + Math.min(l.bottom, v.bottom)) / 2 }; }); + await page.mouse.move(at.x, at.y); + await page.mouse.wheel(0, 400); + await page.waitForFunction(() => new Promise((r) => requestAnimationFrame(() => requestAnimationFrame(() => r(true))))); + } + assert.equal(await below(id), false, `${where}: ${id}'s row reached by the wheel`); + }; // and Observability: its Settings tab is back + await wheelTo("otel"); await page.locator('#builtinList [data-id="otel"] [role="switch"]').click(); await page.waitForSelector('#builtinList [data-id="otel"] [aria-checked="true"]'); assert.ok(await page.locator("#setTab-otel").evaluate((b) => getComputedStyle(b).display !== "none"), `${where}: Observability back`); // Routing switched off: its tab and the panel's go, the page stays. - // Its row and Usage's can be below the fold: the reader scrolls to - // them with the wheel, since the page puts back a scroll that isn't - // the reader's (scrollOnPurpose), a click's own too - const wheelTo = async (id) => { - const list = await page.locator("#builtinList").boundingBox(); - await page.mouse.move(list.x + 20, list.y + 20); - await page.mouse.wheel(0, 400); - await page.waitForFunction((id) => { const r = document.querySelector(`#builtinList [data-id="${id}"] [role="switch"]`).getBoundingClientRect(), foot = document.querySelector("footer.foot"); return r.bottom <= Math.min(document.getElementById("view-plugins").getBoundingClientRect().bottom, foot && foot.offsetParent ? foot.getBoundingClientRect().top : Infinity); }, id); - }; await wheelTo("routing"); await page.locator('#builtinList [data-id="routing"] [role="switch"]').click(); await page.waitForSelector('#builtinList [data-id="routing"] [aria-checked="false"]'); diff --git a/internal/gui/tests/gateway-mode.test.cjs b/internal/gui/tests/gateway-mode.test.cjs index a15233b5d..219e5648a 100644 --- a/internal/gui/tests/gateway-mode.test.cjs +++ b/internal/gui/tests/gateway-mode.test.cjs @@ -84,7 +84,7 @@ const L = { }; const HIDDEN = ["agents", "library"]; // in the order the pages are grouped in (work, models, insights, extend) -const KEPT = ["sessions", "providers", "routing", "gateway", "usage", "plugins"]; +const KEPT = ["sessions", "providers", "routing", "gateway", "usage", "masking", "plugins"]; // the tabs shown, the page shown const tabs = (page) => page.evaluate(() => [...document.querySelectorAll("#nav button[data-view]")].filter((b) => !b.hidden && b.offsetParent).map((b) => b.dataset.view)); @@ -154,7 +154,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", await clickStill(page, "#gatewayModeSegs .opt:nth-child(4)", `${where}: Off`); await page.waitForFunction(() => !document.querySelector('#nav button[data-view="agents"]').hidden); assert.deepEqual(posts.filter((p) => p[0] === "gateway-mode"), [["gateway-mode", "off"]], where); - assert.deepEqual(await tabs(page), ["agents", "sessions", "library", "providers", "routing", "gateway", "usage", "plugins"], `${where}: off`); + assert.deepEqual(await tabs(page), ["agents", "sessions", "library", "providers", "routing", "gateway", "usage", "masking", "plugins"], `${where}: off`); assert.deepEqual(await viewShown(page), ["view-settings"], `${where}: Settings stays`); assert.deepEqual(await agentRows(page), [true, true, true, true, true], `${where}: rows back`); assert.doesNotMatch(await page.locator("#gatewayModeSub").textContent(), new RegExp(L[lang].noAgents), where); @@ -187,7 +187,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", await page.route("**/*", server(lang, [], { web, gateway: false, agents: true })); await page.goto("http://magpie.test/"); await page.waitForSelector("#nav button.on"); - assert.deepEqual(await tabs(page), ["agents", "sessions", "library", "providers", "routing", "gateway", "usage", "plugins"], where); + assert.deepEqual(await tabs(page), ["agents", "sessions", "library", "providers", "routing", "gateway", "usage", "masking", "plugins"], where); assert.deepEqual(await viewShown(page), ["view-agents"], where); await page.locator("#prefs").click(); await page.waitForSelector("#langPick span"); diff --git a/internal/gui/tests/sidebar.test.cjs b/internal/gui/tests/sidebar.test.cjs index 0b2a06325..9b7215a49 100644 --- a/internal/gui/tests/sidebar.test.cjs +++ b/internal/gui/tests/sidebar.test.cjs @@ -60,7 +60,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", assert.equal(await page.locator(".top #nav").count(), 0, "and not in the header"); assert.deepEqual(await page.locator("#nav .nav-gl:visible").allTextContents(), w.groups); assert.deepEqual(await page.locator("#nav button[data-view]").evaluateAll((bs) => bs.map((b) => b.dataset.view)), - ["agents", "sessions", "library", "providers", "routing", "gateway", "usage", "plugins"]); + ["agents", "sessions", "library", "providers", "routing", "gateway", "usage", "masking", "plugins"]); assert.ok(await page.locator("#side .side-foot #prefs").isVisible(), "Settings at the sidebar's foot"); assert.equal((await page.locator("#prefs .side-l").textContent()).trim(), w.settings); // no page's name or group cut, and nothing scrolls sideways