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.
179 lines
10 KiB
JavaScript
179 lines
10 KiB
JavaScript
// Readable instructions, selectable model IDs and keyboard focus with the real assets.
|
|
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 { watchSettingsReads, settingsDrawn } = require("./reader.cjs");
|
|
const assets = path.resolve(__dirname, "../assets");
|
|
const settings = { theme: "light", lang: "en", tray: "panel", textSize: 100, currency: "usd",
|
|
dir: "/config/magpie", gateway: "http://127.0.0.1:3999", version: "0.1.900",
|
|
proxy: "", proxyNow: "none", proxySource: "none", redactWords: [], otel: {},
|
|
visionModels: [], imageGenModels: [], workbuddyCheckins: [], lanURLs: [],
|
|
fx: { rate: 7.2, at: new Date().toISOString(), stale: false } };
|
|
const providers = { providers: [{ id: "acme", name: "Acme", icon: "generic", agents: [],
|
|
chat: "https://acme.test/v1", headers: {}, fallback: [], key: { set: true, masked: "sk-…1234" },
|
|
models: [{ id: "example", name: "Example model", on: true }, { id: "second", name: "Second model", on: true }] }],
|
|
presets: [], excluded: [], gateway: { running: true, window: true, mine: false, url: settings.gateway, calls: [] } };
|
|
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 === "/api/state") return json({ agents: [], profiles: [], settings });
|
|
if (url.pathname === "/api/settings") return json(settings);
|
|
if (url.pathname === "/api/providers") return json(providers);
|
|
if (url.pathname === "/api/groups") return json({ groups: [], models: [] });
|
|
if (url.pathname === "/api/usage/quotas") return json([]);
|
|
if (url.pathname === "/api/plugins") return json({ plugins: [] });
|
|
if (url.pathname.startsWith("/api/")) return json({});
|
|
const file = path.join(assets, url.pathname === "/" ? "index.html" : url.pathname);
|
|
await route.fulfill({ body: await fs.readFile(file), contentType: { ".html": "text/html", ".js": "text/javascript", ".css": "text/css", ".svg": "image/svg+xml", ".png": "image/png" }[path.extname(file)] });
|
|
}
|
|
|
|
async function contrast(locator) {
|
|
return locator.evaluate((element) => {
|
|
const luminance = (color) => color.match(/[\d.]+/g).slice(0, 3).map((value) => {
|
|
const n = Number(value) / 255; return n <= .04045 ? n / 12.92 : ((n + .055) / 1.055) ** 2.4;
|
|
}).reduce((sum, n, i) => sum + n * [.2126, .7152, .0722][i], 0);
|
|
let parent = element, background;
|
|
while (parent) {
|
|
background = getComputedStyle(parent).backgroundColor;
|
|
if (background !== "transparent" && background !== "rgba(0, 0, 0, 0)") break;
|
|
parent = parent.parentElement;
|
|
}
|
|
const fg = luminance(getComputedStyle(element).color), bg = luminance(background);
|
|
return (Math.max(fg, bg) + .05) / (Math.min(fg, bg) + .05);
|
|
});
|
|
}
|
|
|
|
async function selectText(page, locator) {
|
|
await page.mouse.move(600, 300);
|
|
for (let i = 0; i < 12; i++) {
|
|
const box = await locator.boundingBox();
|
|
if (box.y >= 60 && box.y + box.height < 560) break;
|
|
await page.mouse.wheel(0, box.y < 60 ? -200 : 200);
|
|
await page.waitForTimeout(100);
|
|
}
|
|
await page.waitForTimeout(350);
|
|
const rect = await locator.evaluate((element) => {
|
|
const range = document.createRange(); range.selectNodeContents(element);
|
|
const r = range.getBoundingClientRect();
|
|
return { left: r.left, right: r.right, y: r.top + r.height / 2 };
|
|
});
|
|
await page.mouse.move(rect.left + .5, rect.y);
|
|
await page.mouse.down();
|
|
await page.mouse.move(rect.right - .5, rect.y, { steps: 12 });
|
|
await page.mouse.up();
|
|
return page.evaluate(() => getSelection().toString());
|
|
}
|
|
|
|
for (const engine of process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"]) {
|
|
test(`${engine}: readable text, selection and keyboard focus`, async (t) => {
|
|
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
|
t.after(() => browser.close());
|
|
const page = await browser.newPage({ viewport: { width: 1100, height: 600 }, reducedMotion: "reduce" });
|
|
page.setDefaultTimeout(5000);
|
|
const errors = [];
|
|
page.on("pageerror", (e) => errors.push(e.message));
|
|
await page.route("**/*", serve);
|
|
|
|
await t.test("connection instructions and editor help are readable in both themes", async () => {
|
|
await watchSettingsReads(page);
|
|
await page.goto("http://magpie.test/?view=gateway");
|
|
await settingsDrawn(page); // rows found are the ones that stay (#1659)
|
|
await page.locator("#gwModels .name").first().waitFor();
|
|
for (const theme of ["light", "dark"]) {
|
|
await page.evaluate((value) => { document.documentElement.dataset.theme = value; }, theme);
|
|
for (const selector of [".connect label", ".connect .hint", "#gwModels .sub"]) {
|
|
const ratio = await contrast(page.locator(selector).first());
|
|
assert.ok(ratio >= 4.5, `${theme} ${selector}: contrast ${ratio}`);
|
|
}
|
|
}
|
|
await page.locator('#nav button[data-view="providers"]').click();
|
|
await page.locator("#providers .row.provider").click();
|
|
for (const theme of ["light", "dark"]) {
|
|
await page.evaluate((value) => { document.documentElement.dataset.theme = value; }, theme);
|
|
for (const selector of ["#modal .editor label", "#modal .editor .hint"]) {
|
|
const ratio = await contrast(page.locator(selector).first());
|
|
assert.ok(ratio >= 4.5, `${theme} ${selector}: contrast ${ratio}`);
|
|
}
|
|
}
|
|
await watchSettingsReads(page);
|
|
await page.goto("http://magpie.test/?view=settings");
|
|
await settingsDrawn(page); // rows found are the ones that stay (#1659)
|
|
const description = page.locator(".row.pref .sub:visible").filter({ hasText: /\S/ }).first(); // a shown one: Appearance has none now (1ooogle on X)
|
|
await description.waitFor();
|
|
for (const theme of ["light", "dark"]) {
|
|
await page.evaluate((value) => { document.documentElement.dataset.theme = value; }, theme);
|
|
assert.ok(await contrast(description) >= 4.5, `${theme}: settings instructions are readable`);
|
|
}
|
|
});
|
|
|
|
await t.test("selecting a model ID does not activate or redraw its row", async () => {
|
|
await watchSettingsReads(page);
|
|
await page.goto("http://magpie.test/?view=gateway");
|
|
await settingsDrawn(page); // rows found are the ones that stay (#1659)
|
|
const name = page.locator("#gwModels .name").nth(1);
|
|
await name.waitFor();
|
|
const picked = await page.locator("#gwModels .selected .name").textContent();
|
|
assert.equal(await selectText(page, name), await name.textContent());
|
|
assert.equal(await page.locator("#gwModels .selected .name").textContent(), picked);
|
|
assert.equal(await page.locator("body").evaluate((e) => getComputedStyle(e).userSelect ?? getComputedStyle(e).webkitUserSelect), "none");
|
|
await page.evaluate(() => { getSelection().removeAllRanges(); status("Connection refused: acme.test", "err", 60000); });
|
|
assert.equal(await selectText(page, page.locator("#status")), "Connection refused: acme.test");
|
|
await name.click();
|
|
assert.equal(await page.locator("#gwModels .selected .name").textContent(), await name.textContent(), "an ordinary click still picks the model");
|
|
await page.locator('#nav button[data-view="providers"]').click();
|
|
await page.locator("#providers .row.provider").click();
|
|
await page.getByRole("button", { name: "Names & levels", exact: true }).click();
|
|
const id = page.locator(".mname .mwho code").first();
|
|
await id.scrollIntoViewIfNeeded();
|
|
assert.equal(await selectText(page, id), await id.textContent(), "model IDs in the editor can be selected too");
|
|
assert.ok(await contrast(id) >= 4.5);
|
|
});
|
|
|
|
await t.test("keyboard focus can enter the view without allowing pointer clicks to scroll", async () => {
|
|
// each step starts from a fresh page: macOS WebKit doesn't Tab to
|
|
// buttons, and the page keeps the reader's place against a script's scroll
|
|
const setup = async () => {
|
|
await watchSettingsReads(page);
|
|
await page.goto("http://magpie.test/?view=settings");
|
|
await settingsDrawn(page); // rows found are the ones that stay (#1659)
|
|
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";
|
|
const field = document.createElement("input"); field.id = "focus-end";
|
|
first.onclick = () => field.focus();
|
|
v.replaceChildren(first, spacer, field);
|
|
});
|
|
};
|
|
const start = page.locator("#focus-start"), end = page.locator("#focus-end");
|
|
const scroll = () => page.locator("#view-settings").evaluate((v) => v.scrollTop);
|
|
const visibleFocus = () => end.evaluate((f) => {
|
|
const r = f.getBoundingClientRect(), v = f.closest(".view").getBoundingClientRect();
|
|
// Native scrolling rounds scrollTop to CSS pixels in these engines.
|
|
return document.activeElement === f && r.top >= v.top - 2 && r.bottom <= v.bottom + 2;
|
|
});
|
|
const focusDetails = () => end.evaluate((f) => ({ focus: document.activeElement.id, scroll: f.closest(".view").scrollTop, top: f.getBoundingClientRect().top, bottom: f.getBoundingClientRect().bottom, view: f.closest(".view").getBoundingClientRect().bottom }));
|
|
await setup();
|
|
await start.focus();
|
|
await page.keyboard.press("Tab");
|
|
await page.waitForTimeout(600);
|
|
assert.equal(await visibleFocus(), true, "Tab's focused field stays in sight: " + JSON.stringify(await focusDetails()));
|
|
await setup();
|
|
await start.click();
|
|
await page.waitForTimeout(600);
|
|
assert.equal(await scroll(), 0, "a pointer click keeps the reader's position");
|
|
for (const key of ["Enter", "Space"]) {
|
|
await setup();
|
|
await start.focus();
|
|
await page.keyboard.press(key);
|
|
await page.waitForTimeout(600);
|
|
assert.equal(await visibleFocus(), true, `${key}: the field focused by the keyboard action is in sight: ${JSON.stringify(await focusDetails())}`);
|
|
}
|
|
});
|
|
assert.deepEqual(errors, []);
|
|
});
|
|
}
|