From be8e352a2070ffae97990aa1d0f8395c44be601d Mon Sep 17 00:00:00 2001 From: yetone Date: Fri, 13 Nov 2026 04:51:50 +0800 Subject: [PATCH] editor: Proxy takes no room unless Custom is picked MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- internal/gui/assets/app.css | 11 +- internal/gui/assets/app.js | 1 - internal/gui/tests/account-proxy.test.cjs | 18 ++-- internal/gui/tests/proxy-gaps.test.cjs | 124 ++++++++++++++++++++++ 4 files changed, 140 insertions(+), 14 deletions(-) create mode 100644 internal/gui/tests/proxy-gaps.test.cjs diff --git a/internal/gui/assets/app.css b/internal/gui/assets/app.css index 9a70dc1b7..f69cc22ca 100644 --- a/internal/gui/assets/app.css +++ b/internal/gui/assets/app.css @@ -3499,12 +3499,13 @@ body.window .ag-sk-icon { width: 22px; height: 22px; border-radius: 6px; } .editor label { font-size: 12px; color: var(--fg-2); text-align: right; padding-top: 5px; } .editor label.by-list { padding-top: 11px; } .editor .hint { font-size: 11px; color: var(--fg-2); margin-top: 4px; } -/* a provider's own proxy (#237): the address beside the options, its room - kept while it is hidden so a pick never changes the dialog's height */ +/* a provider's own proxy (#237): the address beside the options, and no + room at all while Custom isn't picked (an empty strip under the options + looked broken, the owner, 11-12) */ .editor .proxy-row { display: flex; align-items: center; gap: 8px; min-width: 0; } .editor .proxy-row .proxy-mode { flex: none; } .editor .proxy-row input.proxy-url { flex: 1 1 auto; width: auto; min-width: 0; } -.editor .proxy-row input.proxy-url.off { visibility: hidden; } +.editor .proxy-row input.proxy-url.off { display: none; } .editor .proxy-row .gone { display: none; } .editor .proxy-row .proxy-saved { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: left; } .saved-proxy .sub { overflow-wrap: anywhere; } @@ -3533,10 +3534,10 @@ body.window .ag-sk-icon { width: 22px; height: 22px; border-radius: 6px; } .editor .acct-proxies > .acct-proxy-more { justify-self: start; } /* the login of a SOCKS proxy in the rows outside Settings (#3382): the fields Settings' own row has, stacked under, so an account line is no - wider; off keeps its room as the address beside the options does */ + wider; off takes no room, as the address beside the options doesn't */ .editor .proxy-auth.proxy-login { justify-content: flex-start; } .editor .proxy-auth.proxy-login input.proxy-credential { width: 140px; max-width: 100%; min-width: 0; } -.editor .proxy-auth.proxy-login.off { visibility: hidden; } +.editor .proxy-auth.proxy-login.off { display: none; } .signing .callback-form .proxy-login { flex-basis: 100%; } /* what a balance token's URL wants instead, and a balance checked in the form */ .editor .bal-fix { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; margin-top: 6px; font-size: 12px; line-height: 1.45; color: var(--muted); } diff --git a/internal/gui/assets/app.js b/internal/gui/assets/app.js index a2af8aba8..334dfbd1f 100644 --- a/internal/gui/assets/app.js +++ b/internal/gui/assets/app.js @@ -7757,7 +7757,6 @@ function proxyPicker() { }); seg.classList.add("proxy-mode"); place(draft.proxyMode || ""); - // its room kept while not asked for: a pick never moves the dialog const row = el("div", "proxy-row"); row.append(seg, addr, saved); box.append(row, login, hint); diff --git a/internal/gui/tests/account-proxy.test.cjs b/internal/gui/tests/account-proxy.test.cjs index e2ffe4d92..588852e3a 100644 --- a/internal/gui/tests/account-proxy.test.cjs +++ b/internal/gui/tests/account-proxy.test.cjs @@ -4,11 +4,11 @@ // its Proxy row, a line per account — Provider's proxy | Direct | Custom — // opening on what each has; Save posts accountProxies with each account // that doesn't follow Codex's, and Custom with no address is refused -// before anything is posted. A pick moves nothing and the page stays where -// it is. A subscription with one account has no such lines. A provider's -// keys have the same lines, a key by its fingerprint (Beyfish_Wang on X: -// 不同 key 走不同的代理), and one with one key none. In English and -// Chinese. +// before anything is posted. A pick moves nothing above it and the page +// stays where it is; only Custom's address takes room, under its options. +// A subscription with one account has no such lines. A provider's keys +// have the same lines, a key by its fingerprint (Beyfish_Wang on X: 不同 +// key 走不同的代理), and one with one key none. In English and Chinese. const assert = require("node:assert/strict"); const fs = require("node:fs/promises"); const path = require("node:path"); @@ -112,13 +112,15 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", const addr = (page, user) => line(page, user).locator(".proxy-url"); // what the page and the dialog's scrollers have scrolled const scrolled = (page) => page.evaluate(() => [window.scrollY, ...[...document.querySelectorAll("*")].filter((e) => e.scrollTop > 0).map((e) => `${e.className}:${e.scrollTop}`)].join(" ")); - // a click on one of an account's options: it, the lines and the Save - // button left where they were, nothing scrolled + // a click on one of an account's options: it and the lines down to its + // own left where they were, nothing scrolled (Custom's address, or its + // going, moves the ones under it) const pick = async (page, user, name) => { const b = line(page, user).locator(".proxy-mode .opt", { hasText: name }); await b.scrollIntoViewIfNeeded(); await page.waitForTimeout(200); - const where = () => page.evaluate(() => [...document.querySelectorAll(".editor .acct-proxy, .editor .bar")].map((e) => Math.round(e.getBoundingClientRect().top))); + const n = await line(page, user).evaluate((l) => [...document.querySelectorAll(".editor .acct-proxy")].indexOf(l) + 1); + const where = () => page.evaluate((n) => [...document.querySelectorAll(".editor .acct-proxy")].slice(0, n).map((e) => Math.round(e.getBoundingClientRect().top)), n); const before = await b.evaluate((e) => e.getBoundingClientRect().top), lines = await where(), sc = await scrolled(page); await b.click(); await page.waitForTimeout(250); diff --git a/internal/gui/tests/proxy-gaps.test.cjs b/internal/gui/tests/proxy-gaps.test.cjs new file mode 100644 index 000000000..777bf4f38 --- /dev/null +++ b/internal/gui/tests/proxy-gaps.test.cjs @@ -0,0 +1,124 @@ +// 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, []); + }); + } + } +}