gui: the window's pages down a sidebar in groups, the open page's tabs under it, and a button to have the header's tabs instead

From 1024 points wide (SIDE_AT) the window lays its pages down the left
as a Mac app's sidebar: Work (Agents, Sessions, Library), Models
(Providers, Routing, Gateway), Insights (Usage), Extend (Plugins), with
Settings and the gateway's address at the foot. The open page's own tabs
(Usage, Library, Plugins, Settings) are listed under it, opening and
folding on an iOS-like spring, and the page's strip is hidden. The header
becomes a breadcrumb, and pages whose head held only tools have them in
the title bar. Graphite: the open page is in the text's ink, not purple.
A pressed row darkens and never shrinks. The selection under the tabs
sets off as the row is pressed, on a 0.3s curve (it felt behind the
finger), and is the list's only shape: a sub-row hovered or pressed has
no ground of its own, which showed a block under the finger before the
selection slid there. The page's tab is clicked at once, so what is
typed next goes to it.

The title bar's button (or ⌃⌘S, Ctrl+Shift+S), there at every width,
picks the sidebar or the header's tabs. The choice is kept in
localStorage magpie.navLayout (side or top) at every width, so it is laid
out from the first frame; picked in a narrow window the sidebar is 184
points under 860. The two trade places in
a view transition: the sidebar slides, each tab flies to its place, and
the page slides as one. Without view transitions or under reduced
motion, the change is at once.

With nothing picked, narrower than 1024 the page beside a sidebar would
be narrower than Usage's requests table needs, so the header's tabs come
back. A resize
drops what a click held (heldWidth). Usage's KPI strip goes two to a line
by the room the page gives it (a container query), and Japanese counts
wrap there. Tests whose window is 1024+ were updated for the sidebar,
and docs/subsystems/gui-shell.md says how it works.

