From b02cffee1b8310a026e47fbf8ca550d5a91f2ac6 Mon Sep 17 00:00:00 2001 From: repo-worker-tmp-code-b Date: Mon, 16 Nov 2026 01:42:57 -0600 Subject: [PATCH 1/3] palette: image browser focus + live region --- pkgs/id/web/src/image-browser.test.ts | 41 +++++++++++++++++++++++++++ pkgs/id/web/src/image-browser.ts | 25 ++++++++++++++-- 2 files changed, 64 insertions(+), 2 deletions(-) diff --git a/pkgs/id/web/src/image-browser.test.ts b/pkgs/id/web/src/image-browser.test.ts index 2cecf5a069..aa16fcf38a 100644 --- a/pkgs/id/web/src/image-browser.test.ts +++ b/pkgs/id/web/src/image-browser.test.ts @@ -369,6 +369,47 @@ describe("openImageBrowser", () => { expect(document.querySelector(".pm-image-browser-overlay")).toBeNull(); }); + + it("announces status, exposes selection, and manages focus", async () => { + openImageBrowser(view, richSchema); + + // Focus moves into the dialog on open. + expect(document.activeElement?.className).toContain("pm-image-browser-close"); + + // Loading / empty states are announced via the grid live region. + const grid = document.querySelector(".pm-image-browser-grid"); + expect(grid?.getAttribute("role")).toBe("status"); + expect(grid?.getAttribute("aria-live")).toBe("polite"); + + await vi.waitFor(() => { + expect(document.querySelector(".pm-image-browser-card")).not.toBeNull(); + }); + + // Selection state is exposed to assistive tech. + const firstCard = document.querySelector(".pm-image-browser-card"); + expect(firstCard?.getAttribute("aria-pressed")).toBe("false"); + firstCard?.click(); + expect(firstCard?.getAttribute("aria-pressed")).toBe("true"); + + // Closing returns focus to the editor. + document.querySelector(".pm-image-browser-close")?.click(); + expect(document.activeElement).toBe(view.dom); + }); + + it("announces load failures as an alert", async () => { + vi.stubGlobal( + "fetch", + vi.fn(async () => { + throw new Error("offline"); + }), + ); + openImageBrowser(view, richSchema); + + await vi.waitFor(() => { + expect(document.querySelector('[role="alert"]')).not.toBeNull(); + }); + expect(document.querySelector('[role="alert"]')?.textContent).toContain("Failed to load images"); + }); }); // ── Malformed /api/images payloads (#7812) ───────────────────────── diff --git a/pkgs/id/web/src/image-browser.ts b/pkgs/id/web/src/image-browser.ts index 0100498584..8289b6c785 100644 --- a/pkgs/id/web/src/image-browser.ts +++ b/pkgs/id/web/src/image-browser.ts @@ -95,9 +95,12 @@ export function openImageBrowser(view: EditorView, schema: Schema): void { header.appendChild(title); header.appendChild(closeBtn); - // Grid container + // Grid container (live region: loading / empty states are announced, + // mirroring the search panel's aria-live match count). const grid = document.createElement("div"); grid.className = "pm-image-browser-grid"; + grid.setAttribute("role", "status"); + grid.setAttribute("aria-live", "polite"); grid.textContent = "Loading…"; // Footer with insert button @@ -191,6 +194,7 @@ export function openImageBrowser(view: EditorView, schema: Schema): void { card.setAttribute("role", "button"); card.setAttribute("tabindex", "0"); card.setAttribute("aria-label", `Select image ${img.name}`); + card.setAttribute("aria-pressed", "false"); const thumb = document.createElement("img"); thumb.src = img.url; @@ -208,8 +212,10 @@ export function openImageBrowser(view: EditorView, schema: Schema): void { card.addEventListener("click", () => { for (const c of grid.querySelectorAll(".pm-image-browser-card.selected")) { c.classList.remove("selected"); + c.setAttribute("aria-pressed", "false"); } card.classList.add("selected"); + card.setAttribute("aria-pressed", "true"); selectedImage = img; insertBtn.disabled = false; }); @@ -243,7 +249,11 @@ export function openImageBrowser(view: EditorView, schema: Schema): void { function showLoadError(err: unknown): void { // Keep already-loaded cards visible if a later page fails. if (!hasCards) { - grid.textContent = `Failed to load images: ${err instanceof Error ? err.message : String(err)}`; + grid.textContent = ""; + const alert = document.createElement("div"); + alert.setAttribute("role", "alert"); + alert.textContent = `Failed to load images: ${err instanceof Error ? err.message : String(err)}`; + grid.appendChild(alert); } } @@ -263,9 +273,20 @@ export function openImageBrowser(view: EditorView, schema: Schema): void { } document.removeEventListener("keydown", onKeyDown); overlay.remove(); + // Return focus to the editor, mirroring search-panel / goto-line. + // Guarded: closeImageBrowser() also runs on editor teardown (#1381). + try { + view.focus(); + } catch { + // View already destroyed — nothing to refocus. + } } activeBrowser = { view, close }; + + // Move focus into the dialog so keyboard and screen-reader users land + // inside it instead of staying behind in the editor. + closeBtn.focus(); } // ============================================================================ From e188342ad07f9302ad4b3ff6c232d6d7402d5b60 Mon Sep 17 00:00:00 2001 From: repo-worker-tmp-code-b Date: Mon, 16 Nov 2026 01:50:05 -0600 Subject: [PATCH 2/3] =?UTF-8?q?=E2=9A=A1=20Bolt:=20bound=20/api/sw-probe?= =?UTF-8?q?=20maps=20to=20cap=20unbounded=20memory=20growth?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #10539. recordSwProbe stored every distinct client-supplied string forever; each map is now capped at 64 keys / 512 chars per key (same shape as the #4981 class-key cap), with counts for tracked keys still incrementing. 10k distinct keys -> 64 stored per map; GET payload 30KB bounded vs ~4.7MB and growing. --- pm-stack/aggregator/src/push.ts | 29 +++++++++++++- pm-stack/aggregator/test/alerts.test.ts | 53 ++++++++++++++++++++++++- 2 files changed, 79 insertions(+), 3 deletions(-) diff --git a/pm-stack/aggregator/src/push.ts b/pm-stack/aggregator/src/push.ts index e4fc6292e7..4207df1126 100644 --- a/pm-stack/aggregator/src/push.ts +++ b/pm-stack/aggregator/src/push.ts @@ -96,6 +96,31 @@ export interface SwProbeSummary { const probe: SwProbeSummary = { reports: 0, lastReportAt: null, foreignSeen: {}, evictedSeen: {} }; +/** #10539: bound the observational probe maps. POST /api/sw-probe accepts + * arbitrary client-supplied strings and the old code stored every distinct + * one forever, so repeated requests grew process memory and the GET + * summary payload without limit (request bodies are capped at 100KB, but + * distinct keys accumulate across requests). Each map keeps at most + * MAX_SW_PROBE_KEYS distinct keys; keys past the cap (or longer than + * MAX_SW_PROBE_KEY_LENGTH) are dropped, not stored — same shape as the + * #4981 class-key cap in alerts.ts. Counts for already-tracked keys still + * increment, so the probe keeps its "what did we see" signal at a fixed + * memory ceiling (~2 * 64 * ~512B worst case). */ +export const MAX_SW_PROBE_KEYS = 64; +/** #10539: longest accepted probe key. Real script URLs/paths are short; + * anything longer is not a plausible service-worker script reference. */ +export const MAX_SW_PROBE_KEY_LENGTH = 512; + +/** #10539: record one probe key, enforcing the length + count caps. */ +function noteSwProbeKey(map: Record, key: string): void { + if (key.length === 0 || key.length > MAX_SW_PROBE_KEY_LENGTH) return; + // "__proto__" assignment on a plain object hits the prototype setter + // instead of creating an own key, so it can never be counted — skip it. + if (key === "__proto__") return; + if (!Object.hasOwn(map, key) && Object.keys(map).length >= MAX_SW_PROBE_KEYS) return; + map[key] = (map[key] ?? 0) + 1; +} + /** Our own worker's script path — any other registration is foreign. */ export const SW_SCRIPT_PATH = "/sw.js"; @@ -113,12 +138,12 @@ export function recordSwProbe(report: { registrations?: unknown; evicted?: unkno const regs = Array.isArray(report.registrations) ? report.registrations : []; for (const r of regs) { if (typeof r === "string" && isForeignSwScript(r)) { - probe.foreignSeen[r] = (probe.foreignSeen[r] ?? 0) + 1; + noteSwProbeKey(probe.foreignSeen, r); } } const evicted = Array.isArray(report.evicted) ? report.evicted : []; for (const r of evicted) { - if (typeof r === "string") probe.evictedSeen[r] = (probe.evictedSeen[r] ?? 0) + 1; + if (typeof r === "string") noteSwProbeKey(probe.evictedSeen, r); } return swProbeSummary(); } diff --git a/pm-stack/aggregator/test/alerts.test.ts b/pm-stack/aggregator/test/alerts.test.ts index f849e89e05..a0c08c046e 100644 --- a/pm-stack/aggregator/test/alerts.test.ts +++ b/pm-stack/aggregator/test/alerts.test.ts @@ -31,7 +31,15 @@ import { type Incident, type PushSubscriptionRow, } from "../src/alerts.ts"; -import { isForeignSwScript, type PushOutcome, type PushTarget } from "../src/push.ts"; +import { + isForeignSwScript, + MAX_SW_PROBE_KEY_LENGTH, + MAX_SW_PROBE_KEYS, + type PushOutcome, + type PushTarget, + recordSwProbe, + swProbeSummary, +} from "../src/push.ts"; import { renderAlerts } from "../src/render.ts"; import type { Provenance } from "../src/model.ts"; import { sqlInt, sqlJson, sqlStr, type SupabaseClient } from "../src/supabase.ts"; @@ -364,6 +372,49 @@ describe("sw-probe foreign test (design §6)", () => { expect(isForeignSwScript("https://amd-6.example.ts.net/service-worker.js")).toBe(true); expect(isForeignSwScript("not a url")).toBe(true); }); + + // #10539: the probe maps are observational only, so distinct-key growth + // is capped and over-long keys are dropped — memory and the GET summary + // payload stay bounded no matter how many distinct strings clients send. + test("probe maps are bounded in count and key length", () => { + const tooLong = "k".repeat(MAX_SW_PROBE_KEY_LENGTH + 1); + recordSwProbe({ registrations: [tooLong], evicted: [tooLong] }); + let s = swProbeSummary(); + expect(s.foreignSeen[tooLong]).toBeUndefined(); + expect(s.evictedSeen[tooLong]).toBeUndefined(); + + // Exactly-at-limit keys are still accepted (non-URLs count as foreign). + const edge = "e".repeat(MAX_SW_PROBE_KEY_LENGTH); + recordSwProbe({ registrations: [edge], evicted: [edge] }); + s = swProbeSummary(); + expect(s.foreignSeen[edge]).toBe(1); + expect(s.evictedSeen[edge]).toBe(1); + + // Flood past the cap with unique keys; both maps stop at the cap. + const flood = Array.from( + { length: MAX_SW_PROBE_KEYS + 10 }, + (_, i) => `https://probe-cap-10539.example/sw-${i}.js`, + ); + recordSwProbe({ registrations: flood, evicted: flood }); + s = swProbeSummary(); + expect(Object.keys(s.foreignSeen).length).toBeLessThanOrEqual(MAX_SW_PROBE_KEYS); + expect(Object.keys(s.evictedSeen).length).toBeLessThanOrEqual(MAX_SW_PROBE_KEYS); + // The summary a GET returns stays a small bounded payload. + expect(JSON.stringify(s).length).toBeLessThan(100_000); + + // Already-tracked keys still increment once the cap is reached. + const tracked = Object.keys(s.foreignSeen)[0]; + const n = s.foreignSeen[tracked]; + recordSwProbe({ registrations: [tracked] }); + expect(swProbeSummary().foreignSeen[tracked]).toBe(n + 1); + }); + + test("probe keys cannot pollute the object prototype", () => { + recordSwProbe({ registrations: ["__proto__"], evicted: ["__proto__"] }); + const s = swProbeSummary(); + expect(Object.hasOwn(s.foreignSeen, "__proto__")).toBe(false); + expect(Object.hasOwn(s.evictedSeen, "__proto__")).toBe(false); + }); }); const tickConfig = { From e914f62e8ab051052d46a094caf9711378b7b81d Mon Sep 17 00:00:00 2001 From: repo-worker-tmp-code-b Date: Mon, 16 Nov 2026 01:50:44 -0600 Subject: [PATCH 3/3] Bolt journal: __proto__ trap + shared-checkout discipline --- .jules/bolt.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.jules/bolt.md b/.jules/bolt.md index c8e5c4a320..5354d4c9dd 100644 --- a/.jules/bolt.md +++ b/.jules/bolt.md @@ -22,3 +22,11 @@ **Learning:** `renderWorldSurface` in `pkgs/id/web/src/world-surface.ts` validated every cell of a 120x50 world frame with `Intl.Segmenter.segment()` plus the unicode-width regexes (`\p{Mn}`, `\p{Grapheme_Extend}`) — ~120k segmentations per second at 20 frames/s. On the ASCII path this is pure overhead: a single code unit in U+0020..U+007E is always exactly one grapheme and one column wide. Measured in Bun/JSC, per-frame validation + colour CPU for a full 6000-cell frame fell from 60–169 ms to 2–3 ms (30–55x). Full-render timings in happy-dom are useless for judging this: element creation dominates (hundreds of ms with 4x run-to-run noise) and is unchanged by the fix. **Action:** In hot render loops, fingerprint the common value class (ASCII / single code unit) and take a constant-time fast path before calling Intl or unicode-regex machinery; keep the general path for everything else. Benchmark the CPU component with `document.createElement` stubbed, not happy-dom's DOM. + +## 2026-11-16 - [Client-keyed plain objects silently drop `__proto__`] +**Learning:** Count maps keyed by client strings (`probe.foreignSeen[r] = ...` in `pm-stack/aggregator/src/push.ts`) never record a `"__proto__"` key: assignment hits the prototype setter instead of creating an own property, so the count silently vanishes. The sibling `mergeClasses` in `alerts.ts` takes arbitrary client keys the same way and has the same latent trap. +**Action:** When bounding/capping client-keyed `Record` maps, explicitly skip `__proto__` (and gate new-key checks on `Object.hasOwn`, not `in`); consider `Map` for new code. + +## 2026-11-16 - [Shared laptop checkout: diffs are not all yours] +**Learning:** The dispatch laptop checkout hosts concurrent lanes: `pkgs/id/web/src/image-browser.*` modifications and a `.Jules/palette.md` edit appeared in `git status` mid-run from another lane, after the run started clean. +**Action:** Re-check `git status` right before committing and commit exact file paths only — never `git add .`.