routing: Expand picks how far the stage opens, models or accounts (ipsikent on X)
ipsikent asked on X for a setting for how deep the Routing page opens:
often only which model a route uses matters, not which provider's account
it went to. Expand, at the end of the stage's top line, opens a menu
(openProtoMenu) with Automatic (as before: long lists folded, short ones
open), Models (two or more accounts or keys of one provider fold into the
row naming the model, and start folded) and Accounts (every fold starts
open). Models and Accounts open every group in the group. The pick is
kept in localStorage magpie.routingDepth; picking one forgets the stage's
remembered folds, so every row follows it at once, and a row clicked
after it is kept as before. Accounts and keys isn't changed. Display only:
the gateway's choice of seat is untouched.
It sits in the stage card's top line, not the page head: in the head it
pushed Hide accounts onto a second line at 420px in English. "Expand" is
in the core dictionary, since i18n-keys finds the word in plugged.go.
Run (mica, at this tree on 2649d5d72):
- node --test routing-depth.test.cjs: 20 of 20, Chromium and WebKit, en,
zh, zh-TW, ja, de, at 1100 and 420. Red on origin/main's routing files
(no #rtDepth).
- i18n-keys, i18n-en-no-cjk, routing-group-fold, routing-keys-fold,
routing-fold-accounts-together: ok.
- Screenshots at 1100 (zh) and 420 (en, de): one-line page head, Expand
at the card's right.
The whole GUI suite is queued on mote behind another session's (suite
lock); its reds get issues.
Not tried: the real app, WebKitGTK.
This commit is contained in:
@@ -240,6 +240,17 @@ keys and `provider/model@` for accounts on the stage, `provider/*` and
|
||||
gateway's order and choice of seat don't change. Two stay two rows. See
|
||||
`routing-keys-fold.test.cjs` and `routing-group-fold.test.cjs`.
|
||||
|
||||
How far the stage opens is the reader's to pick (ipsikent on X: often only
|
||||
which model a route uses matters). Expand, at the end of the stage's top
|
||||
line (`#rtDepth`, `DEPTHS`, `openTo`), offers Automatic (as above), Models
|
||||
(two or more accounts or keys of a provider fold, `foldAt`, and start
|
||||
folded) and Accounts (every fold starts open). Both open every group in
|
||||
the group. It is kept in localStorage `magpie.routingDepth`, and picking
|
||||
one forgets what was opened or folded on the stage (the keys without a
|
||||
trailing `/@` or `/*`), so every row follows it at once; a row clicked
|
||||
after it is kept as before. Accounts and keys isn't changed by it. See
|
||||
`routing-depth.test.cjs`.
|
||||
|
||||
### Routing account windows
|
||||
|
||||
A subscription account's row in Accounts and keys shows the one figure
|
||||
|
||||
@@ -81,6 +81,7 @@ const I18N = {
|
||||
"At least: {n} answer tokens in {ms} after the first token, the {r} reasoning tokens left out. No first text was recorded, so reasoning after the first token is counted too": "下限:首字后 {ms} 输出 {n} 个正文 token,{r} 个推理 token 不计。没有记录首个正文的时间,首字后的推理时间也算在里面",
|
||||
"At least: {n} output tokens in {ms}, from the request to its last token, the wait for the first one counted too": "下限:从收到请求到最后一个 token,{ms} 输出 {n} 个 token,等首字的时间也算在里面",
|
||||
"Collapse all": "全部收起",
|
||||
"Expand": "展开",
|
||||
"Expand all": "全部展开",
|
||||
"Found by magpie: {url}": "magpie 自动找到:{url}",
|
||||
"Auto-detect": "自动检测",
|
||||
@@ -5407,6 +5408,7 @@ const I18N = {
|
||||
"At least: {n} answer tokens in {ms} after the first token, the {r} reasoning tokens left out. No first text was recorded, so reasoning after the first token is counted too": "下限:首字後 {ms} 輸出 {n} 個正文 token,{r} 個推理 token 不計。沒有記錄首個正文的時間,首字後的推理時間也算在裡面",
|
||||
"At least: {n} output tokens in {ms}, from the request to its last token, the wait for the first one counted too": "下限:從收到請求到最後一個 token,{ms} 輸出 {n} 個 token,等首字的時間也算在裡面",
|
||||
"Collapse all": "全部收起",
|
||||
"Expand": "展開",
|
||||
"Expand all": "全部展開",
|
||||
"Found by magpie: {url}": "magpie 自動找到:{url}",
|
||||
"Auto-detect": "自動偵測",
|
||||
@@ -10717,6 +10719,7 @@ const I18N = {
|
||||
"At least: {n} answer tokens in {ms} after the first token, the {r} reasoning tokens left out. No first text was recorded, so reasoning after the first token is counted too": "下限:最初のトークン後 {ms} で回答 {n} トークン(推論 {r} トークンは含めず)。最初の本文の時刻が記録されていないため、最初のトークン後の推論の時間も含まれます",
|
||||
"At least: {n} output tokens in {ms}, from the request to its last token, the wait for the first one counted too": "下限:リクエストを受けてから最後のトークンまで {ms} で {n} トークンを出力。最初のトークンを待つ時間も含まれます",
|
||||
"Collapse all": "すべて折りたたむ",
|
||||
"Expand": "展開",
|
||||
"Expand all": "すべて展開",
|
||||
"Found by magpie: {url}": "magpie が自動で見つけました:{url}",
|
||||
"Auto-detect": "自動検出",
|
||||
@@ -16029,6 +16032,7 @@ const I18N = {
|
||||
"At least: {n} answer tokens in {ms} after the first token, the {r} reasoning tokens left out. No first text was recorded, so reasoning after the first token is counted too": "Mindestens: {n} Antwort-Token in {ms} nach dem ersten Token, ohne die {r} Reasoning-Token. Kein erster Text aufgezeichnet, also zählt Reasoning nach dem ersten Token mit",
|
||||
"At least: {n} output tokens in {ms}, from the request to its last token, the wait for the first one counted too": "Mindestens: {n} Ausgabe-Token in {ms}, von der Anfrage bis zu ihrem letzten Token, das Warten auf das erste mitgezählt",
|
||||
"Collapse all": "Alle einklappen",
|
||||
"Expand": "Aufklappen",
|
||||
"Expand all": "Alle ausklappen",
|
||||
"Found by magpie: {url}": "Von magpie gefunden: {url}",
|
||||
"Auto-detect": "Automatisch erkennen",
|
||||
|
||||
@@ -79,7 +79,21 @@ function routingPage(part) {
|
||||
const top = el("div", "rt-top");
|
||||
const what = el("div", "rt-what");
|
||||
const mode = el("p", "rt-mode");
|
||||
top.append(what, mode);
|
||||
// how far the stage opens (openTo), picked at the head's end
|
||||
const depthPick = el("button", "text rt-depth"), depthWord = el("span", "", t("Expand"));
|
||||
depthPick.type = "button";
|
||||
depthPick.id = "rtDepth";
|
||||
depthPick.setAttribute("aria-haspopup", "menu");
|
||||
depthPick.setAttribute("aria-expanded", "false");
|
||||
depthWord.dataset.t = "";
|
||||
depthWord.dataset.en = "Expand";
|
||||
depthPick.dataset.tt = "Expand routes to";
|
||||
depthPick.title = t("Expand routes to");
|
||||
depthPick.innerHTML = '<svg viewBox="0 0 16 16" width="13" height="13" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m5 6 3-3 3 3M5 10l3 3 3-3"/></svg>';
|
||||
depthPick.append(depthWord);
|
||||
const topRow = el("div", "rt-toprow");
|
||||
topRow.append(what, depthPick);
|
||||
top.append(topRow, mode);
|
||||
const stage = el("div", "rt-stage");
|
||||
const wires = document.createElementNS(NS, "svg");
|
||||
wires.setAttribute("class", "rt-wires");
|
||||
@@ -1812,11 +1826,50 @@ function routingPage(part) {
|
||||
const isOpen = (k, dflt) => keysShut.has(k) ? false : keysOpen.has(k) ? true : dflt;
|
||||
function keepOpen(k, open) {
|
||||
if (open) { keysOpen.add(k); keysShut.delete(k); } else { keysOpen.delete(k); keysShut.add(k); }
|
||||
keepFolds();
|
||||
}
|
||||
function keepFolds() {
|
||||
try {
|
||||
localStorage.setItem("magpie.routingKeysOpen", JSON.stringify([...keysOpen]));
|
||||
localStorage.setItem("magpie.routingFolded", JSON.stringify([...keysShut]));
|
||||
} catch {}
|
||||
}
|
||||
// How far the stage opens (ipsikent on X: often only which model a
|
||||
// route uses matters, not which provider's account): "" as above, long
|
||||
// lists folded; "models" folds every provider's accounts and keys, two
|
||||
// or more, into their one row; "accounts" opens each. Both open every
|
||||
// group in the group. Picked from the
|
||||
// stage head's Expand, kept in localStorage magpie.routingDepth. Picking
|
||||
// one forgets what the reader opened or folded on the stage, so every
|
||||
// row follows it at once; a row clicked after is kept as before.
|
||||
const DEPTHS = [["", "Automatic", "Long lists start folded, short ones open"],
|
||||
["models", "Models", "A row for each provider's model, its accounts and keys folded into it"],
|
||||
["accounts", "Accounts", "A row for each account and key"]];
|
||||
let openTo = "";
|
||||
try { openTo = localStorage.getItem("magpie.routingDepth") || ""; } catch {}
|
||||
if (!DEPTHS.some(([v]) => v === openTo)) openTo = "";
|
||||
// a stage fold of n accounts (acct) or keys starts open?
|
||||
const foldStartsOpen = (acct, n) => openTo === "accounts" || !openTo && acct && n < LONG;
|
||||
// how many side by side fold: two already when only models are shown
|
||||
const foldAt = () => openTo === "models" ? 2 : FOLD_AT;
|
||||
{
|
||||
depthPick.onclick = (e) => {
|
||||
e.stopPropagation();
|
||||
if (depthPick.classList.contains("open")) return closeProtoMenu();
|
||||
openProtoMenu(depthPick, DEPTHS.map(([v, name, title]) => ({ v, name, note: "", title: t(title) })), openTo, (v) => {
|
||||
openTo = v;
|
||||
try { if (v) localStorage.setItem("magpie.routingDepth", v); else localStorage.removeItem("magpie.routingDepth"); } catch {}
|
||||
// the stage's own: Accounts and keys' sums (provider/@, provider/*) stay
|
||||
const own = (k) => !/\/[@*]$/.test(k);
|
||||
keysOpen = new Set([...keysOpen].filter((k) => !own(k)));
|
||||
keysShut = new Set([...keysShut].filter((k) => !own(k)));
|
||||
keepFolds();
|
||||
const rs = staged();
|
||||
if (rs.length) steady(() => rebuild(rs, false));
|
||||
render();
|
||||
}, "Expand routes to", "rt-depth-menu", "right");
|
||||
};
|
||||
}
|
||||
const agents = new Map(); // agent → { node, ic, name, sub, wire }
|
||||
let sets = []; // the account sets on the stage, in the order they came
|
||||
const playing = new Map(); // the routes being played → the gen playing each
|
||||
@@ -2822,10 +2875,10 @@ function routingPage(part) {
|
||||
const foldOf = new Map();
|
||||
let run = [];
|
||||
const flush = () => {
|
||||
if (run.length >= FOLD_AT) {
|
||||
if (run.length >= foldAt()) {
|
||||
const w = rows.get(run[0]).w, f = foldNode(foldKey(w, rows.get(run[0]).path), w), acct = w.kind === "account";
|
||||
f.ids = run;
|
||||
shut(f, isOpen(f.pk, acct && run.length < LONG),
|
||||
shut(f, isOpen(f.pk, foldStartsOpen(acct, run.length)),
|
||||
acct ? "Fold these accounts into one row" : "Fold these keys into one row", acct ? "Show each account" : "Show each key");
|
||||
for (const id of run) foldOf.set(id, f);
|
||||
}
|
||||
@@ -2860,7 +2913,7 @@ function routingPage(part) {
|
||||
// a route's heading starts open, whatever its length: a second
|
||||
// agent coming shouldn't fold the first's rows away
|
||||
if (way) shut(s, isOpen(s.pk, true), "Fold this route into one row", "Show where this route goes");
|
||||
else shut(s, isOpen(s.pk, under.get(key) < LONG), "Fold this group into one row", "Show what this group routes to");
|
||||
else shut(s, isOpen(s.pk, openTo ? true : under.get(key) < LONG), "Fold this group into one row", "Show what this group routes to");
|
||||
els.push(s.li);
|
||||
}
|
||||
// folded: what it routes to is its heading's
|
||||
|
||||
@@ -2,6 +2,10 @@
|
||||
// kernel adds them to i18n.js's (magpie.strings).
|
||||
magpie.strings({
|
||||
zh: {
|
||||
"Expand routes to": "路由展开到",
|
||||
"Long lists start folded, short ones open": "长列表先折叠,短的展开",
|
||||
"A row for each provider's model, its accounts and keys folded into it": "每个供应商的模型一行,账号和密钥折叠在里面",
|
||||
"A row for each account and key": "每个账号和密钥各一行",
|
||||
"Turn on Routing": "开启路由",
|
||||
"Their page is on Routing, which is off": "它们的页面在路由里,而路由已关闭",
|
||||
"sign-in refused (answered since)": "登录曾被拒(之后已应答)",
|
||||
@@ -757,6 +761,10 @@ magpie.strings({
|
||||
"Bound to some keys, the group is theirs alone: any other gateway key neither sees it in its model list nor can use it. A request from this computer without a key still can.": "绑定到某些密钥后,这个组只归它们用:其他网关密钥既不会在模型列表里看到它,也用不了它。本机不带密钥的请求仍然可以用。",
|
||||
},
|
||||
"zh-TW": {
|
||||
"Expand routes to": "路由展開到",
|
||||
"Long lists start folded, short ones open": "長列表先摺疊,短的展開",
|
||||
"A row for each provider's model, its accounts and keys folded into it": "每個供應商的模型一行,帳號和金鑰摺疊在裡面",
|
||||
"A row for each account and key": "每個帳號和金鑰各一行",
|
||||
"Turn on Routing": "開啟路由",
|
||||
"Their page is on Routing, which is off": "它們的頁面在路由裡,而路由已關閉",
|
||||
"sign-in refused (answered since)": "登入曾被拒(之後已應答)",
|
||||
@@ -1512,6 +1520,10 @@ magpie.strings({
|
||||
"Bound to some keys, the group is theirs alone: any other gateway key neither sees it in its model list nor can use it. A request from this computer without a key still can.": "綁定到某些金鑰後,這個組只歸它們用:其他閘道金鑰既不會在模型列表裡看到它,也用不了它。本機不帶金鑰的請求仍然可以用。",
|
||||
},
|
||||
ja: {
|
||||
"Expand routes to": "ルートの展開",
|
||||
"Long lists start folded, short ones open": "長いリストは折りたたみ、短いものは展開",
|
||||
"A row for each provider's model, its accounts and keys folded into it": "プロバイダーのモデルごとに1行、アカウントとキーはその中に折りたたみ",
|
||||
"A row for each account and key": "アカウントとキーごとに1行",
|
||||
"Turn on Routing": "ルーティングをオンにする",
|
||||
"Their page is on Routing, which is off": "ページはルーティングの中にあり、ルーティングはオフです",
|
||||
"sign-in refused (answered since)": "サインイン拒否(その後は応答あり)",
|
||||
@@ -2267,6 +2279,10 @@ magpie.strings({
|
||||
"Bound to some keys, the group is theirs alone: any other gateway key neither sees it in its model list nor can use it. A request from this computer without a key still can.": "キーを紐づけると、このグループはそのキー専用になります。ほかのゲートウェイキーではモデル一覧に表示されず、使うこともできません。このコンピューターからキーなしで送るリクエストは引き続き使えます。",
|
||||
},
|
||||
de: {
|
||||
"Expand routes to": "Routen aufklappen bis",
|
||||
"Long lists start folded, short ones open": "Lange Listen zugeklappt, kurze offen",
|
||||
"A row for each provider's model, its accounts and keys folded into it": "Eine Zeile je Modell eines Anbieters, seine Konten und Schlüssel darin zugeklappt",
|
||||
"A row for each account and key": "Eine Zeile je Konto und Schlüssel",
|
||||
"Turn on Routing": "Weiterleitung einschalten",
|
||||
"Their page is on Routing, which is off": "Ihre Seite liegt unter Weiterleitung, und die ist aus",
|
||||
"sign-in refused (answered since)": "Anmeldung abgelehnt (seitdem beantwortet)",
|
||||
|
||||
@@ -3,7 +3,8 @@
|
||||
played by the gateway's own trace. */
|
||||
.rt { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px 12px; margin: 0 0 18px; }
|
||||
.rt-top { display: flex; flex-direction: column; gap: 3px; }
|
||||
.rt-what { font-size: 13px; color: var(--muted); }
|
||||
.rt-toprow { display: flex; align-items: flex-start; gap: 8px; }
|
||||
.rt-what { font-size: 13px; color: var(--muted); flex: 1; min-width: 0; }
|
||||
.rt-what b { color: var(--fg); font-weight: 600; }
|
||||
.rt-mode { margin: 0; font-size: 12.5px; color: var(--fg-2); line-height: 1.45; }
|
||||
/* the agents' and magpie's columns at least 124px, and as wide as their
|
||||
@@ -458,6 +459,8 @@ button.rt-session { cursor: pointer; }
|
||||
.rt-purpose.open svg { transform: rotate(180deg); }
|
||||
.rt-metric-pick { display: inline-flex; align-items: center; gap: 3px; height: 24px; margin-left: 6px; }
|
||||
.rt-metric-pick.open svg { transform: rotate(180deg); }
|
||||
.rt-depth { display: inline-flex; align-items: center; gap: 5px; flex: none; margin: -3px -7px -3px 0; }
|
||||
.rt-depth svg { flex: none; }
|
||||
.rt-fold-all { display: inline-flex; align-items: center; justify-content: center; width: 24px; height: 24px; padding: 0; margin-left: 2px; }
|
||||
.pop.proto-menu.rt-metric-menu { width: 190px; max-width: calc(100vw - 16px); background: var(--card); }
|
||||
.rt-metric-menu .pm-item { align-items: center; }
|
||||
|
||||
@@ -0,0 +1,187 @@
|
||||
// Run with Node's test runner and Playwright on the module path; see README.md.
|
||||
// How far the Routing stage opens is the reader's to pick (ipsikent on X:
|
||||
// often only which model a route uses matters, not which provider's
|
||||
// account it went to). Expand, at the end of the stage's top line, offers Automatic (long
|
||||
// lists folded, short ones open, as before), Models (every provider's
|
||||
// accounts and keys, two or more, folded into one row naming the model;
|
||||
// every group in the group open) and Accounts (each account and key in its
|
||||
// own row). Picking one forgets what the reader had opened or folded on
|
||||
// the stage, so every row follows it at once; it is kept across a reload,
|
||||
// and a row clicked after it is kept as before. In Chromium and WebKit, in
|
||||
// every language, at 1100 and 420 wide; no backend, the API is faked here.
|
||||
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 { reach } = require("./reader.cjs");
|
||||
|
||||
const assets = path.resolve(__dirname, "../assets");
|
||||
const now = new Date();
|
||||
const ago = (s) => new Date(now.getTime() - s * 1e3).toISOString();
|
||||
// a rest runs from when the test builds it, not from when the file loaded:
|
||||
// under load the webkit half runs minutes after, past a 3-minute rest
|
||||
const ahead = (m) => new Date(Date.now() + m * 60e3).toISOString();
|
||||
const M = "gpt-6";
|
||||
const rest = (k) => ({ why: "rate", until: ahead(3), key: k, for: 180e9 });
|
||||
const acct = (p, name, user, extra = {}) => ({ id: `${p}@${user}`, provider: p, name, who: user, kind: "account", model: M, plan: "Pro", ...extra });
|
||||
// the group: a group in it of eight ChatGPT accounts, then a team of
|
||||
// three accounts, a provider of seven and one key
|
||||
const pool = Array.from({ length: 8 }, (_, i) => `p${i + 1}@x.test`);
|
||||
const big = Array.from({ length: 7 }, (_, i) => `b${i + 1}@x.test`);
|
||||
const team = ["t1@x.test", "t2@x.test", "t3@x.test"];
|
||||
const duo = ["d1@x.test", "d2@x.test"];
|
||||
const order = (resting = ["p2@x.test"]) => [
|
||||
...pool.map((u) => acct("chatgpt", "ChatGPT", u, { via: ["pool"], ...(resting.includes(u) ? { rest: rest(`chatgpt@${u}`) } : {}) })),
|
||||
...team.map((u) => acct("team", "Team", u)),
|
||||
...big.map((u) => acct("big", "Big", u)),
|
||||
...duo.map((u) => acct("duo", "Duo", u)),
|
||||
{ id: "solo#s1", provider: "solo", name: "Solo", who: "solo-1", kind: "key", model: M },
|
||||
];
|
||||
const group = { id: "main", name: "Main", routing: "", members: ["chatgpt/" + M, "team/" + M, "big/" + M, "duo/" + M, "solo/" + M],
|
||||
subs: [{ id: "pool", name: "Pool", routing: "order", in: "main" }], via: ["pool", "", "", "", ""] };
|
||||
const route = (id, tries, extra = {}) => ({ id, seq: id, time: ago(60 - id), agent: "codex", model: "main", provider: "chatgpt", done: tries.every((x) => x.done),
|
||||
status: 200, ms: 900, tokens: 1200, group, order: order(), tries, ...extra });
|
||||
const first = route(1, [{ id: "chatgpt@p1@x.test", model: M, start: ago(59), done: true, status: 200, ms: 900 }]);
|
||||
|
||||
function serve(lang, live) {
|
||||
return async (request) => {
|
||||
const url = new URL(request.request().url());
|
||||
const json = (data) => request.fulfill({ json: data });
|
||||
if (url.pathname === "/boot.js") return request.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"${lang}",theme:"light",web:true};` });
|
||||
if (url.pathname === "/wails/runtime.js") return request.fulfill({ contentType: "text/javascript", body: "export const Window = {};" });
|
||||
if (url.pathname === "/api/state") return json({ agents: [{ id: "codex", name: "Codex", path: "/test/config.toml", fields: [] }], profiles: [], settings: { lang, theme: "light" } });
|
||||
if (url.pathname === "/api/gateway/trace") {
|
||||
if (url.searchParams.get("wait")) {
|
||||
if (live.queued.length) return json(live.queued.shift());
|
||||
live.pending.push(request);
|
||||
return;
|
||||
}
|
||||
return json({ mine: true, now: now.toISOString(), seq: 1, totals: { requests: 1, rerouted: 0, errors: 0 }, routes: [first] });
|
||||
}
|
||||
if (url.pathname === "/api/gateway/history") return json({ cut: false, days: [], routes: [] });
|
||||
if (url.pathname === "/api/groups") return json({ groups: [], pools: [] });
|
||||
if (url.pathname === "/api/providers") return json({ providers: [], excluded: [], gateway: { running: true, window: true } });
|
||||
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 request.fulfill({ body: await fs.readFile(file), contentType });
|
||||
};
|
||||
}
|
||||
|
||||
async function open(t, engine, lang, width = 1100) {
|
||||
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
||||
t.after(() => browser.close());
|
||||
const page = await browser.newPage({ viewport: { width, height: 900 }, reducedMotion: "reduce" });
|
||||
page.setDefaultTimeout(5000);
|
||||
page.setDefaultNavigationTimeout(60000);
|
||||
const errors = [];
|
||||
page.on("pageerror", (error) => errors.push(error.message));
|
||||
const live = { pending: [], queued: [], seq: 1 };
|
||||
await page.route("**/*", serve(lang, live));
|
||||
const ready = async () => {
|
||||
await page.goto("http://magpie.test/?view=routing");
|
||||
await page.locator(".rt-accts li.rt-sub").first().waitFor();
|
||||
await page.waitForFunction(() => document.querySelector(".rt-accts li.rt-fold em")?.textContent.trim());
|
||||
};
|
||||
await ready();
|
||||
const send = (...routes) => {
|
||||
const d = { mine: true, now: new Date().toISOString(), seq: ++live.seq, totals: { requests: live.seq }, routes };
|
||||
const r = live.pending.shift();
|
||||
if (r) r.fulfill({ json: d }); else live.queued.push(d);
|
||||
};
|
||||
const say = (key, vars = {}) => page.evaluate(([lang, key, vars]) => {
|
||||
const s = (lang !== "en" && I18N[lang]?.[key]) || key;
|
||||
return s.replace(/\{(\w+)\}/g, (_, k) => vars[k] ?? `{${k}}`);
|
||||
}, [lang, key, vars]);
|
||||
const sub = page.locator(".rt-accts li.rt-sub");
|
||||
const fold = (name) => page.locator(".rt-accts li.rt-fold", { has: page.locator(".who", { hasText: new RegExp(`^${name}$`) }) });
|
||||
// what the stage lists, top to bottom: a group in the group's heading,
|
||||
// a fold (+ open or - folded), or an account's or key's row
|
||||
const names = () => page.locator(".rt-accts > li").evaluateAll((lis) => lis.map((li) => li.classList.contains("rt-sub") ? "sub:" + li.querySelector("b").textContent + (li.classList.contains("open") ? "+" : "-")
|
||||
: li.classList.contains("rt-fold") ? "fold:" + li.querySelector(".who").textContent + (li.classList.contains("open") ? "+" : "-") : li.querySelector(".who")?.textContent));
|
||||
const viewTop = () => page.evaluate(() => document.querySelector("#view-routing").scrollTop);
|
||||
return { page, errors, send, say, sub, fold, names, ready, viewTop };
|
||||
}
|
||||
|
||||
const spills = (page, sel) => page.locator(sel).evaluateAll((els) => els.filter((e) => !e.hidden && e.offsetParent && (e.scrollWidth > e.clientWidth + 1 || e.getBoundingClientRect().right > document.documentElement.clientWidth))
|
||||
.map((e) => e.className + ": " + e.textContent.trim().slice(0, 60)));
|
||||
|
||||
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
||||
for (const lang of ["en", "zh", "zh-TW", "ja", "de"]) {
|
||||
for (const width of [1100, 420]) {
|
||||
test(`${engine} ${lang} ${width}: Expand opens the stage to models or to accounts, kept across a reload`, async (t) => {
|
||||
const { page, errors, say, names, ready } = await open(t, engine, lang, width);
|
||||
const fold = (name) => page.locator(".rt-accts li.rt-fold", { has: page.locator(".who", { hasText: new RegExp(`^${name}$`) }) });
|
||||
const auto = ["sub:Pool-", "fold:Team+", ...team, "fold:Big-", ...duo, "solo-1"];
|
||||
assert.deepEqual(await names(), auto);
|
||||
// the reader had opened Big by hand
|
||||
await fold("Big").click();
|
||||
await page.waitForFunction(() => document.querySelectorAll(".rt-accts > li").length === 1 + 1 + 3 + 1 + 7 + 2 + 1);
|
||||
const pick = async (name) => {
|
||||
const b = page.locator("#rtDepth");
|
||||
assert.equal((await b.textContent()).trim(), await say("Expand"));
|
||||
assert.equal(await b.getAttribute("title"), await say("Expand routes to"));
|
||||
await b.click();
|
||||
const menu = page.locator(".proto-menu.rt-depth-menu");
|
||||
await menu.waitFor();
|
||||
assert.equal(await b.getAttribute("aria-expanded"), "true");
|
||||
assert.equal(await menu.locator(".pm-head").textContent(), await say("Expand routes to"));
|
||||
assert.deepEqual(await menu.locator(".pm-name").allTextContents(), [await say("Automatic"), await say("Models"), await say("Accounts")]);
|
||||
// inside the window, whatever its width
|
||||
const box = await menu.boundingBox();
|
||||
assert.ok(box.x >= 0 && box.x + box.width <= width, `menu at ${box.x}+${box.width}`);
|
||||
await menu.locator(".pm-item", { has: page.locator(".pm-name", { hasText: new RegExp(`^${await say(name)}$`) }) }).click();
|
||||
await menu.waitFor({ state: "detached" });
|
||||
};
|
||||
const ticked = async () => {
|
||||
await page.locator("#rtDepth").click();
|
||||
const on = await page.locator(".proto-menu.rt-depth-menu .pm-item.on .pm-name").textContent();
|
||||
await page.keyboard.press("Escape");
|
||||
await page.locator(".proto-menu.rt-depth-menu").waitFor({ state: "detached" });
|
||||
return on;
|
||||
};
|
||||
const models = ["sub:Pool+", "fold:ChatGPT-", "fold:Team-", "fold:Big-", "fold:Duo-", "solo-1"];
|
||||
await pick("Models");
|
||||
await page.waitForFunction((n) => document.querySelectorAll(".rt-accts > li").length === n, models.length);
|
||||
assert.deepEqual(await names(), models);
|
||||
// a fold names its model, as the reader asked
|
||||
assert.equal(await fold("Duo").locator(".mdl").textContent(), M);
|
||||
assert.equal(await fold("Duo").locator(".n").textContent(), await say("{n} accounts", { n: 2 }));
|
||||
await ready();
|
||||
assert.deepEqual(await names(), models);
|
||||
assert.equal(await ticked(), await say("Models"));
|
||||
// a row clicked after the pick is kept as before
|
||||
await fold("Team").click();
|
||||
await page.waitForFunction((n) => document.querySelectorAll(".rt-accts > li").length === n, models.length + 3);
|
||||
await ready();
|
||||
assert.deepEqual(await names(), ["sub:Pool+", "fold:ChatGPT-", "fold:Team+", ...team, "fold:Big-", "fold:Duo-", "solo-1"]);
|
||||
|
||||
const accounts = ["sub:Pool+", "fold:ChatGPT+", ...pool, "fold:Team+", ...team, "fold:Big+", ...big, ...duo, "solo-1"];
|
||||
await pick("Accounts");
|
||||
await page.waitForFunction((n) => document.querySelectorAll(".rt-accts > li").length === n, accounts.length);
|
||||
assert.deepEqual(await names(), accounts);
|
||||
await ready();
|
||||
assert.deepEqual(await names(), accounts);
|
||||
|
||||
// back to Automatic: long lists folded, short ones open, as at first
|
||||
await pick("Automatic");
|
||||
await page.waitForFunction((n) => document.querySelectorAll(".rt-accts > li").length === n, auto.length);
|
||||
assert.deepEqual(await names(), auto);
|
||||
await ready();
|
||||
assert.deepEqual(await names(), auto);
|
||||
assert.equal(await ticked(), await say("Automatic"));
|
||||
// Expand ends the stage's top line, beside the request line and
|
||||
// inside the card; nothing in the page head or that line spills
|
||||
const box = await page.evaluate(() => {
|
||||
const b = document.querySelector("#rtDepth").getBoundingClientRect(), w = document.querySelector(".rt-what").getBoundingClientRect(), c = document.querySelector(".rt-top").getBoundingClientRect();
|
||||
return { top: Math.round(b.top - w.top), right: Math.round(c.right - b.right), after: b.left >= w.right - 1, h: Math.round(b.height) };
|
||||
});
|
||||
assert.ok(box.after && box.right >= -8 && box.right <= 2 && Math.abs(box.top) <= 6, JSON.stringify(box));
|
||||
assert.deepEqual(await spills(page, "#view-routing .row-head > *"), []);
|
||||
assert.deepEqual(await spills(page, ".rt-toprow > *"), []);
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user