chen2652 (Discord #help) reported that Open Design's icon is almost invisible in dark mode, with no browser dark-mode extension on. The icon is the plugin's own picture, open-design.ai/favicon.svg: a single fill, #26251E, drawn as an <img> on the dark card (#232327). Now icon() judges each picture once, after the picture's own load, so lazy loading is kept (#909). The result is cached per src. If every opaque pixel of a picture is one tone (the range of each channel is at most 24), and that tone is near-black (every channel at most 72) or near-white (every channel at least 224), the picture is replaced by maskSpan, the way a mono logo is drawn: a mask in the text colour. This holds on any ground, Omarchy's themes included. It covers user pictures (file:), plugin pictures, and bundled -color and PNG icons. Audit: every bundled picture icon, plus the plugin registry's pictures, was measured in CIELAB against #232327 and #fff. Two were invisible in dark mode: Open Design's plugin picture and bundled voyage-color.svg (#012E33, in the provider icon picker). Both are now masks. Multi-tone and tiled logos stay as they are (pipellm, zcode, mothx, deepinfra and others: low contrast in places but readable). Mono icons were masks already. Test: icon-one-tone.test.cjs, with the real favicon bytes in fixtures/. - It draws every picture logo on the dark and the light card and measures, on a screenshot, how much of each stands apart from the ground. - It opens Open Design's Installed row on the Plugins page and checks that it is a mask in the icon's text colour and visible in both themes: 5 languages, 980px and 420px, Chromium and WebKit. icon-url and icon-url-saved served a plain black square as the fetched picture. That square is one tone, so it is now a mask. Their fixture is now a coloured tile, like the letter icons the server makes (favicon.go). Run (on mote unless named): - icon-one-tone: 48/48. The 14 icon/theme GUI files (icon-tile, plugin-own-icon, mono-icon-redraw, plugin-registry-icon, models-add-and-icons, market-icon-corners, request-provider-icon, routing-client-icons, routing-log-icons, tray-logos, api-key-theme, icon-url, icon-url-saved, icon-one-tone): green in both engines. - go test ./internal/gui -run 'Budget|I18n|Asset', gofmt -l, GOOS=linux go vet -tags nogui and GOOS=windows go vet of ./internal/gui: all clean, and no size budget was raised. - A whole GUI suite on Linux (WSL) was cut off when the SSH connection to xiaomi-gpu dropped, after about 9,160 passes and 277 reds: - 40 of the reds were icon-url and icon-url-saved (fixed above). - The rest were in 75 other files. Those 75 files were run on mote with this change and at origin/main76f00399c: 196 reds with the change and 208 at main, in the same files. - The one file red only with the change, copilot-ghe (webkit zh, "route.fulfill: Target page ... has been closed"), is #1949's teardown race and passes 6/6 alone. - Every file red at main already has an open issue except redact-words-list, filed as #5288 and fixed bya18ff505bbefore this rebase. - At the pushed head (a18ff505b+ this commit): the budget/vet/gofmt checks above, the 14 icon files, redact-words-list and copilot-ghe, rerun. Broken by hand: with both toneCheck(img) calls commented out, icon-one-tone fails 46 of 48. voyage-color shows 0.0% ink in dark, and the Open Design row stays an <img>. Before and after screenshots of the row in both themes were taken from the same test. Not tried: the real desktop app (Wails, WebKitGTK) and a real install of the Open Design plugin. The page was driven with the API faked and the real favicon bytes. The whole GUI suite has not had a complete run.
156 lines
9.3 KiB
JavaScript
156 lines
9.3 KiB
JavaScript
// Run with Node's test runner and Playwright on the module path; see README.md.
|
|
// hoobnn on Discord: a custom provider's icon given by an image URL wasn't
|
|
// fetched or applied, and on editing it again the URL was gone. The address
|
|
// was sent with Enter only, so one typed and saved was dropped, and nothing
|
|
// kept it. Now an address typed in the box is fetched by Save (or by Use, or
|
|
// by leaving the box), the picture and its address are saved, and the editor
|
|
// opened again shows both. One that can't be used keeps the editor open with
|
|
// the note why, and nothing is saved. In Chromium and WebKit, at 420 and
|
|
// 1100 wide, in every language.
|
|
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");
|
|
const ICON = { url: "file:00000000000000bb.png", other: "file:00000000000000dd.png", letter: "file:00000000000000cc.svg" };
|
|
const GOOD = "https://cdn.example.com/logo.png", OTHER = "https://cdn.example.com/other.png", GONE = "https://cdn.example.com/gone.png";
|
|
const FAILED = "the icon URL answered 404 Not Found";
|
|
|
|
function serve(lang, posts) {
|
|
const relay = {
|
|
id: "relay", name: "My Relay", icon: "generic", host: "relay.example.com", chat: "https://relay.example.com/v1", responses: "", anthropic: "", catalog: "",
|
|
models: [{ id: "gpt-5", name: "gpt-5", on: true }], chosen: ["gpt-5"],
|
|
fetched: new Date(Date.now() - 3600e3).toISOString(), agents: [], fallback: [], headers: {},
|
|
key: { set: true, masked: "sk-…one" }, keyList: [], balanceToken: { takes: false, set: false }, proxy: "",
|
|
};
|
|
const state = { agents: [], profiles: [], settings: { lang, theme: "light" } };
|
|
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:true};` });
|
|
if (url.pathname === "/wails/runtime.js") return route.fulfill({ contentType: "text/javascript", body: "export const Window = {};" });
|
|
const body = req.method() === "POST" ? req.postDataJSON() || {} : null;
|
|
if (body && url.pathname.startsWith("/api/")) posts.push({ path: url.pathname, body });
|
|
if (url.pathname === "/api/state") return json(state);
|
|
if (url.pathname === "/api/plugins") return json({ plugins: [] });
|
|
const list = () => ({ providers: [relay], presets: [], excluded: [], gateway: { running: true, window: true } });
|
|
if (url.pathname === "/api/providers") return json(list());
|
|
if (url.pathname === "/api/groups") return json({ groups: [] });
|
|
if (url.pathname === "/api/icons/url") {
|
|
if (body.url === GONE) return json({ icon: ICON.letter, failed: FAILED });
|
|
return json({ icon: body.url === OTHER ? ICON.other : body.url ? ICON.url : ICON.letter, failed: "" });
|
|
}
|
|
// the save is kept as the backend keeps it, for the editor's next opening
|
|
if (url.pathname === "/api/provider/save") {
|
|
relay.icon = body.icon;
|
|
if (body.iconFrom) relay.iconFrom = body.iconFrom; else delete relay.iconFrom;
|
|
return json(list());
|
|
}
|
|
if (url.pathname.startsWith("/api/icons/")) return route.fulfill({ contentType: "image/svg+xml", body: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 8 8"><rect width="8" height="8" fill="#3875b3"/></svg>' });
|
|
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, body: "" }); }
|
|
};
|
|
}
|
|
|
|
const KEYS = ["Get icon", "Image URL…", "Image URL", "Use", "Save", "That picture couldn't be used, so the icon is the name's letters: {why}"];
|
|
|
|
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
|
for (const width of [420, 1100]) {
|
|
for (const lang of ["en", "zh", "zh-TW", "ja", "de"]) {
|
|
test(`${engine} ${width} ${lang}: an icon's image URL typed and saved is fetched, kept and shown again`, async (t) => {
|
|
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
|
const page = await (await browser.newContext({ viewport: { width, height: 760 }, reducedMotion: "reduce" })).newPage();
|
|
t.after(async () => {
|
|
if (process.env.ARTIFACT_DIR) {
|
|
await fs.mkdir(process.env.ARTIFACT_DIR, { recursive: true });
|
|
await page.screenshot({ path: path.join(process.env.ARTIFACT_DIR, `${engine}-${width}-${lang}-icon-url-saved.png`) });
|
|
}
|
|
await browser.close();
|
|
});
|
|
page.setDefaultTimeout(5000);
|
|
page.setDefaultNavigationTimeout(60000);
|
|
const errors = [];
|
|
page.on("pageerror", (e) => errors.push(e.message));
|
|
const posts = [];
|
|
await page.route("**/*", serve(lang, posts));
|
|
await page.goto("http://magpie.test/?view=providers");
|
|
|
|
const w = await page.evaluate(([lang, keys]) => Object.fromEntries(keys.map((k) => [k, lang === "en" ? k : I18N[lang]?.[k]])), [lang, KEYS]);
|
|
assert.deepEqual(KEYS.filter((k) => !w[k]), [], `${lang} lacks these`);
|
|
|
|
const editor = page.locator("#modal:not([hidden]) .editor");
|
|
const row = page.locator(".row.provider", { hasText: "My Relay" });
|
|
const pick = editor.locator(".icon-pick");
|
|
const box = pick.getByRole("textbox", { name: w["Image URL"] });
|
|
const saveBtn = editor.locator(".bar").getByRole("button", { name: w.Save, exact: true });
|
|
const open = async () => {
|
|
await row.click();
|
|
await pick.waitFor();
|
|
await pick.evaluate((p) => p.scrollIntoView({ block: "start" }));
|
|
};
|
|
const posted = (p) => posts.filter((x) => x.path === p).map((x) => x.body);
|
|
const srcEnds = (sel, icon) => page.waitForFunction(([sel, src]) => document.querySelector(sel)?.getAttribute("src")?.endsWith(src), [sel, icon.slice(5)]);
|
|
const choose = async () => {
|
|
await pick.getByRole("button", { name: w["Get icon"] }).click();
|
|
await page.locator(".proto-menu").getByRole("menuitemradio", { name: new RegExp("^" + w["Image URL…"].replace(/[.*+?^${}()|[\]\\]/g, "\\$&")) }).click();
|
|
await box.waitFor();
|
|
};
|
|
|
|
// an address typed, never Entered, then Save: fetched, then saved with it
|
|
await open();
|
|
await choose();
|
|
await box.fill(GOOD);
|
|
await saveBtn.click();
|
|
await editor.waitFor({ state: "detached" });
|
|
assert.deepEqual(posted("/api/icons/url").map((b) => b.url), [GOOD], "Save didn't fetch the typed address");
|
|
const saves = posted("/api/provider/save");
|
|
assert.equal(saves.length, 1);
|
|
assert.equal(saves[0].icon, ICON.url, "Save didn't send the fetched picture");
|
|
assert.equal(saves[0].iconFrom, GOOD, "Save didn't send the address");
|
|
await srcEnds(".row.provider img", ICON.url);
|
|
|
|
// opened again: the picture, and its address in its box
|
|
await open();
|
|
await srcEnds(".editor .icon-now img", ICON.url);
|
|
await box.waitFor();
|
|
assert.equal(await box.inputValue(), GOOD, "the address wasn't shown again");
|
|
const over = await pick.evaluate((p) => [...p.children].filter((c) => c.getBoundingClientRect().right > p.getBoundingClientRect().right + 1).map((c) => c.className || c.textContent));
|
|
assert.deepEqual(over, [], "the icon row spills out");
|
|
// nothing changed: Save fetches nothing again
|
|
await saveBtn.click();
|
|
await editor.waitFor({ state: "detached" });
|
|
assert.equal(posted("/api/icons/url").length, 1, "an unchanged address was fetched again");
|
|
assert.equal(posted("/api/provider/save")[1].iconFrom, GOOD);
|
|
|
|
// another address with Use, then Save
|
|
await open();
|
|
await box.waitFor();
|
|
await box.fill(OTHER);
|
|
await pick.getByRole("button", { name: w.Use, exact: true }).click();
|
|
await srcEnds(".editor .icon-now img", ICON.other);
|
|
await saveBtn.click();
|
|
await editor.waitFor({ state: "detached" });
|
|
assert.deepEqual(posted("/api/icons/url").map((b) => b.url), [GOOD, OTHER], "Use and Save fetched it twice, or not at all");
|
|
assert.deepEqual([posted("/api/provider/save")[2].icon, posted("/api/provider/save")[2].iconFrom], [ICON.other, OTHER]);
|
|
|
|
// one that can't be used: the note, the editor open, nothing saved
|
|
await open();
|
|
await box.waitFor();
|
|
await box.fill(GONE);
|
|
await saveBtn.click();
|
|
const note = editor.locator(".editor-error");
|
|
await note.waitFor();
|
|
assert.equal(await note.textContent(), w["That picture couldn't be used, so the icon is the name's letters: {why}"].replace("{why}", FAILED));
|
|
assert(await editor.isVisible(), "the editor closed on a picture that couldn't be used");
|
|
assert.equal(posted("/api/provider/save").length, 3, "a picture that couldn't be used was saved");
|
|
assert.equal(await box.inputValue(), GONE);
|
|
assert.deepEqual(errors, []);
|
|
});
|
|
}
|
|
}
|
|
}
|