gui: Masking alert lives on the Masking page

nb5p on Discord (#feedback): "这个脱敏提醒被放到额度设置里了,害得我找半天没找到".
The Masking alert row sat in Settings › Usage. It now closes Insights ›
Masking, after the list of requests, in the page's own `.list.prefs` rows
(same Off/On segs, same ids #maskAlertRow/#maskAlertSegs, same i18n keys
and the same maskAlert setting). Nothing is left in Usage. The page draws
it from page.js after loadSettings, hides it while one request is open,
and gateway mode leaves it out as Settings did. Placed after the list so
the requests still start in the first screen (masking-records at 640px)
and the demo keeps its place between the card and the list.

Run at base 07a3312c5 with this change:
- mask-alert.test.cjs, Chromium (WSL magpie-desktop and mote) and WebKit
  (WSL), en/zh/zh-TW/ja/de at 900 and 380px: all pass.
- WebKit (WSL): mask-alert, masking-records, masking-demo,
  masking-demo-unblurred: 87 pass, 0 fail (tree differed from the pushed
  one by a client.js comment reflow only). Earlier WebKit run: turn-done,
  quota-reads, routing-masking, gateway-mode, builtins, sidebar pass.
- Chromium (WSL) at the final tree: i18n-keys, mask-alert, masking-records,
  masking-demo, masking-demo-unblurred, turn-done, quota-reads,
  routing-masking, gateway-mode, builtins, sidebar: 131 pass, 1 fail. The
  fail is i18n-keys "a plugin's words are its own" on "Unmarked"
  (plugins/routing/i18n.js), red on main, #4524.
- mote: go test -timeout 45m ./internal/gui/...: TestCoreScriptBudget and
  the budgets pass (app.js only shrinks). Red: TestSettingsSaveKeepsWhat-
  ItDoesNotSend (SearchAll, red on origin/main 93b31f5b7 too, #4514),
  TestColdTurnsTaken (passes alone 3 of 3, #4510), and the AppKit window
  tests killed at their 30s bar on mote over ssh (no window session).

Broken by hand: with internal/gui/assets back as on 07a3312c5 (row in
Settings › Usage, none on the page), mask-alert.test.cjs went 11 of 12
red in Chromium; the feature-off test is the one that still passes.

Not tried: the real app (desktop window) and WebKit on mote, whose
Playwright WebKit launch hangs there.
This commit is contained in:
yetone
2026-10-31 14:05:02 +08:00
parent 93b31f5b79
commit 847f0c4703
7 changed files with 61 additions and 32 deletions
+1 -3
View File
@@ -20091,7 +20091,7 @@ function renderSettings() {
}
// gateway mode leaves out what is written into this computer's agents'
// files, and the alerts its desktop would show
for (const r of [$("#plainNamesSegs").parentElement, $("#usageAlertRow"), $("#balanceAlertRow"), $("#resetReminderRow"), $("#turnDoneRow"), $("#maskAlertRow")]) r.hidden = gatewayMode;
for (const r of [$("#plainNamesSegs").parentElement, $("#usageAlertRow"), $("#balanceAlertRow"), $("#resetReminderRow"), $("#turnDoneRow")]) r.hidden = gatewayMode;
// the parts' tabs, one gone whose rows are all hidden here
setSetTab(setTab);
}
@@ -21252,8 +21252,6 @@ function renderAlerts(s, keep) {
const turnOpts = [["0", t("Off")], ...mins.map((m) => [String(m * 60), t("{n} min", { n: m })])];
if (d && !mins.some((m) => m * 60 === d)) turnOpts.push([String(d), d % 60 ? t("{n} s", { n: d }) : t("{n} min", { n: d / 60 })]);
$("#turnDoneSegs").replaceChildren(segs(turnOpts, String(d), (v) => savePrefs({ ...keep, turnDoneAlert: Number(v) })));
// a value masked for the first time (Must2333 on X): off until turned on
$("#maskAlertSegs").replaceChildren(segs([["off", t("Off")], ["on", t("On")]], s.maskAlert ? "on" : "off", (v) => savePrefs({ ...keep, maskAlert: v === "on" })));
}
// AGENT_PREFS: an agent's own settings, by its id, each a row kept in
-4
View File
@@ -323,10 +323,6 @@
<div class="who"><div class="name" data-t>Task done alert</div><div class="sub" id="turnDoneSub"></div></div>
<div id="turnDoneSegs"></div>
</div>
<div class="row pref" id="maskAlertRow" data-feature="redact">
<div class="who"><div class="name" data-t>Masking alert</div><div class="sub wraps" data-t>A notification when masking swaps a value for the first time: its kind and how many, never the value itself</div></div>
<div id="maskAlertSegs"></div>
</div>
</div>
<div class="row-head warm-head" data-feature="warmups"><div class="warm-tabs" id="warmTabs" role="tablist">
<button type="button" role="tab" id="warmTab-codex" data-warm="codex" aria-controls="codexWarmList">Codex</button>
+12 -3
View File
@@ -7,9 +7,12 @@
// list under it each request (or each value) masking changed (between
// them, folded, demo.js's 小鹊 shows how masking works), and a
// request opened says what it carried, what the vendor got instead, and
// how each value was found and put back. The hooks are what the shell
// asks of it: open, refresh (the window came back), reload (Refresh in
// the sidebar), leave, and focus (a masked call's badge opens its request).
// how each value was found and put back. The Masking alert closes the
// page (it sat in Settings › Usage, where nb5p looked for it in vain),
// after the list, so the requests still start in the first screen. The
// hooks are what the shell asks of it: open, refresh (the window came
// back), reload (Refresh in the sidebar), leave, and focus (a masked
// call's badge opens its request).
magpie.plugin("redact", (ctx) => {
ctx.slots.add("page", {
key: "masking",
@@ -26,6 +29,12 @@ magpie.plugin("redact", (ctx) => {
<div class="md-body" id="mdBody" hidden></div>
</section>
<section class="msk-list" id="maskList"></section>
<div class="list prefs msk-prefs" id="maskPrefs">
<div class="row pref" id="maskAlertRow">
<div class="who"><div class="name" data-t>Masking alert</div><div class="sub wraps" data-t>A notification when masking swaps a value for the first time: its kind and how many, never the value itself</div></div>
<div id="maskAlertSegs"></div>
</div>
</div>
<section class="msk-one" id="maskOne" hidden></section>
`,
open() { return maskPageOpen(); },
+12 -1
View File
@@ -90,6 +90,7 @@ function maskPageOpen() {
}
function maskPageLoad(force) {
maskDrawAll();
(prefs ? Promise.resolve() : loadSettings()).then(drawMaskAlert).catch(() => {});
const sum = maskLoad(force)?.then(() => { drawMaskCard(); drawMaskList(); });
const recs = maskL.read && force ? maskRefresh() : maskL.read ? null : maskFetch();
return Promise.all([sum, recs]);
@@ -99,6 +100,15 @@ function maskDrawAll() {
drawMaskList();
if (maskO) drawMaskOne();
}
// the Masking alert (Must2333 on X): a notification when a value is
// masked for the first time, off until turned on. Gateway mode leaves it
// out, as it does the other alerts its desktop would show
function drawMaskAlert() {
const s = prefs || {};
$("#maskPrefs").hidden = gatewayMode;
$("#maskAlertSegs").replaceChildren(segs([["off", t("Off")], ["on", t("On")]], s.maskAlert ? "on" : "off",
(v) => savePrefs({ ...prefsKeep(s), maskAlert: v === "on" }).then(drawMaskAlert)));
}
// while the page is on screen it keeps up with requests as they go
setInterval(() => {
if (view !== "masking" || document.hidden) return;
@@ -628,7 +638,7 @@ function maskOneOpen(key, r) {
if (!key) return;
maskTipOff();
const o = maskO = { key, r: r || maskL.records.find((x) => x.key === key) || null, sent: undefined, leaves: null, vals: new Map(), view: "both", pick: "", open: new Set(), whole: new Set() };
$("#maskCard").hidden = $("#maskList").hidden = $("#maskDemo").hidden = true;
$("#maskCard").hidden = $("#maskList").hidden = $("#maskDemo").hidden = $("#maskPrefs").hidden = true;
xqd?.wake();
$("#maskOne").hidden = false;
drawMaskOne();
@@ -658,6 +668,7 @@ function maskOneClose() {
$("#maskOne").hidden = true;
$("#maskOne").replaceChildren();
$("#maskCard").hidden = $("#maskList").hidden = $("#maskDemo").hidden = false;
$("#maskPrefs").hidden = gatewayMode;
xqd?.wake();
drawMaskList();
}
@@ -86,6 +86,7 @@
/* the list: a bar, facets that narrow it, a day at a time */
.msk-list { margin-top: 14px; }
.msk-prefs { margin-top: 14px; border-radius: 14px; }
.msk-bar { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.msk-live { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; color: var(--muted); }
.msk-live i { width: 6px; height: 6px; border-radius: 50%; background: var(--green, var(--accent)); animation: msk-live 2.4s ease-in-out; }
+5 -4
View File
@@ -144,10 +144,11 @@ node --test --test-concurrency=1 internal/gui/tests/gateway-caller-keys.test.cjs
## Other Browser Regressions
`mask-alert.test.cjs` checks Settings › Usage's Masking alert (Must2333 on
X): after the task done alert, Off to begin with; On saves `maskAlert`,
another setting saved later keeps it, Off saves false, no click moves the
page, and the row goes while masking is switched off. Every language at 900
`mask-alert.test.cjs` checks Insights › Masking's Masking alert (Must2333 on
X): after the page's list and not in Settings › Usage (nb5p on Discord), Off
to begin with; On saves `maskAlert`, another setting saved later keeps it,
Off saves false, no click moves the page, and the row goes while masking is
switched off. Every language at 900
and 380 wide, in Chromium and WebKit, with the API faked.
`local-address.test.cjs` checks the Address of a local server's provider
+30 -17
View File
@@ -1,10 +1,12 @@
// Run with Node's test runner and Playwright on the module path; see README.md.
// The masking alert (Must2333 on X: 我还希望能即时的知道发生了替换,但不是
// 通过随时监控网关的方式): Settings › Usage has "Masking alert" after the
// task done alert, Off to begin with; On saves maskAlert, another setting
// saved later keeps it, Off saves false, and no click moves the page. With
// masking switched off in Plugins › Built-in the row goes with it. Every
// language, wide and narrow, both engines; the API is faked here.
// 通过随时监控网关的方式): Insights › Masking has "Masking alert" after its
// list of requests, and Settings › Usage no longer does (nb5p on Discord: 这个脱敏提醒被
// 放到额度设置里了,害得我找半天没找到). Off to begin with; On saves
// maskAlert, another setting saved later keeps it, Off saves false, and no
// click moves the page. With masking switched off in Plugins › Built-in the
// row goes with it. Every language, wide and narrow, both engines; the API
// is faked here.
const assert = require("node:assert/strict");
const fs = require("node:fs/promises");
const path = require("node:path");
@@ -57,7 +59,7 @@ const words = {
sub: "Eine Benachrichtigung, wenn ein Wert zum ersten Mal maskiert wird: Art und Anzahl, nie der Wert selbst" },
};
async function open(engine, width, lang, posts, featuresOff, t, name) {
async function open(engine, width, lang, posts, featuresOff, t, name, where = "?view=masking") {
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
const page = await (await browser.newContext({ viewport: { width, height: 700 }, reducedMotion: "reduce" })).newPage();
t.after(async () => {
@@ -73,15 +75,15 @@ async function open(engine, width, lang, posts, featuresOff, t, name) {
page.on("pageerror", (e) => errors.push(e.message));
await page.route("**/*", server(lang, posts, featuresOff));
await watchSettingsReads(page);
await page.goto("http://magpie.test/?view=settings&tab=usage");
await settingsDrawn(page); // rows found are the ones that stay (#1659)
await page.goto("http://magpie.test/" + where);
if (where.includes("settings")) await settingsDrawn(page); // rows found are the ones that stay (#1659)
return { page, errors };
}
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
for (const lang of Object.keys(words)) {
for (const width of [900, 380]) {
test(`${engine} ${lang} ${width}px: the masking alert is turned on and off on the Settings page`, async (t) => {
test(`${engine} ${lang} ${width}px: the masking alert is turned on and off on the Masking page`, async (t) => {
const posts = [];
const { page, errors } = await open(engine, width, lang, posts, [], t, "mask-alert");
const posted = async (n) => { for (let i = 0; i < 100 && posts.length < n; i++) await page.waitForTimeout(20); assert.equal(posts.length, n, "posts"); return posts[n - 1]; };
@@ -93,15 +95,16 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
assert.equal((await page.locator("#maskAlertRow .sub").textContent()).trim(), w.sub);
assert.deepEqual(await opts.allTextContents(), [w.off, w.on]);
assert.equal(await page.locator("#maskAlertSegs .opt.on").textContent(), w.off, "off until turned on");
// it is the row after the task done alert, in the same group
assert.equal(await page.locator("#turnDoneRow + #maskAlertRow").count(), 1);
// it is the Masking page's, after its list of requests
assert.equal(await page.locator("#view-masking #maskList + #maskPrefs > #maskAlertRow").count(), 1);
assert.equal(await page.locator("#view-settings #maskAlertRow").count(), 0, "no copy in Settings");
const over = await page.evaluate(() => {
const row = document.querySelector("#maskAlertRow").getBoundingClientRect();
return [...document.querySelectorAll("#maskAlertRow *")].filter((e) => e.getBoundingClientRect().right > Math.max(row.right, innerWidth) + 1).map((e) => e.className || e.id);
});
assert.deepEqual(over, [], "nothing past the edge");
const scrolled = () => page.locator("#view-settings").evaluate((v) => v.scrollTop);
const scrolled = () => page.locator("#view-masking").evaluate((v) => v.scrollTop);
await reach(page, opts.nth(1));
let top = await scrolled();
await opts.nth(1).click();
@@ -110,11 +113,14 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
assert.equal(await page.locator("#maskAlertSegs .opt.on").textContent(), w.on);
assert.equal(await scrolled(), top, "the click moved the page");
// another setting saved later keeps it
await reach(page, page.locator("#currencySegs .opt").nth(1));
// another setting saved later keeps it: the card's Turn off masking
const offBtn = page.locator("#maskCard .msk-head button.text");
await reach(page, offBtn);
top = await scrolled();
await page.locator("#currencySegs .opt").nth(1).click();
assert.equal((await posted(2)).maskAlert, true, "kept by another save");
await offBtn.click();
const second = await posted(2);
assert.equal(second.redact, false, "the card's switch saved");
assert.equal(second.maskAlert, true, "kept by another save");
await page.waitForTimeout(300);
assert.equal(await scrolled(), top, "no click moved the page");
@@ -126,8 +132,15 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
});
}
}
test(`${engine}: Settings › Usage has no masking alert`, async (t) => {
const { page, errors } = await open(engine, 900, "en", [], [], t, "mask-alert-usage", "?view=settings&tab=usage");
await page.locator("#turnDoneSegs .opt").first().waitFor();
assert.equal(await page.locator("#view-settings #maskAlertRow").count(), 0);
assert.equal(await page.locator("#turnDoneRow").isVisible(), true);
assert.deepEqual(errors, []);
});
test(`${engine}: with masking switched off, its alert goes too`, async (t) => {
const { page, errors } = await open(engine, 900, "en", [], ["redact"], t, "mask-alert-off");
const { page, errors } = await open(engine, 900, "en", [], ["redact"], t, "mask-alert-off", "?view=settings&tab=usage");
await page.locator("#turnDoneSegs .opt").first().waitFor();
assert.equal(await page.locator("#maskAlertRow").isVisible(), false);
assert.equal(await page.locator("#turnDoneRow").isVisible(), true);