Files
magpie/internal/gui/tests/sessions-empty-range.test.cjs
T
yetone 11cbf4de1d usage: Sessions' agent filter is a menu, as the model and folder ones beside it
The owner (10-28, screenshot of Usage › Sessions with 13 agents in a strip
across the page): "这应该是个 Combo Box". The agent filter was a segmented
strip, one segment per agent in range, that scrolled sideways in itself
once it ran past the window (#929). It is now the same sessPick button
as 全部模型 and 全部文件夹, with the same searchable menu: "All agents",
then every agent with sessions or usage in the range, the most used
first, each with its tokens under the other two filters. One agent in
range still leaves it hidden; the pick still resets to All when its agent
leaves the range. The request ledger's agent filter was already this menu.

#sessAgent left the CSS rules for scrolling strips; the strip's own test
(sess-agent-strip, #929's sideways scroll) is gone with the strip, and
usage-sessions-agents-fit now checks the menu: no sideways scroll at 860
and 560 wide, the three filters on one line inside the window, the
menu's order, search, a pick shown on the button and kept when the page
is drawn again, All clearing it, one agent hidden. sessions-empty-range
and sessions-overview-once pick their agent from the menu.

Run on mote (node 22, Playwright 1.62.0):
- usage-sessions-agents-fit, sessions-empty-range, sessions-overview-once:
  24 of 24, Chromium and WebKit, every language they cover.
- usage-sessions-agents-fit against origin/main's page.js, client.js and
  app.css: red in all four (BUTTON.sess-pick expected, a div of segments).
- go test -tags nogui -run Budget ./internal/gui: ok.
- 122 other GUI files that touch Usage, sess-pick or i18n, concurrency 3,
  beside another session's full GUI suite (load 36-75): 1944 pass, 24
  fail in gateway-caller-keys, gateway-key-cycle, i18n-keys,
  mcp-oauth-app, usage-ledger and web-page. Rerun alone at concurrency
  1 on this tree and on origin/main (d4f1d6480, then c4972b36e after the
  rebase): the same reds on both. gateway-key-cycle is #4072,
  gateway-caller-keys #3797, usage-ledger's "newest live route" #4078,
  web-page's #gateway .dot #4079. i18n-keys' "masking…" was fixed on
  main in 174250b27. mcp-oauth-app passes alone on both.
- At this tree, rebased onto 6ecc65b6d (the pushed tree):
  usage-sessions-agents-fit, sessions-empty-range,
  sessions-overview-once, i18n-keys and click-scroll 50 of 50, and
  go test -tags nogui -run Budget ./internal/gui ok.
Not run: the whole GUI suite (another session's was running on mote).
2026-10-28 22:52:30 +08:00

48 lines
3.7 KiB
JavaScript

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 today = new Date().toISOString().slice(0, 10);
const old = "2026-01-01T12:00:00Z";
const session = { agent: "opencode", id: "old-chat", name: "OpenCode", title: "Historical conversation", cwd: "/work", start: old, last: old, models: [], input: 0, output: 0, cost: 0, resume: "", path: "/test/opencode.db#old-chat" };
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
for (const [lang, all, width] of [["en", "All", 900], ["zh", "全部", 900], ["zh-TW", "全部", 900], ["ja", "すべて", 900], ["de", "Alle", 420]]) {
test(`${engine} ${lang} ${width}px: empty Today offers existing history without changing the agent`, async (t) => {
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
t.after(() => browser.close());
const page = await browser.newPage({ viewport: { width, height: 760 } });
page.setDefaultTimeout(8000);
await page.route("**/*", 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({ agents: [], profiles: [], settings: { lang, theme: "light" } });
if (url.pathname === "/api/sessions") return json({ sessions: [session, { ...session, agent: "codex", id: "other", name: "Codex", title: "Other conversation" }], dirs: [] });
if (url.pathname === "/api/sessions/stats") return json({ from: url.searchParams.get("days") === "0" ? "2026-01-01" : today, to: today, days: [], agents: { opencode: "OpenCode" } });
if (url.pathname === "/api/sessions/overview") return json({ count: url.searchParams.get("days") === "0" ? 1 : 0, days: [], top: { tokens: [], cost: [], active: [] } });
if (url.pathname === "/api/usage/quotas") return json([]);
if (url.pathname.startsWith("/api/")) return json({});
const file = url.pathname === "/app.js" && process.env.MAGPIE_TEST_APP_JS ? process.env.MAGPIE_TEST_APP_JS : path.join(assets, url.pathname === "/" ? "index.html" : url.pathname);
const body = await fs.readFile(file).catch(() => null);
const contentType = { ".html": "text/html", ".js": "text/javascript", ".css": "text/css", ".svg": "image/svg+xml" }[path.extname(file)];
return body ? route.fulfill({ body, contentType }) : route.fulfill({ status: 404, body: "" });
});
await page.addInitScript(() => { localStorage.setItem("magpie.usageTab", "sessions"); localStorage.setItem("magpie.sessRange", "today"); });
await page.goto("http://magpie.test/?view=usage");
// the agent filter is a menu (as the model and folder ones)
await page.locator("#sessAgent").click();
await page.locator('.sess-menu .pm-item[title="opencode"]').click();
await page.locator("#sessStats .sess-show-history").click();
await page.getByText("Historical conversation", { exact: true }).waitFor();
assert.equal(await page.locator("#sessAgent").innerText(), "OpenCode");
assert.match(await page.locator("#sessAgent").getAttribute("class"), /\bset\b/);
assert.equal(await page.locator("#sessRange .opt.on").innerText(), all);
});
}
}