Run: sidebar.test.cjs and side-toggle.test.cjs 16/16 in chromium and
webkit, in en, zh, zh-TW, ja and de. Each was broken by hand (press
shrink, address cut, press glide, sub-row ground, view transition, kept
choice) and went red. Every page at 560 points with the sidebar picked,
zh and de, both engines: nothing scrolls sideways. session-identity's
ledger row sits under the footer beside the sidebar; WebKit's click
doesn't scroll to it, so the test wheels it up first. Animation frames were checked from a recorded video. The 105
affected GUI files in both engines; their reds were rerun alone and fixed
(filter-ime: the sub-row's click now at once; session-identity, above) or
fail the same on main (tray-logos). The full GUI suite in chromium, on
the rebase onto d5cae267a, was cut short at 352 tests on the owner's
"ship": 6 reds (account-alias, account-models, codex-auto-review,
codex-credits, context-text) each pass alone, here and on main d5cae267a,
so they are timing under the full run's load and are to be filed. After
rebasing onto e4e22b23e: sidebar, side-toggle, session-identity,
filter-ime, library-instr-busy, usage-speed-count and view-scrollbar,
50/50 in chromium and webkit. go build ./... passes.
This commit is contained in:
yetone
2026-10-12 00:41:34 +08:00
parent f11fdd854c
commit 18e82adc62
98 changed files with 1093 additions and 172 deletions
+1
View File
@@ -16,6 +16,7 @@ three.
| API and assets | `Handler` serves `assets/` (embedded with `//go:embed assets`) and the `/api/*` routes, such as `/api/state`, `/api/set` and `/api/agents/{action}/{id}`. `held` lets one API request's reads share one catalog build (`provider.Hold`), and drops it after any write. `revalidated` and `versionedPage` name each script by its content hash, so a cache never serves an old `app.js` under a new page; a file asked for under its current hash (`?v=`) is cached for good (`immutable`), anything else is revalidated by its ETag. | [`api.go`](../../internal/gui/api.go) |
| Browser mode | `StartWeb` serves the page and the gateway for `magpie web`. The browser signs in with a run key in a link. Gateway mode shows Providers, Gateway, Routing, Usage, Sessions, Plugins and Settings on a machine that is only a gateway. `webHandler` gzips the page's text files and the API's JSON for a browser that takes gzip (`webCompressed`, with a `-gzip` ETag that still answers 304); the app's own windows read the page in-process and get it uncompressed. | [`web.go`](../../internal/gui/web.go), [`gatewaymode.go`](../../internal/gui/gatewaymode.go) |
| The page | `app.js` keeps one state object per view and renders it into a list, with no framework. The views have their own files: `routing.js`, `library.js`, `plugins.js`, `sessions.js` and `context.js` (Usage's Context tab, and the context window card the Routing page draws under a request's story, fed by `/api/context` in `context.go`, which scores and tags each agent; clicking a part, a cell or an item opens its text from `/api/context/text`, the last 10 requests' masked bodies in memory (`openCtxText`), rendered 100 items and 20000 characters at a time; its "Tuned for you" cards are fed by `/api/tune` in `tune.go`, see [agent wiring](agent-wiring.md)). Strings go through `t()` with translations in `i18n.js` (zh, zh-TW, ja and de; the English text is the key and the fallback). zh-TW is Traditional Chinese with Taiwan's words; a system language of zh-TW, zh-HK, zh-MO or any zh-Hant picks it, and the tray menu and notifications follow (`trayLang`). Dropdowns use `openProtoMenu`. Every app menu (`openProtoMenu`, `openRowMenu`, `openSessCombo`) is placed by `placeMenu`: under its anchor, or over it when the window runs out below; one that fits neither way takes the larger room, its height held to it, and scrolls inside itself, and a scroll inside a menu doesn't close it (#1437, `removed-groups-menu-scroll.test.cjs`). The highest any popover goes is `popTop`: 8px under `header.top` on a Mac window, where the traffic lights are drawn over the page, and 8px from the top elsewhere; `placeMenu`, the field picker's `placePop` (which also holds `#pop`'s height to that room) and an agent's model list (`openAgentModels`) all use it (#1573, `popover-mac-chrome.test.cjs`). Scrolling is done only by `scrollOnPurpose(e)` with the reader's event. | [`assets/app.js`](../../internal/gui/assets/app.js), [`assets/i18n.js`](../../internal/gui/assets/i18n.js) |
| Window navigation | In the window from 1024 points wide (`SIDE_AT`, the same width as app.css's `side-nav` rules), `layoutNav` moves the brand, the pages (`#nav`) and Settings into the sidebar (`#side`): the pages in four groups (Work, Models, Insights, Extend; a group none of whose pages shows, as in gateway mode, leaves out its name), the gateway's address at its foot (`sideGwRead`, read from `/api/providers` only while there is a sidebar), and the header a breadcrumb (`renderCrumb`). The open page's own tabs (`NAV_SUBS`: Usage, Library, Plugins, Settings) are listed under it as `.nav-s` rows (`role="tab"`, `data-of` the page tab's id) and the page's strip is hidden; a row's click clicks that tab at once, the selection (`.nav-hl`) having set off as the row was pressed (`navSubGlide`; back if the press leaves the row), and is the list's only shape: a row hovered or pressed has no ground of its own, and a `MutationObserver` draws the list again when the strip changes. The list opens and folds with an iOS-like spring (`navSubEnter`, `navSubLeave`; none under reduced motion), and a folding list is out of reach at once. Narrower, the page beside a sidebar would be narrower than Usage's requests table needs (768 points), so they go back into the header's row, as a Mac sidebar gives way in a narrow window. At every width the reader can pick the sidebar or the header's tabs from the title bar's button (`#sideToggle`, ⌃⌘S or Ctrl+Shift+S; `toggleSideNav`), kept in localStorage `magpie.navLayout` (`side` or `top`) and so laid out from the first frame; none picked, the sidebar comes from `SIDE_AT`. Picked in a narrow window the sidebar is narrower (184 points under 860), and magpie web on a phone keeps its own tab bar and has no button. The two layouts trade places in a view transition (`navMorph`, app.css `.nav-morph`): the sidebar slides, each page's tab flies to its place in the other, and the page slides as one (its old image dropped, so no line prints twice); without view transitions or under reduced motion the change is at once. See `side-toggle.test.cjs`. A window made wider or narrower drops what a click held (`heldWidth`): the page laid out again isn't the click's doing. See `sidebar.test.cjs`. | [`assets/app.js`](../../internal/gui/assets/app.js), [`assets/app.css`](../../internal/gui/assets/app.css) |
| No GUI build | `-tags nogui` builds magpie without the GUI: `hasGUI` is false and `runGUI` says to use `magpie tui`. The files of `internal/gui` that need Wails build under `!nogui`. | [`gui_off.go`](../../gui_off.go) |
## Runtime path
+151 -3
View File
@@ -296,6 +296,141 @@ body.window .top.inrow .actions { margin-left: 0; }
@keyframes update-in { from { opacity: 0; transform: translateY(-3px) scale(.94); } }
@keyframes spin { to { transform: rotate(360deg); } }
/* ---- the sidebar (app.js layoutNav) -------------------------------------- */
/* the sidebar has the pages down the left, in groups, the open page's own
tabs under it, Settings and the gateway at the foot; the same #nav that
is the header's tabs otherwise */
.nav-gl, .nav-ic, .side-l, .crumb { display: none; }
/* at any width the reader picks it (app.js layoutNav); in a narrow window
it gives the page more of the room */
body.side-nav { --side-w: 212px; padding-left: var(--side-w); }
@media (max-width: 859px) { body.side-nav { --side-w: 184px; } }
.sidebar {
position: fixed; left: 0; top: 0; bottom: 0; z-index: 10; width: var(--side-w);
display: flex; flex-direction: column;
background: var(--bg); border-right: .5px solid var(--line);
}
.side-top { flex: none; display: flex; align-items: center; height: 46px; padding: 0 18px; }
.side-top .brand { font-size: 13.5px; }
/* the traffic lights are the sidebar's top left, as in a Mac app's sidebar;
the magpie beside them, level with them (see .top above) */
body.window.mac .side-top { height: calc(50px / var(--zoom, 1)); padding: calc(2px / var(--zoom, 1)) 0 0 calc(84px / var(--zoom, 1)); }
/* Windows' title bar above already shows the icon and the name */
body.window:not(.mac):not(.linux):not(.web) .side-top { height: 10px; }
.side-scroll { flex: 1; min-height: 0; overflow-y: auto; padding: 0 10px 10px; scrollbar-width: thin; }
.side-foot { flex: none; max-height: 55%; overflow-y: auto; display: flex; flex-direction: column; gap: 1px; padding: 8px 10px 10px; border-top: .5px solid var(--line-2); }
body.side-nav #nav { position: static; transform: none; display: flex; flex-direction: column; gap: 1px; padding: 0; border-radius: 0; }
body.side-nav .nav-gl { display: block; padding: 14px 8px 4px; font-size: 11px; font-weight: 500; letter-spacing: .04em; color: var(--muted); }
body.side-nav .nav-gl:first-child { padding-top: 2px; }
body.side-nav :is(#nav button[data-view], #prefs) {
display: flex; align-items: center; justify-content: flex-start; gap: 9px;
width: 100%; height: 30px; padding: 0 8px; border-radius: 7px;
font-size: 13px; color: var(--fg-2); text-align: left; white-space: nowrap;
}
body.side-nav :is(#nav button[data-view], #prefs) > span { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
body.side-nav :is(#nav button[data-view], #prefs):hover:not(.on) { background: var(--pill); color: var(--fg); }
body.side-nav :is(#nav button[data-view], #prefs).on { background: var(--card); color: var(--fg); box-shadow: var(--seg-edge); font-weight: 500; }
body.side-nav .nav-ic { display: block; flex: none; color: var(--muted); }
body.side-nav #prefs svg { flex: none; width: 15px; height: 15px; margin: 0 .5px; color: var(--muted); }
/* graphite, as a Mac sidebar is: no colour of its own, the page open in the
text's own ink; the accent is kept for what acts */
body.side-nav :is(#nav button.on .nav-ic, #prefs.on svg) { color: var(--fg); }
body.side-nav .side-l { display: inline; }
body.side-nav #nav button.has-dot::after { top: 50%; right: 10px; margin-top: -3px; width: 6px; height: 6px; }
/* the open page's tabs, under it on a thin line */
.nav-sub { position: relative; display: flex; flex-direction: column; gap: 1px; margin: 2px 0 6px 16px; padding-left: 8px; }
.nav-sub.moving { overflow: hidden; }
.nav-sub::before { content: ""; position: absolute; left: 0; top: 3px; bottom: 3px; width: 1px; background: var(--line); }
.nav-sub > button { position: relative; z-index: 1; display: flex; align-items: center; gap: 6px; height: 26px; padding: 0 10px; border-radius: 6px; font-size: 12.5px; color: var(--ctl-fg); text-align: left; white-space: nowrap; transition: color .2s var(--ease); }
.nav-sub > button > span { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.nav-sub > button > em { margin-left: auto; font-style: normal; font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
/* the selection (.nav-hl) is the only shape in the list: a row hovered or
pressed has no ground of its own, which would show where the finger is
before the selection slides there */
.nav-s:hover:not(.cur) { color: var(--fg); }
.nav-s.cur { color: var(--fg); font-weight: 500; }
/* a row pressed darkens, as a Mac sidebar's does: it never shrinks the way a
button does (.seg button:active, .icon:active below) */
body.side-nav #side button:active { transform: none; }
body.side-nav :is(#nav button[data-view], #prefs, .side-gw):active:not(.on) { background: color-mix(in srgb, var(--fg) 10%, transparent); }
/* the selection: one shape, sliding from row to row, setting off as the row
is pressed (app.js navSubGlide) and most of the way there in a tenth of a
second, so it is under the finger, not catching up with it */
.nav-hl { position: absolute; z-index: 0; top: 0; left: 8px; right: 0; height: 26px; border-radius: 6px; background: color-mix(in srgb, var(--fg) 6.5%, transparent); pointer-events: none; will-change: transform; transition: transform .3s cubic-bezier(.25, .9, .3, 1), height .3s cubic-bezier(.25, .9, .3, 1); }
.nav-hl.still { transition: none; }
@media (prefers-reduced-motion: reduce) { .nav-hl { transition: none; } }
/* beside the sidebar a page whose head holds only its tools has them in the
title bar, to the right of where the reader is (app.js sets the room);
the head's own row goes, the empty band it left with it. The bar between
the tools still drags the window. A page moving in only fades: a moving
ancestor would carry the pinned tools off the bar while it moves */
body.side-nav .view { animation-name: fade-in; }
body.side-nav :is(#view-library .lib-head, #view-plugins .pm-head, #view-settings .set-head) {
position: fixed; z-index: 11; top: 0; left: var(--tools-l, 50%); right: var(--tools-r, 64px);
height: var(--top-h, 46px); min-height: 0; margin: 0; padding: 0;
display: flex; flex-wrap: nowrap; align-items: center; justify-content: flex-end; gap: 10px;
pointer-events: none; --wails-draggable: drag;
}
body.side-nav.mac :is(#view-library .lib-head, #view-plugins .pm-head, #view-settings .set-head) { padding-top: calc(2px / var(--zoom, 1)); }
body.side-nav :is(#view-library .lib-head, #view-plugins .pm-head, #view-settings .set-head) > * { pointer-events: auto; --wails-draggable: no-drag; min-width: 0; }
body.side-nav :is(#view-library .lib-head, #view-plugins .pm-head)::before { display: none; }
body.side-nav :is(#view-library .lib-headacts) { flex-wrap: nowrap; }
body.side-nav :is(#view-library, #view-plugins, #view-settings) { padding-top: 8px; }
/* the gateway, under Settings: where it listens; a click opens its page */
.side-gw { display: flex; align-items: center; gap: 8px; height: 26px; margin-top: 2px; padding: 0 9px; border-radius: 6px; font-size: 11.5px; color: var(--muted); text-align: left; white-space: nowrap; }
.side-gw:hover { background: var(--pill); color: var(--fg-2); }
.side-gw > i { flex: none; width: 7px; height: 7px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 3px var(--green-soft); }
.side-gw.off > i { background: var(--faint); box-shadow: none; }
.side-gw > span { min-width: 0; overflow: hidden; text-overflow: ellipsis; font-variant-numeric: tabular-nums; }
/* beside the sidebar the header says where the reader is, "Work / Library /
MCP servers", and holds the icons; the pages' own tab strips are the
sidebar's now */
body.side-nav .top, body.window.mac.side-nav .top { padding-left: 20px; }
body.side-nav .crumb { display: flex; align-items: baseline; gap: 7px; min-width: 0; overflow: hidden; white-space: nowrap; font-size: 13.5px; }
.crumb > span { color: var(--muted); }
.crumb > i { font-style: normal; color: var(--faint); }
.crumb > b { font-weight: 600; color: var(--fg); overflow: hidden; text-overflow: ellipsis; }
body.side-nav :is(#usageTab, #view-library .lib-tabs, #view-plugins .lib-tabs, #setTabs) { display: none !important; }
/* the sidebar's button (app.js toggleSideNav), in the title bar where a Mac
app has it: the drawing's left pane filled while the sidebar shows */
.side-toggle { flex: none; }
.side-toggle .st-pane { fill: currentColor; opacity: .32; transition: opacity .3s var(--ease); }
body:not(.side-nav) .side-toggle .st-pane { opacity: 0; }
@media (prefers-reduced-motion: reduce) { .side-toggle .st-pane { transition: none; } }
/* the two layouts trade places as one motion (app.js navMorph): the sidebar
slides in from the window's edge or back to it, each page's tab flies to
its place in the other, and the page moves over, all on the spring the
sidebar's lists open on. Each piece is drawn at its own size, never
stretched, the old fading as the new comes in */
.nav-morph #side { view-transition-name: side; }
.nav-morph .brand { view-transition-name: brand; }
.nav-morph #sideToggle { view-transition-name: side-toggle; }
.nav-morph .top .actions { view-transition-name: actions; }
.nav-morph .view:not([hidden]) { view-transition-name: page; }
.nav-morph #nav button[data-view="agents"] { view-transition-name: nav-agents; }
.nav-morph #nav button[data-view="sessions"] { view-transition-name: nav-sessions; }
.nav-morph #nav button[data-view="library"] { view-transition-name: nav-library; }
.nav-morph #nav button[data-view="providers"] { view-transition-name: nav-providers; }
.nav-morph #nav button[data-view="routing"] { view-transition-name: nav-routing; }
.nav-morph #nav button[data-view="gateway"] { view-transition-name: nav-gateway; }
.nav-morph #nav button[data-view="usage"] { view-transition-name: nav-usage; }
.nav-morph #nav button[data-view="plugins"] { view-transition-name: nav-plugins; }
::view-transition-group(*) { z-index: 1; animation-duration: .5s; animation-timing-function: cubic-bezier(.32, .72, 0, 1); }
::view-transition-old(*), ::view-transition-new(*) { inline-size: auto; block-size: auto; }
/* the sidebar's own panel under the tabs flying to it or from it, with the
rest of the window (a fixed panel is drawn last otherwise, over them) */
::view-transition-group(root), ::view-transition-group(side) { z-index: 0; }
/* the page slides as one, the new layout of it, its edge on the sidebar's:
two of it fading over each other would print every line twice */
::view-transition-old(page) { display: none; }
::view-transition-new(page) { animation: none; }
/* the icons at the header's right stay against it */
::view-transition-old(actions), ::view-transition-new(actions) { inset-inline-start: auto; inset-inline-end: 0; }
::view-transition-old(side):only-child { animation: side-out .5s cubic-bezier(.32, .72, 0, 1) both; }
::view-transition-new(side):only-child { animation: side-in .5s cubic-bezier(.32, .72, 0, 1) both; }
@keyframes side-in { from { transform: translateX(-100%); } }
@keyframes side-out { to { transform: translateX(-100%); } }
/* ---- lists ---------------------------------------------------------------- */
.view { flex: 1; min-height: 0; overflow-y: auto; padding: 0 12px 4px; display: flex; flex-direction: column; animation: view-in .24s var(--ease); }
@keyframes view-in { from { opacity: 0; transform: translateY(5px); } }
@@ -581,6 +716,7 @@ body.window .field.solo { grid-column: auto; }
/* the tabs sit on the head's middle line with the refresh beside them, not
at its top as .segs elsewhere do */
.usage-head > .segs { align-self: center; }
.usage-head > .ctx-range { display: flex; align-self: center; }
.subscription-usage { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); align-items: start; gap: 7px; margin-bottom: 8px; flex: none; }
/* packed into columns (packUsage): each card as tall as itself, placed on
rows a pixel high, the gap between cards in its place on them (#860) */
@@ -834,7 +970,9 @@ body.window .field.solo { grid-column: auto; }
.led-strip .blk { min-width: 0; padding: 11px 15px 10px; }
.led-strip .blk + .blk { border-left: 1px solid var(--line-2); }
.led-strip .k { display: block; font-size: 11px; color: var(--muted); }
.led-strip .v { display: block; margin-top: 2px; font-size: 22px; font-weight: 600; letter-spacing: -.02em; font-variant-numeric: tabular-nums; line-height: 1.2; white-space: nowrap; }
/* a figure too long for its card (Japanese's "75 トークン/秒(3 件)") goes on
to a second line before its count, never cut */
.led-strip .v { display: block; margin-top: 2px; font-size: 22px; font-weight: 600; letter-spacing: -.02em; font-variant-numeric: tabular-nums; line-height: 1.2; }
.led-strip .v.cost { color: var(--green); }
/* a figure in parts, as the Output speed card's speed and the replies it is
of: each part kept whole, the second going under the first in a card too
@@ -918,6 +1056,11 @@ body.window .field.solo { grid-column: auto; }
@media (max-width: 860px) {
.led-body { grid-template-columns: minmax(0, 1fr); gap: 8px; }
.led-rail { display: none; }
}
/* the cards two to a line by the width the page gives them, not the
window's: the sidebar beside the page takes its share */
.led-dash { container-type: inline-size; }
@container (max-width: 1000px) {
.led-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.led-strip .blk:nth-child(odd) { border-left: 0; }
.led-strip .blk:nth-child(n + 3) { border-top: 1px solid var(--line-2); }
@@ -1021,7 +1164,10 @@ body.window .field.solo { grid-column: auto; }
.led.tighter .model, .led.tighter .where-name { max-width: 110px; }
.led.tighter th, .led.tighter td { padding-left: 4px; padding-right: 4px; }
.led.tighter th { white-space: normal; }
.led-tight { font-size: 11.5px; color: var(--muted); }
/* only a pointer to the details: it gives way to what shows beside it (the
archive's "Upload failed"), cut short and whole in its tooltip, rather
than the line breaking in two under the reader */
.led-tight { flex: 1 1 0; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-size: 11.5px; color: var(--muted); }
.led-tight[hidden] { display: none; }
.led .where { color: var(--fg-2); }
.led .where-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@@ -1902,7 +2048,9 @@ body.window .ag-sk-icon { width: 22px; height: 22px; border-radius: 6px; }
/* a JSON body's tree: the fold arrow sits in the indent before its line,
taking no width, so the text is the JSON as printed; a line's copy
button shows on its hover, after the value */
.call-body code.jt { padding-left: 11px; }
/* the right: room for a line's copy icon (.jt-copy) past a value that fills
the line, which would otherwise hang out past the box and scroll it */
.call-body code.jt { padding-left: 11px; padding-right: 6px; }
.jt button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
/* no absolute positioning inside: Chromium's innerText would break the
line around a box taken out of the flow */
+323 -13
View File
@@ -4857,6 +4857,7 @@ async function loadProviders() {
else if (view === "gateway" && !$("#gateway").childElementCount) renderGatewayView();
const was = providers;
providers = await api("providers");
renderSideGw(providers.gateway);
// a reload's provider may be gone since
if (typeof editing === "string" && !providers.providers.some((p) => p.id === editing)) editing = null;
// a providers.json that can't be read is not a first use: no Add sheet
@@ -17523,7 +17524,7 @@ function ledFit() {
hint.id = "ledTight";
$("#ledSum").after(hint);
}
hint.textContent = t("Sent, Effort and the cache are in each row's details");
hint.textContent = hint.title = t("Sent, Effort and the cache are in each row's details");
hint.hidden = !tight;
}
@@ -17937,6 +17938,7 @@ function renderUsageTab() {
// the Context tab has its own range, in its pane
$("#period").hidden = on || usageTab === "context";
$("#sessRange").hidden = !on;
$("#ctxRange").hidden = usageTab !== "context";
$("#usagePane").hidden = usageTab !== "usage";
$("#ledgerPane").hidden = usageTab !== "requests";
$("#sessionsPane").hidden = !on;
@@ -19460,7 +19462,7 @@ function applyPrefs(s, rate) {
if (!prefsBusy && (s.textSize || 100) !== textSize) { textSize = s.textSize || 100; newTextSize(); applyZoom(textSize); }
const was = locale;
setLocale(s.lang);
if (was !== locale && mode === "window") queueMicrotask(() => slide($("#nav"), "nav"));
if (was !== locale && mode === "window") queueMicrotask(() => { if (!sideNav()) slide($("#nav"), "nav"); navSubs(); renderSideGw(); renderSideToggle(); });
return was !== locale;
}
@@ -21308,7 +21310,7 @@ function renderReplies(s, keep) {
l.id = "loopGuardRow";
const lwho = el("div", "who");
lwho.append(el("div", "name", t("Stop looping replies")),
el("div", "sub", t("A reply whose reasoning or text goes round the same few lines is ended with an error the agent can retry, not left to run to its output limit")));
el("div", "sub wraps", t("A reply whose reasoning or text goes round the same few lines is ended with an error the agent can retry, not left to run to its output limit")));
const lval = el("div", "val");
lval.append(segs([["off", t("Off")], ["on", t("On")]], s.noLoopGuard ? "off" : "on",
(v) => savePrefs({ ...keep, noLoopGuard: v === "off" })));
@@ -22349,6 +22351,11 @@ function hold(h) {
readerLeaves(v);
}
let holding = false; // one frame loop, whatever the clicks
// A window made wider or narrower lays the whole page out again, the sidebar
// coming or going with it: nothing the click did, and what it held is no
// longer where it was read, so the page isn't scrolled after it
let heldWidth = innerWidth;
addEventListener("resize", () => { if (innerWidth !== heldWidth) { heldWidth = innerWidth; held = null; } });
// A part that grows or shrinks as it plays (the agents' scroll unrolling
// above the button that unrolls it) is held again as soon as it is laid out,
// before it's painted: a frame's loop sees it only as the frame before left
@@ -22427,14 +22434,16 @@ async function show(v) {
$("#pageTitle").dataset.en = title;
$("#pageTitle").textContent = t(title);
if (mode === "window") {
for (const b of $("#nav").querySelectorAll("button")) {
for (const b of $("#nav").querySelectorAll("button[data-view]")) {
const on = b.dataset.view === v;
b.classList.toggle("on", on);
if (on) b.setAttribute("aria-current", "page"); else b.removeAttribute("aria-current");
}
slide($("#nav"), "nav"); navInSight();
if (!sideNav()) { slide($("#nav"), "nav"); navInSight(); }
}
$("#prefs").classList.toggle("on", v === "settings");
if (v === "settings") $("#prefs").setAttribute("aria-current", "page"); else $("#prefs").removeAttribute("aria-current");
navSubs();
for (const id of ["agents", "providers", "gateway", "routing", "usage", "sessions", "library", "plugins", "settings"]) $("#view-" + id).hidden = v !== id;
// back to where the reader was in it, and again once it has what it loads
const back = () => backToReader($("#view-" + v));
@@ -22465,7 +22474,7 @@ function syncURL() {
const s = q.size ? "?" + q : location.pathname;
if (s !== location.search) history.replaceState(null, "", s);
}
if (mode === "window") for (const b of $("#nav").querySelectorAll("button")) b.onclick = () => { show(b.dataset.view); b.blur(); };
if (mode === "window") for (const b of $("#nav").querySelectorAll("button[data-view]")) b.onclick = () => { show(b.dataset.view); b.blur(); };
// setGatewayMode shows or leaves out gateway mode's pages' tabs; the page
// open, one of them, gives way to Providers
function setGatewayMode(on) {
@@ -22474,7 +22483,8 @@ function setGatewayMode(on) {
if (mode !== "window") return;
for (const v of GATEWAY_HIDES) $(`#nav button[data-view="${v}"]`).hidden = on;
if (on && GATEWAY_HIDES.includes(view)) show("providers");
else slide($("#nav"), "nav");
else if (!sideNav()) slide($("#nav"), "nav");
navSubs();
}
// openSettings: the Settings page, in the window (the panel opens it there)
function openSettings() {
@@ -22567,7 +22577,7 @@ $(".top").addEventListener("dblclick", (e) => {
if (document.body.classList.contains("linux") && !e.target.closest("button, nav")) winRuntime.then((w) => w?.Window.ToggleMaximise());
});
if (mode === "window") { $("#open").remove(); $("#openMain").remove(); $("#quit").remove(); }
else { $("#nav").remove(); }
else { $("#nav").remove(); $("#side").remove(); }
if (mode !== "window" || !document.body.classList.contains("linux")) $("#winclose").remove();
// Config files may change underneath us (another magpie, an editor); reload when
@@ -22594,7 +22604,7 @@ function navInSight() {
if (nav.scrollLeft > l) nav.scrollLeft = l;
else if (nav.scrollLeft < r) nav.scrollLeft = r;
}
matchMedia("(max-width: 760px), (pointer: coarse) and (max-width: 1024px)").addEventListener?.("change", () => { fitTop(); navInSight(); });
matchMedia("(max-width: 760px), (pointer: coarse) and (max-width: 1024px)").addEventListener?.("change", () => { layoutNav(); fitTop(); navInSight(); });
// A narrow window has no room for the whole header: the name goes, leaving
// the magpie, and Update becomes its arrow; narrower still, the tabs stop
@@ -22602,14 +22612,17 @@ matchMedia("(max-width: 760px), (pointer: coarse) and (max-width: 1024px)").addE
// further still when they don't fit (the 560px window at 150%).
function fitTop() {
const top = $(".top"), nav = $("#nav"), brand = $(".brand"), actions = $(".actions");
// a phone's browser: the tabs have a row of their own (app.css), at their size
if (phoneWeb()) { top.classList.remove("tight", "cramped", "inrow", "crowded", "packed"); return; }
// a phone's browser: the tabs have a row of their own (app.css), at their size;
// and beside the sidebar the header holds only where the reader is and the icons
if (phoneWeb() || sideNav()) { top.classList.remove("tight", "cramped", "inrow", "crowded", "packed"); return; }
const fits = () => {
const a = actions.getBoundingClientRect();
// the buttons sit against the padding; under a page zoom (the text size)
// their edge can measure a hair past it, which isn't running off (#457)
if (a.right > top.getBoundingClientRect().right - parseFloat(getComputedStyle(top).paddingRight) + 0.5) return false;
const left = brand.offsetParent ? brand.getBoundingClientRect().right
// the sidebar's button, when shown, comes after the brand
const lead = $("#sideToggle")?.offsetParent ? $("#sideToggle") : brand;
const left = lead.offsetParent ? lead.getBoundingClientRect().right
: top.getBoundingClientRect().left + parseFloat(getComputedStyle(top).paddingLeft);
if (!nav?.offsetParent) return left + 8 <= a.left;
const n = nav.getBoundingClientRect();
@@ -22631,6 +22644,303 @@ const topFit = new ResizeObserver(fitTop);
for (const e of [".top", ".brand", ".actions"]) topFit.observe($(e));
document.fonts?.ready.then(fitTop);
// ---- the sidebar ----------------------------------------------------------
// A window wide enough has its pages down a sidebar, as a Mac app's: in
// groups, the open page's own tabs under it, Settings at its foot and the
// gateway's address under that, the header saying where the reader is
// ("Work / Library / MCP servers"). Narrower, and magpie web on a phone,
// the pages go back into the header as tabs and each page shows its own
// tabs again, as iPadOS's sidebar turns into a tab bar when it has no room.
// It is the same #nav, its buttons and handlers, moved between the two.
// (app.css's side-nav rules hold at the same width): narrower, the page
// beside it would be narrower than Usage's requests with their columns left
// out (768 points), and the sidebar gives way to the header's tabs, as a Mac
// app's sidebar does in a narrow window
var SIDE_AT = 1024;
var sideQuery = matchMedia(`(min-width: ${SIDE_AT}px)`);
function sideNav() { return document.body.classList.contains("side-nav"); }
// the reader's own layout, picked with the title bar's button
// (toggleSideNav) and kept for the window as a Mac app keeps its sidebar
// shown or hidden: "side" or "top" at every width, the sidebar narrower in a
// narrow window (app.css); none picked, the sidebar from SIDE_AT
var navPick = "";
try { navPick = localStorage.getItem("magpie.navLayout") || ""; } catch { /* by the width, then */ }
if (navPick !== "side" && navPick !== "top") navPick = "";
function layoutNav() {
if (mode !== "window") return;
// magpie web on a phone has its own tab bar and no title bar
const on = !phoneWeb() && (navPick ? navPick === "side" : sideQuery.matches);
if (layoutNav.done && on === sideNav()) {
// the button goes with the phone's layout all the same
const was = $("#sideToggle").hidden;
renderSideToggle();
if ($("#sideToggle").hidden !== was) fitTop();
return;
}
layoutNav.done = true;
const side = $("#side"), nav = $("#nav"), brand = $(".brand"), prefs = $("#prefs");
document.body.classList.toggle("side-nav", on);
side.hidden = !on;
$("#crumb").hidden = !on;
if (on) {
side.querySelector(".side-top").append(brand);
side.querySelector(".side-scroll").append(nav);
side.querySelector(".side-foot").prepend(prefs);
nav.querySelector(":scope > .thumb")?.remove();
} else {
$(".top").prepend(brand);
$("#crumb").after(nav);
$(".actions").insertBefore(prefs, $("#winclose"));
}
navSubsAt = "";
// the sidebar coming or going isn't a list opening
navSubs.quiet = true;
navSubs();
navSubs.quiet = false;
if (!on) { slide(nav, "nav"); navInSight(); } else { sideGwRead(); renderSideGw(); }
renderSideToggle();
fitTop();
}
// the sidebar's button in the title bar, as a Mac app has it, at every
// width; ⌃⌘S as the Mac's View menu has it
function renderSideToggle() {
const b = $("#sideToggle");
if (!b) return;
b.hidden = mode !== "window" || phoneWeb();
const label = t(sideNav() ? "Hide sidebar" : "Show sidebar");
const keys = web ? "" : /^Mac/.test(navigator.platform) ? "⌃⌘S" : "Ctrl+Shift+S";
b.title = keys ? `${label} (${keys})` : label;
b.setAttribute("aria-label", label);
b.setAttribute("aria-pressed", String(sideNav()));
}
function toggleSideNav() {
if (mode !== "window" || phoneWeb()) return;
navPick = sideNav() ? "top" : "side";
try { localStorage.setItem("magpie.navLayout", navPick); } catch { /* this time only */ }
navMorph(layoutNav);
}
// the two layouts trade places as one motion (app.css .nav-morph): the old
// drawn and the new laid out, the sidebar sliding and each tab flying to
// its place in the other; a webview without view transitions, or a reader
// who asked for less motion, has the new at once
function navMorph(change) {
if (navCalm() || !document.startViewTransition) { change(); return; }
const root = document.documentElement;
root.classList.add("nav-morph");
const vt = document.startViewTransition(change);
vt.finished.finally(() => root.classList.remove("nav-morph"));
}
// where the page shown keeps its own tabs: the sidebar lists them under it
// and picks them there, the page's own strip hidden (app.css)
var NAV_SUBS = {
usage: () => $("#usageTab"),
library: () => $("#view-library .lib-tabs"),
plugins: () => $("#view-plugins .lib-tabs"),
settings: () => $("#setTabs"),
};
function navSubItems(v) { return [...(NAV_SUBS[v]?.()?.querySelectorAll(":scope > button") || [])].filter((b) => !b.hidden); }
var navSubsAt = "";
function navSubs() {
if (mode !== "window") return;
const nav = $("#nav");
// a group none of whose pages shows (gateway mode's) leaves out its name
for (const gl of nav.querySelectorAll(".nav-gl")) {
let any = false;
for (let n = gl.nextElementSibling; n && !n.matches(".nav-gl"); n = n.nextElementSibling) if (n.dataset.view && !n.hidden) any = true;
gl.hidden = !any;
}
const side = sideNav();
const items = side ? navSubItems(view) : [];
const at = view === "settings" ? $("#prefs") : nav.querySelector(`button[data-view="${view}"]`);
const sig = [side, view, locale, ...items.map((b) => b.textContent.trim() + (b.classList.contains("on") ? "*" : ""))].join("|");
if (sig === navSubsAt) return;
navSubsAt = sig;
let box = document.querySelector(".nav-sub:not(.leaving)");
const want = side && at && items.length > 1;
// another page's list folds away as this one's opens, both at once
if (box && (!want || box.dataset.view !== view || box.previousElementSibling !== at)) { navSubLeave(box); box = null; }
if (want) {
const fresh = !box;
if (fresh) {
box = el("div", "nav-sub");
box.setAttribute("role", "tablist");
box.dataset.view = view;
box.append(el("i", "nav-hl"));
box.onkeydown = (e) => {
const all = [...box.querySelectorAll(".nav-s")], i = all.indexOf(document.activeElement);
const to = { ArrowDown: i + 1, ArrowUp: i - 1, Home: 0, End: all.length - 1 }[e.key];
if (i < 0 || to === undefined) return;
e.preventDefault();
all[(to + all.length) % all.length].focus();
};
at.after(box);
}
box.setAttribute("aria-label", at.querySelector("span[data-t]")?.textContent || "");
for (const s of box.querySelectorAll(".nav-s")) s.remove();
items.forEach((b, i) => {
const [name, n] = b.textContent.trim().split(" · ");
const s = el("button", "nav-s");
s.type = "button";
s.setAttribute("role", "tab");
if (b.id) s.dataset.of = b.id;
const cur = b.classList.contains("on");
s.classList.toggle("cur", cur);
s.setAttribute("aria-selected", String(cur));
s.tabIndex = cur ? 0 : -1;
s.append(el("span", "", name));
if (n) s.append(el("em", "", n));
// the selection goes as the finger comes down, as iOS's does, not once
// the page has drawn the tab; let go off the row, it goes back
s.onpointerdown = (e) => { if (e.button === 0) navSubGlide(box, s); };
s.onpointercancel = () => navSubGlide(box, box.querySelector(".nav-s.cur"));
s.onpointerleave = (e) => { if (e.buttons & 1) navSubGlide(box, box.querySelector(".nav-s.cur")); };
// the page draws its strip again as it likes: the one there now is
// clicked at once, so what is typed next goes to the tab picked (the
// press has set the selection off already)
s.onclick = () => {
navSubGlide(box, s);
for (const o of box.querySelectorAll(".nav-s")) o.classList.toggle("cur", o === s);
navSubItems(view)[i]?.click();
};
box.append(s);
});
navSubMark(box, !fresh);
if (fresh && !navSubs.quiet) navSubEnter(box);
}
renderCrumb(items);
}
// the sidebar's lists open and fold the way iOS's do: a spring that
// starts quick and settles slowly, the rows coming in one after another
var NAV_EASE = "cubic-bezier(.32, .72, 0, 1)";
const navCalm = () => matchMedia("(prefers-reduced-motion: reduce)").matches;
// the selection is one shape that slides to the row picked
function navSubMark(box, glide) {
const hl = box.querySelector(".nav-hl"), cur = box.querySelector(".nav-s.cur");
hl.classList.toggle("still", !glide);
hl.hidden = !cur;
if (!cur) return;
hl.style.transform = `translateY(${cur.offsetTop}px)`;
hl.style.height = cur.offsetHeight + "px";
if (!glide) requestAnimationFrame(() => hl.classList.remove("still"));
}
// the selection set off to a row now, ahead of the page (navSubMark puts
// it on the tab the page then shows)
function navSubGlide(box, row) {
const hl = box.querySelector(".nav-hl");
if (!hl || !row || hl.hidden) return;
hl.style.transform = `translateY(${row.offsetTop}px)`;
hl.style.height = row.offsetHeight + "px";
}
function navSubEnter(box) {
if (navCalm()) return;
const cs = getComputedStyle(box);
const to = { height: box.offsetHeight + "px", marginTop: cs.marginTop, marginBottom: cs.marginBottom, opacity: 1 };
box.classList.add("moving");
box.animate([{ height: "0px", marginTop: "0px", marginBottom: "0px", opacity: 0 }, to], { duration: 460, easing: NAV_EASE })
.finished.then(() => box.classList.remove("moving"), () => {});
[...box.querySelectorAll(".nav-s")].forEach((s, i) => s.animate(
[{ opacity: 0, transform: "translateY(-6px)" }, { opacity: 1, transform: "none" }],
{ duration: 380, delay: 60 + i * 28, easing: NAV_EASE, fill: "backwards" }));
box.querySelector(".nav-hl").animate([{ opacity: 0 }, { opacity: 1 }], { duration: 300, delay: 120, fill: "backwards" });
}
// a folding list is out of the way at once: not a tab, not reachable, not
// found by what looks for the sidebar's rows
function navSubLeave(box) {
box.classList.add("leaving");
box.removeAttribute("role");
box.inert = true;
for (const s of box.querySelectorAll(".nav-s")) s.classList.replace("nav-s", "nav-s-gone");
if (navCalm() || navSubs.quiet) { box.remove(); return; }
const cs = getComputedStyle(box);
box.classList.add("moving");
box.animate([{ height: box.offsetHeight + "px", marginTop: cs.marginTop, marginBottom: cs.marginBottom, opacity: 1 },
{ height: "0px", marginTop: "0px", marginBottom: "0px", opacity: 0 }], { duration: 380, easing: NAV_EASE, fill: "forwards" })
.finished.then(() => box.remove(), () => box.remove());
}
// the header beside the sidebar: the group, the page, and its tab
function renderCrumb(items) {
const c = $("#crumb");
if (!c || c.hidden) return;
const parts = [];
if (view === "settings") parts.push($("#prefs .side-l").textContent);
else {
const b = $(`#nav button[data-view="${view}"]`);
let gl = b?.previousElementSibling;
while (gl && !gl.matches(".nav-gl")) gl = gl.previousElementSibling;
if (gl) parts.push(gl.textContent);
if (b) parts.push(b.querySelector("span[data-t]").textContent);
}
const on = items.find((b) => b.classList.contains("on"));
if (on) parts.push(on.textContent.trim().split(" · ")[0]);
c.replaceChildren(...parts.flatMap((p, i) => i ? [el("i", "", "/"), el(i === parts.length - 1 ? "b" : "span", "", p)] : [el(parts.length === 1 ? "b" : "span", "", p)]));
}
// the gateway at the sidebar's foot: where it listens, or that it doesn't
var sideGwAt = null;
function sideGwRead() {
if (sideGwRead.due && sideNav() && !sideGwAt) api("providers").then((r) => renderSideGw(r?.gateway), () => {});
}
function renderSideGw(g) {
const b = $("#sideGw");
if (!b) return;
if (g) sideGwAt = g;
g = sideGwAt;
b.hidden = !g?.url;
if (b.hidden) return;
let host = g.url;
try { host = new URL(g.url).host; } catch {}
b.classList.toggle("off", !g.running);
const s = b.querySelector("span");
s.textContent = g.running ? t("Gateway") + " " + host : t("Gateway stopped");
// the address is what the line is for: a language whose word for the
// gateway leaves it no room ("Zugangspunkt") says the address alone, the
// word kept in its tooltip
if (g.running && s.scrollWidth > s.clientWidth) s.textContent = host;
b.title = g.running ? t("Gateway") + " " + g.url : g.url;
}
if (mode === "window") {
$("#sideGw").onclick = () => { show("gateway"); $("#sideGw").blur(); };
sideQuery.addEventListener?.("change", layoutNav);
layoutNav();
$("#sideToggle").onclick = toggleSideNav;
if (!web) addEventListener("keydown", (e) => {
const mac = /^Mac/.test(navigator.platform);
const mod = mac ? e.metaKey && e.ctrlKey && !e.shiftKey : e.ctrlKey && e.shiftKey && !e.metaKey;
if (!mod || e.altKey || e.repeat || e.code !== "KeyS") return;
e.preventDefault();
toggleSideNav();
}, true);
// the page's strip drawn again (a count, another language, a tab picked
// there or by a link) is drawn again in the sidebar, once a frame
let queued = false;
const again = () => { if (queued) return; queued = true; requestAnimationFrame(() => { queued = false; navSubs(); }); };
const mo = new MutationObserver(again);
for (const v of Object.keys(NAV_SUBS)) mo.observe($("#view-" + v), { childList: true, subtree: true, attributes: true, attributeFilter: ["class", "hidden"] });
// a page whose head is only its tools (Library, Plugins, Settings) has them
// in the title bar beside the sidebar (app.css): between where the reader
// is and the window's own buttons, so no row of its own stands empty
// measured on the next frame, not inside the observer's callback, which
// would ask for a second layout of the same frame
let toolsAt = 0;
const tools = () => {
if (toolsAt) return;
toolsAt = requestAnimationFrame(() => {
toolsAt = 0;
const top = $(".top"), c = $("#crumb").getBoundingClientRect(), a = $(".actions").getBoundingClientRect();
const st = document.documentElement.style;
const set = (k, v) => { if (st.getPropertyValue(k) !== v) st.setProperty(k, v); };
set("--top-h", top.offsetHeight + "px");
set("--tools-l", Math.ceil(c.right + 16) + "px");
set("--tools-r", Math.ceil(innerWidth - a.left + 8) + "px");
});
};
const ro = new ResizeObserver(tools);
for (const e of [$(".top"), $("#crumb"), $(".actions")]) ro.observe(e);
addEventListener("resize", tools);
// the address shown from the start, not only once a page has read the
// providers: read for the sidebar only while there is one
setTimeout(() => { sideGwRead.due = true; sideGwRead(); }, 1500);
}
document.addEventListener("visibilitychange", () => { if (!document.hidden) { load(true); wag(); } });
// an agent's config can be rewritten, or the agent run round magpie, while the
// window is up: ask what drifted now and then, and redraw only on a change —
@@ -23034,7 +23344,7 @@ if (mode === "window" && params.get("view") === "usage") {
history.replaceState(null, "", u);
}
if (mode === "window" && ["providers", "gateway", "routing", "usage", "sessions", "library", "plugins", "settings"].includes(params.get("view"))) show(params.get("view"));
else if (mode === "window" && !gatewayMode) slide($("#nav"), "nav");
else if (mode === "window" && !gatewayMode && !sideNav()) slide($("#nav"), "nav");
// in gateway mode the first page is Providers, Agents' tab gone
if (gatewayMode) setGatewayMode(true);
load();
+1 -1
View File
@@ -16,7 +16,7 @@ i.dot.free { background: var(--k-free); box-shadow: inset 0 0 0 1px color-mix(in
.ctx-card { position: relative; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px 12px; display: flex; flex-direction: column; gap: 14px; min-width: 0; font-variant-numeric: tabular-nums; }
.ctx-head { display: flex; align-items: center; gap: 8px; min-width: 0; }
.ctx-head .grow, .ctx-foot .grow, .ctx-contents-head .grow, .ctx-agent-head .grow, .ctx-agent-foot .grow, .ctx-tools .grow, .ctx-sess-head .grow { flex: 1; }
.ctx-head .grow, .ctx-foot .grow, .ctx-contents-head .grow, .ctx-agent-head .grow, .ctx-agent-foot .grow, .ctx-sess-head .grow { flex: 1; }
.ctx-title { font-size: 13px; font-weight: 600; color: var(--fg); white-space: nowrap; }
.ctx-model { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: var(--code-font, var(--code)); font-size: 11px; color: var(--muted); }
.ctx-state { display: inline-flex; align-items: center; gap: 5px; flex: none; height: 20px; padding: 0 8px; border-radius: 10px; font-size: 11px; font-weight: 500; background: var(--pill); color: var(--fg-2); }
+4 -4
View File
@@ -1124,14 +1124,14 @@
function renderContext() {
const pane = $("#contextPane");
if (!pane) return;
const tools = el("div", "sess-tools ctx-tools");
tools.append(segs(CTX_RANGES.map(([id, n]) => [id, t(n)]), ctxDays, (id) => {
// the range sits in the Usage page's own head, where the other tabs keep
// theirs, so no row of its own stands empty above the pane
$("#ctxRange")?.replaceChildren(segs(CTX_RANGES.map(([id, n]) => [id, t(n)]), ctxDays, (id) => {
ctxDays = id;
try { localStorage.setItem("magpie.ctxDays", id); } catch {}
loadContext();
}));
tools.append(el("span", "grow"));
pane.replaceChildren(tools);
pane.replaceChildren();
pane.classList.toggle("still", ctxDrawn && !!ctxData);
pane.classList.toggle("tune-still", tuneDrawn && !!tuneData);
ctxDrawn = !!ctxData, tuneDrawn = !!tuneData;
+24
View File
@@ -373,6 +373,8 @@ const I18N = {
"Usage": "用量",
"Library": "资源库",
"Settings": "设置",
"Hide sidebar": "隐藏侧边栏",
"Show sidebar": "显示侧边栏",
"By request": "按请求",
"By session": "按会话",
"No session ID": "未提供会话标识",
@@ -2027,6 +2029,10 @@ const I18N = {
// sync and backup
// OpenCode's provider plugins: Settings → Plugins, the add sheet's "From plugins"
"Plugins": "插件",
"Work": "使用",
"Insights": "观测",
"Extend": "扩展",
"Gateway stopped": "网关未运行",
"From plugins": "来自插件",
"signed in by an OpenCode plugin or a pi package": "由 OpenCode 插件或 pi 包登录",
"from the plugin {spec}": "来自插件 {spec}",
@@ -4709,6 +4715,8 @@ const I18N = {
"Usage": "用量",
"Library": "資源庫",
"Settings": "設定",
"Hide sidebar": "隱藏側邊欄",
"Show sidebar": "顯示側邊欄",
"By request": "按請求",
"By session": "按會話",
"No session ID": "未提供會話標識",
@@ -6324,6 +6332,10 @@ const I18N = {
"Copy the gateway URL": "複製閘道位址",
"Gateway URL": "閘道位址",
"Plugins": "外掛",
"Work": "使用",
"Insights": "觀測",
"Extend": "擴充",
"Gateway stopped": "閘道未執行",
"From plugins": "來自外掛",
"signed in by an OpenCode plugin or a pi package": "由 OpenCode 外掛或 pi 包登入",
"from the plugin {spec}": "來自外掛 {spec}",
@@ -9007,6 +9019,8 @@ const I18N = {
"Usage": "使用量",
"Library": "ライブラリ",
"Settings": "設定",
"Hide sidebar": "サイドバーを非表示",
"Show sidebar": "サイドバーを表示",
"By request": "リクエスト別",
"By session": "セッション別",
"No session ID": "セッション ID なし",
@@ -10643,6 +10657,10 @@ const I18N = {
"Copy the gateway URL": "ゲートウェイ URL をコピー",
"Gateway URL": "ゲートウェイ URL",
"Plugins": "プラグイン",
"Work": "利用",
"Insights": "観測",
"Extend": "拡張",
"Gateway stopped": "ゲートウェイ停止中",
"From plugins": "プラグインから",
"signed in by an OpenCode plugin or a pi package": "OpenCode プラグインまたは pi パッケージでサインイン",
"from the plugin {spec}": "プラグイン {spec} から",
@@ -13323,6 +13341,8 @@ const I18N = {
"Usage": "Nutzung",
"Library": "Bibliothek",
"Settings": "Einstellungen",
"Hide sidebar": "Seitenleiste ausblenden",
"Show sidebar": "Seitenleiste einblenden",
"By request": "Nach Anfrage",
"By session": "Nach Sitzung",
"No session ID": "Keine Sitzungs-ID",
@@ -14961,6 +14981,10 @@ const I18N = {
"Copy the gateway URL": "Zugangspunkt-URL kopieren",
"Gateway URL": "Zugangspunkt-URL",
"Plugins": "Erweiterungen",
"Work": "Arbeit",
"Insights": "Einblick",
"Extend": "Zusätze",
"Gateway stopped": "Zugangspunkt aus",
"From plugins": "Aus Erweiterungen",
"signed in by an OpenCode plugin or a pi package": "angemeldet über eine OpenCode-Erweiterung oder ein pi-Paket",
"from the plugin {spec}": "aus der Erweiterung {spec}",
File diff suppressed because one or more lines are too long
+3
View File
@@ -65,3 +65,6 @@ html.omarchy .icon.winclose { background: transparent; }
html.omarchy .icon.winclose:hover { background: var(--red-soft); color: var(--red); }
html.omarchy ::selection { background: var(--om-sel); color: var(--accent); }
html.omarchy body.side-nav :is(#nav button[data-view], #prefs).on { background: var(--om-sel); box-shadow: inset 0 0 0 1px var(--om-sel-line); color: var(--accent); }
html.omarchy .nav-hl { background: var(--om-sel); }
html.omarchy .nav-s.cur { color: var(--accent); }
@@ -69,7 +69,7 @@ async function open(browser, lang, width, posts, over) {
await page.route("**/*", server(lang, posts, over));
await page.goto("http://magpie.test/?view=usage");
await page.locator("#prefs").click();
await page.locator("#setTab-privacy").click();
await page.locator(":is(#setTab-privacy, .nav-s[data-of=setTab-privacy]):visible").click();
await page.locator("#discoveryList .opt").first().waitFor();
return { context, page, errors };
}
@@ -107,12 +107,12 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
await page.clock.fastForward(31e3);
await settle();
const m = asked();
await page.locator("#usageTab .opt").nth(1).click();
await page.locator(":is(#usageTab .opt, .nav-s):visible").nth(1).click();
await page.evaluate(() => window.dispatchEvent(new Event("focus")));
await settle();
assert.equal(asked(), m, `the Requests tab brought back asks nothing: ${acct.reads}`);
acct.vendor = 80;
await page.locator("#usageTab .opt").first().click();
await page.locator(":is(#usageTab .opt, .nav-s):visible").first().click();
await shows(80);
assert.equal(asked(), m + 1, `the Overview picked asks: ${acct.reads}`);
+2 -2
View File
@@ -119,11 +119,11 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
await page.mouse.move(500, 400);
await page.mouse.wheel(0, -5000);
for (const choice of ["Dark", "Light", "System"]) {
await page.locator("#setTab-general").click();
await page.locator(":is(#setTab-general, .nav-s[data-of=setTab-general]):visible").click();
await page.locator("#themeSegs").getByRole("button", { name: choice, exact: true }).click();
await page.waitForFunction((want) => (document.documentElement.dataset.theme || "system") === want, choice.toLowerCase());
await page.waitForFunction(() => !document.documentElement.classList.contains("theming"));
await page.locator("#setTab-network").click();
await page.locator(":is(#setTab-network, .nav-s[data-of=setTab-network]):visible").click();
const { colors: c, elements: e } = await palette(page, { card: "#lanList", key: "#lanList .lan-url" });
assert.equal(e.card.bg, c.card);
assert.equal(e.key.color, c["fg-2"]);
+5 -1
View File
@@ -134,7 +134,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
assert.deepEqual(await page.locator("#usageKeys .num b").allTextContents(), ["2.2K", "1.1K"]);
assert.deepEqual(await page.locator("#usageKeys .cost").allTextContents(), ["≈$0.400", "≈$0.200"]);
assert(!/Workspace|Personal/.test(await page.locator("#usageKeys").textContent()));
await page.locator("#usageTab .opt").nth(1).click();
await page.locator(":is(#usageTab .opt, .nav-s):visible").nth(1).click();
await page.locator(".led tbody tr").first().waitFor();
assert.equal(await page.locator(".led tbody tr").first().locator("td").nth(3).textContent(), "Relay · relay.example");
assert((await page.locator(".led tbody tr").first().locator("td").nth(3).getAttribute("title")).includes("relay.example"));
@@ -162,6 +162,10 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
assert(!requests.at(-1).has("key") && !requests.at(-1).has("callerKey"));
assert.equal(await page.locator(".led tbody tr").last().locator("td").nth(3).textContent(), "Relay · relay.example");
await page.setViewportSize({ width: 560, height: 700 });
// WebKit applies the sidebar's media rule to the new width at the next
// frame (matchMedia already answers for it), so measure after that frame
await page.waitForFunction(() => !document.body.classList.contains("side-nav"));
await page.evaluate(() => new Promise((r) => requestAnimationFrame(() => requestAnimationFrame(r))));
assert(await page.locator("#view-usage").evaluate((v) => v.scrollWidth <= v.clientWidth));
if (process.env.ARTIFACT_DIR) {
await fs.mkdir(process.env.ARTIFACT_DIR, { recursive: true });
+12 -7
View File
@@ -41,8 +41,9 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
test(`${engine}: the logo and name in the header`, async (t) => {
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
t.after(() => browser.close());
for (const c of cases) {
const context = await browser.newContext({ viewport: { width: 1100, height: 700 }, reducedMotion: "reduce" });
// in the header's row, and at the sidebar's top when the window is wide
for (const width of [860, 1100]) for (const c of cases) {
const context = await browser.newContext({ viewport: { width, height: 700 }, reducedMotion: "reduce" });
await context.addInitScript((p) => Object.defineProperty(Navigator.prototype, "platform", { get: () => p }), c.platform);
const page = await context.newPage();
page.setDefaultTimeout(5000);
@@ -51,15 +52,19 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
await page.route("**/*", serve(c.web));
await page.goto("http://magpie.test/");
await page.waitForSelector("#nav button.on");
const where = `${c.web ? "web" : "window"} on ${c.platform}`;
const brand = page.locator(".top .brand");
const where = `${c.web ? "web" : "window"} on ${c.platform} at ${width}px`;
const side = width >= 1024;
const brand = page.locator(side ? "#side .side-top .brand" : ".top .brand");
assert.equal(await brand.isVisible(), c.shown, where);
if (c.shown) {
assert.ok(await brand.locator(".logo svg").isVisible(), `${where}: logo`);
assert.ok(await brand.getByText("magpie", { exact: true }).isVisible(), `${where}: name`);
// beside the tabs, not under them
// a header short of room keeps the logo only (fitTop's tight)
const tight = !side && await page.locator(".top.tight").count();
if (!tight) assert.ok(await brand.getByText("magpie", { exact: true }).isVisible(), `${where}: name`);
// beside the tabs, not under them; above the sidebar's pages
const [b, n] = [await brand.boundingBox(), await page.locator("#nav").boundingBox()];
assert.ok(b.x + b.width <= n.x, `${where}: ${JSON.stringify(b)} overlaps the tabs ${JSON.stringify(n)}`);
if (side) assert.ok(b.y + b.height <= n.y, `${where}: ${JSON.stringify(b)} overlaps the pages ${JSON.stringify(n)}`);
else assert.ok(b.x + b.width <= n.x, `${where}: ${JSON.stringify(b)} overlaps the tabs ${JSON.stringify(n)}`);
}
assert.deepEqual(errors, [], where);
await context.close();
+1 -1
View File
@@ -93,7 +93,7 @@ async function open(browser, lang, ctl, errors) {
page.on("pageerror", (e) => errors.push(e.message));
await page.route("**/*", server(lang, ctl));
await page.goto("http://magpie.test/?view=settings");
await page.locator("#setTab-about").click();
await page.locator(":is(#setTab-about, .nav-s[data-of=setTab-about]):visible").click();
await page.locator("#setPage-about").waitFor({ state: "visible" });
const row = page.locator("#about .row.pref.cli-row");
await row.locator(".cli-shell").first().waitFor();
@@ -59,12 +59,12 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
// Share on local network's address is kept the same way
await page.locator("#prefs").click();
await page.locator("#setTab-network").click();
await page.locator(":is(#setTab-network, .nav-s[data-of=setTab-network]):visible").click();
await page.locator("#lanList .lan-address-row").waitFor();
await pick("#lanList .lan-interface", "10.0.0.10");
await page.reload();
await page.locator("#prefs").click();
await page.locator("#setTab-network").click();
await page.locator(":is(#setTab-network, .nav-s[data-of=setTab-network]):visible").click();
await page.locator("#lanList .lan-address-row").waitFor();
assert.match(await shown("#lanList .lan-interface"), /10\.0\.0\.10:3999/);
+3 -1
View File
@@ -102,7 +102,9 @@ function serve(lang, asked) {
// the reader scrolls (the wheel) until what they'll point at is in view:
// the app puts back a scroll that isn't the reader's, a test's own included
async function wheelTo(page, l) {
await page.mouse.move(200, 300);
// over the page, not the sidebar beside it
const v = await page.locator("#view-usage").boundingBox();
await page.mouse.move(v.x + v.width / 2, 300);
for (let i = 0; i < 40 && await l.evaluate((b) => b.getBoundingClientRect().bottom > innerHeight - 70); i++) {
await page.mouse.wheel(0, 120);
await page.waitForTimeout(50);
+3 -3
View File
@@ -94,7 +94,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
// Settings: the currency row, its rate in the tooltip
await page.locator("#prefs").click();
await page.locator("#setTab-usage").click();
await page.locator(":is(#setTab-usage, .nav-s[data-of=setTab-usage]):visible").click();
await page.locator("#currencySegs .opt").first().waitFor();
const segs = page.locator("#currencySegs .opt");
assert.equal(await segs.count(), 2);
@@ -141,7 +141,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
// and back to Settings, ¥ CNY is still picked after a reload
await page.reload();
await page.locator("#prefs").click();
await page.locator("#setTab-usage").click();
await page.locator(":is(#setTab-usage, .nav-s[data-of=setTab-usage]):visible").click();
await page.locator("#currencySegs .opt").first().waitFor();
assert.equal(await page.locator('#currencySegs .opt', { hasText: cny }).evaluate((b) => b.classList.contains("on")), true);
@@ -190,7 +190,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
// Settings agrees
await page.locator("#prefs").click();
await page.locator("#setTab-usage").click();
await page.locator(":is(#setTab-usage, .nav-s[data-of=setTab-usage]):visible").click();
await page.locator("#currencySegs .opt").first().waitFor();
assert.equal(await page.locator("#currencySegs .opt", { hasText: cny }).evaluate((b) => b.classList.contains("on")), true);
+1 -1
View File
@@ -189,7 +189,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
const q = page.locator(".pm-find input");
await q.waitFor();
// from Installed, the first key goes to Discover
await page.locator(".lib-tabs .opt", { hasText: w.installed }).click();
await page.locator(":is(.lib-tabs .opt, .nav-s):visible", { hasText: w.installed }).click();
await watch(page, ".pm-find input");
await q.focus();
await typeIn(page, "1");
@@ -61,7 +61,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
assert.match(await page.locator("#usageKeys").textContent(), /Laptop/);
assert.equal(await page.locator("#usageKeysHead").textContent(), lang === "zh" ? "网关密钥" : "Gateway keys");
assert.equal(await page.locator("#usageCallerKeys").count(), 0, "there is only one API key section");
await page.locator("#usageTab").getByRole("button", { name: w.requests, exact: true }).click();
await page.locator(":is(#usageTab .opt, .nav-s):visible", { hasText: new RegExp("^" + w.requests + "(?!\\p{L})", "u") }).click();
await page.locator("#ledKey").click();
await page.locator(".sess-menu .pm-item", { hasText: "Laptop" }).click();
await page.waitForFunction(() => document.querySelectorAll("#ledWrap tbody tr").length === 1);
@@ -71,7 +71,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
assert(events.some((e) => e.action === "export" && e.query.includes("callerKey=laptop") && !e.query.includes("key=") && !e.query.includes("user=")));
await page.reload();
await page.locator("#prefs").click();
await page.locator("#setTab-network").click();
await page.locator(":is(#setTab-network, .nav-s[data-of=setTab-network]):visible").click();
const share = page.locator("#lanList").getByRole("button", { name: lang === "zh" ? "开启" : "On", exact: true });
await share.waitFor();
// Real wheel input lets the page remember the reader's scroll position.
@@ -110,7 +110,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
await confirmKeyAction(page, lanRow, w.remove);
await page.waitForFunction(() => document.querySelectorAll("#gatewayKeys .acc[data-key]").length === 4);
await page.locator("#prefs").click();
await page.locator("#setTab-network").click();
await page.locator(":is(#setTab-network, .nav-s[data-of=setTab-network]):visible").click();
await page.locator("#lanList .lan-address-row").waitFor();
await page.locator("#lanList").getByRole("button", { name: lang === "zh" ? "关闭" : "Off", exact: true }).click();
await page.locator("#lanList .lan-address-row").waitFor({ state: "detached" });
@@ -38,7 +38,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
await page.locator("#prefs").click();
await page.locator("#setTab-network").click();
await page.locator(":is(#setTab-network, .nav-s[data-of=setTab-network]):visible").click();
const on = page.locator("#lanList").getByRole("button", { name: w.on, exact: true });
await on.waitFor();
const bounds = await on.boundingBox();
@@ -69,7 +69,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
};
await page.route("**/api/caller-keys", lateList);
await page.locator("#prefs").click();
await page.locator("#setTab-network").click();
await page.locator(":is(#setTab-network, .nav-s[data-of=setTab-network]):visible").click();
await page.locator("#lanList").waitFor();
await page.locator("#nav").getByRole("button", { name: w.gateway, exact: true }).click();
await started;
@@ -169,7 +169,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
await expectSecret("fixture-created-2");
assert.equal(await page.locator("#connectKey code").textContent(), "Replacement");
await page.locator("#prefs").click();
await page.locator("#setTab-network").click();
await page.locator(":is(#setTab-network, .nav-s[data-of=setTab-network]):visible").click();
await page.locator("#lanList .lan-address-row").waitFor();
await page.locator("#lanList").getByRole("button", { name: w.off, exact: true }).click();
await page.locator("#lanList .lan-address-row").waitFor({ state: "detached" });
+5 -4
View File
@@ -71,10 +71,11 @@ const L = {
zh: { mode: "网关模式", noAgents: "当前开启:本机没有 Agent", off: "当前关闭:本机找到了 Agent" },
};
const HIDDEN = ["agents", "library"];
const KEPT = ["providers", "gateway", "routing", "usage", "sessions", "plugins"];
// in the order the pages are grouped in (work, models, insights, extend)
const KEPT = ["sessions", "providers", "routing", "gateway", "usage", "plugins"];
// the tabs shown, the page shown
const tabs = (page) => page.evaluate(() => [...document.querySelectorAll("#nav button")].filter((b) => !b.hidden && b.offsetParent).map((b) => b.dataset.view));
const tabs = (page) => page.evaluate(() => [...document.querySelectorAll("#nav button[data-view]")].filter((b) => !b.hidden && b.offsetParent).map((b) => b.dataset.view));
const viewShown = (page) => page.evaluate(() => [...document.querySelectorAll("main.view")].filter((v) => !v.hidden).map((v) => v.id));
// the rows gateway mode leaves out of Settings, each shown or not
const agentRows = (page) => page.evaluate(() => ["#plainNamesSegs", "#codexAgentsV1Segs", "#fullContextSegs", "#codexTitlesPick", "#codexAutoReviewPick", "#usageAlertSegs", "#balanceAlertSegs", "#resetReminderSegs", "#turnDoneSegs"]
@@ -141,7 +142,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", "providers", "gateway", "routing", "usage", "sessions", "library", "plugins"], `${where}: off`);
assert.deepEqual(await tabs(page), ["agents", "sessions", "library", "providers", "routing", "gateway", "usage", "plugins"], `${where}: off`);
assert.deepEqual(await viewShown(page), ["view-settings"], `${where}: Settings stays`);
assert.deepEqual(await agentRows(page), [true, true, true, true, true, true, true, true, true], `${where}: rows back`);
assert.doesNotMatch(await page.locator("#gatewayModeSub").textContent(), new RegExp(L[lang].noAgents), where);
@@ -174,7 +175,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", "providers", "gateway", "routing", "usage", "sessions", "library", "plugins"], where);
assert.deepEqual(await tabs(page), ["agents", "sessions", "library", "providers", "routing", "gateway", "usage", "plugins"], where);
assert.deepEqual(await viewShown(page), ["view-agents"], where);
await page.locator("#prefs").click();
await page.waitForSelector("#langSegs .opt");
+2 -1
View File
@@ -65,7 +65,8 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
// tall enough for the whole editor, its Cancel clicked where it is
// (under the names setting over the groups)
const page = await (await browser.newContext({ viewport: { width: 1100, height: 1600 }, reducedMotion: "reduce" })).newPage();
// the window wider by the sidebar beside the page: the editor's foot in sight
const page = await (await browser.newContext({ viewport: { width: 1360, height: 1600 }, reducedMotion: "reduce" })).newPage();
t.after(() => browser.close());
page.setDefaultTimeout(5000);
const errors = [], posts = [];
+1 -1
View File
@@ -62,7 +62,7 @@ for (const [name, engine] of [["webkit", webkit], ["chromium", chromium]]) {
assert.ok(got.offered.includes("de:Deutsch"));
if (want === "de") {
assert.equal(got.lang, "de-DE");
assert.deepEqual(got.nav, ["Agenten", "Anbieter", "Zugangspunkt", "Weiterleitung", "Nutzung"]);
assert.deepEqual(got.nav, ["Agenten", "Sitzungen", "Bibliothek", "Anbieter", "Weiterleitung"]);
}
await page.close();
}
+1 -1
View File
@@ -62,7 +62,7 @@ for (const [name, engine] of [["webkit", webkit], ["chromium", chromium]]) {
assert.ok(got.offered.includes("ja:日本語"));
if (want === "ja") {
assert.equal(got.lang, "ja-JP");
assert.deepEqual(got.nav, ["エージェント", "プロバイダ", "ゲートウェイ", "ルーティング", "使用量"]);
assert.deepEqual(got.nav, ["エージェント", "セッション", "ライブラリ", "プロバイダ", "ルーティング"]);
}
await page.close();
}
+1 -1
View File
@@ -77,7 +77,7 @@ for (const [name, engine] of [["webkit", webkit], ["chromium", chromium]]) {
assert.ok(got.offered.includes("zh-TW:繁體中文") && got.offered.includes("zh:简体中文"), got.offered.join());
if (want === "zh-TW") {
assert.equal(got.lang, "zh-TW");
assert.deepEqual(got.nav, ["Agent", "供應商", "閘道", "路由", "用量"]);
assert.deepEqual(got.nav, ["Agent", "會話", "資源庫", "供應商", "路由"]);
assert.deepEqual(got.units, ["1.33 億", "6.8 萬"]);
}
if (want === "zh") assert.deepEqual(got.units, ["1.33 亿", "6.8 万"]);
@@ -68,6 +68,8 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
await page.waitForFunction(() => !document.querySelector("#update").hidden);
let middle = 0, inrow = 0;
for (let w = 1100; w >= 560; w -= 10) {
// wide enough for the sidebar, the pages are down it: no tabs here
if (Math.round(w / zoom) >= 1024) continue;
await page.setViewportSize({ width: Math.round(w / zoom), height: 600 });
await settled(page);
const h = await header(page), at = `${w}pt: ${JSON.stringify(h)}`;
+1 -1
View File
@@ -68,7 +68,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
await p.route("**/*", server(lang, asked));
await p.goto("http://magpie.test/");
await p.locator('[data-view="usage"]').first().click();
await p.locator("#usageTab .opt").nth(1).click();
await p.locator(":is(#usageTab .opt, .nav-s):visible").nth(1).click();
await p.locator("#ledWrap .led tbody tr").first().waitFor();
await p.waitForTimeout(200);
+1 -1
View File
@@ -84,7 +84,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
await browser.close();
});
await page.goto("http://magpie.test/?view=usage");
await page.locator("#usageTab .opt").nth(1).click();
await page.locator(":is(#usageTab .opt, .nav-s):visible").nth(1).click();
const rows = page.locator(".led tbody tr.led-row");
await rows.nth(ROWS.length - 1).waitFor({ timeout: 15000 });
+2 -2
View File
@@ -89,7 +89,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
});
await page.goto("http://magpie.test/?view=usage");
const tr = (k, vars) => page.evaluate(([k, vars]) => t(k, vars), [k, vars || {}]);
await page.locator("#usageTab .opt").nth(1).click();
await page.locator(":is(#usageTab .opt, .nav-s):visible").nth(1).click();
const rows = page.locator(".led tbody tr.led-row");
await rows.nth(3).waitFor({ timeout: 15000 });
@@ -173,7 +173,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
assert(await noHScroll(), "the page runs past the window");
// the Usage page's overview counts the same way
await page.locator("#usageTab .opt").nth(0).click();
await page.locator(":is(#usageTab .opt, .nav-s):visible").nth(0).click();
const both = (await tr("{n} failed", { n: 1 })) + " · " + (await tr("{n} answered on a retry", { n: 1 }));
await page.waitForFunction((s) => document.querySelector("#view-usage").textContent.includes(s), both);
assert.deepEqual(errors, []);
@@ -68,7 +68,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
for (const kind of ["skills", "mcp"]) {
if (kind === "mcp") {
await view.locator(".lib-tabs .opt", { hasText: words[lang].tabs[1] }).click();
await view.page().locator(":is(.lib-tabs .opt, .nav-s):visible", { hasText: words[lang].tabs[1] }).click();
await view.locator('.mk[data-market="mcp"] .mk-card').first().waitFor();
}
await t.test(`${kind}: the market is far down, and the button takes the reader there`, async () => {
@@ -103,7 +103,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
}
await t.test("the Instructions tab has no Discover button", async () => {
await view.locator(".lib-tabs .opt", { hasText: words[lang].tabs[0] }).click();
await view.page().locator(":is(.lib-tabs .opt, .nav-s):visible", { hasText: words[lang].tabs[0] }).click();
await view.locator(".lib-body").first().waitFor();
assert.equal(await head.locator(".lib-discover").count(), 0);
});
+2 -2
View File
@@ -149,9 +149,9 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
const side = await card.evaluate((c) => getComputedStyle(c).borderLeftWidth);
assert.equal(side, "0px");
// on every tab
await page.locator("#view-library .lib-tabs .opt").first().click();
await page.locator(":is(#view-library .lib-tabs .opt, .nav-s):visible").first().click();
await card.waitFor();
await page.locator("#view-library .lib-tabs .opt").nth(2).click();
await page.locator(":is(#view-library .lib-tabs .opt, .nav-s):visible").nth(2).click();
await page.locator("#view-library .lib-body:not(.lib-skel) .lib-row").first().waitFor();
const again = card.getByRole("button", { name: words[lang].again });
+2 -1
View File
@@ -44,7 +44,8 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
test(engine + ": the Library while it loads", async (t) => {
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
t.after(() => browser.close());
const ctx = await browser.newContext({ viewport: { width: 980, height: 800 } });
// under the sidebar's width: the tabs here are the page's own strip
const ctx = await browser.newContext({ viewport: { width: 860, height: 800 } });
await ctx.addInitScript(() => { try { if (!sessionStorage.getItem("seeded")) { localStorage.setItem("magpie.libTab", "skills"); sessionStorage.setItem("seeded", "1"); } } catch {} });
const page = await ctx.newPage();
page.setDefaultTimeout(5000);
@@ -151,8 +151,8 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
assert.ok(slowBox.height <= 18 && slowBox.width <= 220, "the step's name widens or wraps the status: " + JSON.stringify(slowBox));
// back from another tab: not checked again
await page.locator(".lib-tabs button", { hasText: w.skills }).click();
await page.locator(".lib-tabs button", { hasText: /MCP/ }).click();
await page.locator(":is(.lib-tabs button, .nav-s):visible", { hasText: w.skills }).click();
await page.locator(":is(.lib-tabs button, .nav-s):visible", { hasText: /MCP/ }).click();
await status("files").waitFor();
await page.waitForTimeout(150);
assert.equal(checks.length, 1, "the servers were checked again on coming back");
+2 -2
View File
@@ -92,8 +92,8 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
assert.equal(await v.locator(".lib-rtk-sandbox").textContent(), w.sandbox);
// the RTK tab opened again: read again, the count it has now
await v.locator(".lib-tabs button", { hasText: w.skills }).click();
await v.locator(".lib-tabs button", { hasText: "RTK" }).click();
await v.page().locator(":is(.lib-tabs button, .nav-s):visible", { hasText: w.skills }).click();
await v.page().locator(":is(.lib-tabs button, .nav-s):visible", { hasText: "RTK" }).click();
await page.waitForFunction((want) => document.querySelector("#view-library .lib-rtk-gain")?.textContent.startsWith(want), w.saved).catch(() => {});
assert.equal(await gain.textContent(), w.saved + " " + w.scope);
assert.equal(await v.locator(".lib-rtk-sandbox").count(), 0);
+4 -4
View File
@@ -107,7 +107,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
assert.deepEqual(await serverNames(), ["gamma", "beta", "Alpha"]);
// the skills: by source at first, then one flat list by name
await page.locator("#view-library .lib-tabs .opt").nth(2).click();
await page.locator(":is(#view-library .lib-tabs .opt, .nav-s):visible").nth(2).click();
await page.locator("#view-library .lib-group").first().waitFor();
const skillBox = page.locator('.segs.sortby[data-sort="libSkills"]');
assert.deepEqual(await skillBox.locator(".opt").allTextContents(), [w.source, "A→Z", "Z→A"]);
@@ -123,10 +123,10 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
// each list keeps its own pick through a reload
await openLib();
assert.deepEqual(await skillNames(), ["pear", "mango", "kiwi", "cherry", "apple"]);
await page.locator("#view-library .lib-tabs .opt").nth(1).click();
await page.locator(":is(#view-library .lib-tabs .opt, .nav-s):visible").nth(1).click();
await page.locator("#view-library .lib-body:not(.lib-skel) .lib-list .lib-row").first().waitFor();
assert.deepEqual(await serverNames(), ["gamma", "beta", "Alpha"]);
await page.locator("#view-library .lib-tabs .opt").nth(2).click();
await page.locator(":is(#view-library .lib-tabs .opt, .nav-s):visible").nth(2).click();
await pick("libSkills", 0);
await page.locator("#view-library .lib-group").first().waitFor();
@@ -134,7 +134,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
const pluginNames = () => names("#view-plugins .pm-list .pm-row > .who > .name > span:first-child");
const openPlugins = async () => {
await page.goto("http://magpie.test/?view=plugins");
await page.locator("#view-plugins .lib-tabs .opt").nth(1).click();
await page.locator(":is(#view-plugins .lib-tabs .opt, .nav-s):visible").nth(1).click();
await page.locator("#view-plugins .pm-row").first().waitFor();
};
await openPlugins();
+1 -1
View File
@@ -124,7 +124,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
});
await t.test("a skill removed is no longer marked added", async () => {
await view.locator(".lib-tabs .opt").nth(2).click();
await view.page().locator(":is(.lib-tabs .opt, .nav-s):visible").nth(2).click();
await card("skills", "acme/skills/pdf").locator(".mk-have").waitFor();
await view.locator(".lib-row", { hasText: "pdf" }).locator(".lib-icon.danger").click();
await page.locator(".lib-editor").getByRole("button", { name: words[lang].removeSkill, exact: true }).click();
+2
View File
@@ -42,6 +42,8 @@ async function serve(route) {
if (url.pathname === "/api/usage/quotas" || url.pathname === "/api/usage/quotas/history" || url.pathname === "/api/agents/install") return json([]);
if (url.pathname === "/api/whatsnew") return json({});
if (url.pathname === "/api/upstream") return json({ vendors: [], providers: {} });
// the sidebar's gateway line, when no page has read the providers
if (url.pathname === "/api/providers") return json({ providers: [], gateway: { url: "http://127.0.0.1:3425", running: true } });
assert(!url.pathname.startsWith("/api/"), "Unexpected API: " + url.pathname);
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)];
+6 -6
View File
@@ -108,7 +108,7 @@ async function check(p, card, western, what) {
// every other count the Usage page shows, in the one unit or the other
const has = (x, western) => western ? !/[万亿]/.test(x) && /\d[KMB]\b/.test(x) : !/\d[KMB]\b/.test(x) && /[万亿]/.test(x);
async function rest(p, western, what) {
await p.locator("#usageTab .opt").nth(0).click();
await p.locator(":is(#usageTab .opt, .nav-s):visible").nth(0).click();
await p.locator("#stats .kpi b").first().waitFor();
const tiles = await p.locator("#stats .kpi").allInnerTexts();
assert.equal(tiles[0].split("\n")[0], western ? "1.54B" : "15.4 亿", what + ": the Overview's tokens");
@@ -118,19 +118,19 @@ async function rest(p, western, what) {
assert(tiles.some((x) => /(hit rate|命中率) 66%/.test(x)), `${what}: the Overview's hit rate in ${JSON.stringify(tiles)}`);
assert.equal((await p.locator("#chart .peak").textContent()).trim(), western ? "1.46B" : "14.6 亿", what + ": the Overview chart's peak");
await p.locator("#usageTab .opt").nth(1).click();
await p.locator(":is(#usageTab .opt, .nav-s):visible").nth(1).click();
await p.locator("#ledChart svg").waitFor();
const sum = (await p.locator("#ledSum").textContent()).trim();
assert(has(sum, western), `${what}: the Requests summary "${sum}"`);
assert(sum.includes(western ? "15M" : "1540 万"), `${what}: the Requests summary "${sum}"`);
await p.locator("#usageTab .opt").nth(2).click();
await p.locator(":is(#usageTab .opt, .nav-s):visible").nth(2).click();
await p.waitForFunction(() => !document.querySelector("#sessStats .kpi.stale") && /\d/.test(document.querySelectorAll("#sessStats .kpi b")[1]?.textContent || ""));
const st = await p.locator("#sessStats .kpi").allInnerTexts();
assert.equal(st[1].split("\n")[0], western ? "1.54B" : "15.4 亿", what + ": the Sessions tokens");
assert(st[0].includes(western ? "500M" : "5 亿"), `${what}: the Sessions median "${st[0]}"`);
assert(has(st[3], western), `${what}: the Sessions cache "${st[3]}"`);
await p.locator("#usageTab .opt").nth(1).click();
await p.locator(":is(#usageTab .opt, .nav-s):visible").nth(1).click();
}
const settingsView = (p) => p.locator("#view-settings").evaluate((v) => v.scrollTop);
@@ -151,7 +151,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
await p.route("**/*", serve(lang, store, false));
const requests = async () => {
await p.locator('[data-view="usage"]').first().click();
await p.locator("#usageTab .opt").nth(1).click();
await p.locator(":is(#usageTab .opt, .nav-s):visible").nth(1).click();
await p.locator("#ledChart svg").waitFor();
};
@@ -164,7 +164,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
await p.locator("#prefs").click();
await p.locator("#setTab-usage").click();
await p.locator(":is(#setTab-usage, .nav-s[data-of=setTab-usage]):visible").click();
await p.locator("#currencySegs .opt").first().waitFor();
if (lang === "en") {
assert.equal(await p.locator("#unitsRow").isHidden(), true, "no Number units row in English");
+2 -2
View File
@@ -125,13 +125,13 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
assert.equal(p.otel.bodiesWhole, true);
assert.equal(p.otel.bodies, true);
assert.equal(await mode.textContent(), modes[2]);
await page.locator("#setTab-usage").click();
await page.locator(":is(#setTab-usage, .nav-s[data-of=setTab-usage]):visible").click();
p = await saved(() => page.locator("#currencySegs .opt").nth(1).click());
assert.equal(p.otel.enabled, true);
assert.equal(p.otel.bodiesWhole, true);
assert.equal(p.otel.endpoint, "https://collector.test/api/public/otel");
assert.equal(p.otel.headers.Authorization, "Basic YWJjZA==");
await page.locator("#setTab-otel").click();
await page.locator(":is(#setTab-otel, .nav-s[data-of=setTab-otel]):visible").click();
p = await saved(() => page.locator("#otelExportRow .opt").first().click());
assert.equal(p.otel.enabled, false);
await page.reload();
+1 -1
View File
@@ -86,7 +86,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
assert.equal(await card.locator(".pm-logo img").getAttribute("src"), "/api/icons/aiderpic.png");
assert.equal(await card.locator(".pm-logo svg").count(), 0);
await view.locator(".lib-tabs .opt", { hasText: w.installed }).click();
await view.page().locator(":is(.lib-tabs .opt, .nav-s):visible", { hasText: w.installed }).click();
const row = (name) => view.locator(".pm-row").filter({ has: page.locator(".name", { hasText: name }) });
const aider = row("aider");
await aider.waitFor();
@@ -96,7 +96,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
await page.goto("http://magpie.test/?view=plugins");
const view = page.locator("#view-plugins");
await view.locator(".lib-tabs .opt", { hasText: w.installed }).click();
await view.page().locator(":is(.lib-tabs .opt, .nav-s):visible", { hasText: w.installed }).click();
const row = (spec) => view.locator(".pm-row").filter({ has: page.locator(".name span", { hasText: new RegExp("^" + spec.replace(/[/@-]/g, "\\$&") + "$") }) });
await row(COPILOT).waitFor();
// nothing newer known yet: no Update offered
+1 -1
View File
@@ -86,7 +86,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
await page.goto("http://magpie.test/?view=plugins");
const view = page.locator("#view-plugins");
await view.waitFor({ state: "visible" });
await view.locator(".lib-tabs .opt", { hasText: w.installed }).click();
await view.page().locator(":is(.lib-tabs .opt, .nav-s):visible", { hasText: w.installed }).click();
const row = (n) => view.locator(".pm-row", { has: page.locator(".name span", { hasText: new RegExp("^" + n + "$") }) });
const mine = row("my-acme"), theirs = row("opencode-acme-auth");
await mine.waitFor();
+1 -1
View File
@@ -121,7 +121,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
// Installed: known by its package, at the commit installed, and
// with the repository at that commit, nothing to update
await view.locator(".lib-tabs .opt", { hasText: w.installed }).click();
await view.page().locator(":is(.lib-tabs .opt, .nav-s):visible", { hasText: w.installed }).click();
const row = view.locator(".pm-row").first();
await row.waitFor();
for (let i = 0; i < 100 && !asked.some(([k]) => k === "git"); i++) await new Promise((r) => setTimeout(r, 20));
+1 -1
View File
@@ -116,7 +116,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
assert.deepEqual(asked.find(([k]) => k === "add")[1], { spec: FOLDER });
// Installed: the folder's own name, its page from the folder's README
await view.locator(".lib-tabs .opt", { hasText: w.tab === "Plugins" ? "Installed" : "已安装" }).click();
await view.page().locator(":is(.lib-tabs .opt, .nav-s):visible", { hasText: w.tab === "Plugins" ? "Installed" : "已安装" }).click();
const row = view.locator(".pm-row").first();
await row.waitFor();
assert.equal((await row.locator(".name span").first().innerText()).trim(), w.folderName, "the folder names it, not the whole path");
+1 -1
View File
@@ -209,7 +209,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
await q.fill("");
// Installed: why one didn't load, an update, a removal
await view.locator(".lib-tabs .opt", { hasText: w.installed }).click();
await view.page().locator(":is(.lib-tabs .opt, .nav-s):visible", { hasText: w.installed }).click();
const rows = view.locator(".pm-row");
await rows.first().waitFor();
assert.equal(await rows.count(), 2);
@@ -59,7 +59,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
await page.route("**/*", server(lang));
await page.goto("http://magpie.test/?view=plugins");
const view = page.locator("#view-plugins");
await view.locator(".lib-tabs .opt", { hasText: w.installed }).click();
await view.page().locator(":is(.lib-tabs .opt, .nav-s):visible", { hasText: w.installed }).click();
const row = (name) => view.locator(".pm-row").filter({ has: page.locator(".name", { hasText: name }) });
const alias = row("alias.middleware.js");
@@ -159,7 +159,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
});
await page.goto("http://magpie.test/?view=plugins");
const view = page.locator("#view-plugins");
await view.locator(".lib-tabs .opt", { hasText: w.installed }).click();
await view.page().locator(":is(.lib-tabs .opt, .nav-s):visible", { hasText: w.installed }).click();
const row = (name) => view.locator(".pm-row").filter({ has: page.locator(".name", { hasText: name }) });
const alias = row("alias.middleware.js");
await alias.waitFor();
@@ -61,7 +61,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
await page.waitForFunction(() => document.querySelector('#nav button[data-view="plugins"]')?.classList.contains("has-dot"));
await page.locator('#nav button[data-view="plugins"]').click();
const view = page.locator("#view-plugins");
await view.locator(".lib-tabs .opt", { hasText: "Installed" }).click();
await view.page().locator(":is(.lib-tabs .opt, .nav-s):visible", { hasText: "Installed" }).click();
await view.locator(".pm-row").nth(cases.length - 1).waitFor();
const rows = await view.locator(".pm-row").evaluateAll((rs) => rs.map((r) => ({
@@ -71,7 +71,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
await view.waitFor({ state: "visible" });
// Installed, while npm (and the whole market) hasn't answered
await view.locator(".lib-tabs .opt", { hasText: w.installed }).click();
await view.page().locator(":is(.lib-tabs .opt, .nav-s):visible", { hasText: w.installed }).click();
const row = view.locator(".pm-row").first();
await row.waitFor();
assert.equal((await row.locator(".name span").first().innerText()).trim(), "Copilot");
@@ -80,7 +80,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
assert.equal(await row.locator(".pm-chip.up").count(), 0, "no update until npm says so");
// Discover: the cards, their buttons waiting on npm
await view.locator(".lib-tabs .opt", { hasText: w.discover }).click();
await view.page().locator(":is(.lib-tabs .opt, .nav-s):visible", { hasText: w.discover }).click();
const card = view.locator(`.pm-card[data-pkg="${ZED}"]`);
await card.waitFor();
assert.equal(await card.locator(".pm-dl").count(), 0);
@@ -94,7 +94,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
assert.equal((await card.locator(".pm-ver").innerText()).trim(), "v0.2.0");
assert.equal((await act.innerText()).trim(), w.install);
assert.equal(await act.isDisabled(), false);
await view.locator(".lib-tabs .opt", { hasText: w.installed }).click();
await view.page().locator(":is(.lib-tabs .opt, .nav-s):visible", { hasText: w.installed }).click();
await view.locator(".pm-row .pm-chip.up", { hasText: w.out }).waitFor();
assert.ok(!asked.includes("/api/plugins/market"), "the whole market isn't asked for: " + asked.join(" "));
+1 -1
View File
@@ -83,7 +83,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
await page.locator('#nav button[data-view="plugins"]').click();
const view = page.locator("#view-plugins");
await view.waitFor({ state: "visible" });
await view.locator(".lib-tabs .opt", { hasText: w.installed }).click();
await view.page().locator(":is(.lib-tabs .opt, .nav-s):visible", { hasText: w.installed }).click();
const zed = view.locator(".pm-row").filter({ hasText: "Zed" });
const chip = zed.locator(".pm-chip.moved");
await chip.waitFor();
+1 -1
View File
@@ -80,7 +80,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
assert.equal((await view.locator(`.pm-card[data-pkg="${ZED}"] .pm-act`).innerText()).trim(), w.signIn);
// Installed: the row names the other, quietly
await view.locator(".lib-tabs .opt", { hasText: w.installed }).click();
await view.page().locator(":is(.lib-tabs .opt, .nav-s):visible", { hasText: w.installed }).click();
const qoder = view.locator(".pm-row").filter({ hasText: "Qoder CN" });
await qoder.waitFor();
const b = qoder.locator(".val button", { hasText: w.other });
+4 -3
View File
@@ -61,13 +61,14 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
const nav = page.locator('#nav button[data-view="plugins"]');
await page.waitForFunction(() => document.querySelector('#nav button[data-view="plugins"]')?.classList.contains("has-dot"));
assert.equal(await nav.getAttribute("title"), w.out);
// the dot is drawn, small, inside the button
// the dot is drawn, small, inside the button (a little larger at the
// sidebar row's end than at a tab's corner)
const dot = await nav.evaluate((b) => { const s = getComputedStyle(b, "::after"); return { w: s.width, pos: s.position }; });
assert.deepEqual(dot, { w: "5px", pos: "absolute" });
assert.deepEqual(dot, { w: await page.evaluate(() => document.body.classList.contains("side-nav")) ? "6px" : "5px", pos: "absolute" });
await nav.click();
const view = page.locator("#view-plugins");
await view.locator(".lib-tabs .opt", { hasText: w.installed }).click();
await view.page().locator(":is(.lib-tabs .opt, .nav-s):visible", { hasText: w.installed }).click();
const chip = view.locator(".pm-chip.soft", { hasText: w.auto });
await chip.waitFor();
assert.match(await chip.getAttribute("title"), w.from);
@@ -79,7 +79,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
await page.route("**/*", server(lang, posts));
await page.goto("http://magpie.test/?view=usage");
await page.locator("#prefs").click();
await page.locator("#setTab-usage").click();
await page.locator(":is(#setTab-usage, .nav-s[data-of=setTab-usage]):visible").click();
const pill = page.locator("#trayUsagePick button");
await pill.waitFor();
await pill.scrollIntoViewIfNeeded();
@@ -36,7 +36,7 @@ async function setup(t, engine, lang, width, options) {
const shown = (sel) => page.locator(sel).textContent();
const settingsTab = async (tab) => {
if (!(await page.locator("#view-settings").isVisible())) await page.locator("#prefs").click();
await page.locator("#setTab-" + tab).click();
await page.locator(`:is(#setTab-${tab}, .nav-s[data-of=setTab-${tab}]):visible`).click();
};
const fits = async (where) => assert.equal(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth), true, where + " wider than the window");
return { page, errors, open, shown, settingsTab, fits };
+1 -1
View File
@@ -82,7 +82,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
await page.route("**/*", server(lang, posts));
await page.goto("http://magpie.test/?view=usage");
await page.locator("#prefs").click();
await page.locator("#setTab-usage").click();
await page.locator(":is(#setTab-usage, .nav-s[data-of=setTab-usage]):visible").click();
const row = page.locator("#quotaReadsRow");
const opts = row.locator("#quotaReadsSegs .opt");
await opts.first().waitFor();
+1 -1
View File
@@ -130,7 +130,7 @@ for (const engine of process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
// buttons, and the page keeps the reader's place against a script's scroll
const setup = async () => {
await page.goto("http://magpie.test/?view=settings");
await page.locator("#setTab-general").waitFor();
await page.locator(":is(#setTab-general, .nav-s[data-of=setTab-general]):visible").waitFor();
await page.locator("#view-settings").evaluate((v) => {
const first = document.createElement("button"); first.id = "focus-start"; first.textContent = "Edit";
const spacer = document.createElement("div"); spacer.style.cssText = "flex:none;height:1400px";
+1 -1
View File
@@ -114,7 +114,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
// the Usage page's requests: each row, its tooltip, and the period's
await page.goto("http://magpie.test/");
await page.locator('[data-view="usage"]').first().click();
await page.locator("#usageTab .opt").nth(1).click();
await page.locator(":is(#usageTab .opt, .nav-s):visible").nth(1).click();
await page.locator("#ledWrap .led tbody tr").first().waitFor();
await page.waitForTimeout(300);
const heads = await page.locator(".led thead th").evaluateAll((ths) => ths.filter((th) => th.offsetParent).map((th) => th.textContent));
@@ -142,7 +142,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
// the Usage page's Requests: muted, with the same title; the swap amber
await page.goto("http://magpie.test/");
await page.locator('nav [data-view="usage"], [data-view="usage"]').first().click();
await page.locator("#usageTab .opt").nth(1).click();
await page.locator(":is(#usageTab .opt, .nav-s):visible").nth(1).click();
await page.locator("#ledWrap .led tbody tr").nth(1).waitFor();
const cells = await page.locator("#ledWrap .led tbody tr").evaluateAll((trs) => trs.map((tr) => {
const s = [...tr.querySelectorAll("span")].find((e) => e.textContent === "deepseek/deepseek-v4.1-flash" || e.textContent === "gpt-6-luna");
@@ -105,7 +105,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
});
await p.goto("http://magpie.test/");
await p.locator('[data-view="usage"]').first().click();
await p.locator("#usageTab .opt").nth(1).click();
await p.locator(":is(#usageTab .opt, .nav-s):visible").nth(1).click();
const rows = p.locator(".led tbody tr.led-row");
await rows.first().waitFor();
assert.equal(await rows.count(), 3);
+1 -1
View File
@@ -130,7 +130,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
// the Usage page's requests: the switch at the top right of their list
await page.locator('[data-view="usage"]').first().click();
await page.locator("#usageTab .opt").nth(1).click();
await page.locator(":is(#usageTab .opt, .nav-s):visible").nth(1).click();
await page.locator(".led tbody tr.led-row").first().waitFor();
const sw = page.locator("#ledArchive .led-arch-sw");
await sw.waitFor();
+1 -1
View File
@@ -133,7 +133,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
// the Usage page's Requests: a request's details name it
await page.locator('[data-view="usage"]').first().click();
await page.locator("#usageTab .opt").nth(1).click();
await page.locator(":is(#usageTab .opt, .nav-s):visible").nth(1).click();
const rows = page.locator(".led tbody tr.led-row");
await rows.nth(1).waitFor();
const top = () => page.locator("#view-usage").evaluate((v) => v.scrollTop);
+6 -3
View File
@@ -64,7 +64,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
await page.goto("http://magpie.test/");
await page.locator("#prefs").click();
await page.locator("#setTab-sync").click();
await page.locator(":is(#setTab-sync, .nav-s[data-of=setTab-sync]):visible").click();
const list = page.locator("#syncList");
const first = list.locator(".row.pref").first();
await first.waitFor({ state: "visible" });
@@ -92,7 +92,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
// at the page's end, then back up by the wheel till the choice is in sight
await toEnd();
const segTop = () => page.evaluate(() => document.querySelector(".sync-form .segs").getBoundingClientRect().top - document.querySelector("#view-settings").getBoundingClientRect().top);
for (let i = 0; i < 40 && (await segTop()) < 40; i++) { await page.mouse.wheel(0, -40); await page.waitForTimeout(15); }
for (let i = 0; i < 40 && (await segTop()) < 10; i++) { await page.mouse.wheel(0, -40); await page.waitForTimeout(15); }
await page.waitForTimeout(300);
const before = await top();
assert.ok(before > 0, "the settings page must be scrolled");
@@ -127,7 +127,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
// going back and forth, the shorter form too, moves nothing
// the fields filled scrolled the choice out of sight: wheeled back to it
await page.mouse.move(450, 300);
for (let i = 0; i < 40 && (await segTop()) < 40; i++) { await page.mouse.wheel(0, -40); await page.waitForTimeout(15); }
for (let i = 0; i < 40 && (await segTop()) < 10; i++) { await page.mouse.wheel(0, -40); await page.waitForTimeout(15); }
await page.waitForTimeout(300);
const at = await top();
assert.ok(at > 0, "the settings page must still be scrolled");
@@ -166,6 +166,9 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
assert.equal(await form.locator("label.tick input").first().isChecked(), true);
await page.setViewportSize({ width: 520, height: 700 });
// WebKit applies the sidebar's media rule to the new width at the next
// frame, so measure after that frame
await page.evaluate(() => new Promise((r) => requestAnimationFrame(() => requestAnimationFrame(r))));
assert.equal(await form.evaluate((e) => e.scrollWidth > e.clientWidth), false);
assert.deepEqual(errors, []);
});
+8 -1
View File
@@ -50,7 +50,7 @@ for (const engine of ["chromium", "webkit"]) {
});
await page.goto("http://magpie.test/");
await page.locator('[data-view="usage"]').first().click();
await page.locator("#usageTab .opt").nth(1).click();
await page.locator(":is(#usageTab .opt, .nav-s):visible").nth(1).click();
await page.locator(".led-row").first().waitFor();
const cells = page.locator(".led-row .where");
const localName = lang === "zh" ? "本地会话" : "Local session";
@@ -110,6 +110,13 @@ for (const engine of ["chromium", "webkit"]) {
await page.locator(".led-wrap").screenshot({path:process.env.MAGPIE_STYLE_SHOTS+"/badges-"+theme+".png"});
await page.setViewportSize({width:1200,height:900});
}
// beside the sidebar the cards above wrap and the row sits under the
// footer, where WebKit's click leaves it: the reader's wheel brings
// it up first
const rowTop = (await page.locator(".led-row").nth(2).boundingBox()).y;
await page.mouse.move(700, 400);
await page.mouse.wheel(0, rowTop - 400);
await page.waitForFunction((y) => document.querySelectorAll(".led-row")[2].getBoundingClientRect().top < y - 100, rowTop);
await page.locator(".led-row").nth(2).click();
const detail = page.locator(".led-detail");
assert((await detail.textContent()).includes("relay"),"raw provider ID remains available in details");
+1 -1
View File
@@ -108,7 +108,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
await page.route("**/*", server(lang, posts, over));
const go = async () => {
await page.locator("#prefs").click();
await page.locator("#setTab-usage").click();
await page.locator(":is(#setTab-usage, .nav-s[data-of=setTab-usage]):visible").click();
await page.locator("#warmSegs .opt").first().waitFor({ state: "attached" });
};
await page.goto("http://magpie.test/");
+2 -2
View File
@@ -109,7 +109,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
// a row's own words, in the language shown: that row alone, under
// its part's name, the tabs set aside
await page.locator("#setTab-usage").click();
await page.locator(":is(#setTab-usage, .nav-s[data-of=setTab-usage]):visible").click();
await type(page, await tr("Appearance"));
let s = await state(page);
assert.deepEqual([s.parts, s.tabs, s.none], [["general"], false, ""]);
@@ -152,7 +152,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
await page.waitForTimeout(100);
assert.equal(await q.inputValue(), "");
assert.deepEqual(await state(page), { parts: ["usage"], tabs: true, none: "", misses: 0 });
assert.equal(await page.locator("#setTab-usage").getAttribute("aria-selected"), "true");
assert.equal(await page.locator(":is(#setTab-usage, .nav-s[data-of=setTab-usage]):visible").getAttribute("aria-selected"), "true");
assert(await seen(page, "#warmTabs"), "the warm-ups' tabs back");
assert(await seen(page, "#trayUsagePick"), "every row back");
// so does clearing it by hand
@@ -158,23 +158,23 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
assert.equal(posts.length, posted, id + ": a tab posts nothing");
}
// the warm-ups are in Allowances, still a tab each
await page.locator("#setTab-usage").click();
await page.locator(":is(#setTab-usage, .nav-s[data-of=setTab-usage]):visible").click();
assert(await page.locator("#warmTab-codex").isVisible(), "the warm-ups under Allowances");
// a part's control posts what it did
await page.locator("#setTab-general").click();
await page.locator(":is(#setTab-general, .nav-s[data-of=setTab-general]):visible").click();
await page.locator("#themeSegs .opt").nth(2).click();
for (let i = 0; i < 50 && !posts.length; i++) await page.waitForTimeout(40);
assert.equal(posts.at(-1)?.theme, "dark", "the theme still saves");
await page.locator("#setTab-usage").click();
await page.locator(":is(#setTab-usage, .nav-s[data-of=setTab-usage]):visible").click();
await page.locator("#currencySegs .opt").nth(1).click();
for (let i = 0; i < 50 && posts.at(-1)?.currency !== "cny"; i++) await page.waitForTimeout(40);
assert.equal(posts.at(-1).currency, "cny", "the currency still saves");
// the keyboard: one tab in the Tab order, the arrows, Home and End
await page.locator("#setTab-privacy").click();
await page.locator(":is(#setTab-privacy, .nav-s[data-of=setTab-privacy]):visible").click();
assert.deepEqual(await page.locator("#setTabs [role=tab]").evaluateAll((bs) => bs.filter((b) => b.tabIndex === 0).map((b) => b.dataset.set)), ["privacy"]);
await page.locator("#setTab-privacy").focus();
await page.locator(":is(#setTab-privacy, .nav-s[data-of=setTab-privacy]):visible").focus();
await page.keyboard.press("ArrowRight");
assert.deepEqual((await shown(page)).parts, ["otel"]);
assert.equal((await shown(page)).focus, "otel");
@@ -231,7 +231,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
const under = await page.evaluate(() => document.querySelector("#setPage-general").getBoundingClientRect().top - document.querySelector("#setTabs").getBoundingClientRect().bottom);
assert(under >= 0, what + ": the part under the tabs");
// the last tab, on the last line, reached with one click, moving nothing
await page.locator("#setTab-about").click();
await page.locator(":is(#setTab-about, .nav-s[data-of=setTab-about]):visible").click();
await page.waitForTimeout(150);
assert.deepEqual((await shown(page)).parts, ["about"], what);
assert.equal(await top(page), 0, what + ": the click must not scroll the page");
+196
View File
@@ -0,0 +1,196 @@
// Run with Node's test runner and Playwright on the module path; see README.md.
// The sidebar's button (app.js toggleSideNav): at every width the reader
// picks the sidebar or the header's tabs, the choice kept for the next time
// the window opens, and the two trade places as one motion.
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");
function serve(lang) {
const state = { agents: [], 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:${JSON.stringify(lang)},theme:"light",web:false};` });
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/providers") return json({ providers: [], presets: [], excluded: [], gateway: { url: "http://127.0.0.1:3425", running: true, window: true } });
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)];
await route.fulfill({ body: await fs.readFile(file), contentType });
};
}
const words = {
en: ["Hide sidebar", "Show sidebar"],
zh: ["隐藏侧边栏", "显示侧边栏"],
"zh-TW": ["隱藏側邊欄", "顯示側邊欄"],
ja: ["サイドバーを非表示", "サイドバーを表示"],
de: ["Seitenleiste ausblenden", "Seitenleiste einblenden"],
};
const frame = (page) => page.evaluate(() => new Promise((r) => requestAnimationFrame(() => requestAnimationFrame(r))));
const side = (page) => page.evaluate(() => document.body.classList.contains("side-nav"));
// the header's row: the button, the tabs and the icons apart, in the window
async function headerFits(page) {
const [b, n, a, w, sw] = await page.evaluate(() => [
document.querySelector("#sideToggle").getBoundingClientRect().toJSON(),
document.querySelector(".top #nav").getBoundingClientRect().toJSON(),
document.querySelector(".top .actions").getBoundingClientRect().toJSON(),
document.documentElement.clientWidth, document.documentElement.scrollWidth]);
assert.ok(b.right <= n.left, `the button clear of the tabs: ${b.right} ${n.left}`);
assert.ok(n.right <= a.left, `the tabs clear of the icons: ${n.right} ${a.left}`);
assert.ok(sw <= w, "the window does not scroll sideways");
}
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
test(`${engine}: the sidebar's button`, async (t) => {
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
t.after(() => browser.close());
for (const [lang, [hide, show]] of Object.entries(words)) await t.test(lang, async () => {
const context = await browser.newContext({ viewport: { width: 1280, height: 760 }, reducedMotion: "reduce" });
const page = await context.newPage();
page.setDefaultTimeout(5000);
const errors = [];
page.on("pageerror", (e) => errors.push(e.message));
await page.route("**/*", serve(lang));
// whether the sidebar was ever laid out, from the first frame on
await page.addInitScript(() => {
addEventListener("DOMContentLoaded", () => {
window.sideSeen = document.body.classList.contains("side-nav");
new MutationObserver(() => { if (document.body.classList.contains("side-nav")) window.sideSeen = true; }).observe(document.body, { attributes: true, attributeFilter: ["class"] });
});
});
await page.goto("http://magpie.test/");
await page.waitForSelector("#nav button.on");
const mac = await page.evaluate(() => /^Mac/.test(navigator.platform));
const keys = mac ? "⌃⌘S" : "Ctrl+Shift+S";
// the sidebar to start with, and the button saying it hides it
const btn = page.locator("#sideToggle");
assert.ok(await side(page));
assert.ok(await btn.isVisible(), "the button in the title bar");
assert.equal(await btn.getAttribute("title"), `${hide} (${keys})`);
assert.equal(await btn.getAttribute("aria-pressed"), "true");
assert.equal(await btn.locator(".st-pane").evaluate((p) => getComputedStyle(p).opacity), "0.32", "its left pane filled");
// the header's tabs, kept
await btn.click();
await page.waitForFunction(() => !document.body.classList.contains("side-nav"));
await frame(page);
assert.ok(await page.locator(".top #nav").isVisible(), "the tabs in the header");
assert.equal(await page.locator("#side").isVisible(), false);
assert.ok(await btn.isVisible(), "the button stays to bring the sidebar back");
assert.equal(await btn.getAttribute("title"), `${show} (${keys})`);
assert.equal(await btn.getAttribute("aria-pressed"), "false");
assert.equal(await btn.locator(".st-pane").evaluate((p) => getComputedStyle(p).opacity), "0", "its pane empty");
await headerFits(page);
assert.equal(await page.evaluate(() => localStorage.getItem("magpie.navLayout")), "top");
// opened again: the header from the first frame, no sidebar on the way
await page.reload();
await page.waitForSelector("#nav button.on");
await frame(page);
assert.equal(await side(page), false);
assert.equal(await page.evaluate(() => window.sideSeen), false, "the sidebar never laid out");
await headerFits(page);
// narrower than the sidebar comes at by itself: the button stays, the
// header holds
await page.setViewportSize({ width: 1023, height: 760 });
await frame(page);
assert.ok(await btn.isVisible(), "the button at every width");
assert.equal(await side(page), false, "the header still");
await headerFits(page);
// and the sidebar picked in a narrow window: narrower, the page beside it
await page.setViewportSize({ width: 640, height: 760 });
await frame(page);
assert.ok(await btn.isVisible());
await btn.click();
await page.waitForFunction(() => document.body.classList.contains("side-nav"));
await frame(page);
assert.equal(await page.evaluate(() => localStorage.getItem("magpie.navLayout")), "side");
assert.equal(Math.round((await page.locator("#side").boundingBox()).width), 184, "a narrower sidebar");
assert.ok(await page.evaluate(() => document.documentElement.scrollWidth <= document.documentElement.clientWidth), "the window does not scroll sideways");
const [tb, cr, ac] = await page.evaluate(() => ["#sideToggle", "#crumb", ".top .actions"].map((q) => document.querySelector(q).getBoundingClientRect().toJSON()));
assert.ok(tb.right <= cr.left + 0.5 && cr.right <= ac.left + 0.5, `the header's row apart: ${tb.right} ${cr.left} ${cr.right} ${ac.left}`);
// widened, the choice holds
await page.setViewportSize({ width: 1280, height: 760 });
await frame(page);
assert.ok(await side(page), "the sidebar still");
// the shortcut trades them, and keeps what it gives
await page.keyboard.press(mac ? "Control+Meta+KeyS" : "Control+Shift+KeyS");
await page.waitForFunction(() => !document.body.classList.contains("side-nav"));
assert.equal(await page.evaluate(() => localStorage.getItem("magpie.navLayout")), "top");
await page.keyboard.press(mac ? "Control+Meta+KeyS" : "Control+Shift+KeyS");
await page.waitForFunction(() => document.body.classList.contains("side-nav"));
assert.equal(await page.evaluate(() => localStorage.getItem("magpie.navLayout")), "side");
assert.ok(await page.locator("#side .side-scroll #nav").isVisible());
assert.equal(await btn.getAttribute("title"), `${hide} (${keys})`);
assert.ok(await page.evaluate(() => document.documentElement.scrollWidth <= document.documentElement.clientWidth));
// Settings' tabs still listed under it
await page.locator("#prefs").click();
await page.locator("#side .nav-sub:not(.leaving) .nav-s").first().waitFor();
assert.deepEqual(errors, []);
await context.close();
});
await t.test("the two trade places as one motion", async () => {
const context = await browser.newContext({ viewport: { width: 1280, height: 760 } });
const page = await context.newPage();
const errors = [];
page.on("pageerror", (e) => errors.push(e.message));
await page.route("**/*", serve("en"));
await page.goto("http://magpie.test/");
await page.waitForSelector("#nav button.on");
assert.ok(await page.evaluate(() => !!document.startViewTransition), "the webview has view transitions");
// what plays, read as the button is clicked: the old drawn, the new laid out
const playing = () => page.evaluate(() => new Promise((r) => {
const at = () => document.getAnimations().map((a) => a.effect?.pseudoElement).filter(Boolean);
requestAnimationFrame(() => requestAnimationFrame(() => r({ anims: at(), morph: document.documentElement.classList.contains("nav-morph") })));
}));
await page.locator("#sideToggle").click();
let p = await playing();
assert.ok(p.morph, "the layouts trade places");
assert.ok(p.anims.includes("::view-transition-old(side)"), `the sidebar slides away: ${p.anims}`);
assert.ok(p.anims.includes("::view-transition-group(nav-usage)"), "each tab flies to the header");
assert.ok(p.anims.includes("::view-transition-group(page)"), "the page moves over");
// on the sidebar's spring
const ease = await page.evaluate(() => getComputedStyle(document.documentElement, "::view-transition-group(page)").animationTimingFunction);
assert.match(ease, /cubic-bezier\(0?\.32, 0?\.72, 0, 1\)/);
await page.waitForFunction(() => !document.documentElement.classList.contains("nav-morph"));
assert.equal(await side(page), false);
await headerFits(page);
await page.locator("#sideToggle").click();
p = await playing();
assert.ok(p.anims.includes("::view-transition-new(side)"), `the sidebar slides in: ${p.anims}`);
await page.waitForFunction(() => !document.documentElement.classList.contains("nav-morph"));
assert.ok(await side(page));
assert.ok(await page.locator("#side .side-scroll #nav").isVisible());
assert.deepEqual(errors, []);
await context.close();
});
await t.test("less motion: at once", async () => {
const context = await browser.newContext({ viewport: { width: 1280, height: 760 }, reducedMotion: "reduce" });
const page = await context.newPage();
await page.route("**/*", serve("en"));
await page.goto("http://magpie.test/");
await page.waitForSelector("#nav button.on");
await page.evaluate(() => { window.morphed = false; new MutationObserver(() => { if (document.documentElement.classList.contains("nav-morph")) window.morphed = true; }).observe(document.documentElement, { attributes: true }); });
await page.locator("#sideToggle").click();
assert.equal(await side(page), false, "the header at once");
assert.equal(await page.evaluate(() => window.morphed), false);
await context.close();
});
});
}
+188
View File
@@ -0,0 +1,188 @@
// Run with Node's test runner and Playwright on the module path; see README.md.
// The window's sidebar (app.js layoutNav): from 1024 points the pages are
// listed down the left in their groups, the open one's own tabs under it in
// place of the page's strip, Settings and the gateway's address at the foot
// and the header a breadcrumb; narrower, they go back into the header's row.
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");
function serve(lang, reads) {
const state = { agents: [], 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:${JSON.stringify(lang)},theme:"light",web:false};` });
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/providers") { reads.push(performance.now()); return json({ providers: [], presets: [], excluded: [], gateway: { url: "http://127.0.0.1:3425", running: true, window: true } }); }
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)];
await route.fulfill({ body: await fs.readFile(file), contentType });
};
}
// each language's group names, and Settings' Models tab
const words = {
en: { groups: ["Work", "Models", "Insights", "Extend"], settings: "Settings", models: "Models" },
zh: { groups: ["使用", "模型", "观测", "扩展"], settings: "设置", models: "模型" },
"zh-TW": { groups: ["使用", "模型", "觀測", "擴充"], settings: "設定", models: "模型" },
ja: { groups: ["利用", "モデル", "観測", "拡張"], settings: "設定", models: "モデル" },
de: { groups: ["Arbeit", "Modelle", "Einblick", "Zusätze"], settings: "Einstellungen", models: "Modelle" },
};
const frame = (page) => page.evaluate(() => new Promise((r) => requestAnimationFrame(() => requestAnimationFrame(r))));
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
test(`${engine}: the window's sidebar`, async (t) => {
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
t.after(() => browser.close());
for (const [lang, w] of Object.entries(words)) await t.test(lang, async () => {
const reads = [];
const context = await browser.newContext({ viewport: { width: 1024, height: 760 }, reducedMotion: "reduce" });
const page = await context.newPage();
page.setDefaultTimeout(5000);
const errors = [];
page.on("pageerror", (e) => errors.push(e.message));
await page.route("**/*", serve(lang, reads));
await page.goto("http://magpie.test/");
await page.waitForSelector("#nav button.on");
// at 1024 points the pages are down the left, in their groups
assert.ok(await page.evaluate(() => document.body.classList.contains("side-nav")), "a sidebar from 1024 points");
assert.ok(await page.locator("#side .side-scroll #nav").isVisible(), "the pages are in the sidebar");
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"]);
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
const cut = await page.locator("#side :is(.nav-gl, button[data-view] > span, #prefs .side-l)").evaluateAll((es) => es.filter((e) => e.scrollWidth > e.clientWidth + 1).map((e) => e.textContent));
assert.deepEqual(cut, [], "names read whole");
assert.ok(await page.evaluate(() => document.documentElement.scrollWidth <= document.documentElement.clientWidth), "the window does not scroll sideways");
// the open page in the graphite of the text, not an accent colour
const [ic, fg] = await page.evaluate(() => [getComputedStyle(document.querySelector("#nav button.on .nav-ic")).color, getComputedStyle(document.body).color]);
assert.equal(ic, fg, "the open page's icon is the text's colour");
// a row pressed darkens and keeps its size: no button's squeeze
for (const sel of ['#nav button[data-view="usage"]', "#prefs"]) {
const r = page.locator(sel);
const bg = await r.evaluate((b) => getComputedStyle(b).backgroundColor);
const box = await r.boundingBox();
await page.mouse.move(box.x + box.width / 2, box.y + box.height / 2);
await page.mouse.down();
await page.waitForTimeout(250);
const [tf, pressed] = await r.evaluate((b) => [getComputedStyle(b).transform, getComputedStyle(b).backgroundColor]);
await page.mouse.move(box.x + box.width + 400, box.y);
await page.mouse.up();
assert.equal(tf, "none", `${sel} pressed is not squeezed`);
assert.notEqual(pressed, bg, `${sel} pressed darkens`);
}
// the gateway's address at the foot, read once the window has settled
await page.locator("#sideGw").waitFor();
assert.match(await page.locator("#sideGw").textContent(), /127\.0\.0\.1:3425/);
assert.ok(await page.locator("#sideGw span").evaluate((s) => s.scrollWidth <= s.clientWidth), "the address is read whole");
assert.equal(reads.length, 1, "read once for the sidebar");
// Settings: its tabs listed under it, its own strip hidden, and picked there
await page.locator("#prefs").click();
const subs = page.locator("#side .nav-sub:not(.leaving) .nav-s");
await subs.first().waitFor();
assert.equal(await subs.count(), 8);
assert.equal(await page.locator("#setTabs").isVisible(), false, "the page's own strip is hidden");
assert.deepEqual(await subs.evaluateAll((ss) => ss.map((s) => s.dataset.of)),
["setTab-general", "setTab-usage", "setTab-network", "setTab-models", "setTab-privacy", "setTab-otel", "setTab-sync", "setTab-about"]);
assert.deepEqual(await subs.evaluateAll((ss) => ss.filter((s) => s.scrollWidth > s.clientWidth + 1).map((s) => s.textContent)), [], "tab names read whole");
// the selection sets off as the row is pressed, ahead of the page,
// and goes back when the press leaves the row
const hlTo = () => page.evaluate(() => { const h = document.querySelector(".nav-sub:not(.leaving) .nav-hl"); return h.style.transform; });
const rowAt = (of) => page.evaluate((of) => `translateY(${document.querySelector(`.nav-s[data-of=${of}]`).offsetTop}px)`, of);
const startAt = await hlTo();
const net = await page.locator(".nav-s[data-of=setTab-network]").boundingBox();
await page.mouse.move(net.x + net.width / 2, net.y + net.height / 2);
await page.mouse.down();
assert.equal(await hlTo(), await rowAt("setTab-network"), "pressed, the selection is going to it");
assert.equal(await page.locator("#setTab-network").evaluate((b) => b.classList.contains("on")), false, "before the page has the tab");
// the selection is the one shape: the row pressed has no ground of its own
assert.equal(await page.locator(".nav-s[data-of=setTab-network]").evaluate((b) => getComputedStyle(b).backgroundColor), "rgba(0, 0, 0, 0)", "no block under the finger ahead of the selection");
await page.mouse.move(net.x + net.width / 2, net.y + 200);
assert.equal(await hlTo(), startAt, "the press left the row: back");
await page.mouse.up();
assert.equal(await page.locator("#setTab-network").evaluate((b) => b.classList.contains("on")), false, "nothing picked");
await page.locator(".nav-s[data-of=setTab-models]").click();
await page.waitForFunction(() => document.querySelector("#setTab-models").classList.contains("on"));
await frame(page);
assert.equal(await page.locator(".nav-s.cur").getAttribute("data-of"), "setTab-models");
assert.equal(await page.locator(".nav-s.cur").getAttribute("aria-selected"), "true");
const crumb = await page.locator("#crumb").evaluate((c) => [...c.querySelectorAll("span, b")].map((e) => e.textContent));
assert.deepEqual(crumb, [w.settings, w.models], "the header says where the reader is");
// the selection sits on the tab picked
const [hl, cur] = await page.evaluate(() => [document.querySelector(".nav-sub:not(.leaving) .nav-hl").getBoundingClientRect().top, document.querySelector(".nav-s.cur").getBoundingClientRect().top]);
assert.ok(Math.abs(hl - cur) < 1, `the selection is on the tab: ${hl} ${cur}`);
// another page without tabs of its own: the list folds away
await page.locator('#nav button[data-view="agents"]').click();
await page.waitForFunction(() => !document.querySelector(".nav-sub"));
// a point narrower, the header's row has them again, and no sidebar
await page.setViewportSize({ width: 1023, height: 760 });
await page.waitForFunction(() => !document.body.classList.contains("side-nav"));
await frame(page);
assert.ok(await page.locator(".top #nav").isVisible(), "the pages are in the header");
assert.equal(await page.locator("#side").isVisible(), false);
assert.equal(await page.locator("#crumb").isVisible(), false);
assert.equal(await page.locator("#nav .nav-gl:visible").count(), 0, "no group names in the header's row");
assert.ok(await page.evaluate(() => document.documentElement.scrollWidth <= document.documentElement.clientWidth), "the window does not scroll sideways");
// Settings' tabs are its own strip again
await page.locator("#prefs").click();
await page.locator("#setTabs").waitFor();
assert.equal(await page.locator(".nav-sub").count(), 0);
assert.deepEqual(errors, []);
await context.close();
});
await t.test("narrow from the start: the gateway is not read for a sidebar", async () => {
const reads = [];
const context = await browser.newContext({ viewport: { width: 900, height: 700 }, reducedMotion: "reduce" });
const page = await context.newPage();
await page.route("**/*", serve("en", reads));
await page.goto("http://magpie.test/");
await page.waitForSelector("#nav button.on");
await page.waitForTimeout(2000);
assert.equal(reads.length, 0, "no read with no sidebar to show it");
// and read when the window is made wide
await page.setViewportSize({ width: 1200, height: 700 });
await page.locator("#sideGw").waitFor();
assert.equal(reads.length, 1);
await context.close();
});
await t.test("the list opens and folds as it plays", async () => {
const context = await browser.newContext({ viewport: { width: 1200, height: 760 } });
const page = await context.newPage();
await page.route("**/*", serve("en", []));
await page.goto("http://magpie.test/");
await page.waitForSelector("#nav button.on");
await page.locator("#prefs").click();
const box = page.locator("#side .nav-sub").first();
await box.waitFor();
assert.ok(await box.evaluate((b) => b.getAnimations().length > 0), "the list unrolls");
await page.locator('#nav button[data-view="agents"]').click();
// folding: out of reach at once, gone once it has played
assert.equal(await page.locator(".nav-sub:not(.leaving)").count(), 0);
assert.equal(await page.locator(".nav-s").count(), 0, "its rows are no tabs while they fold");
await page.waitForFunction(() => !document.querySelector(".nav-sub"));
await context.close();
});
});
}
@@ -90,7 +90,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
await page.goto("http://magpie.test/");
await page.locator("#prefs").click();
await page.locator("#setTab-sync").click();
await page.locator(":is(#setTab-sync, .nav-s[data-of=setTab-sync]):visible").click();
const list = page.locator("#syncList");
const rowNamed = (name) => list.locator(".row.pref").filter({ has: page.locator(".name", { hasText: name }) });
const auto = rowNamed(w.auto);
+1 -1
View File
@@ -77,7 +77,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
page.setDefaultTimeout(5000);
await page.goto("http://magpie.test/");
await page.locator("#prefs").click();
await page.locator("#setTab-sync").click();
await page.locator(":is(#setTab-sync, .nav-s[data-of=setTab-sync]):visible").click();
const first = page.locator("#syncList .row.pref").first();
await first.waitFor({ state: "visible" });
const said = await first.locator(".who > .sub").first().textContent();
+1 -1
View File
@@ -89,7 +89,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
await page.goto("http://magpie.test/");
await page.locator("#prefs").click();
await page.locator("#setTab-sync").click();
await page.locator(":is(#setTab-sync, .nav-s[data-of=setTab-sync]):visible").click();
const list = page.locator("#syncList");
const first = list.locator(".row.pref").first();
await first.waitFor({ state: "visible" });
+1 -1
View File
@@ -68,7 +68,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
page.setDefaultTimeout(5000);
await page.goto("http://magpie.test/");
await page.locator("#prefs").click();
await page.locator("#setTab-sync").click();
await page.locator(":is(#setTab-sync, .nav-s[data-of=setTab-sync]):visible").click();
const first = page.locator("#syncList .row.pref").first();
await first.waitFor({ state: "visible" });
const status = first.locator(".who > .sub").first();
+1 -1
View File
@@ -68,7 +68,7 @@ async function open(browser, lang, posts, platform, over) {
await page.route("**/*", server(lang, posts, over));
await page.goto("http://magpie.test/?view=usage");
await page.locator("#prefs").click();
await page.locator("#setTab-usage").click();
await page.locator(":is(#setTab-usage, .nav-s[data-of=setTab-usage]):visible").click();
await page.locator("#trayUsagePick button").waitFor();
return { context, page };
}
+1 -1
View File
@@ -76,7 +76,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
await page.route("**/*", server(lang, posts));
await page.goto("http://magpie.test/?view=usage");
await page.locator("#prefs").click();
await page.locator("#setTab-usage").click();
await page.locator(":is(#setTab-usage, .nav-s[data-of=setTab-usage]):visible").click();
const pill = page.locator("#trayUsagePick button");
await pill.waitFor();
await pill.scrollIntoViewIfNeeded();
+1 -1
View File
@@ -68,7 +68,7 @@ async function open(browser, lang, posts, platform, over) {
await page.route("**/*", server(lang, posts, over));
await page.goto("http://magpie.test/?view=usage");
await page.locator("#prefs").click();
await page.locator("#setTab-usage").click();
await page.locator(":is(#setTab-usage, .nav-s[data-of=setTab-usage]):visible").click();
await page.locator("#trayUsagePick button").waitFor();
return { context, page };
}
@@ -63,7 +63,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
// from Agents: the Usage page would have read the allowances already
await page.goto("http://magpie.test/?view=agents");
await page.locator("#prefs").click();
await page.locator("#setTab-usage").click();
await page.locator(":is(#setTab-usage, .nav-s[data-of=setTab-usage]):visible").click();
const pill = page.locator("#trayUsagePick button");
await pill.waitFor();
assert.equal(await page.evaluate(() => quotas), null, "the allowances were read before the click");
+1 -1
View File
@@ -92,7 +92,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
await page.goto("http://magpie.test/?view=usage");
await page.locator("#prefs").click();
await page.locator("#setTab-usage").click();
await page.locator(":is(#setTab-usage, .nav-s[data-of=setTab-usage]):visible").click();
const pill = page.locator("#trayUsagePick button");
await pill.waitFor();
await page.waitForFunction(() => document.querySelector("#trayUsagePick button").textContent.trim() === "Copilot");
+1 -1
View File
@@ -100,7 +100,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
await page.goto("http://magpie.test/?view=settings");
// the rows are in Settings' About part
const aboutTab = async () => {
await page.locator("#setTab-about").click();
await page.locator(":is(#setTab-about, .nav-s[data-of=setTab-about]):visible").click();
await page.locator("#setPage-about").waitFor({ state: "visible" });
};
await aboutTab();
+1 -1
View File
@@ -54,7 +54,7 @@ async function open(browser, lang, ctl, errors) {
page.on("pageerror", (e) => errors.push(e.message));
await page.route("**/*", server(lang, ctl));
await page.goto("http://magpie.test/?view=settings");
await page.locator("#setTab-about").click();
await page.locator(":is(#setTab-about, .nav-s[data-of=setTab-about]):visible").click();
await page.locator("#setPage-about").waitFor({ state: "visible" });
return page;
}
+1 -1
View File
@@ -73,7 +73,7 @@ async function open(browser, lang, ctl, errors) {
page.on("pageerror", (e) => errors.push(e.message));
await page.route("**/*", server(lang, ctl));
await page.goto("http://magpie.test/?view=settings");
await page.locator("#setTab-about").click();
await page.locator(":is(#setTab-about, .nav-s[data-of=setTab-about]):visible").click();
await page.locator("#setPage-about").waitFor({ state: "visible" });
const row = page.locator("#about .row.pref.update-mirror-row");
await row.waitFor();
+1 -1
View File
@@ -92,7 +92,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
assert(await page.locator("#usageAccounts .row").evaluateAll((rs) => rs.every((r) => parseFloat(getComputedStyle(r).borderLeftWidth) === 0)));
// Requests: the Account filter asks for one account's calls
await page.locator("#usageTab .opt").nth(1).click();
await page.locator(":is(#usageTab .opt, .nav-s):visible").nth(1).click();
await page.locator(".led tbody tr").first().waitFor();
assert.equal(await page.locator("#ledAccount").isHidden(), false);
assert.equal((await page.locator("#ledAccount").textContent()).trim(), w.all);
+1 -1
View File
@@ -117,7 +117,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
await p.route("**/*", serve(lang, currency, scale, false));
await p.goto("http://magpie.test/");
await p.locator('[data-view="usage"]').first().click();
await p.locator("#usageTab .opt").nth(1).click();
await p.locator(":is(#usageTab .opt, .nav-s):visible").nth(1).click();
await p.locator("#ledChart svg").waitFor();
for (let i = 0; i < 3; i++) {
await p.locator("#ledMetric .opt").nth(i).click();
+2 -2
View File
@@ -98,7 +98,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
};
const requests = async (p) => {
await p.locator('[data-view="usage"]').first().click();
await p.locator("#usageTab .opt").nth(1).click();
await p.locator(":is(#usageTab .opt, .nav-s):visible").nth(1).click();
await p.locator(".led tbody tr.led-row").first().waitFor();
};
@@ -177,7 +177,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
const posts = [];
const { p, errors } = await open("http://magpie.test/", { width: 900, height: 420 }, false, [], [], posts);
await p.locator("#prefs").click();
await p.locator("#setTab-sync").click();
await p.locator(":is(#setTab-sync, .nav-s[data-of=setTab-sync]):visible").click();
const first = p.locator("#syncList .row.pref").first();
await first.waitFor({ state: "visible" });
const toEnd = async () => {
@@ -130,7 +130,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
// the window, on the Overview
const calls = { state: 0, overview: 0, requests: 0 }, cur = { v: 0 };
const p = await open("http://magpie.test/?view=usage", { width: 1180, height: 760 }, calls, cur);
if (await p.locator("#usageTab .opt.on").evaluate((b) => b !== b.parentElement.firstElementChild)) await p.locator("#usageTab .opt").first().click();
if (await p.locator("#usageTab .opt.on").evaluate((b) => b !== b.parentElement.firstElementChild)) await p.locator(":is(#usageTab .opt, .nav-s):visible").first().click();
const BAR = "#chart .bars .bar";
await p.locator(BAR).first().waitFor();
assert.equal(await p.locator(BAR).count(), DAYS);
@@ -151,7 +151,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
assert.equal(await p.locator("#chart").isVisible(), true);
// the Requests tab: its columns stay
await p.locator("#usageTab .opt").nth(1).click();
await p.locator(":is(#usageTab .opt, .nav-s):visible").nth(1).click();
const COL = "#ledgerPane .led-chart rect.col";
await p.locator(COL).first().waitFor();
await p.waitForTimeout(300);
@@ -160,7 +160,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
await back(p, calls, "requests");
assert.deepEqual(await flashes(p), [], "the Requests chart isn't blanked");
assert.deepEqual(await kept(p, COL), Array.from({ length: cols }, (_, i) => i + 1), "the same columns stay");
await p.locator("#usageTab .opt").first().click(); // the tab is remembered: leave it on the Overview
await p.locator(":is(#usageTab .opt, .nav-s):visible").first().click(); // the tab is remembered: leave it on the Overview
// the tray panel's Usage tab: not dimmed, not drawn again
const pc = { state: 0, overview: 0, requests: 0 };
+1 -1
View File
@@ -90,7 +90,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
await p.route("**/*", server(lang, theme, variant, asked));
await p.goto("http://magpie.test/");
await p.locator('[data-view="usage"]').first().click();
await p.locator("#usageTab .opt").nth(1).click();
await p.locator(":is(#usageTab .opt, .nav-s):visible").nth(1).click();
await p.locator("#ledRank .rk").first().waitFor();
return { p, errors, asked, context };
};
@@ -65,7 +65,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
await page.route("**/*", server("en", seen, held));
await page.goto("http://magpie.test/");
await page.locator('[data-view="usage"]').first().click();
await page.locator("#usageTab .opt").nth(1).click();
await page.locator(":is(#usageTab .opt, .nav-s):visible").nth(1).click();
// the tab's opening reads, let go so the page is drawn
await settle(page, seen, 2);
held.splice(0).forEach((go) => go());
@@ -138,7 +138,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
await p.route("**/*", server(lang, theme, variant, asked, exported));
await p.goto("http://magpie.test/");
await p.locator('[data-view="usage"]').first().click();
await p.locator("#usageTab .opt").nth(1).click();
await p.locator(":is(#usageTab .opt, .nav-s):visible").nth(1).click();
if (variant !== "none") await p.locator("#ledRank .rk").first().waitFor();
if (["many", "unpriced"].includes(variant)) await p.locator("#ledSplit .opt").nth(SPLIT.provider).click();
return { p, errors, asked, exported, context };
@@ -414,7 +414,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
// are divided — the two sources the Requests tab draws keep none of it
assert.equal(await p.locator("#ledKpi .blk").nth(2).evaluate((b) => getComputedStyle(b).borderLeftWidth), "0px", "a totals card starting a row carries no left line");
assert.notEqual(await p.locator("#ledKpi .blk").nth(2).evaluate((b) => getComputedStyle(b).borderTopWidth), "0px", "and the rows are divided");
await p.locator("#usageTab .opt").nth(1).click();
await p.locator(":is(#usageTab .opt, .nav-s):visible").nth(1).click();
await p.locator("#ledVia .blk").first().waitFor();
assert.equal(await p.locator("#ledVia .blk").nth(1).evaluate((b) => getComputedStyle(b).borderLeftWidth), "0px", "a source cell carries no line between cells of one bar");
// a hovered end cell rounds as the bar does, never a square corner over
@@ -108,7 +108,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
await p.route("**/*", server(lang, asked, refreshed));
await p.goto("http://magpie.test/");
await p.locator('[data-view="usage"]').first().click();
await p.locator("#usageTab .opt").nth(1).click();
await p.locator(":is(#usageTab .opt, .nav-s):visible").nth(1).click();
await p.locator("#ledWrap .led tbody tr").first().waitFor();
const rows = p.locator(".led tbody tr.led-row");
@@ -218,7 +218,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
await p.route("**/*", server("en", asked, refreshed));
await p.goto("http://magpie.test/");
await p.locator('[data-view="usage"]').first().click();
await p.locator("#usageTab .opt").nth(1).click();
await p.locator(":is(#usageTab .opt, .nav-s):visible").nth(1).click();
await p.locator("#ledWrap .led tbody tr").first().waitFor();
await reader.click(p, p.locator(".led tbody tr.led-row").nth(0));
await p.locator(".led-cx .cx-sec").first().waitFor();
@@ -95,7 +95,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
await p.route("**/*", server(lang, refreshed));
await p.goto("http://magpie.test/");
await p.locator('[data-view="usage"]').first().click();
await p.locator("#usageTab .opt").nth(1).click();
await p.locator(":is(#usageTab .opt, .nav-s):visible").nth(1).click();
await p.locator("#ledWrap .led tbody tr").first().waitFor();
const rows = p.locator(".led tbody tr.led-row");
+4 -3
View File
@@ -91,7 +91,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
await p.route("**/*", server(lang));
await p.goto("http://magpie.test/");
await p.locator('[data-view="usage"]').first().click();
await p.locator("#usageTab .opt").nth(1).click();
await p.locator(":is(#usageTab .opt, .nav-s):visible").nth(1).click();
await p.locator("#ledWrap .led tbody tr").first().waitFor();
await p.waitForTimeout(300);
return p;
@@ -111,8 +111,9 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
await reader.click(p, p.locator(".led tbody tr.led-row").nth(2).locator("td").nth(2));
assert((await p.locator(".led tbody tr.led-detail").textContent()).includes("gpt-5.6-luna"), "and in the row's details");
// wide enough: the line is there
const q = await open(1100);
// wide enough: the line is there (the window wider by the sidebar
// beside the page)
const q = await open(1320);
assert.deepEqual(await fits(q), { scroll: true, status: true });
assert(await q.locator(".led tbody tr.led-row").nth(2).locator(".price-reference").isVisible(), "the price reference line at a wider window");
assert.deepEqual(errors, []);
+3 -3
View File
@@ -145,7 +145,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
await page.route("**/*", server(lang, theme, asked));
await page.goto("http://magpie.test/");
await page.locator('nav [data-view="usage"], [data-view="usage"]').first().click();
await page.locator("#usageTab .opt").nth(1).click();
await page.locator(":is(#usageTab .opt, .nav-s):visible").nth(1).click();
await page.locator("#ledWrap .led tbody tr").first().waitFor();
return { page, errors };
};
@@ -219,7 +219,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
await t.test(lang, async () => {
const asked = [];
const { page, errors } = await open(lang, "light", asked);
assert.deepEqual(await page.locator("#usageTab .opt").allTextContents(), w.tabs);
assert.deepEqual(await page.locator(":is(#usageTab .opt, .nav-s):visible").allTextContents(), w.tabs);
assert.equal(asked.at(-1).get("period"), "today");
assert.equal(asked.at(-1).get("offset"), "0");
assert.deepEqual(await page.locator(".led thead th").allTextContents(), w.cols);
@@ -446,7 +446,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
if (shots) await page.screenshot({ path: path.join(shots, `${engine}-usage-ledger-${lang}-narrow-dark.png`) });
// nor with the tab bar's other tabs, now three
for (const i of [0, 2]) {
await page.locator("#usageTab .opt").nth(i).click();
await page.locator(":is(#usageTab .opt, .nav-s):visible").nth(i).click();
await page.waitForTimeout(300);
const [wider, wide] = await sideways();
assert(!wider && !wide.length, `tab ${i}: the page does not scroll sideways: ${wide}`);
@@ -92,7 +92,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
await p.route("**/*", server(lang, asked));
await p.goto("http://magpie.test/");
await p.locator('[data-view="usage"]').first().click();
await p.locator("#usageTab .opt").nth(1).click();
await p.locator(":is(#usageTab .opt, .nav-s):visible").nth(1).click();
await p.locator("#ledWrap .led tbody tr").first().waitFor();
await p.waitForTimeout(300);
+2 -2
View File
@@ -70,7 +70,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
const p = await open();
await p.locator('[data-view="usage"]').first().click();
await p.locator("#usageTab .opt").nth(1).click(); // Requests
await p.locator(":is(#usageTab .opt, .nav-s):visible").nth(1).click(); // Requests
await p.locator("#ledWrap .led tbody tr").first().waitFor();
assert.equal((await p.locator("#usageEvery").textContent()).trim(), w.label, "every 5 s to begin with");
@@ -109,7 +109,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
assert(/\d{1,2}:\d{2}:\d{2}/.test(await p.locator("#usageReload").getAttribute("title")), "when they were read");
// on Overview it reads the summary, and the allowances are read now too
await p.locator("#usageTab .opt").nth(0).click();
await p.locator(":is(#usageTab .opt, .nav-s):visible").nth(0).click();
await p.locator("#stats .kpi:not(.loading-kpi)").first().waitFor();
const o = calls.overview, q = calls.quotas, a = calls.asked;
await p.locator("#usageReload").click();
@@ -126,7 +126,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
await p.route("**/*", server(lang));
await p.goto("http://magpie.test/");
await p.locator('[data-view="usage"]').first().click();
await p.locator("#usageTab .opt").nth(1).click();
await p.locator(":is(#usageTab .opt, .nav-s):visible").nth(1).click();
await p.locator("#ledWrap .led tbody tr").first().waitFor();
const heads = await p.locator(".led thead th").evaluateAll((ths) => ths.filter((th) => th.offsetParent).map((th) => th.textContent));
@@ -158,7 +158,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
assert((await codex.textContent()).includes(sol), "overview: " + (await codex.textContent()));
assert(!(await p.locator("#usageAgents .row.stat").nth(1).locator(".sub").textContent()).includes("/"), "a group with no speed says none");
await p.locator("#usageTab .opt").nth(1).click();
await p.locator(":is(#usageTab .opt, .nav-s):visible").nth(1).click();
await p.locator("#ledWrap .led tbody tr").first().waitFor();
await p.waitForTimeout(200);
+1 -1
View File
@@ -118,7 +118,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
await p.goto("http://magpie.test/");
assert(await p.evaluate(() => document.body.classList.contains("window")), "the app's window");
await p.locator('[data-view="usage"]').first().click();
await p.locator("#usageTab .opt").nth(1).click();
await p.locator(":is(#usageTab .opt, .nav-s):visible").nth(1).click();
await p.locator("#ledWrap .led tbody tr").first().waitFor();
await p.waitForTimeout(300);
@@ -82,7 +82,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
await p.route("**/*", server(lang));
await p.goto("http://magpie.test/");
await p.locator('[data-view="usage"]').first().click();
await p.locator("#usageTab .opt").nth(1).click();
await p.locator(":is(#usageTab .opt, .nav-s):visible").nth(1).click();
await p.locator("#ledWrap .led tbody tr").first().waitFor();
await p.waitForTimeout(300);
+1 -1
View File
@@ -115,7 +115,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
// the request archive's switch, over the Usage page's requests
await page.locator('[data-view="usage"]').first().click();
await page.locator("#usageTab .opt").nth(1).click();
await page.locator(":is(#usageTab .opt, .nav-s):visible").nth(1).click();
const sw = page.locator("#ledArchive .led-arch-sw");
await sw.waitFor();
assert.equal(await sw.textContent(), w.name);
@@ -63,7 +63,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
await page.goto("http://magpie.test/");
await page.locator("#prefs").click();
await page.locator("#setTab-sync").click();
await page.locator(":is(#setTab-sync, .nav-s[data-of=setTab-sync]):visible").click();
const list = page.locator("#syncList");
const first = list.locator(".row.pref").first();
await first.waitFor({ state: "visible" });