The owner (11-12, "这些空白看起来好难受"): the Custom address and its login
were visibility:hidden while not picked, so each account kept an empty
strip (43px) between its proxy segs and the next account's name. They are
display:none now, so the gaps are even. proxy-gaps measures the segs'
bottom to the next element's top at 900 and 420 in every language;
account-proxy's no-move check now covers the lines above the pick.
Run (mica, mica-run, both engines, en de ja zh zh-TW where a file takes
languages; mote was over 18 load every check):
- The four changes together: account-weight, account-proxy, routing-js
26/26; routing-advanced, proxy-gaps, login-export, routing-save,
key-weight green; account-arrange red as on main (#6010).
- About 40 files around the editor (prefs, check-in, warm-up, proxy,
routing, export): 698/730. The same reds on origin/main 2d2333cfa:
checkin-now-account (#6029), editor-advanced-align (#4615),
settings-lines-wrap chromium de 440 (#6353), account-arrange (#6010).
Flakes under the concurrent run: ResizeObserver page errors in
checkin-account and codex-auto-reset-settings (commented on #6108),
provider-advanced-fold webkit zh growth (#2552, #5417),
proxy-login-fields chromium zh click (#6374, 5/5 alone here and on
main). Two passes over those five files again: only proxy-login-fields
chromium zh, once.
- i18n-keys green (no strings added).
Broken by hand, each red:
- dialog: without `.row.pref { position: relative }` account-weight
goes red in both engines ("the dialog scrolls beside the editor
(945,810)").
- Routing back on the editor (ed.append): routing-advanced 10/10 red.
- Export with the plus again: login-export red ("Export has the plus").
- Proxy's .off back to visibility:hidden: proxy-gaps 20/20 red ("43px
under the provider's options").
Not tried: the whole GUI suite (another session's full suite was on
mica, mote over load), the real Linux WebKitGTK app, Windows. No Go
changed.
125 lines
7.1 KiB
JavaScript
125 lines
7.1 KiB
JavaScript
// Run with Node's test runner and Playwright on the module path; see README.md.
|
|
// A proxy that isn't Custom takes no room for an address it doesn't have
|
|
// (the owner, 11-12: "这些空白看起来好难受"): under the provider's Global
|
|
// proxy | Direct | Custom and under each account's Provider's proxy |
|
|
// Direct | Custom, the address and its login show for Custom only, and
|
|
// nothing hidden keeps a strip of its own. An account's options sit as far
|
|
// from the next account's name as every other's do, and picking Custom
|
|
// and back gives the same gap again. In every language, both engines, at
|
|
// a phone's width too.
|
|
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 claude = {
|
|
id: "claude", name: "Claude", icon: "claude-color", chat: "", responses: "", anthropic: "", catalog: "",
|
|
models: [{ id: "claude-opus-5", name: "Claude Opus 5", on: true }], agents: [], fallback: [], headers: {}, keyList: [],
|
|
account: {
|
|
agent: "claude", agentName: "Claude Code", user: "one@example.com", plan: "MAX",
|
|
logins: [
|
|
{ user: "one@example.com", plan: "MAX", active: true, on: true },
|
|
{ user: "two@example.com", plan: "MAX", on: true },
|
|
{ user: "three@example.com", plan: "PRO", on: true },
|
|
{ user: "four@example.com", plan: "PRO", on: true },
|
|
],
|
|
},
|
|
proxy: "",
|
|
accountProxies: { "two@example.com": "direct", "four@example.com": "socks5://10.0.0.5:1080" },
|
|
};
|
|
|
|
function serve(lang) {
|
|
const providers = { providers: [claude], presets: [], excluded: [], gateway: { running: true, window: true } };
|
|
const state = { agents: [], profiles: [], settings: { lang, theme: "light" } };
|
|
return async (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:"${lang}",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/providers") return json(providers);
|
|
if (url.pathname === "/api/groups") return json({ groups: [] });
|
|
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 });
|
|
};
|
|
}
|
|
|
|
// the room under each proxy row: from the options' bottom to the top of
|
|
// what is shown next (the hint under the provider's, the next account's
|
|
// name under an account's), and whether its address is shown
|
|
const gaps = (page) => page.evaluate(() => {
|
|
// shown: takes room and can be seen (a hidden one keeping its room is the bug)
|
|
const shown = (e) => !!e.getBoundingClientRect().height && getComputedStyle(e).visibility !== "hidden";
|
|
const next = (e) => { let n = e.nextElementSibling; while (n && !shown(n)) n = n.nextElementSibling; return n; };
|
|
const under = (row, after) => Math.round(after.getBoundingClientRect().top - row.getBoundingClientRect().bottom);
|
|
const own = document.querySelector(".editor .proxy-pick");
|
|
const ownRow = own.querySelector(".proxy-row");
|
|
const lines = [...document.querySelectorAll(".editor .acct-proxy")];
|
|
return {
|
|
provider: under(ownRow, next(ownRow)),
|
|
accounts: lines.map((l, i) => {
|
|
const row = l.querySelector(".proxy-row");
|
|
const after = lines[i + 1]?.querySelector(".who") || next(l);
|
|
const custom = shown(l.querySelector(".proxy-url"));
|
|
return { user: l.dataset.user, gap: under(custom ? l.querySelector(".proxy-auth") : row, after), custom };
|
|
}),
|
|
};
|
|
});
|
|
|
|
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 [900, 420]) {
|
|
test(`${engine} ${lang} ${width}px: a proxy that isn't Custom leaves no empty strip`, async (t) => {
|
|
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
|
const page = await (await browser.newContext({ viewport: { width, height: 900 }, reducedMotion: "reduce" })).newPage();
|
|
t.after(async () => {
|
|
if (process.env.ARTIFACT_DIR) {
|
|
await fs.mkdir(process.env.ARTIFACT_DIR, { recursive: true });
|
|
await page.locator(".editor .proxy-pick").screenshot({ path: path.join(process.env.ARTIFACT_DIR, `${engine}-${lang}-${width}-proxy-gaps.png`) }).catch(() => {});
|
|
}
|
|
await browser.close();
|
|
});
|
|
page.setDefaultTimeout(5000);
|
|
page.setDefaultNavigationTimeout(60000);
|
|
const errors = [];
|
|
page.on("pageerror", (e) => errors.push(e.message));
|
|
await page.route("**/*", serve(lang));
|
|
await page.goto("http://magpie.test/?view=providers");
|
|
await page.locator(".row.provider", { hasText: "Claude" }).first().click();
|
|
const adv = page.locator(".editor details.advanced");
|
|
await adv.waitFor({ state: "attached" });
|
|
if (!(await adv.evaluate((d) => d.open))) await adv.locator(":scope > summary").click();
|
|
await page.locator(".editor .acct-proxy").first().waitFor();
|
|
|
|
const first = await gaps(page);
|
|
// the provider's Global proxy: its hint right under the options
|
|
assert(first.provider <= 12, `${first.provider}px under the provider's options`);
|
|
assert.deepEqual(first.accounts.map((a) => a.custom), [false, false, false, true], JSON.stringify(first.accounts));
|
|
// every account but the last: the same room before the next name,
|
|
// Custom's address and login counted as its own
|
|
const between = first.accounts.slice(0, -1).map((a) => a.gap);
|
|
assert(between.every((g) => g >= 0 && g <= 12), `gaps ${between}`);
|
|
assert(Math.max(...between) - Math.min(...between) <= 1, `uneven gaps ${between}`);
|
|
|
|
// Custom on the first, then back: its gap comes back as it was
|
|
const opts = page.locator(".editor .acct-proxy").first().locator(".proxy-mode .opt");
|
|
await opts.nth(2).click();
|
|
assert.equal((await gaps(page)).accounts[0].custom, true);
|
|
await opts.nth(0).click();
|
|
assert.deepEqual((await gaps(page)).accounts.map((a) => a.gap), first.accounts.map((a) => a.gap));
|
|
// the provider's own Custom shows its address, Global proxy hides it
|
|
const own = page.locator(".editor .proxy-pick > .proxy-row .proxy-mode .opt");
|
|
await own.nth(2).click();
|
|
assert(await page.locator(".editor .proxy-pick > .proxy-row .proxy-url").isVisible());
|
|
await own.nth(0).click();
|
|
assert.equal((await gaps(page)).provider, first.provider);
|
|
assert.deepEqual(errors, []);
|
|
});
|
|
}
|
|
}
|
|
}
|