1ooogle's mockup on X redrew Settings › General the way macOS System
Settings reads it. The owner approved, and this follows it.
Rows that now show only their name:
- Appearance, Text size, Interface and Code font, the tray click,
Provider in model names, the Codex titles, auto-review and memories
model rows, Open at login and Show in Dock.
- A font row's line shows only while its fonts are loading or have
failed.
- The text size keys (⌘0 / Ctrl+0) move into the choices' tooltip.
Rows that keep one short line, because the name alone doesn't explain
the setting or what it costs:
- Codex subagents, Long conversations, Lightweight mode, Prevent sleep
and Session terminal.
Renames:
- "Tray icon" becomes "Click the tray icon to", with the choices "Open
the quick panel" and "Open the main window" (点击托盘图标: 打开快捷面板 /
打开主窗口).
- "Keep awake while agents work" becomes "Prevent sleep" (防止休眠: 在
magpie 运行任务时,让电脑保持唤醒状态).
- "Dock" becomes "Show in Dock" (显示程序坞).
Language is one button showing the language picked (renderLangPick).
It opens in the app's own menu (openProtoMenu, styled like Session
terminal's sess-pick), not a native <select> and not six segments.
Every language gets the same text: en, zh, zh-TW, ja and de. The 25
strings no longer used are removed from all four translations.
Tests:
- New: settings-general.test.cjs. In Chromium and WebKit, en, zh,
zh-TW, ja and de, at 1000 and 440 px, on a Mac, it checks that:
- the rows that should show only their name have no line;
- the kept lines are one line each, and none is cut short at 1000px;
- Language is a button showing the language, and its menu lists all
six;
- a pick saves lang and redraws the page in that language, with the
button staying under the pointer;
- nothing has a left stripe and nothing scrolls sideways.
I broke it by hand twice and saw it fail both times: once by giving
the Dock row a line back, once by making the pick save nothing.
- Updated to the new text and controls: codex-titles,
codex-auto-review, codex-memories-settings, model-suffix-own,
plain-names, lightweight, keep-awake, text-size, gateway-mode,
omarchy, settings-search, gui-zh-tw (Language's button and menu fit
at 1000/440px), header-relang (picks through the menu) and
readable-focus (the first shown line).
- German's long-conversations line was shortened to fit on one line at
1000px.
What was run:
- go test -tags nogui ./internal/gui passes; gofmt -l is clean; go vet
passes on darwin, linux and windows.
- The whole GUI suite (601 files, --test-concurrency=4): 6584 passed,
33 failed. Every failing file was then run alone:
- mobile-web fails on purpose. It compares desktop screenshots with
origin/main, and only the Settings page differs.
- routing-group-fold, text-size, routing-sessions and pick-skills
are #1672; searcher-pick is #1745. Each also fails alone on
origin/main 260ded9af.
- routing-provider-off, routing-steady and usage-sum-whole pass when
run alone, both here and on main.
- Screenshots before and after (zh, en and de light at 1000px, zh at
440px, zh dark) were looked at.
Not tried in the real Wails window.
190 lines
12 KiB
JavaScript
190 lines
12 KiB
JavaScript
// Run with Node's test runner and Playwright on the module path; see README.md.
|
|
// Gateway mode (Player on Discord): magpie web on a server that is only
|
|
// the gateway for other computers' agents. boot.js says so and the page
|
|
// opens on Providers with no Agents or Library tab, an address
|
|
// kept for one of them opening Providers; Settings leaves out what is
|
|
// written into this computer's agents' files (provider in model names,
|
|
// Codex subagents, long conversations, Codex thread titles) and the
|
|
// desktop's alerts, and General has the switch — Automatic, On, Off —
|
|
// saying why it is on. Off brings the tabs and the rows back at once, the
|
|
// Agents page opening again; Automatic takes them away again. magpie web
|
|
// not in gateway mode keeps every tab, and the switch is magpie web's
|
|
// alone. No click scrolls the page, no native <select>, no left border.
|
|
// English and Chinese; 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 assets = path.resolve(__dirname, "../assets");
|
|
|
|
function settingsPayload(over) {
|
|
return {
|
|
theme: "light", lang: "en", tray: "panel", quotaLeft: false, currency: "usd", textSize: 100,
|
|
dock: false, dockWindow: false, proxy: "", redact: false, redactPersonal: false, redactWords: [],
|
|
codexWarmup: "", claudeWarmup: "", codexWarmAt: "", claudeWarmAt: "", workbuddyCheckin: false, noStats: false,
|
|
trayUsage: "", trayUsageEvery: 3, vision: "", imageGen: "",
|
|
version: "0.1.400", dir: "/config/home/.config/magpie", gateway: "http://127.0.0.1:3425",
|
|
proxyNow: "none", proxySource: "none", login: false,
|
|
visionModels: [], imageGenModels: [], workbuddyCheckins: [], lanURLs: [],
|
|
fx: { rate: 7.2, at: new Date().toISOString(), stale: false },
|
|
...over,
|
|
};
|
|
}
|
|
|
|
// agents says whether magpie found agents here: Automatic is on without
|
|
function server(lang, posts, { web = true, gateway = true, agents = false } = {}) {
|
|
const why = (mode) => (mode === "on" || mode === "off" ? mode : agents ? "" : "no-agents");
|
|
const on = (mode) => web && (mode === "on" || (mode !== "off" && !agents));
|
|
let cur = settingsPayload({ lang, web, gatewayMode: "", gatewayOn: web && gateway, gatewayWhy: web && gateway ? why("") : "" });
|
|
return async (route) => {
|
|
const req = route.request(), url = new URL(req.url());
|
|
const json = (data) => route.fulfill({ json: data });
|
|
if (url.pathname === "/boot.js") return route.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"${lang}",theme:"light",web:${web}${web && gateway ? ",gateway:true" : ""}};` });
|
|
if (url.pathname === "/wails/runtime.js") return route.fulfill({ contentType: "text/javascript", body: "export const Window = {};" });
|
|
if (url.pathname === "/api/state") return json({ agents: [], profiles: [], settings: { lang, theme: "light" }, fx: cur.fx });
|
|
if (url.pathname === "/api/settings/gateway-mode") {
|
|
const { mode } = req.postDataJSON();
|
|
posts.push(["gateway-mode", mode]);
|
|
cur = { ...cur, gatewayMode: mode, gatewayOn: on(mode), gatewayWhy: on(mode) || mode === "off" ? why(mode) : "" };
|
|
return json(cur);
|
|
}
|
|
if (url.pathname === "/api/settings") {
|
|
if (req.method() === "POST") { posts.push(["settings", req.postDataJSON()]); cur = { ...cur, ...req.postDataJSON() }; }
|
|
return json(cur);
|
|
}
|
|
if (url.pathname === "/api/providers") return json({ providers: [], presets: [], excluded: [], gateway: { running: true, window: true } });
|
|
if (url.pathname === "/api/plugins") return json({ plugins: [] });
|
|
if (url.pathname === "/api/usage/quotas") return json([]);
|
|
if (url.pathname === "/api/groups") return json({ groups: [], models: [] });
|
|
if (url.pathname === "/api/window/fit") return route.fulfill({ status: 204 });
|
|
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 L = {
|
|
en: { mode: "Gateway mode", noAgents: "Now on: no agents on this computer", off: "Now off: agents found on this computer" },
|
|
zh: { mode: "网关模式", noAgents: "当前开启:本机没有 Agent", off: "当前关闭:本机找到了 Agent" },
|
|
};
|
|
const HIDDEN = ["agents", "library"];
|
|
// 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[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"]
|
|
.map((s) => !document.querySelector(s).closest(".row").hidden));
|
|
|
|
async function noSelectNoBorder(page, where) {
|
|
const bad = await page.evaluate(() => {
|
|
const out = [];
|
|
for (const s of document.querySelectorAll("select")) if (s.offsetParent) out.push("select " + (s.id || s.className));
|
|
for (const e of [document.querySelector("#gatewayModeRow"), ...document.querySelectorAll("#gatewayModeRow *")]) {
|
|
const cs = getComputedStyle(e);
|
|
if (parseFloat(cs.borderLeftWidth) > 0 && cs.borderLeftStyle !== "none" && cs.borderLeftColor !== cs.borderTopColor) out.push("left border " + (e.id || e.className));
|
|
}
|
|
return out;
|
|
});
|
|
assert.deepEqual(bad, [], where);
|
|
}
|
|
|
|
// clicks what at, and says the page didn't move
|
|
async function clickStill(page, at, where) {
|
|
const before = await page.evaluate(() => { const v = [...document.querySelectorAll("main.view")].find((x) => !x.hidden); return [v.id, v.scrollTop, scrollY]; });
|
|
await page.locator(at).click();
|
|
await page.waitForTimeout(250);
|
|
const after = await page.evaluate((id) => [id, document.getElementById(id).scrollTop, scrollY], before[0]);
|
|
assert.deepEqual(after, before, `${where}: the click scrolled`);
|
|
}
|
|
|
|
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
|
test(`${engine}: gateway mode`, async (t) => {
|
|
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
|
t.after(() => browser.close());
|
|
for (const lang of ["en", "zh"]) {
|
|
const where = `${engine} ${lang}`;
|
|
const context = await browser.newContext({ viewport: { width: 1100, height: 560 }, reducedMotion: "reduce" });
|
|
const page = await context.newPage();
|
|
page.setDefaultTimeout(5000);
|
|
const errors = [], posts = [];
|
|
page.on("pageerror", (e) => errors.push(e.message));
|
|
await page.route("**/*", server(lang, posts));
|
|
await page.goto("http://magpie.test/");
|
|
await page.waitForSelector("#nav button.on");
|
|
assert.deepEqual(await tabs(page), KEPT, `${where}: the tabs`);
|
|
assert.deepEqual(await viewShown(page), ["view-providers"], `${where}: opens on Providers`);
|
|
assert.equal(await page.locator("#nav button.on").getAttribute("data-view"), "providers", where);
|
|
|
|
// an address kept for a page left out opens Providers
|
|
for (const v of HIDDEN) {
|
|
await page.goto(`http://magpie.test/?view=${v}`);
|
|
await page.waitForSelector("#nav button.on");
|
|
assert.deepEqual(await viewShown(page), ["view-providers"], `${where}: ?view=${v}`);
|
|
}
|
|
|
|
// Settings: the switch, why it is on, and the agents' rows gone
|
|
await clickStill(page, "#prefs", `${where}: Settings`);
|
|
await page.waitForSelector("#gatewayModeSegs .opt");
|
|
assert.ok(await page.locator("#gatewayModeRow").isVisible(), `${where}: the switch`);
|
|
assert.equal((await page.locator("#gatewayModeRow .name").textContent()).trim(), L[lang].mode, where);
|
|
assert.match(await page.locator("#gatewayModeSub").textContent(), new RegExp(L[lang].noAgents), where);
|
|
assert.equal(await page.locator("#gatewayModeSegs .opt.on").evaluate((b) => [...b.parentElement.children].filter((x) => x.matches(".opt")).indexOf(b)), 0, `${where}: Automatic picked`);
|
|
assert.deepEqual(await agentRows(page), [false, false, false, false, false, false, false, false, false], `${where}: agents' rows in gateway mode`);
|
|
await noSelectNoBorder(page, where);
|
|
|
|
// Off: the tabs and the rows are back, Settings stays open
|
|
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", "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);
|
|
await clickStill(page, '#nav button[data-view="agents"]', `${where}: Agents`);
|
|
assert.deepEqual(await viewShown(page), ["view-agents"], `${where}: the Agents page opens`);
|
|
|
|
// Automatic again: gone again
|
|
await clickStill(page, "#prefs", `${where}: Settings again`);
|
|
await clickStill(page, "#gatewayModeSegs .opt:nth-child(2)", `${where}: Automatic`);
|
|
await page.waitForFunction(() => document.querySelector('#nav button[data-view="agents"]').hidden);
|
|
assert.deepEqual(posts.filter((p) => p[0] === "gateway-mode").at(-1), ["gateway-mode", ""], where);
|
|
assert.deepEqual(await tabs(page), KEPT, `${where}: automatic`);
|
|
assert.deepEqual(await agentRows(page), [false, false, false, false, false, false, false, false, false], where);
|
|
// the Settings page's own saves never send it
|
|
assert.ok(posts.filter((p) => p[0] === "settings").every((p) => !("gatewayMode" in p[1])), where);
|
|
assert.deepEqual(errors, [], where);
|
|
await context.close();
|
|
}
|
|
|
|
// magpie web with agents here, and the app's window: every tab; the
|
|
// switch is magpie web's alone
|
|
for (const [web, name] of [[true, "web with agents"], [false, "window"]]) {
|
|
for (const lang of ["en", "zh"]) {
|
|
const where = `${engine} ${lang} ${name}`;
|
|
const context = await browser.newContext({ viewport: { width: 1100, height: 560 }, reducedMotion: "reduce" });
|
|
const page = await context.newPage();
|
|
page.setDefaultTimeout(5000);
|
|
const errors = [];
|
|
page.on("pageerror", (e) => errors.push(e.message));
|
|
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", "sessions", "library", "providers", "routing", "gateway", "usage", "plugins"], where);
|
|
assert.deepEqual(await viewShown(page), ["view-agents"], where);
|
|
await page.locator("#prefs").click();
|
|
await page.waitForSelector("#langPick span");
|
|
assert.equal(await page.locator("#gatewayModeRow").isVisible(), web, `${where}: the switch`);
|
|
if (web) assert.match(await page.locator("#gatewayModeSub").textContent(), new RegExp(L[lang].off), where);
|
|
assert.deepEqual(errors, [], where);
|
|
await context.close();
|
|
}
|
|
}
|
|
});
|
|
}
|