onkashiko on X: DeepSeek, Kimi (China), Zhipu and other domestic vendors
price in yuan, the rest in dollars, and one currency for every cost made
the Usage page read wrong for half of them.
Settings > Usage > Currency gains a third choice, By provider. With it,
a figure of one provider's calls (a model's, an account's, a key's row,
a request, a routing try, a quota card's whole) shows in the currency
that provider sells in, and every sum across providers (the total,
agents, sessions, charts, the tray, Bark's daily, the day page) in the
currency a "Totals in" row picks, a row shown only while By provider is
chosen. GUI, TUI and CLI agree. Costs stay stored in dollars; only the
display converts, at the live rate (internal/fx).
Which providers sell in yuan (provider.PricesInYuan): a .cn host; a
preset at its own site that is a yuan preset (deepseek, zhipu,
volcengine, tencent-cloud, bailian, siliconflow…), ends in -cn, or is in
its China region; a plugin id ending in -cn; a provider of one's own
with a yuan models.dev catalog served at that catalog's site. A relay
made from DeepSeek's preset, Z.ai, Kimi's and MiniMax's international
endpoints stay in dollars: they share a catalog with their Chinese
twins, so the catalog alone can't tell.
Known limit: models.dev has only dollar prices (converted from the
vendors' yuan at ~6.7-7.0), so a yuan figure is that dollar price at
today's rate and can differ a few percent from the vendor's own list.
A second ask from onkashiko: set the currency of the menu bar and of
the totals apart, sums converted by themselves.
So Settings > Usage also gains an Advanced fold (closed by default, open while
set) with one row, Menu bar currency: Same as totals (the default), $ or
¥ (settings.TrayCurrency, TrayCostIn). It sets the menu bar's totals
cards and the tray tooltip's cost; the Usage page, the panel, the TUI,
the CLI and Bark's daily message stay in the totals' currency
(totalsCurrency). Like the other menu bar settings it stays on this
computer (KeepOwn). Every sum is still made in dollars and converted
once, at the live rate, so a mixed-currency total is never added up
from yuan and dollars.
Settings' currency rows (Currency, Totals in, Menu bar currency and the
rate in the tooltip) moved out of app.js into currencyprefs.js, imported
when Settings draws its usage prefs, and costInYuan is packed: the core
is 3 bytes under coreScriptBudget, with no raise.
Run:
- go test -count=1 at this tree on mote: internal/settings,
settingsapi, tui, cli, catalog, provider, fx and gui all ok
(TestCoreScriptBudget included). The full go test ./... and the whole
GUI suite are queued behind other sessions' suites on suite.lock
(mote and mica, load 35 and 60) and had not started at push.
- GUI files at this tree (mica): currency-provider, currency, i18n-keys,
i18n-en-no-cjk, tray-cost, tray-totals, every settings-*, old-webkit:
362 pass, 28 red. Every red is red the same at origin/main ac0b5c287
on mote, and filed: settings-search (#6133, #6353), settings-hints
(#6107, #6353), settings-lines-wrap de 440px (#6353), old-webkit
appearance.js (#6467) and :has() (#5919). The one red of this change,
settings-groups' list of Usage's parts (now with the Advanced fold),
is fixed here: 14 of 14.
- currency-provider.test.cjs (new): en, zh, zh-TW, ja, de at 900 and
420px, both engines; By provider, Totals in ¥, then Advanced: $ for
the menu bar with totals in ¥, totals stay ¥21.60, the fold opens
itself after a reload. Plus currency.test.cjs (3 choices now),
i18n-keys, i18n-en-no-cjk, tray-cost: green in both engines.
- TestTrayCostIn (values, refused eur/provider, KeepOwn),
TestFXByProvider (trayCurrency vs totalsCurrency), TestCoreScriptBudget.
- gofmt -l clean; GOOS=linux go vet -tags nogui ./...,
GOOS=windows go vet ./..., GOOS=linux go build -tags nogui,
GOOS=windows go build on mote at this tree: ok.
- Broken by hand, each red: costInYuan ignoring the provider (GUI
test: deepseek showed $1.00 for ¥7.20), PricesInYuan without the
preset's site check (a relay made from DeepSeek's preset read as
yuan), CostIn without its By provider branch (settings test),
TrayCostIn ignoring TrayCurrency (TestTrayCostIn, TestFXByProvider),
the fold not opening while set (webkit), the row saving into
totalCurrency (chromium).
- Real app in a sandbox HOME on mote (dev build, magpie web and magpie
usage) with DeepSeek, OpenAI and Z.ai presets and one call each: the
window and the CLI both show deepseek-v4-pro ≈¥15.44, gpt-4.1 ≈$1.00,
glm-4.6 ≈$0.290 and the total ≈¥24.07 at 6.685; /api/settings' fx
carries yuan ["deepseek"].
Not tried: Windows and Linux windows and trays, the real menu bar with
Menu bar currency changed (drawn natively; covered through trayCurrency
in Go), a real Kimi CN or Zhipu account.
303 lines
20 KiB
JavaScript
303 lines
20 KiB
JavaScript
// Run with Node's test runner and Playwright on the module path; see README.md.
|
|
// The page runs in the system's WebKit, which on macOS 12 can be Safari
|
|
// 15.0's (#220 uclort: on 12.7.6 the panel showed its tabs and headings and
|
|
// nothing else, no button working — a regex lookbehind in app.js is a
|
|
// syntax error before Safari 16.4, so the whole file never ran). What the
|
|
// scripts and styles may use is held to Safari 15.0 here:
|
|
// - every script parses, and none has syntax newer than it: a regex
|
|
// lookbehind (16.4) or v flag (17) or modifiers, a class static block
|
|
// (16.4), decorators, import attributes, `using`;
|
|
// - no built-in newer than it is used unless compat.js (loaded before the
|
|
// rest) fills it in;
|
|
// - the styles have no :has() (15.4), :focus-visible only in rules of its
|
|
// own (a list with it and more drops them all before 15.4), no nesting, no dvh
|
|
// units, and container queries, subgrid and a color-mix() custom property
|
|
// only with an @supports fallback in the same file;
|
|
// - in WebKit with those built-ins taken away, the panel and the window
|
|
// draw every page with no error.
|
|
// Syntax is parsed with the Babel parser Playwright bundles, so no other
|
|
// module is needed.
|
|
const assert = require("node:assert/strict");
|
|
const fs = require("node:fs/promises");
|
|
const path = require("node:path");
|
|
const { test } = require("node:test");
|
|
const { webkit } = require("playwright");
|
|
const { babelParse } = require("playwright/lib/transform/babelBundle");
|
|
|
|
const assets = path.resolve(__dirname, "../assets");
|
|
// the page's scripts, the built-in plugins' under plugins/ among them, as
|
|
// index.html names them
|
|
const scripts = async () => (await fs.readdir(assets, { recursive: true })).map((f) => f.split(path.sep).join("/")).filter((f) => f.endsWith(".js")).sort();
|
|
const styles = async () => (await fs.readdir(assets)).filter((f) => f.endsWith(".css")).sort();
|
|
const read = (f) => fs.readFile(path.join(assets, f), "utf8");
|
|
|
|
// Syntax Safari 15.0 can't parse; one of these fails the whole file.
|
|
const LOOKBEHIND = /\(\?<[=!]/;
|
|
const MODIFIERS = /\(\?[ims]*-?[ims]+:/;
|
|
function badSyntax(ast) {
|
|
const found = [];
|
|
const at = (n) => n.loc ? `:${n.loc.start.line}` : "";
|
|
const regex = (n, pattern, flags) => {
|
|
if (LOOKBEHIND.test(pattern)) found.push(`${at(n)} regex lookbehind (Safari 16.4): /${pattern}/${flags}`);
|
|
if (/v/.test(flags)) found.push(`${at(n)} regex v flag (Safari 17): /${pattern}/${flags}`);
|
|
if (MODIFIERS.test(pattern)) found.push(`${at(n)} regex modifiers: /${pattern}/${flags}`);
|
|
};
|
|
const walk = (n) => {
|
|
if (!n || typeof n.type !== "string") return;
|
|
switch (n.type) {
|
|
case "RegExpLiteral": regex(n, n.pattern, n.flags); break;
|
|
case "StaticBlock": found.push(`${at(n)} class static block (Safari 16.4)`); break;
|
|
case "Decorator": found.push(`${at(n)} decorator`); break;
|
|
case "ClassAccessorProperty": found.push(`${at(n)} accessor field`); break;
|
|
case "ImportAttribute": found.push(`${at(n)} import attributes`); break;
|
|
case "VariableDeclaration": if (/using/.test(n.kind)) found.push(`${at(n)} ${n.kind} declaration`); break;
|
|
case "NewExpression": case "CallExpression": {
|
|
// new RegExp("…") takes the same syntax, a SyntaxError when it runs
|
|
const a = n.arguments?.[0];
|
|
if (n.callee?.type === "Identifier" && n.callee.name === "RegExp" && a) {
|
|
const text = a.type === "StringLiteral" ? a.value : a.type === "TemplateLiteral" ? a.quasis.map((q) => q.value.cooked).join("") : null;
|
|
const flags = n.arguments[1]?.type === "StringLiteral" ? n.arguments[1].value : "";
|
|
if (text != null) regex(n, text, flags);
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
for (const k of Object.keys(n)) {
|
|
if (k === "loc" || k === "extra" || k === "leadingComments" || k === "trailingComments") continue;
|
|
const v = n[k];
|
|
if (Array.isArray(v)) v.forEach(walk);
|
|
else if (v && typeof v === "object") walk(v);
|
|
}
|
|
};
|
|
walk(ast.program);
|
|
return found;
|
|
}
|
|
|
|
// Built-ins Safari 15.0 lacks. `fill` is what compat.js tests for when it
|
|
// fills one in; the others must not be used at all.
|
|
const BUILTINS = [
|
|
{ name: "Array.prototype.at", re: /\.at\(/, since: "15.4", fill: "Array.prototype.at" },
|
|
{ name: "findLast", re: /\.findLast\(/, since: "15.4", fill: "Array.prototype.findLast" },
|
|
{ name: "findLastIndex", re: /\.findLastIndex\(/, since: "15.4", fill: "Array.prototype.findLastIndex" },
|
|
{ name: "Object.hasOwn", re: /\bObject\.hasOwn\(/, since: "15.4", fill: "Object.hasOwn" },
|
|
{ name: "structuredClone", re: /\bstructuredClone\(/, since: "15.4", fill: "window.structuredClone" },
|
|
{ name: "toSorted/toReversed/toSpliced", re: /\.to(Sorted|Reversed|Spliced)\(/, since: "16" },
|
|
{ name: "Array.prototype.with", re: /\]\.with\(|\bArray\.prototype\.with\b/, since: "16" },
|
|
{ name: "String isWellFormed/toWellFormed", re: /\.(is|to)WellFormed\(/, since: "16.4" },
|
|
{ name: "AbortSignal.timeout/any", re: /\bAbortSignal\.(timeout|any)\(/, since: "16/17.4" },
|
|
{ name: "URL.canParse", re: /\bURL\.canParse\(/, since: "17" },
|
|
{ name: "Set methods", re: /\.(union|intersection|difference|symmetricDifference|isSubsetOf|isSupersetOf|isDisjointFrom)\(/, since: "17" },
|
|
{ name: "Array.fromAsync", re: /\bArray\.fromAsync\(/, since: "16.4" },
|
|
{ name: "Object.groupBy/Map.groupBy", re: /\b(Object|Map)\.groupBy\(/, since: "17.4" },
|
|
{ name: "Promise.withResolvers", re: /\bPromise\.withResolvers\(/, since: "17.4" },
|
|
{ name: "Iterator helpers", re: /\bIterator\.from\(|\.(keys|values|entries)\(\)\.(map|filter|take|drop|toArray|reduce|some|every|find|forEach|flatMap)\(/, since: "18.4" },
|
|
{ name: "checkVisibility", re: /\.checkVisibility\(/, since: "17.4" },
|
|
{ name: "popover", re: /\.(showPopover|hidePopover|togglePopover)\(|\.popover\s*=/, since: "17" },
|
|
{ name: "RegExp.escape", re: /\bRegExp\.escape\(/, since: "18.2" },
|
|
{ name: "Promise.try", re: /\bPromise\.try\(/, since: "18.2" },
|
|
];
|
|
const stripComments = (s) => s.replace(/\/\*[\s\S]*?\*\//g, "").replace(/(^|[^:\\"'`])\/\/.*$/gm, "$1");
|
|
|
|
test("every script parses with no syntax newer than Safari 15.0", async () => {
|
|
const bad = [];
|
|
for (const f of await scripts()) {
|
|
let ast;
|
|
try { ast = babelParse(await read(f), f, false); } catch (e) { bad.push(`${f}: does not parse: ${e.message.split("\n")[0]}`); continue; }
|
|
for (const x of badSyntax(ast)) bad.push(f + x);
|
|
}
|
|
assert.deepEqual(bad, []);
|
|
});
|
|
|
|
test("the checks catch what broke macOS 12", () => {
|
|
const found = (src) => badSyntax(babelParse(src, "x.js", false));
|
|
assert.equal(found('const re = /("[^"]*"|(?<==)\\S+)/g;').length, 1, "lookbehind");
|
|
assert.equal(found("s.replace(/(?<![\\w-])fill/g, f);").length, 1, "negative lookbehind");
|
|
assert.equal(found('const re = new RegExp("(?<=a)b");').length, 1, "lookbehind in new RegExp");
|
|
assert.equal(found("class A { static { init(); } }").length, 1, "static block");
|
|
assert.equal(found("const re = /[\\p{L}--a]/v;").length, 1, "v flag");
|
|
assert.deepEqual(found('const re = /(?<name>a)(?=b)(?!c)\\k<name>/g; a ??= b; class B { #x; #m() {} }'), [], "what Safari 15 has");
|
|
});
|
|
|
|
test("no built-in newer than Safari 15.0 unless compat.js fills it in", async () => {
|
|
const compat = await read("compat.js");
|
|
const bad = [];
|
|
for (const f of await scripts()) {
|
|
if (f === "compat.js") continue;
|
|
const lines = stripComments(await read(f)).split("\n");
|
|
for (const b of BUILTINS) {
|
|
if (b.fill && compat.includes(`if (!${b.fill})`)) continue;
|
|
lines.forEach((l, i) => { if (b.re.test(l)) bad.push(`${f}:${i + 1} ${b.name} (Safari ${b.since}): ${l.trim().slice(0, 100)}`); });
|
|
}
|
|
}
|
|
assert.deepEqual(bad, []);
|
|
});
|
|
|
|
test("compat.js is the first of the page's own scripts", async () => {
|
|
const html = await read("index.html");
|
|
// boot.js, theme.js and omarchy.js run in the head, before the first
|
|
// paint: theme.js is ES5 with nothing newer than Safari 10.1's
|
|
// URLSearchParams, and omarchy.js does nothing off Omarchy, whose
|
|
// WebKitGTK is a current one
|
|
const all = [...html.matchAll(/<script\s+src="([^"]+)"/g)].map((m) => m[1]);
|
|
const srcs = all.filter((s) => s !== "boot.js" && s !== "theme.js" && s !== "omarchy.js");
|
|
assert.equal(srcs[0], "compat.js", "loaded first: " + srcs.join(", "));
|
|
// webfonts.js is imported by app.js in a browser tab only, cfgblocked.js
|
|
// when magpie can't write its folder, signsheets.js when a sign-in asks a
|
|
// value first, ruleedit.js on a masking rule's Edit, ratewindows.js when
|
|
// a provider editor draws its rate windows, traywindows.js when the menu
|
|
// bar shows a card, autoresetown.js when Settings draws Codex's auto-use
|
|
// rows, registry.js when Plugins draws its npm registry, navlamp.js when
|
|
// the pointer comes over the sidebar, whatsnew.js when release notes
|
|
// open, claudemode.js when a Claude provider's editor opens, ctxtext.js
|
|
// when a context window part is opened, resetask.js when a Codex reset's
|
|
// Use is pressed, quotaall.js when a provider has two accounts, quotatable.js when the Usage page's table is picked,
|
|
// quitask.js when a Quit asks first, proxies.js when Settings draws its saved proxies, checkinnow.js when Settings' Check
|
|
// in now for one account is pressed, autobackup.js when Settings draws
|
|
// Sync, scrollends.js on the window's first scroll, profilerename.js
|
|
// when a saved profile's Rename is pressed, keyspend.js when the
|
|
// provider editor draws a key's row, syncfiles.js when Sync's server form,
|
|
// Export or Import opens, agentcompact.js when an agent sheet holds Long
|
|
// conversations, balfound.js when the editor draws a relay's balance
|
|
// with no Balance URL, passerrors.js when it draws a key provider's
|
|
// Errors, tlscerts.js when it draws the certificate rows,
|
|
// keybalance.js when it draws a key whose vendor tells no
|
|
// balance, modellimits.js when it draws a model's row, notices.js when
|
|
// About's Open-source licenses opens, videogen.js when Settings draws
|
|
// Image generation, provlinks.js when Settings' search first wants its
|
|
// provider links, pageshare.js when a plugin's page shares a picture,
|
|
// panelfirst.js when the panel's Usage tab's account count is pressed,
|
|
// panelarrange.js when its Allowances tab's Arrange is, modelfind.js
|
|
// when Model settings draws many models, agentsmanager.js when the
|
|
// Agents page's Manage is pressed, agentsuffix.js when an agent's Details
|
|
// open, phonetabs.js when magpie web is laid out for a phone,
|
|
// pluginmd.js (a README's renderer) once plugins.js has run;
|
|
// plugincounts.js (Discover's counts) when the Plugins page loads;
|
|
// navicons.js (the sidebar lists' marks) with the first list drawn;
|
|
// autoswitchtip.js when a provider's accounts draw their switch;
|
|
// codexprojects.js when the open Codex app shows fewer projects;
|
|
// pipecheck.js when Settings draws Models;
|
|
// addfloat.js when the Providers page's add sheet first opens;
|
|
// plugingrid.js when Plugins first draws;
|
|
// rotfig.js when a routing's In turn is first shown;
|
|
// ompadvisor.js when an omp's settings first show;
|
|
// claudemagpie.js when Claude Desktop's twin button or Advanced fold first shows;
|
|
// keyrates.js when a provider with two or more keys opens;
|
|
// the checks above
|
|
// still read them
|
|
for (const f of await scripts()) if (!["webfonts.js", "cfgblocked.js", "signsheets.js", "ruleedit.js", "ratewindows.js", "traywindows.js", "autoresetown.js", "registry.js", "navlamp.js", "whatsnew.js", "claudemode.js", "ctxtext.js", "resetask.js", "quotaall.js", "quotatable.js", "quitask.js", "checkinnow.js", "proxies.js", "autobackup.js", "scrollends.js", "profilerename.js", "settingshints.js", "keyspend.js", "syncfiles.js", "agentcompact.js", "agentwindow.js", "balfound.js", "passerrors.js", "tlscerts.js", "keybalance.js", "modellimits.js", "notices.js", "videogen.js", "provlinks.js", "setfeats.js", "pageshare.js", "panelfirst.js", "panelarrange.js", "modelfind.js", "agentsmanager.js", "agentsuffix.js", "phonetabs.js", "pluginmd.js", "bark.js", "acctexport.js", "plugincounts.js", "navicons.js", "autoswitchtip.js", "codexprojects.js", "pipecheck.js", "addfloat.js", "plugingrid.js", "rotfig.js", "ompadvisor.js", "claudemagpie.js", "keyrates.js", "updatetrust.js", "currencyprefs.js"].includes(f)) assert(all.includes(f), f + " is not loaded by index.html");
|
|
});
|
|
|
|
test("the styles hold up in Safari 15.0", async () => {
|
|
const bad = [];
|
|
for (const f of await styles()) {
|
|
const css = (await read(f)).replace(/\/\*[\s\S]*?\*\//g, "");
|
|
const lineOf = (i) => css.slice(0, i).split("\n").length;
|
|
const each = (re, what) => { for (const m of css.matchAll(re)) bad.push(`${f}:~${lineOf(m.index)} ${what}: ${m[0].trim().slice(0, 90)}`); };
|
|
each(/:has\(/g, ":has() (Safari 15.4)");
|
|
each(/[\d.]+(dvh|svh|lvh|dvw|svw|lvw)\b/g, "dynamic viewport units (Safari 15.4)");
|
|
each(/[^{}]*&[^{}]*\{/g, "nesting (Safari 16.5)");
|
|
// a selector list with :focus-visible and more: all of it is dropped
|
|
for (const m of css.matchAll(/([^{}]+)\{/g)) {
|
|
const sel = m[1].trim();
|
|
if (sel.startsWith("@")) continue;
|
|
// the list's own commas, not those inside :is() or :not()
|
|
const parts = []; let depth = 0, from = 0;
|
|
for (let i = 0; i < sel.length; i++) {
|
|
if (sel[i] === "(") depth++;
|
|
else if (sel[i] === ")") depth--;
|
|
else if (sel[i] === "," && !depth) { parts.push(sel.slice(from, i)); from = i + 1; }
|
|
}
|
|
parts.push(sel.slice(from));
|
|
if (parts.some((p) => p.includes(":focus-visible")) && !parts.every((p) => p.includes(":focus-visible"))) bad.push(`${f}:~${lineOf(m.index)} :focus-visible in a selector list (Safari 15.4 drops the rule): ${sel.slice(0, 90)}`);
|
|
if (/:is\([^)]*:focus-visible/.test(sel)) bad.push(`${f}:~${lineOf(m.index)} :focus-visible inside :is(): ${sel.slice(0, 90)}`);
|
|
}
|
|
// a rule kept off a focused control drops whole there: one for :focus beside it
|
|
if (/:not\([^)]*:focus-visible/.test(css) && !/@supports not selector\(:focus-visible\)/.test(css)) bad.push(`${f}: :not(:focus-visible) (Safari 15.4) with no @supports not selector(:focus-visible) fallback`);
|
|
if (/@container\b/.test(css) && !/@supports not \(container-type: inline-size\)/.test(css)) bad.push(`${f}: @container (Safari 16) with no @supports not (container-type: inline-size) fallback`);
|
|
if (/:\s*subgrid\b/.test(css) && !/@supports not \(grid-template-columns: subgrid\)/.test(css)) {
|
|
// a subgrid that only lines rows up across cards may go without
|
|
for (const m of css.matchAll(/grid-template-columns:\s*subgrid/g)) bad.push(`${f}:~${lineOf(m.index)} grid-template-columns: subgrid (Safari 16) with no fallback`);
|
|
}
|
|
// a custom property is never checked: one holding color-mix() goes
|
|
// invalid where it is used, and whatever it painted goes clear
|
|
if (/--[\w-]+:\s*color-mix\(/.test(css) && !/@supports not \(color: color-mix\(/.test(css)) bad.push(`${f}: a custom property with color-mix() (Safari 16.2) and no @supports not (color: color-mix(…)) fallback`);
|
|
}
|
|
assert.deepEqual(bad, []);
|
|
});
|
|
|
|
// In WebKit with what Safari 15.0 lacks taken away, every page is drawn with
|
|
// no error: compat.js fills them in, and nothing else needs them.
|
|
const TAKEN = `
|
|
for (const k of ["at", "findLast", "findLastIndex", "toSorted", "toReversed", "toSpliced", "with"]) delete Array.prototype[k];
|
|
delete Object.hasOwn; delete window.structuredClone; delete Promise.withResolvers; delete Object.groupBy;
|
|
`;
|
|
const state = {
|
|
agents: [{ id: "codex", name: "Codex", path: "/test/config.toml", fields: [{ key: "model", label: "model", value: "gpt-6", options: [{ value: "gpt-6", label: "gpt-6" }] }] }],
|
|
profiles: [{ name: "work" }], settings: { lang: "en", theme: "light" },
|
|
};
|
|
async function serve(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:"en",theme:"light",web:true};' });
|
|
if (url.pathname === "/wails/runtime.js") return route.fulfill({ contentType: "text/javascript", body: "export const Window = {};" });
|
|
if (url.pathname === "/api/state") return json(state);
|
|
if (url.pathname === "/api/usage/quotas") return json([]);
|
|
if (url.pathname === "/api/groups") return json({ groups: [] });
|
|
if (url.pathname === "/api/providers") return json({ providers: [], presets: [], gateway: { running: true } });
|
|
if (url.pathname === "/api/gateway/trace") {
|
|
if (url.searchParams.get("wait")) await new Promise((r) => setTimeout(r, 20e3));
|
|
return json({ mine: true, now: new Date().toISOString(), seq: 0, totals: { requests: 0, rerouted: 0, errors: 0 }, routes: [] });
|
|
}
|
|
if (url.pathname === "/api/gateway/history") return json({ cut: false, days: [], routes: [] });
|
|
if (url.pathname === "/api/sessions/manage") {
|
|
const last = new Date(Date.now() - 3600e3).toISOString();
|
|
return json({
|
|
agents: [{ agent: "claude", count: 1, deletable: true, name: "Claude Code", icon: "claudecode-color" }], agent: "claude", terminal: false, trashDir: "~/x/trash/sessions", trash: [],
|
|
sessions: [{ agent: "claude", id: "s1", cwd: "/work/app", title: "fix the build", start: last, last, resume: "cd /work/app && claude --resume s1", path: "~/.claude/projects/-work-app/s1.jsonl", size: 2048, messages: 4, files: 1, deletable: 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)];
|
|
try { await route.fulfill({ body: await fs.readFile(file), contentType }); } catch { await route.fulfill({ status: 404 }); }
|
|
}
|
|
|
|
test("with Safari 15.0's built-ins, the panel and the window draw every page", async () => {
|
|
const browser = await webkit.launch();
|
|
try {
|
|
for (const mode of ["panel", "window"]) {
|
|
const page = await browser.newPage({ viewport: mode === "panel" ? { width: 380, height: 640 } : { width: 1100, height: 760 } });
|
|
const errors = [];
|
|
page.on("pageerror", (e) => errors.push(e.message));
|
|
await page.addInitScript(TAKEN);
|
|
await page.route("**/*", serve);
|
|
await page.goto(`http://magpie.test/?mode=${mode}`);
|
|
await page.locator("#agents .row").first().waitFor();
|
|
assert.equal(await page.evaluate(() => [1, 2, 3].findLast((x) => x < 3)), 2, "compat.js fills findLast in");
|
|
assert.deepEqual(await page.evaluate(() => { const a = { b: [1] }, c = structuredClone(a); return [c.b[0], c !== a && c.b !== a.b]; }), [1, true]);
|
|
assert.equal(await page.evaluate(() => [1, 2, 3].at(-1)), 3);
|
|
if (mode === "panel") {
|
|
assert(await page.locator("#ptabs").isVisible(), "the panel's tabs are the page's own, drawn by app.js");
|
|
for (const tab of ["usage", "routing", "agents"]) {
|
|
const b = page.locator(`#ptabs [data-ptab="${tab}"]`);
|
|
if (await b.isVisible()) await b.click();
|
|
await page.waitForTimeout(150);
|
|
}
|
|
await page.locator("#profBtn").click();
|
|
await page.locator("#save").click();
|
|
assert(await page.locator(".profiles.naming > .chip-input").isVisible(), "Save current opens the name field");
|
|
} else {
|
|
for (const v of ["providers", "gateway", "routing", "usage", "sessions", "library", "agents"]) {
|
|
await page.locator(`#nav [data-view="${v}"]`).click();
|
|
await page.locator(`#view-${v}`).waitFor();
|
|
await page.waitForTimeout(200);
|
|
}
|
|
}
|
|
assert.deepEqual(errors, [], mode + ": no error on the page");
|
|
await page.close();
|
|
}
|
|
} finally {
|
|
await browser.close();
|
|
}
|
|
});
|