diff --git a/docs/subsystems/gui-shell.md b/docs/subsystems/gui-shell.md index a05a62447..cd5b0a2ce 100644 --- a/docs/subsystems/gui-shell.md +++ b/docs/subsystems/gui-shell.md @@ -457,7 +457,7 @@ covers it in both engines, every language and a narrow window. - In Usage → Allowances, Trends → Cycle offers each account's own recorded cycle menu beside its curve (`quotaCurve`, `quotaRecordedCycles` in [`app.js`](../../internal/gui/assets/app.js)). The longest window (usually weekly) owns the menu; shorter windows are drawn over the selected dates with their own reset breaks. `/api/usage/quotas/history?days=45` supplies all retained readings, including remote cards. Completed cycles come from observed boundaries, not seven-day arithmetic; an early reset ends the previous cycle at the vendor's new start if it fits between readings, otherwise at the first new reading. Each menu option gives its observed duration, so an early reset is not labelled as a full seven days. The selected meters, plot, legend, tooltip and dashed pace use that cycle's last readings, never today's percentages. A window without a reading in the selected interval says so instead of showing a current value. A local account's past cycle asks `/api/usage/quotas/history/holds?provider=&user=&from=&to=` once per selection (`quotaCycleHoldsOf`), which asks no vendor (#2009, NorethSea): `HistoricalWindowHolds` in [`window_holds_history.go`](../../internal/usage/window_holds_history.go) reckons each window's whole at its own last reading in that cycle, from the request log up to that reading, so the 5-hour figure is the cycle's last 5-hour window, never its short windows added up. Its tooltip names that window's start and the reading's time. It shows "Loading…" until the answer comes. A window it can't reckon says "not enough data" with the reason, as a current card does; a reply that comes after another cycle was picked is dropped, and a card's Refresh or an asked read reckons again. Historical meters show the cycle end and sampling time; current account actions, balances and policies are left out until returning to the current view. Accounts are independent, and a selection survives card refreshes in the same page. Trends → 2 days temporarily shows recent readings; Off removes the curves; the tray always shows its current cycle. See `quota-curve.test.cjs` and the [history limits and reset inference](providers-accounts.md#constraints-and-failure-behavior). - The Usage page's cards are packed into columns, never all stretched to a row's height (`packUsage`, #860): each card in that order goes to the leftmost column that ends highest, on 1px grid rows, so short cards stack beside a tall one. The last card in each column then reaches down to where the tallest column ends (a `min-height`, cleared before the cards are measured again), so cards side by side in one row are as tall as each other and a stack ends with the tall card beside it (ikunbots on X); content stays at each card's top. The page's order (DOM, dragging, Alt+arrows) stays `UsageOrder`. The column count is the most 260px columns that fit, or one fewer when that leaves much less empty room; it is chosen again only when the cards change or the width fits another number of columns, so a card opened or folded stays where it is, even as the scrollbar comes in. See `usage-pack.test.cjs`. - The Providers page has a search box over its list (#1614, `findProviders` in [`app.js`](../../internal/gui/assets/app.js)): the words typed keep the rows, on and off, whose text or data say them all: name, id, preset, addresses, every model's id and name, the account's user and plan and each login's, account names and key names. The Turned off fold stays open while searching; Escape or clearing the box shows every row and the fold as it was. A row that is on reorders by dragging its logo, Alt+↑/↓, Alt+Shift+↑/↓ (top, bottom) or its right-click menu (`openProviderMenu`: Move to top, Move up, Move down, Move to bottom). While searching, a step or a drop moves it among the rows shown (it takes the place of the row it passes, `stepProvider`, `shownToOn`) and the hidden ones keep their order; Move to top and Move to bottom go to the ends of the whole list. Every move saves the whole order through `POST /api/providers/arrange`. See `provider-find.test.cjs` and `provider-order.test.cjs`. -- Hide accounts (`window.hideAccounts` at the end of [`app.js`](../../internal/gui/assets/app.js), stored in `magpie.maskEmails`, which the panel follows) masks every account name and address in the page's text and tooltips. While it is on, an account's name on the provider editor's row (`accountNameButton`, and the one-account line) and on its Usage card (`quotaWho`), and on the tray panel's Usage card (`panelQuotaCard`'s `.pq-who`, in sight while the card is hovered), has an eye (`hideAccounts.eye`), in sight on hover or keyboard focus. A click shows that one account, its address and the name the user gave it together (`kin`), everywhere that page draws it, tooltips included, while the others stay hidden (yogurt36 on Discord, for a screen share). The accounts shown are a set held in memory that `hits()` skips; nothing stores them. The window and the panel are pages of their own, each with its own set: one shown in the window stays hidden in the panel and the other way round, so a screenshot of either shows only what was shown there. Closing the window hides them again: the page stays loaded while the window is hidden, so `hideMain` runs `mainClosedJS` (`hideAccounts.closed`) first. Putting the panel away hides the panel's again, from its `visibilitychange` (the one that drops `panelPeek`) (`account-eye.test.cjs`, `TestClosingHidesShownAccounts`). +- Hide accounts (`window.hideAccounts` at the end of [`app.js`](../../internal/gui/assets/app.js)) masks every account name and address in the window's text and tooltips, its menus and dialogs too, by the switch of the page in sight (`cur`, again on each `show`). Routing's and Usage's buttons, and Settings › Privacy's row, are one switch, stored in `magpie.maskEmails`, which the panel follows; the Providers page has its own (`#pvMask` beside its search box, `magpie.maskProviders`), so Routing's leaves Providers alone (a Discord user in #feedback). A `magpie.maskProviders` not stored yet starts from `magpie.maskEmails`, so one who had it on before keeps Providers hidden; while neither is chosen, both follow Mask personal data, and turning that on (`set(true, true)`) turns both on (`provider-mask.test.cjs`). While it is on, an account's name on the provider editor's row (`accountNameButton`, and the one-account line) and on its Usage card (`quotaWho`), and on the tray panel's Usage card (`panelQuotaCard`'s `.pq-who`, in sight while the card is hovered), has an eye (`hideAccounts.eye`), in sight on hover or keyboard focus. A click shows that one account, its address and the name the user gave it together (`kin`), everywhere that page draws it, tooltips included, while the others stay hidden (yogurt36 on Discord, for a screen share). The accounts shown are a set held in memory that `hits()` skips; nothing stores them. The window and the panel are pages of their own, each with its own set: one shown in the window stays hidden in the panel and the other way round, so a screenshot of either shows only what was shown there. Closing the window hides them again: the page stays loaded while the window is hidden, so `hideMain` runs `mainClosedJS` (`hideAccounts.closed`) first. Putting the panel away hides the panel's again, from its `visibilitychange` (the one that drops `panelPeek`) (`account-eye.test.cjs`, `TestClosingHidesShownAccounts`). - A new user's Agents page (the window's first page and the panel's Agents tab) has a *Get started* card above the agents in the welcome's place (wangye1644294 on X, `guideCard` in [`app.js`](../../internal/gui/assets/app.js)). Its three steps are: add a model source; connect an agent, where the agents magpie found that can be connected are named and each is connected in one click (`agents/connect`); and, optional, a routing group, with the most harmless starter template that can be made from the user's models (`provider.Templates`, Never stuck first) added in one click through `POST /api/groups/template`. Every tick comes from the state: the models magpie serves (`served` in `/api/state`, groups left out), an agent wired, or a group that isn't automatic. None comes from the card having been seen. The card goes once the first two steps are done. Its close button saves `settings.GuideHidden` through `POST /api/settings/guide`, so the panel, the window and a reload agree, and the Settings save keeps it. See `getting-started.test.cjs`. - A connected agent's row in the window opens and closes on a click anywhere on it that isn't one of its controls, as a disclosure row does on the Mac (NG_shiyu on X, `connectRow` in [`app.js`](../../internal/gui/assets/app.js)): the click is handed to the row's *Models {n}* link (`expandLink`), which stays the control the keyboard and a screen reader use and keeps `aria-expanded`. Buttons, links, inputs, anything with a role, the grip and the opened sheet (`.ag-exp`) keep their own clicks, and a click that ends a text selection does nothing. The panel's rows did this already (`agent-row-disclose.test.cjs`). - An agent whose own model menu is the list picked in magpie (ZCode, Claude Desktop, Cursor Private Inference, …: `listsMenu`) says that list as its ticks are, on its button and on the panel row (`menuSaid` in [`app.js`](../../internal/gui/assets/app.js)): every model ticked is *All N models*, one or two by their names, more as *Showing x / N models*, none as *No models*. It never says the first names and a +N: routing groups come first, so that read as a pick of one group and one model while every model was on (NG_shiyu on X). Other agents' start pickers still say the one model or group they start on (`agent-menu-label.test.cjs`). diff --git a/internal/gui/assets/app.css b/internal/gui/assets/app.css index 7e63a14b5..b2c18ed9c 100644 --- a/internal/gui/assets/app.css +++ b/internal/gui/assets/app.css @@ -2430,7 +2430,13 @@ body.window .ag-sk-icon { width: 22px; height: 22px; border-radius: 6px; } /* Providers' search (#1614): a toolbar field over the list, at its right edge as Settings' is; across the page when the window is narrow. While searching, the Turned off fold stays open on the ones that match. */ -#view-providers .pv-head { display: flex; justify-content: flex-end; margin: 0 0 10px; flex: none; } +#view-providers .pv-head { display: flex; justify-content: flex-end; gap: 8px; margin: 0 0 10px; flex: none; } +/* Hide accounts, on Routing, Usage and (its own switch) Providers. On, it + says so in its struck eye and its words, a shade darker: a page tool, + not a banner */ +.rt-mask { display: inline-flex; align-items: center; gap: 5px; flex: none; } +.rt-mask svg { width: 13px; height: 13px; flex: none; } +.rt-mask[aria-pressed="true"] { color: var(--fg-2); } #view-providers .pv-q { flex: 0 1 220px; min-width: 120px; } #view-providers .pv-none { margin: 18px 2px; } #view-providers .off-head .fold:disabled { cursor: default; opacity: 1; } @@ -3992,6 +3998,7 @@ body.panel .modal { padding: 16px 12px; } body.web .usage-head > .segs { max-width: 100%; flex-wrap: wrap; } body.web .usage-head > .grow, body.web .sess-tools > .grow { display: none; } body.web .sess-filter { order: 1; flex: 1 1 100%; width: 100%; } + body.web .pv-head > .rt-mask { order: 2; } body.web .sess-pick { min-height: 44px; max-width: 100%; font-size: 14px; } body.web .stats, body.web .stats.six { grid-template-columns: repeat(2, minmax(0, 1fr)); } body.web .kpi small { white-space: normal; overflow: visible; overflow-wrap: anywhere; } diff --git a/internal/gui/assets/app.js b/internal/gui/assets/app.js index 67f768d73..bd606eed9 100644 --- a/internal/gui/assets/app.js +++ b/internal/gui/assets/app.js @@ -21785,7 +21785,7 @@ function renderRedact(s, keep) { row(t("Mask personal data"), t("Emails, phone numbers, ID and bank card numbers too"), onOff(s.redactPersonal, (redactPersonal) => { // turned on, the accounts on screen are hidden too - if (redactPersonal) window.hideAccounts?.set(true); + if (redactPersonal) window.hideAccounts?.set(true, true); savePrefs({ ...keep, redactPersonal }); })); // each other kind of personal data, on or off of its own while personal @@ -23172,6 +23172,7 @@ async function show(v) { magpie.call(view, "leave"); } view = v; + window.hideAccounts?.page(); // the page the reader leaves is the one the window opens on next (keptView) if (mode === "window") { try { localStorage.setItem("magpie.lastView", v); } catch { /* not kept */ } } const title = magpie.page(v)?.title ?? ({ agents: "Agents", providers: "Providers", plugins: "Plugins", settings: "Settings" })[v]; @@ -24285,22 +24286,24 @@ window.noteAccounts = noteAccounts; // it is no account, so only an address is hidden there (#1973: the // project lingting-react-ui with the account lingting) const NAMELESS = "#sessionsPane, #contextPane"; - // chosen is the Hide accounts choice made on this computer; until one is, - // the accounts are hidden while Privacy masks personal data, which is - // where one who wants them kept out of sight turns it on (inaction on - // Discord: another computer with it on still showed the addresses) - let masked = false, chosen = null; - try { chosen = localStorage.getItem("magpie.maskEmails"); masked = chosen === "1"; } catch {} - // where it hides: the whole window, every page, its model pickers, menus - // and dialogs, which sit outside a page (PaulT on Discord: a Codex - // account's address in the tray's picker stayed in sight; Zhenbao TONG: - // the window's Providers page showed every account while the tray hid - // them). Routing and Usage each have a button for it; the tray panel - // follows the window's setting. - const targets = [["body", mode === "panel" ? [] : ["#rtMask", "#usageMask"]]]; - const pages = targets.map(([v, bs]) => { - const view = $(v); - if (!view) return () => {}; + // A switch's chosen is the Hide accounts choice made on this computer; + // until one is, the accounts are hidden while Privacy masks personal + // data (inaction on Discord: another computer with it on still showed + // the addresses). It hides in the whole window, its menus and dialogs + // (PaulT, Zhenbao TONG on Discord), by the switch of the page in sight: + // Routing's and Usage's, or the Providers page's own (#feedback: the one + // on Routing hid Providers too). The tray panel follows the first. + const sw = [["magpie.maskEmails", ["#rtMask", "#usageMask"]], ["magpie.maskProviders", ["#pvMask"]]].map(([k, bs]) => { + let c = null; + try { c = localStorage.getItem(k); } catch {} + return { k, c, on: c === "1", btns: mode === "panel" ? [] : bs.map((b) => $(b)).filter(Boolean) }; + }); + // one who chose before Providers had its own keeps that choice there + if (sw[1].c === null && sw[0].c !== null) { Object.assign(sw[1], { c: sw[0].c, on: sw[0].on }); try { localStorage.setItem(sw[1].k, sw[1].c); } catch {} } + const cur = () => sw[+(mode !== "panel" && view === "providers")]; + let masked = false; + const page = (() => { + const view = document.body; function mask(root = view) { const all = finder(), reOf = (e) => e?.closest(NAMELESS) ? EMAIL : all; const walk = document.createTreeWalker(root, NodeFilter.SHOW_TEXT), found = []; @@ -24359,56 +24362,56 @@ window.noteAccounts = noteAccounts; for (const e of roots) if (![...roots].some((o) => o !== e && o.contains(e))) mask(e); watch.observe(view, OBS); }); - const btns = bs.map((b) => $(b)).filter(Boolean); - for (const btn of btns) btn.onclick = () => { - setMasked(!masked); - // pixelated in when asked for, not again each time the page redraws - view.classList.add("masking"); - clearTimeout(btn._t); - btn._t = setTimeout(() => view.classList.remove("masking"), 450); - }; return (on) => { - for (const btn of btns) { - btn.setAttribute("aria-pressed", String(on)); - // what it is now, in its icon and its words: an open eye while the - // accounts show, struck through once they're hidden - btn.querySelector("path").setAttribute("d", on ? EYE_OFF : EYE); - const label = btn.querySelector("[data-t]"); - label.dataset.en = on ? "Accounts hidden" : "Hide accounts"; - label.textContent = t(label.dataset.en); - // and how to have them back, for one who never turned it on (#653) - btn.dataset.enTitle = on ? "Accounts are masked for a screenshot — click to show them" - : "Mask the accounts on this page — email addresses and account names — for a screenshot to share"; - btn.title = t(btn.dataset.enTitle); - } + masked = on; view.classList.toggle("masked", on); // a name learnt since it was masked: hidden afresh if (on) { watch.disconnect(); unmask(); mask(); watch.observe(view, OBS); } else { watch.disconnect(); unmask(); } }; - }); - function setMasked(on, keep) { - masked = on; - if (!keep) { chosen = on ? "1" : "0"; try { localStorage.setItem("magpie.maskEmails", chosen); } catch {} } - for (const set of pages) set(on); + })(); + function setMasked(s, on, keep) { + s.on = on; + if (!keep) { s.c = on ? "1" : "0"; try { localStorage.setItem(s.k, s.c); } catch {} } + for (const btn of s.btns) { + btn.setAttribute("aria-pressed", String(on)); + // what it is now, in its icon and its words: an open eye while the + // accounts show, struck through once they're hidden + btn.querySelector("path").setAttribute("d", on ? EYE_OFF : EYE); + const label = btn.querySelector("[data-t]"); + label.dataset.en = on ? "Accounts hidden" : "Hide accounts"; + label.textContent = t(label.dataset.en); + // and how to have them back, for one who never turned it on (#653) + btn.dataset.enTitle = on ? "Accounts are masked for a screenshot — click to show them" + : "Mask the accounts on this page — email addresses and account names — for a screenshot to share"; + btn.title = t(btn.dataset.enTitle); + } + page(cur().on); } + for (const s of sw) for (const btn of s.btns) btn.onclick = () => { + setMasked(s, !s.on); + // pixelated in when asked for, not again each time the page redraws + document.body.classList.add("masking"); + clearTimeout(btn._t); + btn._t = setTimeout(() => document.body.classList.remove("masking"), 450); + }; const kin = (u, pid) => { const k = [u]; for (const p of providers?.providers || []) if (p.id === pid) for (const m of [p.accountNames, p.accountUsers]) for (const [a, n] of Object.entries(m || {})) if (a === low(u) || n === u) k.push(a, n); for (const q of quotas || []) if (q.provider === pid && (q.user === u || q.alias === u)) k.push(q.user, q.alias); return k.filter(Boolean).map((x) => sk(pid, x)); }; - const paint = (b) => { + const paintEye = (b) => { const on = shown.has(sk(b._p, b._u)); b.setAttribute("aria-pressed", on); b.title = t(on ? "Hide this account" : "Show this account"); b.querySelector("path").setAttribute("d", on ? EYE : EYE_OFF); }; const redraw = () => { - document.querySelectorAll(".acct-eye").forEach(paint); - if (masked) for (const set of pages) set(true); + document.querySelectorAll(".acct-eye").forEach(paintEye); + if (masked) page(true); }; - // Settings' Privacy has the same switch, and the settings follow + // Settings' Privacy has the first switch, and the settings follow window.hideAccounts = { eye: (u, p) => { const b = el("button", "acct-eye"); @@ -24417,7 +24420,7 @@ window.noteAccounts = noteAccounts; b.setAttribute("aria-label", t("Show this account")); b.append(svg("", 13, 2)); b.firstChild.setAttribute("viewBox", "0 0 24 24"); - paint(b); + paintEye(b); b.onclick = (e) => { e.stopPropagation(); const on = !shown.has(sk(p, u)); @@ -24429,17 +24432,21 @@ window.noteAccounts = noteAccounts; // the window closed (hideMain) or the panel put away: every account // hidden again closed: () => { if (shown.size) { shown.clear(); redraw(); } }, - on: () => masked, - set: (on) => setMasked(on), - follow: (personal) => { if (chosen === null && personal !== masked) setMasked(personal, true); }, + on: () => sw[0].on, + // all: personal data masked from now, so every page's switch too + set: (on, all) => { for (const s of all ? sw : [sw[0]]) setMasked(s, on); }, + follow: (personal) => { for (const s of sw) if (s.c === null && personal !== s.on) setMasked(s, personal, true); }, + // another page in sight: its own switch + page: () => { if (cur().on !== masked) page(cur().on); }, }; // turned in the window: the tray panel (or another window) follows window.addEventListener("storage", (e) => { - if (e.key !== "magpie.maskEmails") return; - chosen = e.newValue; - if ((e.newValue === "1") !== masked) setMasked(e.newValue === "1", true); + const s = sw.find((x) => x.k === e.key); + if (!s) return; + s.c = e.newValue; + if ((e.newValue === "1") !== s.on) setMasked(s, e.newValue === "1", true); }); - setMasked(masked, true); + for (const s of sw) setMasked(s, s.on, true); })(); // Opened on a magpie://import link: fetch what it describes (once — the diff --git a/internal/gui/assets/index.html b/internal/gui/assets/index.html index 2b6d4e3f4..6d9e6a18b 100644 --- a/internal/gui/assets/index.html +++ b/internal/gui/assets/index.html @@ -131,7 +131,7 @@
- +
diff --git a/internal/gui/assets/plugins/redact/page.js b/internal/gui/assets/plugins/redact/page.js index ebbb695e4..2cbc66bc9 100644 --- a/internal/gui/assets/plugins/redact/page.js +++ b/internal/gui/assets/plugins/redact/page.js @@ -246,7 +246,7 @@ function maskTurnOn(e) { .then(() => { const back = maskWasPersonal; maskWasPersonal = false; - if (back) window.hideAccounts?.set(true); + if (back) window.hideAccounts?.set(true, true); return savePrefs({ ...prefsKeep(prefs), redact: true, ...(back ? { redactPersonal: true } : {}) }); }) .then(() => { maskDrawn = ""; drawMaskCard(); }) diff --git a/internal/gui/assets/plugins/routing/routing.css b/internal/gui/assets/plugins/routing/routing.css index e78ebbca0..412bea667 100644 --- a/internal/gui/assets/plugins/routing/routing.css +++ b/internal/gui/assets/plugins/routing/routing.css @@ -223,8 +223,8 @@ #view-routing .row-head { margin: 14px 0 6px; padding: 0 2px; gap: 0; } #view-routing .row-head .note { font-size: 11px; color: var(--faint); margin-left: 8px; } #view-routing .row-head .rt-livedot + .note { margin-left: 8px; } -.rt-mask, .rt-newgroup, .rt-gogroups { display: inline-flex; align-items: center; gap: 5px; } -.rt-mask svg, .rt-newgroup svg, .rt-gogroups svg { width: 13px; height: 13px; flex: none; } +.rt-newgroup, .rt-gogroups { display: inline-flex; align-items: center; gap: 5px; } +.rt-newgroup svg, .rt-gogroups svg { width: 13px; height: 13px; flex: none; } /* the routing groups, far below with many models: the head goes to them */ .rt-gogroups { margin-right: 6px; flex: none; } .rt-gogroups[data-fit="icon"] > span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; } @@ -234,9 +234,6 @@ requests, out of sight on a first look (#944) */ .rt-newgroup { margin-right: 6px; } .rt-gnew { display: inline-flex; align-items: center; gap: 4px; } -/* on, it says so in its struck eye and its words, a shade darker: a - page tool, not a banner */ -.rt-mask[aria-pressed="true"] { color: var(--fg-2); } /* an email, hidden: stand-in letters of its shape, softly blurred — coming in out of focus when asked for */ .pii { filter: blur(2.2px); opacity: .5; user-select: none; } diff --git a/internal/gui/tests/account-eye.test.cjs b/internal/gui/tests/account-eye.test.cjs index f7cf771cb..b0ff800d7 100644 --- a/internal/gui/tests/account-eye.test.cjs +++ b/internal/gui/tests/account-eye.test.cjs @@ -114,7 +114,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", assert.equal(await eye(ME).count(), 1); assert.equal(await opacity(eye(ME)), "none", "no eye while Hide accounts is off"); - await page.evaluate(() => hideAccounts.set(true)); + await page.evaluate(() => hideAccounts.set(true, true)); await sample(page); await page.waitForFunction(() => document.querySelectorAll("#sample .pii").length === 3); await page.waitForFunction((me) => document.querySelector(`.editor .acc[data-account-id="${me}"] .acct-user .pii`), ME); @@ -185,7 +185,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", assert.equal(await eye(ME).getAttribute("aria-pressed"), "false"); // and Hide accounts off: the eyes go - await page.evaluate(() => hideAccounts.set(false)); + await page.evaluate(() => hideAccounts.set(false, true)); assert.equal(await opacity(eye(ME)), "none"); assert.equal(await page.locator("select").count(), 0, "no native select"); diff --git a/internal/gui/tests/provider-mask.test.cjs b/internal/gui/tests/provider-mask.test.cjs new file mode 100644 index 000000000..3f799fdfe --- /dev/null +++ b/internal/gui/tests/provider-mask.test.cjs @@ -0,0 +1,140 @@ +// Run with Node's test runner and Playwright on the module path; see README.md. +// The Providers page has a Hide accounts switch of its own, and each page +// follows its own (a Discord user in #feedback: Routing's switch hid the +// Providers page too, which had no switch to turn it back). One who had +// Hide accounts on before keeps Providers hidden: its switch starts from +// the choice made then. Every language, wide and narrow; no backend. +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 MAIL = "dev.one@example.com"; + +function serve(lang) { + const base = { icon: "generic", chat: "", responses: "", anthropic: "", catalog: "", agents: [], fallback: [], headers: {}, keyList: [], proxy: "" }; + const providers = { providers: [ + { ...base, id: "codex", name: "Codex", icon: "codex-color", models: [{ id: "gpt-6", name: "GPT-6", on: true }], account: { agent: "codex", agentName: "Codex", user: MAIL, plan: "PLUS", logins: [{ agent: "codex", user: MAIL, plan: "PLUS", active: true, on: true }] } }, + ], presets: [], excluded: [], gateway: { running: true, window: true } }; + const 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({ agents: [], profiles: [], settings }); + if (url.pathname === "/api/settings") return json(settings); + if (url.pathname === "/api/providers") return json(providers); + if (url.pathname === "/api/groups") return json({ 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)]; + try { await route.fulfill({ body: await fs.readFile(file), contentType }); } catch { await route.fulfill({ status: 404, body: "" }); } + }; +} + +const KEYS = ["Hide accounts", "Accounts hidden", "Mask the accounts on this page — email addresses and account names — for a screenshot to share", "Accounts are masked for a screenshot — click to show them"]; + +for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) { + for (const lang of ["en", "zh", "zh-TW", "ja", "de"]) { + for (const width of [1000, 420]) { + // stored: what an earlier version left in magpie.maskEmails + const open = async (t, stored) => { + const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" })); + t.after(() => browser.close()); + const context = await browser.newContext({ viewport: { width, height: 800 }, reducedMotion: "reduce" }); + await context.addInitScript((v) => { try { if (!sessionStorage.getItem("seeded")) { if (v !== null) localStorage.setItem("magpie.maskEmails", v); sessionStorage.setItem("seeded", "1"); } } catch {} }, stored); + const page = await context.newPage(); + page.setDefaultTimeout(5000); + page.setDefaultNavigationTimeout(60000); + page.errors = []; + page.on("pageerror", (e) => page.errors.push(e.message)); + await page.route("**/*", serve(lang)); + return page; + }; + const provText = (page) => page.evaluate(() => document.querySelector("#providers").innerText); + const listed = (page) => page.waitForFunction(() => document.querySelector("#providers")?.innerText.includes("Codex")); + + test(`${engine} ${lang} ${width}: Providers' Hide accounts is its own`, async (t) => { + const page = await open(t, null); + await page.goto("http://magpie.test/?view=routing"); + await page.locator("#rtMask").waitFor(); + await page.evaluate((m) => { const d = document.createElement("div"); d.id = "sample"; d.textContent = "Codex as " + m; document.querySelector("#view-routing").append(d); }, MAIL); + + // Routing's switch hides Routing's accounts + await page.locator("#rtMask").click(); + await page.waitForFunction(() => document.querySelector("#sample .pii")); + + // and leaves the Providers page alone, whose own switch is off + await page.evaluate(() => show("providers")); + await listed(page); + const pv = page.locator("#pvMask"); + await pv.waitFor(); + assert.ok((await provText(page)).includes(MAIL), "Providers shows the account while its own switch is off"); + assert.equal(await page.locator("#view-providers .pii").count(), 0); + assert.equal(await pv.getAttribute("aria-pressed"), "false"); + assert.equal(await pv.locator("[data-t]").textContent(), await page.evaluate((k) => t(k), KEYS[0])); + assert.equal(await pv.getAttribute("title"), await page.evaluate((k) => t(k), KEYS[2])); + + // placed as Routing's: in the page's head row, at its right end + const box = await pv.boundingBox(), q = await page.locator("#pvQ").boundingBox(); + assert.ok(Math.abs((box.y + box.height / 2) - (q.y + q.height / 2)) < 4, `beside the search box: ${JSON.stringify([box, q])}`); + assert.ok(box.x >= q.x + q.width - 1, `at the right end: ${JSON.stringify([box, q])}`); + assert.ok(box.x + box.width <= width, "inside the window"); + + // turned on here: Providers hidden, the choice kept + await pv.click(); + await page.waitForFunction(() => document.querySelector("#view-providers .pii")); + assert.ok(!(await provText(page)).includes(MAIL)); + assert.equal(await pv.getAttribute("aria-pressed"), "true"); + assert.equal(await pv.locator("[data-t]").textContent(), await page.evaluate((k) => t(k), KEYS[1])); + assert.equal(await page.evaluate(() => localStorage.getItem("magpie.maskProviders")), "1"); + + // Routing's turned off: Routing back, Providers still hidden + await page.evaluate(() => show("routing")); + await page.locator("#rtMask").click(); + await page.waitForFunction(() => !document.querySelector("#sample .pii")); + assert.equal(await page.locator("#sample").textContent(), "Codex as " + MAIL); + await page.evaluate(() => show("providers")); + assert.ok(await page.locator("#view-providers .pii").count() > 0, "Routing's switch turned Providers' off"); + assert.ok(!(await provText(page)).includes(MAIL)); + + // and after a reload + await page.reload(); + await listed(page); + await page.waitForFunction(() => document.querySelector("#view-providers .pii")); + assert.equal(await page.locator("#pvMask").getAttribute("aria-pressed"), "true"); + assert.equal(await page.evaluate(() => localStorage.getItem("magpie.maskEmails")), "0"); + + assert.equal(await page.locator("select").count(), 0, "no native select"); + assert.equal(await pv.evaluate((b) => getComputedStyle(b).borderLeftWidth), "0px"); + assert.ok(!/gradient/.test(await pv.evaluate((b) => getComputedStyle(b).backgroundImage)), "no gradient"); + assert.equal(await page.evaluate(() => document.documentElement.scrollWidth - document.documentElement.clientWidth), 0, `no sideways scroll at ${width}px`); + const missing = await page.evaluate(([keys, lang]) => lang === "en" ? [] : keys.filter((k) => !I18N[lang]?.[k]), [KEYS, lang]); + assert.deepEqual(missing, [], `every string has its ${lang}`); + assert.deepEqual(page.errors, []); + }); + + // one who had Hide accounts on keeps Providers hidden; one who had it + // off keeps it off, even with Mask personal data on later + for (const stored of ["1", "0"]) { + test(`${engine} ${lang} ${width}: Hide accounts ${stored === "1" ? "on" : "off"} before the update stays so on Providers`, async (t) => { + const page = await open(t, stored); + await page.goto("http://magpie.test/?view=providers"); + await listed(page); + await page.locator("#pvMask").waitFor(); + if (stored === "1") await page.waitForFunction(() => document.querySelector("#view-providers .pii")); + assert.equal(await page.locator("#view-providers .pii").count() > 0, stored === "1"); + assert.equal((await provText(page)).includes(MAIL), stored === "0"); + assert.equal(await page.locator("#pvMask").getAttribute("aria-pressed"), String(stored === "1")); + assert.equal(await page.evaluate(() => localStorage.getItem("magpie.maskProviders")), stored); + await page.evaluate(() => hideAccounts.follow(true)); + assert.equal(await page.locator("#pvMask").getAttribute("aria-pressed"), String(stored === "1"), "a default never turns the user's choice"); + assert.deepEqual(page.errors, []); + }); + } + } + } +} diff --git a/internal/gui/tests/window-mask.test.cjs b/internal/gui/tests/window-mask.test.cjs index 427b612ad..e8b594c85 100644 --- a/internal/gui/tests/window-mask.test.cjs +++ b/internal/gui/tests/window-mask.test.cjs @@ -82,8 +82,9 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", assert.ok(!(await page.locator("#floating").textContent()).includes(MAIL[1])); assert.ok(!(await page.locator("#floating").getAttribute("title")).includes("dev.two")); - // turned off in Settings › Privacy's switch: back as they were - await page.evaluate(() => window.hideAccounts.set(false)); + // turned off with the Providers page's own switch (under the + // editor here): back as they were + await page.evaluate(() => document.querySelector("#pvMask").click()); await page.waitForFunction(() => !document.querySelector(".pii")); assert.equal(await page.locator("#floating").textContent(), "Switch to " + MAIL[1]); assert.equal(await page.locator("#floating").getAttribute("title"), MAIL[1]);