diff --git a/internal/gui/assets/context.css b/internal/gui/assets/context.css index 97799ae07..1d8569310 100644 --- a/internal/gui/assets/context.css +++ b/internal/gui/assets/context.css @@ -121,6 +121,14 @@ i.dot.free { background: var(--k-free); box-shadow: inset 0 0 0 1px color-mix(in opens and the page doesn't follow it (it moved 4px with a 10px one) */ .ctx-card.shut > :not(.ctx-head) { display: none; } :where(.ctx-card.shut.max420) .ctx-model { display: none; } +/* folded, the head is one line of a fixed height whatever a live request + puts in it, so nothing under it moves; a thin bar of what fills the + window, a part each, takes the room between the figure and the model */ +.ctx-card.shut .ctx-head { height: 20px; white-space: nowrap; } +.ctx-stack { display: none; flex: 1 1 0; min-width: 24px; max-width: 360px; height: 6px; border-radius: 3px; background: var(--k-free); overflow: hidden; } +.ctx-card.shut .ctx-stack { display: flex; } +.ctx-stack i { flex: none; height: 100%; background: var(--k); transition: width .3s var(--ease, ease); } +@media (prefers-reduced-motion: reduce) { .ctx-stack i { transition: none; } } /* the Usage page's Context tab */ .ctx-agents { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 340px), 1fr)); gap: 12px; margin: 4px 0 18px; } diff --git a/internal/gui/assets/context.js b/internal/gui/assets/context.js index 9a53dbc04..77d214814 100644 --- a/internal/gui/assets/context.js +++ b/internal/gui/assets/context.js @@ -233,8 +233,11 @@ // (0xBCD18E on X: it took most of the height, three rows were left) let ctxShut = false; try { ctxShut = localStorage.getItem("magpie.ctxShut") === "1"; } catch {} + // opts.open: this request was opened to see its context window (the + // Usage page's Context tab), so it shows unfolded, it alone: the next + // request drawn in the card takes the reader's choice again function ctxCard(r, opts = {}) { - const card = el("div", "ctx-card" + (opts.foldable && ctxShut ? " shut" : "")); + const card = el("div", "ctx-card" + (opts.foldable && ctxShut && !opts.open ? " shut" : "")); card.dataset.place = opts.place || ""; if (cardWidth[card.dataset.place] !== undefined) sizeCard(card, cardWidth[card.dataset.place]); cardSizes.observe(card); @@ -348,6 +351,7 @@ const live = !r.done; // the head: what it is and how it was counted + if (opts.foldable) card.classList.toggle("shut", ctxShut && !opts.open); const head = el("div", "ctx-head"); let title = el("span", "ctx-title", t("Context window")); if (opts.foldable) { @@ -364,6 +368,7 @@ tip.hidden = true; e.currentTarget.setAttribute("aria-expanded", String(!ctxShut)); try { localStorage.setItem("magpie.ctxShut", ctxShut ? "1" : "0"); } catch {} + opts.onFold?.(ctxShut); }; title = fold; } @@ -373,7 +378,23 @@ : p.counted ? "As many tokens as the vendor counted; the parts are measured from the request and scaled to it" : "Estimated from what the agent sent: the vendor didn't say how many tokens it read"); head.append(title); - if (opts.foldable) head.append(el("span", "ctx-short", fmtK(p.tokens) + (window ? " / " + fmtK(window) + " · " + pct(full) : ""))); + if (opts.foldable) { + head.append(el("span", "ctx-short", fmtK(p.tokens) + (window ? " / " + fmtK(window) + " · " + pct(full) : ""))); + // folded, a thin bar of what fills the window, a part each; it is + // morphed with the head, so a live request moves its widths only + const bar = el("span", "ctx-stack"); + bar.setAttribute("role", "img"); + bar.setAttribute("aria-label", t("{used} of {window} tokens used", { used: fmtK(p.tokens), window: fmtK(window || p.tokens) })); + const scale = Math.max(window, p.tokens, 1); + for (const k of PARTS) { + const n = p.parts.find((x) => x.kind === k)?.tokens || 0; + const i = el("i", "k-" + k); + i.title = partName(k); + i.style.width = +(Math.max(0, n) / scale * 100).toFixed(2) + "%"; + bar.append(i); + } + head.append(bar); + } head.append(el("span", "grow")); if (r.model) head.append(el("code", "ctx-model", r.model)); head.append(st); @@ -633,7 +654,7 @@ if (a.latestId) { const go = el("button", "text", t("Latest request")); go.type = "button"; - go.onclick = () => window.openRoute(a.latestId, a.latestTime).catch((e) => status(e.message, "err")); + go.onclick = () => window.openRoute(a.latestId, a.latestTime, { context: true }).catch((e) => status(e.message, "err")); foot.append(go); } card.append(head, scores, tags, facts, mix, foot); @@ -669,7 +690,7 @@ still: true, cache, place: "session", series: s.points, crumbs: [agentLabel(s.agent), s.title || s.key.slice(0, 12), t("latest request")], - onPoint: (pt) => window.openRoute(pt.id, pt.time).catch((e) => status(e.message, "err")), + onPoint: (pt) => window.openRoute(pt.id, pt.time, { context: true }).catch((e) => status(e.message, "err")), })); } return box; diff --git a/internal/gui/assets/routing.js b/internal/gui/assets/routing.js index 2e14e6e89..484e9fdda 100644 --- a/internal/gui/assets/routing.js +++ b/internal/gui/assets/routing.js @@ -1428,7 +1428,11 @@ // (Zhenzhen on Discord: each new request flashed the whole card, and its // grid went and came back); a request the reader picks comes in afresh, // its cells one after another - let ctxKey = "", ctxShown = 0, ctxTab = "all"; + // + // ctxFor is a request opened to see its context window (the Usage + // page's Context tab): its card shows unfolded, it alone, whatever the + // reader keeps folded + let ctxKey = "", ctxShown = 0, ctxTab = "all", ctxFor = 0; function renderCtx(r) { if (!r.prompt || !window.ctxCard) { // a live request whose prompt the gateway is still reading keeps @@ -1443,7 +1447,8 @@ const series = (sk || r.conv) && !r.kind ? listed().filter(same).sort((a, b) => a.id - b.id) .map((x) => ({ id: x.id, tokens: x.prompt.tokens, time: x.time })) : null; if (series && !series.some((x) => x.id === r.id)) series.push({ id: r.id, tokens: r.prompt.tokens, time: r.time }); - const key = JSON.stringify([document.documentElement.lang, r.id, r.done, r.prompt.tokens, r.prompt.counted, r.prompt.window, r.usage?.length, series?.map((x) => x.id + ":" + x.tokens).join()]); + if (ctxFor && ctxFor !== r.id) ctxFor = 0; + const key = JSON.stringify([document.documentElement.lang, ctxFor, r.id, r.done, r.prompt.tokens, r.prompt.counted, r.prompt.window, r.usage?.length, series?.map((x) => x.id + ":" + x.tokens).join()]); if (key === ctxKey) return; ctxKey = key; const still = ctxShown === r.id; @@ -1453,6 +1458,7 @@ const draw = card?.ctxUpdate && (still || !pinned) ? card.ctxUpdate : (r, o) => ctxBox.replaceChildren(window.ctxCard(r, o)); draw(r, { still, series, tab: ctxTab, place: "routing", foldable: true, + open: ctxFor === r.id, onFold: () => { ctxFor = 0; }, onTab: (id) => { ctxTab = id; }, crumbs: [agentName(r.agent), sess && (sess.length > 14 ? sess.slice(0, 12) + "…" : sess), "#" + r.id], onPoint: (pt) => { @@ -1549,7 +1555,9 @@ say(affWhy(r, true) || ruleWhy(r, true) || firstWhy(r)); } - window.openRoute = async (id, time) => { + // o.context: opened to see its context window (the Usage page's + // Context tab), which shows unfolded for it + window.openRoute = async (id, time, o = {}) => { let r = routes.get(id); if (!r) { const res = await fetch("/api/gateway/route?id=" + encodeURIComponent(id) + "&day=" + encodeURIComponent(time.slice(0, 10))); @@ -1566,6 +1574,7 @@ if (!matchesPurpose(r)) purpose = []; offline(""); window.show("routing"); + if (o.context) ctxFor = r.id; pick(r); }; diff --git a/internal/gui/tests/routing-context-fold.test.cjs b/internal/gui/tests/routing-context-fold.test.cjs new file mode 100644 index 000000000..26551ac01 --- /dev/null +++ b/internal/gui/tests/routing-context-fold.test.cjs @@ -0,0 +1,209 @@ +// Run with Node's test runner and Playwright on the module path; see README.md. +// Routing: the context window's card folded to its head (routing-ctx-fold +// tests the fold itself) is one line of a fixed height with a thin bar of +// what fills the window, a part each, beside how full it is (PILIPALA on +// X: on a wide window the card took the screen, and the requests and the +// magpies flying were out of sight under it; Jeremy.Zhou on Discord: the +// page is too crowded). Folded, the stage and the request list are in view +// without scrolling at 1440x900 and 1920x1080; at a narrow 440px the head +// is all the card takes (the stage and the story stacked above it are what +// is left before the list). Unfolding by its title doesn't move the page. A +// request picked keeps the fold; one opened from the Usage page's Context +// tab shows its card unfolded, that request only, and the reader's choice +// is untouched. In Chromium and WebKit, in English, Chinese and German. +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 = Date.now(); +const iso = (ms) => new Date(ms).toISOString(); +const seat = { id: "codex@me", provider: "codex", name: "ChatGPT", who: "me@example.com", kind: "account", model: "gpt-6.1-sol", known: true, plan: "Pro" }; + +// a codex prompt, a little more each request +const prompt = (n) => ({ + window: 272000, tokens: 90000 + n * 8000, counted: true, turns: n, + parts: [ + { kind: "system", tokens: 9000, items: [{ name: "prompt", tokens: 9000 }] }, + { kind: "tools", tokens: 12000, items: [{ name: "exec_command", tokens: 7000 }, { name: "apply_patch", tokens: 5000 }] }, + { kind: "files", tokens: 30000 + n * 4000, items: [{ name: "/work/app/routing.js", tag: "read", tokens: 20000 + n * 3000 }, { name: "/work/app/context.js", tag: "read", tokens: 10000 + n * 1000 }] }, + { kind: "results", tokens: 20000 + n * 2000, items: [{ name: "exec_command", tag: "result", n: n + 2, tokens: 20000 + n * 2000 }] }, + { kind: "chat", tokens: 19000 + n * 2000, items: [{ name: "turn", tag: "turns", n, tokens: 19000 + n * 2000 }] }, + ], +}); +function req(id) { + const t0 = now - (200 - id) * 1000; + return { + id, seq: id * 10, time: iso(t0), agent: "codex", session: "019a-session", model: "gpt-6.1-sol", provider: "codex", + order: [seat], tries: [{ id: seat.id, model: seat.model, start: iso(t0), done: true, status: 200, ms: 4000 }], + done: true, status: 200, ms: 4000, tokens: 2000, cost: 0.05, priced: true, usage: [{ in: 3000, cache_read: 87000 + id * 100, out: 400 }], + prompt: prompt(id - 100), + }; +} +const routes = Array.from({ length: 12 }, (_, i) => req(101 + i)); +const newest = routes[routes.length - 1]; + +const words = { en: "Context window", zh: "上下文窗口", de: "Kontextfenster" }; + +function serve(lang) { + const state = { agents: [{ id: "codex", name: "Codex", path: "/test/codex", fields: [] }], profiles: [], settings: { lang, theme: "light" } }; + 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:"${lang}",theme:"light",web:true};` }); + if (url.pathname === "/wails/runtime.js") return route.fulfill({ contentType: "text/javascript", body: "export const Window = {};" }); + if (url.pathname === "/api/state") return json(state); + if (url.pathname === "/api/gateway/trace") { + if (url.searchParams.get("wait")) return new Promise(() => {}); + return json({ mine: true, now: new Date().toISOString(), seq: newest.seq, 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") return json({ groups: [], models: [], pools: [] }); + if (url.pathname === "/api/providers") return json({ providers: [], presets: [], excluded: [], gateway: { running: true, window: true, url: "http://127.0.0.1:3999" } }); + if (url.pathname === "/api/plugins") return json({ plugins: [] }); + if (url.pathname === "/api/usage/quotas") return json([]); + 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 route.fulfill({ body: await fs.readFile(file).catch(() => ""), contentType }); + }; +} + +async function open(browser, lang, width, height) { + const context = await browser.newContext({ viewport: { width, height } }); + const page = await context.newPage(); + // folded is the reader's own choice, kept in magpie.ctxShut; set once, so a reload keeps what the page stores + await page.addInitScript(() => { try { if (!sessionStorage.getItem("seeded")) { sessionStorage.setItem("seeded", "1"); localStorage.setItem("magpie.ctxShut", "1"); } } catch {} }); + page.setDefaultTimeout(5000); + const errors = []; + page.on("pageerror", (e) => errors.push(e.message)); + await page.route("**/*", serve(lang)); + await page.goto("http://magpie.test/?view=routing"); + await page.locator(".rt-req").nth(routes.length - 1).waitFor(); + await page.locator(".rt-ctx > *").first().waitFor(); + await page.waitForTimeout(500); + return { context, page, errors }; +} +// the reader scrolls to what they click with the wheel (as routing-ctx-fold +// does): a card opened afresh can sit under the window's bottom +async function click(page, b) { + const h = page.viewportSize().height; + for (let i = 0; i < 20; i++) { + const r = await b.boundingBox(); + if (r && r.y >= 0 && r.y + r.height <= h) break; + await page.mouse.move(page.viewportSize().width / 2, h / 2); + await page.mouse.wheel(0, r && r.y < 0 ? -200 : 200); + await page.waitForTimeout(100); + } + await b.click(); + await page.waitForTimeout(300); +} +const scrollTop = (page) => page.evaluate(() => document.querySelector("#view-routing").scrollTop); +const stored = (page) => page.evaluate(() => localStorage.getItem("magpie.ctxShut")); + +for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) { + test(`${engine}: the context window on Routing folds to one line`, async (t) => { + const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" })); + t.after(() => browser.close()); + + for (const [width, height] of [[1920, 1080], [1440, 900], [440, 900]]) { + for (const lang of Object.keys(words)) { + await t.test(`${lang} ${width}x${height}: folded to one line, the stage and the requests in view`, async () => { + const { context, page, errors } = await open(browser, lang, width, height); + const box = page.locator(".rt-ctx"); + const fold = box.locator(".ctx-fold"); + assert.equal(await box.locator(".ctx-card.shut").count(), 1, "folded, as the reader keeps it"); + assert.equal(await fold.getAttribute("aria-expanded"), "false"); + assert.equal(await fold.innerText(), words[lang]); + assert.equal(await box.locator(".ctx-short").innerText(), "186K / 272K · 68%"); + assert.match(await box.locator(".ctx-crumbs").textContent(), /#112$/); + // a bar of what fills the window, a part each (this prompt has no memory) + assert.deepEqual(await box.locator(".ctx-stack > i").evaluateAll((is) => is.map((i) => i.className + " " + i.style.width)), + ["k-system 3.31%", "k-tools 4.41%", "k-memory 0%", "k-files 28.68%", "k-results 16.18%", "k-chat 15.81%"]); + const at = await page.evaluate(() => { + const r = (s) => document.querySelector(s).getBoundingClientRect(); + const card = r(".rt-ctx .ctx-card"), head = r(".rt-ctx .ctx-head"), bar = r(".rt-ctx .ctx-stack"), c = document.querySelector(".rt-ctx .ctx-card"); + return { vh: innerHeight, stage: r(".rt-stage").bottom, head: r(".rt-req-head").top + 24, row: r(".rt-req").bottom, cardH: card.height, headH: head.height, + bar: bar.width, barIn: bar.right <= head.right + 0.5, over: c.scrollWidth - c.clientWidth, wide: document.documentElement.scrollWidth <= innerWidth }; + }); + assert.equal(await scrollTop(page), 0); + assert(at.stage <= at.vh, `the magpies' stage is in view: ${JSON.stringify(at)}`); + if (width >= 1440) { + assert(at.head <= at.vh, `the request list's heading is in view: ${JSON.stringify(at)}`); + assert(at.row <= at.vh, `the first request is in view: ${JSON.stringify(at)}`); + } + assert(at.cardH < 60 && at.headH === 20, `one line: ${JSON.stringify(at)}`); + assert(at.bar >= 24 && at.barIn, `the bar is there and in the line: ${JSON.stringify(at)}`); + assert(at.over <= 0 && at.wide, `nothing runs over: ${JSON.stringify(at)}`); + assert.deepEqual(errors, []); + await context.close(); + }); + } + } + + await t.test("unfolded by its title without moving the page", async () => { + const { context, page, errors } = await open(browser, "en", 1440, 900); + // the reader scrolls down a little first, so a click that moved the page would show + await page.mouse.move(700, 500); + await page.mouse.wheel(0, 120); + await page.waitForTimeout(400); + const y = await scrollTop(page); + assert(y > 0, "the page scrolled"); + const fold = page.locator(".rt-ctx .ctx-fold"); + const foldTop = await fold.evaluate((e) => e.getBoundingClientRect().top); + await fold.click(); + await page.locator(".rt-ctx .ctx-card:not(.shut) .ctx-waffle").waitFor(); + assert.equal(await page.locator(".rt-ctx .ctx-waffle > i").count(), 400); + assert.equal(await fold.getAttribute("aria-expanded"), "true"); + assert.equal(await page.locator(".rt-ctx .ctx-stack").evaluate((e) => e.getClientRects().length), 0, "open, the bar is the card's own legend"); + await page.waitForTimeout(800); + assert.equal(await scrollTop(page), y, "unfolding doesn't move the page"); + const after = await fold.evaluate((e) => e.getBoundingClientRect().top); + assert(Math.abs(after - foldTop) <= 1, `the title stays under the pointer: ${foldTop} → ${after}`); + assert.equal(await stored(page), "0"); + assert.deepEqual(errors, []); + await context.close(); + }); + + await t.test("a request picked keeps the fold; one opened for its context window shows it, for itself only", async () => { + const { context, page, errors } = await open(browser, "en", 1440, 900); + const shut = () => page.locator(".rt-ctx .ctx-card").evaluate((c) => c.classList.contains("shut")); + const crumb = () => page.locator(".rt-ctx .ctx-crumbs").evaluate((c) => c.textContent.split(" › ").pop()); + const y = await scrollTop(page); + await page.locator(".rt-req").nth(3).click(); + await page.waitForTimeout(300); + assert.equal(await shut(), true, "a request picked stays folded"); + assert.equal(await crumb(), "#109"); + assert.equal(await scrollTop(page), y, "the pick doesn't move the page"); + + // the Usage page's Context tab's Latest request, or a point of its line + await page.evaluate((r) => window.openRoute(r.id, r.time, { context: true }), routes[2]); + await page.locator(".rt-ctx .ctx-card:not(.shut) .ctx-waffle").waitFor(); + assert.equal(await crumb(), "#103"); + assert.equal(await page.locator(".rt-ctx .ctx-fold").getAttribute("aria-expanded"), "true"); + assert.equal(await stored(page), "1", "the reader's own choice is untouched"); + + await page.locator(".rt-req").nth(5).click(); + await page.waitForTimeout(300); + assert.equal(await shut(), true, "the next request is folded again"); + assert.equal(await crumb(), "#107"); + assert.equal(await page.locator(".rt-ctx .ctx-fold").getAttribute("aria-expanded"), "false"); + + // opened for it again, then folded by its title: folded it stays, for it and the next + await page.evaluate((r) => window.openRoute(r.id, r.time, { context: true }), routes[2]); + await page.locator(".rt-ctx .ctx-card:not(.shut)").waitFor(); + await click(page, page.locator(".rt-ctx .ctx-fold")); + assert.equal(await shut(), true, "the title folds it"); + assert.equal(await stored(page), "1"); + await click(page, page.locator(".rt-req").nth(5)); + await page.evaluate((r) => window.openRoute(r.id, r.time), routes[2]); + await page.waitForTimeout(300); + assert.equal(await crumb(), "#103"); + assert.equal(await shut(), true, "a request opened from the list or a link stays folded"); + assert.deepEqual(errors, []); + await context.close(); + }); + }); +} diff --git a/internal/gui/tests/routing-live-patch.test.cjs b/internal/gui/tests/routing-live-patch.test.cjs index 41ca21890..7e033c7c7 100644 --- a/internal/gui/tests/routing-live-patch.test.cjs +++ b/internal/gui/tests/routing-live-patch.test.cjs @@ -8,7 +8,8 @@ // nodes, the new one goes in beside them, the context window's card and // grid are the ones that were there, patched, and the grid and its box // keep their height on every frame between. In Chromium and WebKit, at a -// phone's width and a desk's. +// phone's width and a desk's; with the card open, and folded to its head +// (magpie.ctxShut), whose nodes, bar and height stay the same too. const assert = require("node:assert/strict"); const fs = require("node:fs/promises"); const path = require("node:path"); @@ -74,7 +75,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" })); t.after(() => browser.close()); for (const [width, height] of [[420, 760], [1100, 760]]) { - await t.test(`${width}x${height}`, async () => { + await t.test(`${width}x${height}, open`, async () => { const context = await browser.newContext({ viewport: { width, height } }); const page = await context.newPage(); page.setDefaultTimeout(5000); @@ -159,6 +160,70 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", feed.next?.(req(999, "done")); await context.close(); }); + await t.test(`${width}x${height}, folded`, async () => { + const context = await browser.newContext({ viewport: { width, height } }); + const page = await context.newPage(); + await page.addInitScript(() => { try { localStorage.setItem("magpie.ctxShut", "1"); } catch {} }); + page.setDefaultTimeout(5000); + const errors = []; + page.on("pageerror", (e) => errors.push(e.message)); + const feed = { next: null }; + await page.route("**/*", serve(feed)); + await page.goto("http://magpie.test/?view=routing"); + await page.locator(".rt-req").nth(first.length - 1).waitFor(); + await page.locator(".rt-ctx .ctx-card.shut").waitFor(); + await page.waitForTimeout(600); + await page.evaluate(() => { + const box = document.querySelector(".rt-ctx"); + window.__was = { rows: [...document.querySelectorAll(".rt-req")], line: box.querySelector(".ctx-card"), head: box.querySelector(".ctx-head"), bar: box.querySelector(".ctx-stack"), h: box.offsetHeight, list: document.querySelector(".rt-reqs").getBoundingClientRect().top }; + window.__sizes = []; + window.__ro = new ResizeObserver(() => window.__sizes.push(box.offsetHeight)); + window.__ro.observe(box); + window.__scroll = []; + document.querySelector("#view-routing").addEventListener("scroll", (e) => window.__scroll.push(e.target.scrollTop)); + }); + const said = []; + for (const id of [104, 105]) { + for (const step of ["start", "read", "done"]) { + for (let i = 0; i < 60 && !feed.next; i++) await page.waitForTimeout(50); + assert(feed.next, "the page asks for the next trace"); + const next = feed.next; + feed.next = null; + next(req(id, step)); + await page.waitForTimeout(400); + said.push(await page.evaluate(() => { + const box = document.querySelector(".rt-ctx"); + return box.querySelector(".ctx-short").textContent + " " + box.querySelector(".ctx-crumbs").textContent.split(" › ").pop() + + " " + [...box.querySelectorAll(".ctx-stack > i")].map((i) => i.style.width).join(","); + })); + } + } + // the folded head waits for a prompt in its place, then tells of it + const bar = (f, r, c) => `3.31%,4.41%,0%,${f}%,${r}%,${c}%`; + assert.deepEqual(said, [ + "114K / 272K · 42% #103 " + bar(15.44, 9.56, 9.19), + ...Array(3).fill("122K / 272K · 45% #104 " + bar(16.91, 10.29, 9.93)), + ...Array(2).fill("130K / 272K · 48% #105 " + bar(18.38, 11.03, 10.66)), + ]); + const got = await page.evaluate(() => { + window.__ro.disconnect(); + const box = document.querySelector(".rt-ctx"), w = window.__was, rows = [...document.querySelectorAll(".rt-req")]; + return { + kept: w.rows.every((r) => rows.includes(r)), line: box.querySelector(".ctx-card") === w.line && box.querySelector(".ctx-head") === w.head, bar: box.querySelector(".ctx-stack") === w.bar, + card: !box.querySelector(".ctx-card").classList.contains("shut") || box.querySelector(".ctx-waffle").getClientRects().length > 0, h: box.offsetHeight, h0: w.h, sizes: window.__sizes, scroll: window.__scroll, + list: document.querySelector(".rt-reqs").getBoundingClientRect().top, list0: w.list, + }; + }); + assert(got.kept, "the requests listed before are the same nodes"); + assert(got.line && got.bar, "the folded card, its head and bar are the ones that were there"); + assert(!got.card, "it stays folded, its grid out of sight"); + for (const h of [got.h, ...got.sizes]) assert.equal(h, got.h0, `the folded card keeps its height: ${JSON.stringify([got.h0, got.sizes])}`); + assert.equal(got.list, got.list0, "the request list stays where it was"); + assert.deepEqual(got.scroll, [], "the page doesn't scroll by itself"); + assert.deepEqual(errors, []); + feed.next?.(req(999, "done")); + await context.close(); + }); } }); }