web: attention / "Needs you" surface — bell, sheet, dismissals (R15, R2)

This commit is contained in:
2026-10-19 04:52:34 +01:00
parent 9555bfe58f
commit f3bc6ed126
6 changed files with 1107 additions and 5 deletions
+220
View File
@@ -187,6 +187,14 @@ try {
browser = await launchChrome({ width: 1440, height: 900 });
page = await browser.openPage(`http://127.0.0.1:${port}/`);
// Deterministic dismissals: the attention set is read from localStorage once at
// boot, so clear the key and reload before connecting so the surface derives
// from an empty set regardless of any stale profile state.
step("clearing the attention storage key before connecting");
await page.evaluate(`localStorage.removeItem("pipelines.web.attention.v1")`);
await page.evaluate(`location.reload()`);
await page.waitForSelector("#url", { timeout: 15000 });
step("connecting the page to the server through its own proxy");
await page.fill("#url", `ws://127.0.0.1:${port}/connect`);
await page.click("#connectBtn");
@@ -455,6 +463,218 @@ try {
console.log(` usage: ${usageLabels.join(", ")}`);
console.log(` day headers: ${dayHeaders.slice(0, 3).join(" | ")}`);
// ---------------------------------------------------------------------
// R15: the attention / "Needs you" surface. The bell lives in the top bar on
// every view; its badge, the sheet's rows and the dismissal identities all
// come from the pure src/attention.js model. The live server currently has
// failed runs and no run parked in `waiting`, so the sheet is exercised with
// real failed entries and that live-data limitation is reported below. The
// decision path (open without dismissing) is unit-tested.
// ---------------------------------------------------------------------
step("checking the attention bell + badge");
await page.waitForSelector("#attentionBell", { timeout: 15000 });
const bell = await page.evaluate(`(() => {
const b = document.querySelector("#attentionBell");
const badge = b.querySelector(".attention-badge");
return {
label: b.getAttribute("aria-label"),
hasBadge: !!badge,
count: badge ? badge.textContent : null,
dataCount: badge ? badge.dataset.count : null,
};
})()`);
const attentionCount = Number(bell.dataCount ?? 0);
if (!(attentionCount > 0)) {
throw new Error(`no attention entries on the live server: ${JSON.stringify(bell)}`);
}
if (bell.label !== `Notifications, ${attentionCount} needing attention`) {
throw new Error(`the bell's accessible name is wrong: ${bell.label}`);
}
if (!bell.hasBadge || bell.count !== String(attentionCount)) {
throw new Error(`the badge is wrong: ${JSON.stringify(bell)}`);
}
if (await page.evaluate(`!!document.querySelector(".attention-sheet")`)) {
throw new Error("the sheet was already open before the bell was clicked");
}
console.log(` bell: aria-label="${bell.label}", badge=${bell.count}`);
shots.push(await page.screenshot(`${out}/35-attention-bell.png`));
step("opening the Needs you sheet");
await page.click("#attentionBell");
await page.waitForSelector(".attention-sheet", { timeout: 15000 });
const sheet = await page.evaluate(`(() => {
const rows = [...document.querySelectorAll(".attention-sheet .attention-row")];
return {
title: document.querySelector(".attention-sheet-title")?.textContent ?? "",
clearAll: document.querySelector(".attention-clear")?.textContent ?? null,
empty: document.querySelector(".attention-empty")?.textContent ?? null,
focused: document.activeElement?.className ?? "",
rows: rows.map((row) => {
const open = row.querySelector(".attention-row-open");
const dismiss = row.querySelector(".attention-dismiss");
return {
runId: Number(open?.dataset.runId),
kind: open?.dataset.kind ?? "",
label: open?.querySelector(".attention-label")?.textContent ?? "",
desc: open?.querySelector(".attention-desc")?.textContent ?? "",
icon: open?.querySelector(".attention-icon")?.textContent ?? "",
dismissName: dismiss?.getAttribute("aria-label") ?? "",
};
}),
};
})()`);
if (sheet.title !== "Needs you") throw new Error(`the sheet title is wrong: ${sheet.title}`);
if (sheet.empty !== null) throw new Error(`a non-empty sheet showed the empty copy: ${sheet.empty}`);
if (sheet.clearAll !== "Clear all") throw new Error(`Clear all is missing: ${sheet.clearAll}`);
if (sheet.rows.length !== attentionCount) {
throw new Error(`the sheet drew ${sheet.rows.length} rows for a badge of ${attentionCount}`);
}
if (!sheet.focused.includes("attention-sheet-close")) {
throw new Error(`focus did not move into the sheet on open: ${sheet.focused}`);
}
const kindRanks = { decision: 0, failed: 1 };
let lastKindRank = -1;
for (const row of sheet.rows) {
if (!row.icon) throw new Error(`row ${row.runId} has no status icon`);
if (!row.label) throw new Error(`row ${row.runId} has no primary label`);
if (!row.desc.includes(" · ")) throw new Error(`row ${row.runId} description is wrong: ${row.desc}`);
if (row.dismissName !== "Dismiss") {
throw new Error(`row ${row.runId}'s trailing control is not named Dismiss: ${row.dismissName}`);
}
const rank = kindRanks[row.kind];
if (rank == null) throw new Error(`row ${row.runId} has an unknown kind ${row.kind}`);
if (rank < lastKindRank) throw new Error(`the rows are out of kind order at run ${row.runId}`);
lastKindRank = rank;
}
const firstRow = sheet.rows[0];
const kindName = (kind) => (kind === "decision" ? "Decision" : "Failed");
console.log(
` sheet: ${sheet.rows.length} row(s); first ${firstRow.runId} (${firstRow.kind}) ` +
`"${firstRow.label}" — ${firstRow.desc}`,
);
if (!sheet.rows.some((row) => row.kind === "decision")) {
console.log(
" -- no `waiting` run exists on the live server; the sheet used real failed runs " +
"and the decision path (open without dismissing) is covered by unit tests",
);
}
shots.push(await page.screenshot(`${out}/36-attention-sheet.png`));
step("dismissing one entry individually");
await page.evaluate(`document.querySelector(".attention-sheet .attention-row .attention-dismiss").click()`);
await eventually(
async () =>
(await page.evaluate(`document.querySelectorAll(".attention-sheet .attention-row").length`)) ===
attentionCount - 1,
{ what: "the individual dismissal to land" },
);
const afterDismiss = await page.evaluate(`(() => ({
rows: document.querySelectorAll(".attention-sheet .attention-row").length,
badge: document.querySelector("#attentionBell .attention-badge")?.dataset.count ?? null,
stored: localStorage.getItem("pipelines.web.attention.v1"),
}))()`);
if (afterDismiss.rows !== attentionCount - 1) {
throw new Error(`the sheet still shows ${afterDismiss.rows} rows after one dismissal`);
}
if (Number(afterDismiss.badge) !== attentionCount - 1) {
throw new Error(`the badge did not follow the dismissal: ${afterDismiss.badge}`);
}
if (!String(afterDismiss.stored).includes(`${firstRow.runId}:${kindName(firstRow.kind)}`)) {
throw new Error(`the dismissed identity was not persisted: ${afterDismiss.stored}`);
}
console.log(
` dismissed ${firstRow.runId}:${kindName(firstRow.kind)}; rows ${attentionCount} -> ` +
`${afterDismiss.rows}, stored ${afterDismiss.stored}`,
);
shots.push(await page.screenshot(`${out}/37-attention-dismissed.png`));
step("opening a Failed row: it opens the run and persists its dismissal");
const rowToOpen = await page.evaluate(`(() => {
const open = document.querySelector(".attention-sheet .attention-row .attention-row-open");
return { runId: Number(open.dataset.runId), kind: open.dataset.kind };
})()`);
if (rowToOpen.kind !== "failed") {
throw new Error(`expected a Failed row to open, got ${rowToOpen.kind}`);
}
await page.evaluate(`document.querySelector(".attention-sheet .attention-row .attention-row-open").click()`);
await eventually(
async () => !(await page.evaluate(`!!document.querySelector(".attention-sheet")`)),
{ what: "the sheet to close on row activation" },
);
await page.waitForSelector(".detail .detail-tabs", { timeout: 25000 });
const openedIdentity = await page.evaluate(
`document.querySelector(".run-identity")?.textContent ?? ""`,
);
if (!openedIdentity.startsWith(`run ${rowToOpen.runId} ·`)) {
throw new Error(`row ${rowToOpen.runId} did not open its run: ${openedIdentity}`);
}
const storedAfterOpen = await page.evaluate(`localStorage.getItem("pipelines.web.attention.v1")`);
if (!String(storedAfterOpen).includes(`${rowToOpen.runId}:Failed`)) {
throw new Error(`opening a Failed row did not persist its dismissal: ${storedAfterOpen}`);
}
console.log(` opened run ${rowToOpen.runId}; ${rowToOpen.runId}:Failed now persisted`);
step("reopening the sheet and clearing all");
await page.click("#attentionBell");
await page.waitForSelector(".attention-sheet", { timeout: 15000 });
const beforeClear = await page.evaluate(
`document.querySelectorAll(".attention-sheet .attention-row").length`,
);
if (beforeClear !== attentionCount - 2) {
throw new Error(`expected ${attentionCount - 2} rows before Clear all, got ${beforeClear}`);
}
await page.evaluate(`document.querySelector(".attention-sheet .attention-clear").click()`);
await eventually(
async () =>
(await page.evaluate(`document.querySelector(".attention-empty")?.textContent ?? ""`)) ===
"Nothing needs you right now.",
{ what: "the empty attention state after Clear all" },
);
const cleared = await page.evaluate(`(() => ({
empty: document.querySelector(".attention-empty")?.textContent ?? "",
rows: document.querySelectorAll(".attention-sheet .attention-row").length,
clearAll: !!document.querySelector(".attention-clear"),
badge: !!document.querySelector("#attentionBell .attention-badge"),
label: document.querySelector("#attentionBell").getAttribute("aria-label"),
badges: document.querySelectorAll(".attention-badge").length,
}))()`);
if (cleared.empty !== "Nothing needs you right now.") {
throw new Error(`the empty copy is wrong: ${cleared.empty}`);
}
if (cleared.rows !== 0) throw new Error(`the cleared sheet still shows ${cleared.rows} rows`);
if (cleared.clearAll) throw new Error("Clear all is still offered on the empty sheet");
if (cleared.badge || cleared.badges !== 0) throw new Error("the badge is still visible after Clear all");
if (cleared.label !== "Notifications") {
throw new Error(`the emptied bell is named wrong: ${cleared.label}`);
}
console.log(` after Clear all: "${cleared.empty}", no Clear all, bell aria-label="${cleared.label}"`);
shots.push(await page.screenshot(`${out}/38-attention-cleared.png`));
step("closing the sheet with Escape returns focus to the bell");
await page.evaluate(
`document.dispatchEvent(new KeyboardEvent("keydown", { key: "Escape", bubbles: true }))`,
);
await eventually(
async () => !(await page.evaluate(`!!document.querySelector(".attention-sheet")`)),
{ what: "Escape to close the attention sheet" },
);
const focusAfterEscape = await page.evaluate(`document.activeElement?.id ?? ""`);
if (focusAfterEscape !== "attentionBell") {
throw new Error(`Escape did not return focus to the bell: ${focusAfterEscape}`);
}
console.log(" Escape closed the sheet and focus returned to #attentionBell");
step("closing the sheet with a backdrop click");
await page.click("#attentionBell");
await page.waitForSelector(".attention-sheet", { timeout: 15000 });
await page.evaluate(`document.querySelector(".attention-sheet").click()`);
await eventually(
async () => !(await page.evaluate(`!!document.querySelector(".attention-sheet")`)),
{ what: "the backdrop click to close the attention sheet" },
);
console.log(" backdrop click closed the sheet");
step(`scrolling the list to the older day group (${fullDateHeader})`);
const scrolledTo = await page.evaluate(`(() => {
const scroll = document.querySelector(".run-scroll");