gui: a one-letter account name is masked too (Shinji_Zl on X)

Shinji_Zl's WorkBuddy account is named 他. With account names hidden,
Usage → Overview and the quota cards still showed it: noteAccount and
names() kept only names of two characters or more, and mask() skipped
text nodes shorter than two.

A name of one character is now kept when it is a single letter past
ASCII (nameLike: a CJK name like 他), never one ASCII letter or digit,
which would mask every "a" or "1" on the page. Such a name is masked
only where it stands apart: next to another letter or digit of any
script it is part of a word (inWord: 其他 keeps its 他). mask() now
looks at text nodes of any length.

The core scripts' budget is kept, not raised: the new code is written
short, and three of the masking block's comments are cut to what they
say (the stand-in letters, names(), the accounts shown).

Run (mote, on e7185daeb):
- the GUI files that mask names or show account names
  (--test-concurrency=4): 674 tests, 651 pass. 22 reds are
  usage-agents-hide, which fails the same 22 alone at origin/main
  f849ccced (#2276, #3414). One is account-mask chromium zh's click on
  #usageMask timing out (#3951, same on main in a whole run); the file
  passes 5 of 5 runs alone here and 5 of 5 at origin/main.
- broken by hand: app.js as on main, account-mask 0 of 4; the inWord
  line taken out, 0 of 4 (the 他 of 其他 is masked, 4 names not 3).
- TestCoreScriptBudget (go test ./internal/gui -run Budget) and
  i18n-keys: ok.

Not tried: the whole GUI suite (14k tests, ~200 known reds), and the
reporter's real WorkBuddy account.
This commit is contained in:
yetone
2026-11-02 15:21:18 +08:00
parent 58541e5b8c
commit c74b932c82
2 changed files with 23 additions and 21 deletions
+13 -13
View File
@@ -24180,10 +24180,12 @@ const accountNames = new Set();
// words no account is named, lest each is hidden: "api key", "signed in"
// (and "(2)") name a plugin's nameless account (pluginLabels, outloudvi)
const NOT_ACCOUNTS = new Set(["default", "own", "desktop", "account", "main", "local", "unknown", "none", "free", "pro", "api key", "signed in"]);
// one letter is a name past ASCII only: 他 (Shinji_Zl), never "a"
const nameLike = (s) => [...s].length > 1 || /^(?!\p{ASCII})\p{L}$/u.test(s);
function noteAccount(s) {
if (typeof s !== "string") return;
s = s.trim();
if (s.length >= 2 && s.length <= 80 && !/[\n\r]/.test(s)) accountNames.add(s);
if (nameLike(s) && s.length <= 80 && !/[\n\r]/.test(s)) accountNames.add(s);
}
// noteAccounts: an answer's user, account, or route account (kind account)
function noteAccounts(x, depth = 0) {
@@ -24207,14 +24209,11 @@ window.noteAccounts = noteAccounts;
// an address a vendor has half masked itself (Zhipu's abc***gh@…) is one
// address still, the letters before its stars hidden too
const EMAIL = /[\w.+*•-]+@[\w*•-]+(?:\.[\w*•-]+)+/g, IS_EMAIL = new RegExp("^" + EMAIL.source + "$");
// stand-in letters of the account's shape, the same each time it's drawn:
// blurred, they read as a name without being one
// stand-in letters of its shape, the same each time: blurred, a name
const dots = (s) => { let h = 7; return s.replace(/[^@.]/g, (c) => (h = (h * 31 + c.charCodeAt(0)) >>> 0, "aeiounrstlcmdh"[h % 14])); };
const esc = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
// names: the accounts that aren't addresses, longest first so one inside
// another is hidden whole; a name that is a provider's, an agent's or a
// card's own (WorkBuddy's account with no nickname is "WorkBuddy") is not
// one to hide
// names: the accounts not addresses, longest first; a provider's, an
// agent's or a card's own name ("WorkBuddy") is not one to hide
function names() {
const all = new Set(accountNames), not = new Set(NOT_ACCOUNTS);
for (const p of providers?.providers || []) {
@@ -24232,7 +24231,7 @@ window.noteAccounts = noteAccounts;
if (q.alias && !q.named && q.alias !== q.seat) all.add(q.alias.trim());
}
for (const a of state?.agents || []) for (const n of [a.id, a.name]) if (n) not.add(String(n).toLowerCase());
return [...all].filter((n) => n.length >= 2 && !IS_EMAIL.test(n) && !not.has(n.toLowerCase().replace(/ \(\d+\)$/, ""))).sort((a, b) => b.length - a.length);
return [...all].filter((n) => nameLike(n) && !IS_EMAIL.test(n) && !not.has(n.toLowerCase().replace(/ \(\d+\)$/, ""))).sort((a, b) => b.length - a.length);
}
let findKey = null, find = EMAIL;
// finder is the pattern of everything to hide now: an address, or a name
@@ -24252,10 +24251,10 @@ window.noteAccounts = noteAccounts;
// an address always is
const WORD = /[A-Za-z0-9_]/, JOIN = /[-.]/;
const joined = (s, i, step) => WORD.test(s[i] || "") || (JOIN.test(s[i] || "") && WORD.test(s[i + step] || ""));
// accounts shown while the rest stay hidden (yogurt36), this page's
// only: the window and the tray panel are pages of their own, so one
// shown in either never shows in the other; kept by provider
// (outloudvi: one address on two services showed on both)
// a one-letter name stands apart: 他, not the 他 of 其他
const inWord = (s, i, end) => /[\p{L}\p{N}]$/u.test(s.slice(0, i)) || /^[\p{L}\p{N}]/u.test(s.slice(end));
// accounts shown while the rest hide (yogurt36), this page's only,
// kept by provider (outloudvi: one address on two services)
const shown = new Set(), low = (x) => String(x).trim().toLowerCase(), sk = (p, k) => p + "\n" + low(k);
// by an eye, its provider's only; elsewhere, shown under any
const isShown = (k, e) => {
@@ -24269,6 +24268,7 @@ window.noteAccounts = noteAccounts;
if (isShown(m[0], at)) continue;
const name = !m[0].includes("@"), end = m.index + m[0].length;
if (name && ((WORD.test(m[0][0]) && joined(s, m.index - 1, -1)) || (WORD.test(m[0].at(-1)) && joined(s, end, 1)))) continue;
if (name && [...m[0]].length < 2 && inWord(s, m.index, end)) continue;
yield m;
}
}
@@ -24303,7 +24303,7 @@ window.noteAccounts = noteAccounts;
const all = finder(), reOf = (e) => e?.closest(NAMELESS) || e?.closest?.(LABELS) ? EMAIL : all;
const walk = document.createTreeWalker(root, NodeFilter.SHOW_TEXT), found = [];
for (let n; (n = walk.nextNode());) {
if (n.data.length < 2 || SKIP.has(n.parentElement?.tagName) || n.parentElement?.closest(".pii, " + KEEP)) continue;
if (!n.data || SKIP.has(n.parentElement?.tagName) || n.parentElement?.closest(".pii, " + KEEP)) continue;
const re = reOf(n.parentElement);
re.lastIndex = 0;
if (re.test(n.data)) found.push(n);
+10 -8
View File
@@ -7,7 +7,8 @@
// stays, as do magpie's own labels for a nameless account ("API key") and
// a name inside a longer word. The tray panel follows the
// window's setting, as it is turned. English and Chinese; no backend, the
// API is faked here.
// API is faked here. A one-letter name (Shinji_Zl's WorkBuddy account 他)
// is hidden too, where it stands apart, not the 他 of 其他.
const assert = require("node:assert/strict");
const fs = require("node:fs/promises");
const path = require("node:path");
@@ -18,6 +19,7 @@ const assets = path.resolve(__dirname, "../assets");
const quotas = () => [
{ provider: "workbuddy", name: "WorkBuddy", icon: "workbuddy-color", plan: "Free", user: "李雷", windows: [{ name: "Credits", used: 8.9, display: "500.52 / 5600" }] },
{ provider: "workbuddy", name: "WorkBuddy", icon: "workbuddy-color", plan: "Free", user: "138****5678", windows: [{ name: "Credits", used: 1, display: "56 / 5600" }] },
{ provider: "workbuddy", name: "WorkBuddy", icon: "workbuddy-color", plan: "Free", user: "他", windows: [{ name: "Credits", used: 2, display: "112 / 5600" }] },
{ provider: "zcode", name: "ZCode", icon: "zcode", plan: "Start", user: "ZCode", windows: [{ name: "5 hours", used: 10 }] },
{ provider: "qoder", name: "Qoder", icon: "qoder", plan: "Pro", user: "Lee", windows: [{ name: "Credits", used: 3 }] },
{ provider: "codex", name: "Codex", icon: "openai", plan: "Plus", user: "dev.one@example.com", windows: [{ name: "5 hours", used: 20 }] },
@@ -80,7 +82,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
await page.evaluate(() => {
const d = document.createElement("div");
d.id = "sample";
d.textContent = "李雷 checked in · Sleeper Lee · ZCode · or an API key · Signed in";
d.textContent = "李雷 checked in · Sleeper Lee · ZCode · or an API key · Signed in · 其他 · 他";
d.title = "WorkBuddy · 138****5678";
document.querySelector("#view-usage").append(d);
});
@@ -88,7 +90,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
assert.equal((await btn.textContent()).trim(), w.hidden);
assert.match(await btn.getAttribute("title"), w.back);
assert.match(await page.locator("#rtMask").getAttribute("title"), w.back);
await page.waitForFunction(() => document.querySelectorAll("#sample .pii").length === 2);
await page.waitForFunction(() => document.querySelectorAll("#sample .pii").length === 3);
const got = await page.evaluate(() => ({
users: [...document.querySelectorAll(".subscription-account .user")].map((u) => ({ raw: u.querySelector(".pii")?.dataset.raw ?? null, text: u.textContent, title: u.title })),
heads: [...document.querySelectorAll(".subscription-head b")].map((b) => b.textContent),
@@ -97,7 +99,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
sampleTitle: document.querySelector("#sample").title,
}));
const byRaw = Object.fromEntries(got.users.map((u) => [u.raw, u]));
for (const name of ["李雷", "138****5678", "Lee", "dev.one@example.com"]) {
for (const name of ["李雷", "138****5678", "Lee", "dev.one@example.com", "他"]) {
assert.ok(byRaw[name], `${name} is hidden: ${JSON.stringify(got.users)}`);
assert.ok(!byRaw[name].text.includes(name), `${name} isn't in sight`);
assert.ok(!byRaw[name].title.includes(name), `${name} isn't in its tooltip: ${byRaw[name].title}`);
@@ -106,10 +108,10 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
// ZCode signed in with no name of its own is the card's name: kept
assert.ok(got.users.some((u) => u.raw === null && u.text === "ZCode"), "ZCode's own name stays");
assert.ok(got.heads.includes("WorkBuddy") && got.heads.includes("ZCode"), got.heads.join());
assert.deepEqual(got.sampleRaws, ["李雷", "Lee"]);
assert.deepEqual(got.sampleRaws, ["李雷", "Lee", "他"]);
// magpie's labels for a plugin's nameless accounts are words, kept
// (outloudvi: Kiro's summary "…or an API key" was blurred)
assert.match(got.sample, /^\S+ checked in · Sleeper \S+ · ZCode · or an API key · Signed in$/);
assert.match(got.sample, /^\S+ checked in · Sleeper \S+ · ZCode · or an API key · Signed in · 其他 · \S+$/);
assert.equal(got.sampleTitle, "WorkBuddy · •••••••••••");
// Routing: a route's account, learnt from what the gateway answered
@@ -128,7 +130,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
await panel.evaluate(() => setPanelTab("usage"));
await panel.waitForFunction(() => [...document.querySelectorAll("#panelQuota .pq-user .pii")].some((e) => e.dataset.raw === "李雷"));
const pq = await panel.evaluate(() => [...document.querySelectorAll("#panelQuota .pq-card")].map((c) => ({ text: c.querySelector(".pq-user").textContent, title: c.title })));
for (const c of pq) assert.ok(!/李雷|138\*|dev\.one|Lee\b/.test(c.text + c.title), JSON.stringify(c));
for (const c of pq) assert.ok(!/李雷|138\*|dev\.one|Lee\b|^他$/.test(c.text) && !/李雷|138\*|dev\.one|Lee\b|他/.test(c.title), JSON.stringify(c));
// and its model picker, which sits outside the panel's view: a Codex
// account's address beside its model (PaulT on Discord)
await panel.evaluate(() => {
@@ -148,7 +150,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
assert.equal(await panel.locator("#pickRow").textContent(), "GPT-6-Astra via magpie dev.one@example.com");
assert.ok(await panel.evaluate(() => [...document.querySelectorAll("#panelQuota .pq-user")].some((e) => e.textContent === "李雷")));
// and back as they were in the window
assert.equal(await page.locator("#sample").textContent(), "李雷 checked in · Sleeper Lee · ZCode · or an API key · Signed in");
assert.equal(await page.locator("#sample").textContent(), "李雷 checked in · Sleeper Lee · ZCode · or an API key · Signed in · 其他 · 他");
assert.equal(await page.locator("#sample").getAttribute("title"), "WorkBuddy · 138****5678");
assert.equal(await page.locator(".subscription-account .user", { hasText: "李雷" }).getAttribute("title"), "李雷");
assert.deepEqual(errors, []);