gui: an account's eye shows that provider's account, and a Kiro account's eye works
outloudvi on Discord (#feedback, 1564924864052207627): on Usage's overview
with Hide accounts on, Kiro's eye did nothing, and one username on two
platforms was shown or hidden by either card's eye.
- Kiro: the plugin names an account "email (Google)" (nameOf in
packages/kiro). The finder tried the address pattern first, so only the
address was hidden. The eye kept the whole name, which never matched
what was hidden. A name with an address in it is now found whole,
before the address pattern.
- One name on two providers: shown was keyed by the account alone, and
kin() gathered names from every provider. Each entry is now keyed
"provider\naccount". eye(u, p) takes the provider id at every call: the
provider editor, the account button, the panel's quota card and Usage's
quotaWho. Text by an eye (its row, or its card one level down) follows
that eye's provider. Text that is near no eye, like a sentence elsewhere
in the window, shows when the account is shown under any provider, as
before.
New test account-eye-provider: Usage cards for Kiro (one email, Google
and GitHub), Codex and ZCode (the same address) are rendered with Hide
accounts on. It runs en and zh, at 900 and 360px, in both engines.
Run on mote:
- account-eye-provider at this tree: 4/4.
- go test -tags nogui -run Budget ./internal/gui: ok (no budget raised).
- 124 GUI files the masking, Usage, panel and storage code reaches, both
engines, run with the next commit on top: 1761/1792. All 7 red top-level
tests are in quota-count-wrap (#3404, #2228), usage-agents-hide (#3414,
#2276) and usage-ledger (#3104), plus one masking-records zh-TW and one
quota-refresh-order. Those five files were run again at origin/main
33af28ed6 and at this tree: the same 29 reds on both. masking-records
and quota-refresh-order were green in that rerun (quota-refresh-order
had failed on keep(), fixed in the commit before).
Broken by hand:
- Back to the old eye and finder: every case red at "the Kiro account's
eye shows it" (chromium and webkit, en and zh).
- Only the provider keying undone: every case red at "the same address
on ZCode stays hidden".
Not tried: a real Kiro account (the name's shape comes from the plugin's
source), and Linux and Windows.
This commit is contained in:
+28
-18
@@ -9227,7 +9227,7 @@ function drawEditor(p, presetID) {
|
||||
if (p.move) ed.append(...renderMove(p));
|
||||
} else {
|
||||
const acct = el("div", "acct");
|
||||
acct.append(icon(a.agentIcon), el("span", "n", a.user), hideAccounts.eye(a.user), el("span", "plan", accountPlan(a)));
|
||||
acct.append(icon(a.agentIcon), el("span", "n", a.user), hideAccounts.eye(a.user, p.id), el("span", "plan", accountPlan(a)));
|
||||
ed.append(...field(t("Account"), acct, t("{agent}'s sign-in, read from its own files. Sign out there and this provider goes away.", { agent: a.agentName })));
|
||||
}
|
||||
ed.append(...field(t("Models"), renderModels(p), ""));
|
||||
@@ -13595,7 +13595,7 @@ function accountNameButton(p, user) {
|
||||
s.title = t("The same seat as the key plan {name}, shown once, on this account's card", { name: seat });
|
||||
wrap.append(s);
|
||||
}
|
||||
wrap.append(hideAccounts.eye(user));
|
||||
wrap.append(hideAccounts.eye(user, p.id));
|
||||
return wrap;
|
||||
}
|
||||
// an account or key list's last row, adding one
|
||||
@@ -17237,7 +17237,7 @@ function panelQuotaCard(q) {
|
||||
// and its eye while Hide accounts is on, as on the Usage page (yogurt36)
|
||||
const who = el("span", "pq-who");
|
||||
who.append(el("span", "pq-user", q.alias || q.user || q.name));
|
||||
if ((q.user || q.alias) && window.hideAccounts) who.append(hideAccounts.eye(q.user || q.alias));
|
||||
if ((q.user || q.alias) && window.hideAccounts) who.append(hideAccounts.eye(q.user || q.alias, q.provider));
|
||||
card.append(who);
|
||||
card.title = [q.name, q.alias, q.user, q.seat && q.seat !== q.alias && "≡ " + q.seat, q.plan, q.until ? planTerm(q) : "", q.balance && t("Balance") + " " + q.balance].filter(Boolean).join(" · ");
|
||||
if (q.error) {
|
||||
@@ -24324,7 +24324,9 @@ window.noteAccounts = noteAccounts;
|
||||
const ns = names(), key = ns.join("\n");
|
||||
if (key !== findKey) {
|
||||
findKey = key;
|
||||
find = ns.length ? new RegExp(EMAIL.source + "|" + ns.map(esc).join("|"), "g") : EMAIL;
|
||||
// whole, not its address: Kiro's "a@b.c (GitHub)" (outloudvi)
|
||||
const at = (n) => n.includes("@");
|
||||
find = ns.length ? new RegExp([...ns.filter(at).map(esc), EMAIL.source, ...ns.filter((n) => !at(n)).map(esc)].join("|"), "g") : EMAIL;
|
||||
}
|
||||
return find;
|
||||
}
|
||||
@@ -24336,12 +24338,19 @@ window.noteAccounts = noteAccounts;
|
||||
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
|
||||
const shown = new Set(), low = (x) => String(x).trim().toLowerCase();
|
||||
function* hits(s, re) {
|
||||
// shown in either never shows in the other; kept by provider
|
||||
// (outloudvi: one address on two services showed on both)
|
||||
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) => {
|
||||
if (!shown.size) return false;
|
||||
for (; e && e !== document.body; e = e.parentElement) { const b = e.querySelector?.(":scope>.acct-eye,:scope>*>.acct-eye"); if (b?._p) return shown.has(sk(b._p, k)); }
|
||||
return [...shown].some((s) => s.endsWith("\n" + low(k)));
|
||||
};
|
||||
function* hits(s, re, at) {
|
||||
re.lastIndex = 0; // matchAll starts where the pattern's last test ended
|
||||
for (const m of s.matchAll(re)) {
|
||||
if (shown.has(low(m[0]))) continue;
|
||||
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;
|
||||
yield m;
|
||||
@@ -24385,7 +24394,7 @@ window.noteAccounts = noteAccounts;
|
||||
for (const n of found) {
|
||||
const bits = [];
|
||||
let last = 0;
|
||||
for (const m of hits(n.data, reOf(n.parentElement))) {
|
||||
for (const m of hits(n.data, reOf(n.parentElement), n.parentElement)) {
|
||||
if (m.index > last) bits.push(n.data.slice(last, m.index));
|
||||
const s = el("span", "pii", dots(m[0]));
|
||||
s.dataset.raw = m[0];
|
||||
@@ -24403,7 +24412,7 @@ window.noteAccounts = noteAccounts;
|
||||
// one masked already reads as an account too, its stars and all
|
||||
if (!e.dataset || "piiTitle" in e.dataset || !e.title) continue;
|
||||
let out = "", last = 0;
|
||||
for (const m of hits(e.title, reOf(e))) {
|
||||
for (const m of hits(e.title, reOf(e), e)) {
|
||||
out += e.title.slice(last, m.index) + m[0].replace(m[0].includes("@") ? /[^@.]/g : /./gu, "•"); // a tooltip can't blur
|
||||
last = m.index + m[0].length;
|
||||
}
|
||||
@@ -24464,14 +24473,14 @@ window.noteAccounts = noteAccounts;
|
||||
if (!keep) { chosen = on ? "1" : "0"; try { localStorage.setItem("magpie.maskEmails", chosen); } catch {} }
|
||||
for (const set of pages) set(on);
|
||||
}
|
||||
const kin = (u) => {
|
||||
const kin = (u, pid) => {
|
||||
const k = [u];
|
||||
for (const p of providers?.providers || []) for (const [a, n] of Object.entries(p.accountNames || {})) if (a === low(u) || n === u) k.push(a, n);
|
||||
for (const q of quotas || []) if (q.user === u || q.alias === u) k.push(q.user, q.alias);
|
||||
return k.filter(Boolean).map(low);
|
||||
for (const p of providers?.providers || []) if (p.id === pid) for (const [a, n] of Object.entries(p.accountNames || {})) if (a === low(u) || n === u) k.push(a, n);
|
||||
for (const q of quotas || []) if (q.provider === pid && (q.user === u || q.alias === u)) k.push(q.user, q.alias);
|
||||
return k.filter(Boolean).map((x) => sk(pid, x));
|
||||
};
|
||||
const paint = (b) => {
|
||||
const on = shown.has(low(b._u));
|
||||
const on = shown.has(sk(b._p, b._u));
|
||||
b.setAttribute("aria-pressed", on);
|
||||
b.title = t(on ? "Hide this account" : "Show this account");
|
||||
b.querySelector("path").setAttribute("d", on ? EYE : EYE_OFF);
|
||||
@@ -24482,17 +24491,18 @@ window.noteAccounts = noteAccounts;
|
||||
};
|
||||
// Settings' Privacy has the same switch, and the settings follow
|
||||
window.hideAccounts = {
|
||||
eye: (u) => {
|
||||
eye: (u, p) => {
|
||||
const b = el("button", "acct-eye");
|
||||
b._u = u;
|
||||
b._p = p;
|
||||
b.setAttribute("aria-label", t("Show this account"));
|
||||
b.append(svg("", 13, 2));
|
||||
b.firstChild.setAttribute("viewBox", "0 0 24 24");
|
||||
paint(b);
|
||||
b.onclick = (e) => {
|
||||
e.stopPropagation();
|
||||
const on = !shown.has(low(u));
|
||||
for (const k of kin(u)) on ? shown.add(k) : shown.delete(k);
|
||||
const on = !shown.has(sk(p, u));
|
||||
for (const k of kin(u, p)) on ? shown.add(k) : shown.delete(k);
|
||||
redraw();
|
||||
};
|
||||
return b;
|
||||
|
||||
@@ -405,7 +405,7 @@ function quotaWho(q) {
|
||||
out.push(s);
|
||||
} else if (q.seat) out[0].title += "\n" + t("The same seat as the key plan {name}, shown once, on this account's card", { name: q.seat });
|
||||
if (q.sharedKeys) out.push(sharedKeysNote(q));
|
||||
if (q.user || q.alias) out.push(hideAccounts.eye(q.user || q.alias));
|
||||
if (q.user || q.alias) out.push(hideAccounts.eye(q.user || q.alias, q.provider));
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,106 @@
|
||||
// Run with Node's test runner and Playwright on the module path; see README.md.
|
||||
// Usage's per-account eye, with Hide accounts on (outloudvi on Discord):
|
||||
// - a Kiro plugin account is named "email (way it was signed in to)"; its
|
||||
// eye showed nothing, since the address inside the name was found and
|
||||
// hidden alone while the eye kept the whole name. Pressed, it shows that
|
||||
// account, and the account of the same email signed in another way
|
||||
// stays hidden.
|
||||
// - one address on two services is two accounts: the eye on one card shows
|
||||
// that card's, the other card's stays hidden. A sentence elsewhere in the
|
||||
// window naming the address follows the account shown, as before.
|
||||
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 SAME = "same@example.com", KG = "kiro@example.com (Google)", KH = "kiro@example.com (GitHub)";
|
||||
const inHours = (h) => new Date(Date.now() + h * 3600e3 + 60e3).toISOString();
|
||||
const card = (provider, name, user, plan) => ({ provider, name, icon: provider, plan, user, windows: [{ name: "5 hours", used: 30, resetsAt: inHours(3) }] });
|
||||
const quotas = () => [
|
||||
card("kiro", "Kiro", KG, "Pro"),
|
||||
card("kiro", "Kiro", KH, "Free"),
|
||||
card("codex", "Codex", SAME, "Plus"),
|
||||
card("zcode", "ZCode", SAME, "Lite"),
|
||||
];
|
||||
|
||||
function serve(lang) {
|
||||
const settings = { theme: "light", lang, tray: "panel", quotaLeft: false, currency: "usd" };
|
||||
const providers = { providers: [], presets: [], excluded: [], gateway: { running: true, window: true } };
|
||||
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({ agents: [], profiles: [], settings });
|
||||
if (url.pathname === "/api/settings") return json(settings);
|
||||
if (url.pathname === "/api/providers") return json(providers);
|
||||
if (url.pathname === "/api/usage/quotas") return json(quotas());
|
||||
if (url.pathname === "/api/groups") return json({ groups: [], models: [] });
|
||||
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);
|
||||
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: "" }); }
|
||||
};
|
||||
}
|
||||
|
||||
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
||||
for (const lang of ["en", "zh"]) {
|
||||
test(`${engine} ${lang}: a Usage card's eye shows its own provider's account, a Kiro plugin account included`, async (t) => {
|
||||
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
||||
t.after(() => browser.close());
|
||||
for (const width of [900, 360]) {
|
||||
const context = await browser.newContext({ viewport: { width, height: 900 }, reducedMotion: "reduce" });
|
||||
const page = await context.newPage();
|
||||
page.setDefaultTimeout(5000);
|
||||
const errors = [];
|
||||
page.on("pageerror", (e) => errors.push(e.message));
|
||||
await page.route("**/*", serve(lang));
|
||||
await page.goto("http://magpie.test/?view=usage");
|
||||
await page.locator(".subscription-account").nth(3).waitFor();
|
||||
const row = (provider, user) => page.locator(`.subscription-account[data-card="${provider}|${user}"]`);
|
||||
const hidden = (provider, user) => row(provider, user).evaluate((e) => e.querySelectorAll(".pii").length > 0 && !e.textContent.includes(e.dataset.card.split("|")[1]));
|
||||
const shown = (provider, user) => row(provider, user).evaluate((e) => !e.querySelector(".pii") && e.textContent.includes(e.dataset.card.split("|")[1]));
|
||||
const settle = () => page.evaluate(() => new Promise((r) => requestAnimationFrame(() => requestAnimationFrame(r))));
|
||||
|
||||
await page.locator("#usageMask").click();
|
||||
await page.evaluate((same) => {
|
||||
const d = document.createElement("div");
|
||||
d.id = "sample";
|
||||
d.textContent = `mail ${same} today`;
|
||||
document.querySelector("main, body").append(d);
|
||||
}, SAME);
|
||||
await page.waitForFunction(() => document.querySelectorAll(".subscription-account .pii").length >= 4 && document.querySelector("#sample .pii"));
|
||||
for (const [p, u] of [["kiro", KG], ["kiro", KH], ["codex", SAME], ["zcode", SAME]]) assert.ok(await hidden(p, u), `${p} ${u} is hidden first`);
|
||||
|
||||
// Kiro's account named by its email and its way in: the eye shows it
|
||||
await row("kiro", KG).locator(".acct-eye").click();
|
||||
await settle();
|
||||
assert.ok(await shown("kiro", KG), "the Kiro account's eye shows it");
|
||||
assert.equal(await row("kiro", KG).locator(".acct-eye").getAttribute("aria-pressed"), "true");
|
||||
assert.ok(await hidden("kiro", KH), "the same email signed in with GitHub stays hidden");
|
||||
assert.equal(await row("kiro", KH).locator(".acct-eye").getAttribute("aria-pressed"), "false");
|
||||
|
||||
// one address on two services: the Codex card's eye shows Codex's only
|
||||
await row("codex", SAME).locator(".acct-eye").click();
|
||||
await settle();
|
||||
assert.ok(await shown("codex", SAME), "Codex's account shows");
|
||||
assert.ok(await hidden("zcode", SAME), "the same address on ZCode stays hidden");
|
||||
assert.equal(await row("zcode", SAME).locator(".acct-eye").getAttribute("aria-pressed"), "false");
|
||||
assert.equal(await page.locator("#sample").textContent(), `mail ${SAME} today`, "a sentence elsewhere follows the account shown");
|
||||
|
||||
// pressed again: hidden again, everywhere
|
||||
await row("codex", SAME).locator(".acct-eye").click();
|
||||
await page.waitForFunction(() => document.querySelector("#sample .pii"));
|
||||
assert.ok(await hidden("codex", SAME));
|
||||
assert.ok(await shown("kiro", KG), "the Kiro account stays shown");
|
||||
|
||||
assert.equal(await page.locator("select").count(), 0, "no native select");
|
||||
assert.deepEqual(errors, []);
|
||||
await context.close();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user