The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
test(e2e): #5676 AC-3/AC-4 in a browser, plus a listener-leak guard
M3gA-Mindb569383f619e
diff --git a/app/test/playwright/specs/app-shell-listener-hygiene.spec.ts b/app/test/playwright/specs/app-shell-listener-hygiene.spec.tsnew file mode 100644index 0000000000..df298ffa8c--- /dev/null+++ b/app/test/playwright/specs/app-shell-listener-hygiene.spec.ts@@ -0,0 +1,128 @@+import { expect, type Page, test } from '@playwright/test';++import { bootAuthenticatedPage, dismissWalkthroughIfPresent } from '../helpers/core-rpc';++// See app-shell-sidebar.spec.ts for why the budget is raised here rather than+// in the shared playwright.config.ts.+test.describe.configure({ timeout: 180_000 });++/**+ * Window listener hygiene around the sidebar resize drag — W5 BUG-12.+ *+ * The drag attaches four window listeners and detaches three. It adds+ * `'blur'` but removes `'blur-sm'`:+ *+ * components/ui/Sidebar.tsx:291 window.addEventListener('blur', detach);+ * components/ui/Sidebar.tsx:283 window.removeEventListener('blur-sm', detach);+ *+ * and `RootShellLayout.tsx` repeats it at :202 / :185. `'blur-sm'` is not an+ * event — nothing is ever registered under that name — so the removal is a+ * no-op and the real listener survives every drag. `rg "'blur-sm'" app/src`+ * returns exactly these two hits, both inside `removeEventListener` and neither+ * in a `className`, which is what points at a Tailwind v4 `blur` -> `blur-sm`+ * class-rename codemod reaching into string arguments.+ *+ * The leak is functionally quiet — each stale handler still runs a teardown+ * that is idempotent — so nothing fails today. What accumulates is window+ * listeners, on a desktop window that is not reloaded for days.+ *+ * This spec instruments `add`/`removeEventListener` before the app boots and+ * counts. It is written to FAIL on `main` today: it describes the contract the+ * code intends, not the behaviour it has. See the note on the failing+ * assertion.+ */++/** Wrap window listener registration so the test can count what is live. */+async function instrumentListeners(page: Page): Promise<void> {+ await page.addInitScript(() => {+ const counts = new Map<string, number>();+ (window as unknown as { __listenerCounts: Map<string, number> }).__listenerCounts = counts;++ const add = window.addEventListener.bind(window);+ const remove = window.removeEventListener.bind(window);++ window.addEventListener = function (type: string, ...rest: unknown[]) {+ counts.set(type, (counts.get(type) ?? 0) + 1);+ return (add as (...a: unknown[]) => void)(type, ...rest);+ } as typeof window.addEventListener;++ window.removeEventListener = function (type: string, ...rest: unknown[]) {+ // Only decrement for a type we have seen added, so a stray removal+ // cannot drive the count negative and mask a leak.+ if ((counts.get(type) ?? 0) > 0) counts.set(type, (counts.get(type) ?? 0) - 1);+ return (remove as (...a: unknown[]) => void)(type, ...rest);+ } as typeof window.removeEventListener;+ });+}++const countOf = (page: Page, type: string) =>+ page.evaluate(+ t =>+ (window as unknown as { __listenerCounts: Map<string, number> }).__listenerCounts.get(t) ?? 0,+ type+ );++const sidebar = (page: Page) => page.locator('[data-testid="root-shell-sidebar"]');++/** Drag the rail from the half of its hit area that receives events (BUG-11). */+async function dragRail(page: Page, dx: number): Promise<void> {+ const box = await sidebar(page).boundingBox();+ expect(box).not.toBeNull();+ const x = box!.x + box!.width - 2;+ const y = box!.y + box!.height / 2;+ await page.mouse.move(x, y);+ await page.mouse.down();+ await page.mouse.move(x + dx, y, { steps: 8 });+ await page.mouse.up();+}++test.describe('App shell — the resize drag cleans up after itself (BUG-12)', () => {+ test.beforeEach(async ({ page }) => {+ await instrumentListeners(page);+ await bootAuthenticatedPage(page, 'pw-listener-hygiene-user');+ await dismissWalkthroughIfPresent(page);+ });++ test('pointer listeners are balanced across a drag', async ({ page }) => {+ // The three correctly-paired ones, as a control: if these did not balance,+ // the instrumentation itself would be suspect and the blur result below+ // would mean nothing.+ const before = {+ pointermove: await countOf(page, 'pointermove'),+ pointerup: await countOf(page, 'pointerup'),+ pointercancel: await countOf(page, 'pointercancel'),+ };++ await dragRail(page, 40);++ await expect.poll(() => countOf(page, 'pointermove')).toBe(before.pointermove);+ await expect.poll(() => countOf(page, 'pointerup')).toBe(before.pointerup);+ await expect.poll(() => countOf(page, 'pointercancel')).toBe(before.pointercancel);+ });++ test('blur listeners are balanced across a drag — KNOWN FAILING, W5 BUG-12', async ({ page }) => {+ // `test.fail()`: this asserts the contract the code intends, and that+ // contract is currently broken, so the expected outcome on `main` is a+ // failure. Playwright inverts the result — the spec is GREEN today and goes+ // RED the moment someone fixes the bug, which is the prompt to delete this+ // annotation and the note below.+ //+ // A plain red test would just be broken CI. A skipped one would say+ // nothing. This is the only form that both reports the defect and cleans+ // itself up.+ //+ // Measured on main: baseline 3, +2 per drag (one per leaking site), so+ // three drags end at 9. Verified fix — replace the two `'blur-sm'` string+ // literals with `'blur'` in Sidebar.tsx:283 and RootShellLayout.tsx:185 —+ // makes this pass and leaves the rest of the suite green.+ test.fail();++ const before = await countOf(page, 'blur');++ await dragRail(page, 40);+ await dragRail(page, -40);+ await dragRail(page, 25);++ expect(await countOf(page, 'blur')).toBe(before);+ });+});diff --git a/app/test/playwright/specs/app-shell-sidebar-resize.spec.ts b/app/test/playwright/specs/app-shell-sidebar-resize.spec.tsnew file mode 100644index 0000000000..4d96cca016--- /dev/null+++ b/app/test/playwright/specs/app-shell-sidebar-resize.spec.ts@@ -0,0 +1,198 @@+import { expect, type Page, test } from '@playwright/test';++import { bootAuthenticatedPage, dismissWalkthroughIfPresent } from '../helpers/core-rpc';++// See app-shell-sidebar.spec.ts for why the budget is raised here rather than+// in the shared playwright.config.ts.+test.describe.configure({ timeout: 180_000 });++/**+ * Sidebar drag-resize, arrow-key resize, and the seam indicator.+ *+ * These are acceptance criteria 3 and 4 of openhuman#5676. **This spec does NOT+ * close that issue** — read the note at the bottom of this comment before+ * claiming it does.+ *+ * #5676 asks for a *visual* pass on a real desktop build, and its four criteria+ * split cleanly by what a browser can reach:+ *+ * AC-1 no native webview punch-through in the collapsed state — OUT OF REACH.+ * The web lane is a browser tab; there is no native webview to punch+ * through, so a green run here says nothing about it.+ * AC-2 macOS traffic lights stay clear of the collapsed rail — OUT OF REACH.+ * No window chrome exists in this lane.+ * AC-3 the `SidebarRail` seam paints `bg-line-chrome` rather than `bg-line`+ * on hover/focus — REACHABLE. The issue notes that unit tests "only+ * assert the class name is applied, never its rendered colour";+ * `getComputedStyle` in a real engine is exactly the missing instrument.+ * AC-4 drag-resize works, the width persists across a restart, and arrow-key+ * steps still apply — REACHABLE, and untested anywhere today.+ *+ * So this covers the two behavioural criteria and leaves the two compositing+ * ones for the desktop pass the issue actually asks for.+ */++const sidebar = (page: Page) => page.locator('[data-testid="root-shell-sidebar"]');+const rail = (page: Page) => page.locator('[data-testid="root-shell-divider"]');++const widthOf = (page: Page) =>+ sidebar(page).evaluate(el => Math.round(el.getBoundingClientRect().width));++/**+ * The rail itself has **zero layout width** — `w-0`, deliberately, so it adds+ * nothing to the content card's left gutter (`components/ui/Sidebar.tsx:330`).+ * That makes Playwright treat it as *not visible*: `toBeVisible()` fails and+ * `hover()` can never act on it, however correct the element is.+ *+ * Two absolutely-positioned children carry the real geometry:+ * nth(0) — the widened hit area (`-left-1 -right-1`), what a user points at+ * nth(1) — the 1px seam, what carries the colour classes+ *+ * So: point at the hit area, read colour off the seam, and assert the rail's+ * presence by count rather than by visibility.+ *+ * And point at its LEFT half specifically. Measured with `elementFromPoint`+ * (sidebar right edge at x=224, hit area x=220..228):+ *+ * x=221 -> SPAN.absolute inset-y-0 -left-1 -right-1 (the rail)+ * x=222 -> SPAN (the rail)+ * x=224 -> DIV.relative flex flex-1 ... (content viewport)+ * x=227 -> DIV (content viewport)+ *+ * The content surface is painted over the `-right-1` half despite the hit+ * area's `z-10`, so only x 220..223 actually reaches the rail. Aiming at the+ * element's centre — what `hover()` and `boundingBox()` centre do — lands on+ * the dead side and the action never arrives. See W5 BUG-11.+ */+const hitArea = (page: Page) => rail(page).locator('span').nth(0);+const seam = (page: Page) => rail(page).locator('span').nth(1);++/**+ * A point inside the half of the hit area that actually receives events: two+ * pixels left of the sidebar's right edge. This is also where a user's cursor+ * sits when the `cursor-col-resize` affordance appears.+ */+async function railPoint(page: Page): Promise<{ x: number; y: number }> {+ const box = await sidebar(page).boundingBox();+ expect(box).not.toBeNull();+ return { x: box!.x + box!.width - 2, y: box!.y + box!.height / 2 };+}++const SIDEBAR_KEYBOARD_STEP = 16; // components/ui/Sidebar.tsx:53++test.describe('App shell — sidebar resize (#5676 AC-4)', () => {+ test.beforeEach(async ({ page }) => {+ await bootAuthenticatedPage(page, 'pw-sidebar-resize-user');+ await dismissWalkthroughIfPresent(page);+ });++ test('ArrowRight and ArrowLeft resize the column in 16px steps', async ({ page }) => {+ const before = await widthOf(page);++ await rail(page).focus();+ await page.keyboard.press('ArrowRight');+ await expect.poll(() => widthOf(page)).toBe(before + SIDEBAR_KEYBOARD_STEP);++ await page.keyboard.press('ArrowLeft');+ await expect.poll(() => widthOf(page)).toBe(before);++ // Two steps in one direction accumulate — a handler that snapped back to a+ // single step would pass the first assertion and fail here.+ await page.keyboard.press('ArrowLeft');+ await page.keyboard.press('ArrowLeft');+ await expect.poll(() => widthOf(page)).toBe(before - 2 * SIDEBAR_KEYBOARD_STEP);+ });++ test('dragging the rail resizes the column', async ({ page }) => {+ const before = await widthOf(page);+ // A real pointer drag, not a synthetic width write: press on the rail, move,+ // release. `handlePointerDown` attaches window-level pointermove/pointerup+ // listeners, so the move has to happen at the page level to be seen.+ const { x: startX, y: startY } = await railPoint(page);+ await page.mouse.move(startX, startY);+ await page.mouse.down();+ await page.mouse.move(startX + 60, startY, { steps: 10 });+ await page.mouse.up();++ await expect.poll(() => widthOf(page)).toBeGreaterThan(before);+ });++ test('a resized width survives a reload', async ({ page }) => {+ // The web lane maps "restart the app" onto a reload+ // (VITE_OPENHUMAN_E2E_RESTART_APP_AS_RELOAD=true), which is the closest this+ // lane gets to #5676's "persists across an app restart". The width lives in+ // the persisted panel-layout store, so a reload exercises the same+ // rehydration path a restart would.+ const before = await widthOf(page);++ await rail(page).focus();+ await page.keyboard.press('ArrowRight');+ await page.keyboard.press('ArrowRight');+ const resized = before + 2 * SIDEBAR_KEYBOARD_STEP;+ await expect.poll(() => widthOf(page)).toBe(resized);++ await page.reload();+ await dismissWalkthroughIfPresent(page);++ await expect.poll(() => widthOf(page), { timeout: 20_000 }).toBe(resized);+ // And specifically NOT back at the default — the assertion above would also+ // hold if `resized` happened to equal the default width.+ expect(resized).not.toBe(before);+ });++ test('the rail is absent while collapsed — the icon column is fixed, not draggable', async ({+ page,+ }) => {+ // Presence by count, not visibility — see the `hitArea` note above.+ await expect(rail(page)).toHaveCount(1);++ await page.getByRole('button', { name: 'Hide sidebar' }).click();+ await expect(sidebar(page)).toHaveAttribute('data-state', 'collapsed');++ // `RootShellLayout.tsx` renders the rail behind `isOpen &&` precisely so a+ // collapsed column cannot be dragged to an arbitrary width.+ await expect(rail(page)).toHaveCount(0);++ await page.getByTestId('root-shell-reopen').click();+ await expect(sidebar(page)).toHaveAttribute('data-state', 'expanded');+ await expect(rail(page)).toHaveCount(1);+ });+});++test.describe('App shell — the resize seam paints on interaction (#5676 AC-3)', () => {+ test.beforeEach(async ({ page }) => {+ await bootAuthenticatedPage(page, 'pw-sidebar-seam-user');+ await dismissWalkthroughIfPresent(page);+ });++ test('the seam is transparent at rest and paints a visible colour on hover', async ({ page }) => {+ // #5676: "unit tests only assert the class name is applied, never its+ // rendered colour". This reads the colour the engine actually resolved.+ const restColour = await seam(page).evaluate(el => getComputedStyle(el).backgroundColor);++ const pt = await railPoint(page);+ await page.mouse.move(pt.x, pt.y);++ await expect+ .poll(async () => seam(page).evaluate(el => getComputedStyle(el).backgroundColor))+ .not.toBe(restColour);++ const hoverColour = await seam(page).evaluate(el => getComputedStyle(el).backgroundColor);+ // Not transparent, and not fully see-through — the seam has to be visible+ // for the affordance to exist at all.+ expect(hoverColour).not.toBe('rgba(0, 0, 0, 0)');+ expect(hoverColour).not.toMatch(/,\s*0\)$/);+ });++ test('the seam also paints on keyboard focus, not only on hover', async ({ page }) => {+ // The rail is a `role="separator"` the user can Tab to; a seam that only+ // responds to hover leaves keyboard users with no visible target.+ const restColour = await seam(page).evaluate(el => getComputedStyle(el).backgroundColor);++ await rail(page).focus();++ await expect+ .poll(async () => seam(page).evaluate(el => getComputedStyle(el).backgroundColor))+ .not.toBe(restColour);+ });+});