Files
buzz/desktop/tests/e2e/channel-composer-overflow.spec.ts
Matt Toohey 0052b2354e test(desktop): gate flaky E2E specs on the state they assume (#8681)
## Summary

Test-side fixes for ten desktop E2E flake clusters and six long-tail
rows from the 21–28 Oct 2026 CI audit. Each spec now waits for the state
it assumes (a rendered row, a mounted listener, a finished animation, a
held boot read), not a fixed delay or a one-shot probe. Two mock-bridge
seams support this.

The PR changes test code and mock-bridge seams only, apart from one
product constant extracted with its value unchanged. It is one of seven
PRs split out of the `flakey-tests` branch (siblings below).

### Related issue

None found.

- #8622, #8244 and #8386 touch some of these spec files, but not the
tests fixed here.
- §7 mode A (`navigation:472`) is left to open PR #6852, which already
sets the width and measures in one polled evaluate.
- Draft #8279 queues cold-launch nostr-bind links in the product. Its
mock returns null, so the §12 listener seam is still needed.

### Mock-bridge seams

- `__BUZZ_E2E_EVENT_LISTENER_COUNT__(event)` counts live **app**
listeners per Tauri event. It wraps the mocked
`plugin:event|listen`/`unlisten`. The spec-facing
`__TAURI_INTERNALS__.listen` passes a marker target that the wrapper
skips, so a spec's own subscription can't satisfy the wait. Tauri
2.11.1's mock ignores targets, so delivery is unchanged.
- `deferFirstChannelsRead` arms the existing channels-read hold at boot.
`__BUZZ_E2E_RELEASE_CHANNELS_READ__` releases it.
- `CREATE_PROJECT_REFOCUS_DELAY_MS` moves to `createProjectFormFocus.ts`
with its value unchanged (50 ms). Both `CreateProjectFormContent` and
`project-commit-detail.spec` import it.

### Flaky tests fixed

| Test | Failing runs | Cause | Change |
|---|---|---|---|
| §2 `overscroll-boundary.spec.ts:34` (and its sibling) | 39601763602,
40367495044, 40583830861, 40597484657, 40373404267 | The
`message-timeline` test id first lands on the loading skeleton, which
doesn't overflow, so the scroll lock rightly cancels the wheel. | Wait
for a rendered row, and content taller than the viewport, before
dispatching wheels. |
| §4 `project-conversation-load-failure.spec.ts:73` | 40367495044 (all 3
attempts), 40608383847, 40583830861; PRs 39541263507, 40509460168 | The
seeded root and reply were dated `now`. The panel's live REQ (`since =
floor(now)`) still replayed the reply, so the error card never appeared.
| Date both events a minute in the past, and correct the comment. |
| §6 `workflows.spec.ts` `createWorkflow` cluster (:222, :365, :297,
:525, :471, :406, :614, :997) | 14 of 50 main jobs; :222 ×4, e.g.
40353619362 | `AnimatePresence mode="wait"` keeps the trigger body
mounted through its exit, so "Message text" could fill the trigger's
field (:222 and the callers). For :297, `isVisible()` read "closed" one
frame before the dialog opened its own channel list. | Wait for the step
body's "Step details" control before filling. Create dialogs wait for
the list; only the duplicate dialog clicks it. |
| §12 `nostr-bind.spec.ts` (:156, :198, :228, :247, :260, :335, :417,
:447) | 8 main jobs, each test once | The spec emitted
`deep-link-nostr-bind` before the app subscribed, and the mock drops
events that have no listener. | Wait for
`__BUZZ_E2E_EVENT_LISTENER_COUNT__` to report the app listener before
emitting. |
| §15 `profile.spec.ts:1128` (integration) | 7 of 50 main jobs | The 320
ms motion-sampling window started before the click. | Start the window
when `activeTab` reads "runtime". |
| §17 `agent-availability.spec.ts:602`, both shutdown-failure variants
(integration) | 6 jobs (4 disconnected-online, 2 failed-online) | The
"shutdown refused" toast sits over the Delete row and pauses while the
pointer is on it, so the retry click is intercepted. | Assert the toast,
then retry with focus + Enter. The toaster has no close button. |
| §19 `virtualization.spec.ts:247` "08 — cascading older pages…" | 4 of
50 main jobs; PR 40605736093 (all 3 attempts) | The 120 ms and 400 ms
windows were timed from before the wheel bursts, and CDP can deliver
wheels late. | Count the wheels the page receives. Each window opens at
the first wheel and closes only after all have landed, then waits for
still frames. **A second, product-side mode remains** (see below). |
| §20 `message-copy-link.spec.ts:160` | 4 of 50 main jobs (5 failed
attempts), e.g. 40595483966 | The huddle row reused `"d".repeat(64)`,
which is a seeded ordinary `#general` message. | Use ids that no seed
uses, and emit only after `waitForMockChannelHeadReady`. |
| §21 `navigation.spec.ts:687` | 4 of 50 main jobs | The pending chip's
`boundingBox()` was read once, and can be null while the row mounts. |
Poll until the chip has a width. |
| §23 `sidebar-snapshot.spec.ts:358`, `:388`, `:438` | PR 40427822003
(all 3 attempts); never on main | The 500 ms loading-state budget
counted app boot, so a slow runner finished the channels read first. |
Hold the first channels read with `deferFirstChannelsRead`, assert the
loading state, then release it. |
| `project-commit-detail.spec.ts:259` | 1–2 CI failures (audit long
tail) | A 50 ms refocus timer can land mid-fill and type the description
into the name field. | Once the name field is focused, wait out a page
timer of `CREATE_PROJECT_REFOCUS_DELAY_MS`; equal-delay timers fire in
order. |
| `project-pr-review.spec.ts:3520` | 1–2 CI failures | The same timer
pattern in `CreateProjectWorkItemDialog`. | Wait for `toBeFocused()` on
the title, which only that timer can satisfy. |
| `thread-load-failure.spec.ts:79` | 1–2 CI failures |
`openWelcomeThread` branched on a one-shot `count()` and fell back to a
hover-only Reply click. | Wait for the summary row, then click it. |
| `virtualization.spec.ts:201` | 1–2 CI failures | The drop point sat 2
px above the target's bottom edge, after two fixed frames. | Drop at the
centre, after dnd-kit's live region names the target. |
| `channel-composer-overflow.spec.ts:217` | 1–2 CI failures |
Same-second emits sort by id, and the clearance was checked once. |
`createdAt: base + i` and `expect.poll`. |
| `scroll-history.spec.ts:1289` | 1–2 CI failures | A fixed 250 ms wait
before idle sampling. | Poll for coverage first. |

Local before/after counts are from the original `flakey-tests` commits
(e286a6ae0, 816c7c35e, 67185df6a). Each used a forcing that made
`main`'s copy fail with CI's signature:

| Test | Before | After |
|---|---|---|
| §2 | 3/15 | 15/15 |
| §4 | 0/10 | 10/10 |
| §6 :222 | 0/3 | 3/3 |
| §6 :297 | 0/3 | 3/3 |
| §12 | 0/3 | 3/3 |
| §15 | 0/3 | 3/3 |
| §17 | 1/4 | 4/4 |
| §19 late-wheel modes | 0/3 | 3/3 and 2/3 |
| §23 | 2/6 | 6/6 |
| project-commit-detail | 0/3 | 3/3 |
| project-pr-review | 0/3 | 3/3 |

§20, §21, `thread-load-failure:79`, `virtualization:201`,
`channel-composer-overflow:217` and `scroll-history:1289` were not
reproduced; they get the fix that matches their CI signature.

Not fixed (follow-up): `virtualization:247` also has a product-side
mode. In one frame after a prepend, `scrollHeight` can drop 458–639 px
while `scrollTop` moves only 50–114 px, so the anchor row jumps 382–457
px. That is lost anchor compensation, and this test can still fail on
it.

### Verification

This branch was pushed without local re-verification, by the user's
choice: local test runs were overloading the machine and failing for
that reason. **Hosted CI is the check.** It was pushed with `git push
--no-verify`, because the pre-push hook runs typecheck and the unit
suites. #8613's flake-check lane will also repeat the changed specs.

- Every file except `virtualization.spec.ts` is byte-identical to its
final version on `flakey-tests` (67185df6a). That file carries only this
PR's hunks; see "Merge order".
- Checked for this PR: `git diff --check`, biome on the partial spec (no
changes, the same as on `main`), and a conflict-free merge with all six
siblings onto `main`.

### Readiness

Test and mock-bridge change; the one product edit is a constant
extraction with its value unchanged. AGENTS.md's readiness steps (agent
review, then human confirmation) are still outstanding, so
`buzz-review-completed` is not set.

### Merge order

No required order. `desktop/tests/e2e/virtualization.spec.ts` is also
edited by **flakey-tests-desktop-races**, which adds one test after line
929; this PR's hunks are all above line 551. They don't touch, so the
two merge cleanly in either order, as checked with `git merge-tree`.

### Sibling PRs

Split from `flakey-tests` (one PR per area): #8676 (PostgreSQL lease +
lane), #8677 (relay E2E helper + Windows shell), #8678 (mobile), #8679
(Tauri apt cache + Windows Rust cap), #8680 (desktop product races),
#8682 (desktop E2E composer + row actions).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Signed-off-by: Matt Toohey <contact@matttoohey.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Jitter <2b2e6415e748c35180847a37aadae06a11e30dddc76b784e7fd9354c4eb42e7a@buzz.block.builderlab.xyz>
2026-10-30 09:59:40 +11:00

360 lines
12 KiB
TypeScript

import { expect, test } from "@playwright/test";
import { waitForAnimations } from "../helpers/animations";
import { installMockBridge, TEST_IDENTITIES } from "../helpers/bridge";
// The channel and thread composers float over their conversation scrollers.
// When the conversation is scrolled up, later rows pass underneath the
// composer overlay — the overlay must mask them (gradient fade + solid
// bottom strip, mirroring the inbox treatment from PR #2143) instead of
// letting them bleed out below the composer box.
const CHANNEL = "general";
const TYPING_KIND = 20002;
async function waitForMockLiveSubscription(
page: import("@playwright/test").Page,
channelName: string,
kind?: number,
) {
await expect
.poll(() =>
page.evaluate(
({ channelName, kind }) =>
window.__BUZZ_E2E_HAS_MOCK_LIVE_SUBSCRIPTION__?.({
channelName,
kind,
}) ?? false,
{ channelName, kind },
),
)
.toBe(true);
}
async function emit(
page: import("@playwright/test").Page,
content: string,
parentEventId: string | null = null,
createdAt?: number,
) {
const event = await page.evaluate(
(payload) =>
window.__BUZZ_E2E_EMIT_MOCK_MESSAGE__?.({
channelName: payload.channel,
content: payload.content,
createdAt: payload.createdAt,
parentEventId: payload.parentEventId,
}),
{ channel: CHANNEL, content, createdAt, parentEventId },
);
if (!event) throw new Error("mock message emitter is not installed");
return event as { created_at: number; id: string };
}
type ComposerDockGeometry = {
composerBottom: number;
composerLeft: number;
composerRight: number;
composerTop: number;
dockHeight: number;
dockTop: number;
};
async function composerDockGeometry(
overlay: import("@playwright/test").Locator,
): Promise<ComposerDockGeometry> {
return overlay.evaluate((element) => {
const composer = element.querySelector<HTMLElement>(
'[data-testid="message-composer"]',
);
const dock = element.querySelector<HTMLElement>(".composer-dock");
if (!composer || !dock) throw new Error("Missing composer dock geometry");
const composerRect = composer.getBoundingClientRect();
const dockRect = dock.getBoundingClientRect();
return {
composerBottom: composerRect.bottom,
composerLeft: composerRect.left,
composerRight: composerRect.right,
composerTop: composerRect.top,
dockHeight: dockRect.height,
dockTop: dockRect.top,
};
});
}
async function expectOverlayBottomMask(
overlay: import("@playwright/test").Locator,
) {
const hasMask = await overlay.evaluate((element) => {
const after = getComputedStyle(element, "::after");
const before = getComputedStyle(element, "::before");
const composer = element.querySelector<HTMLElement>(
'[data-testid="message-composer"]',
);
const cornerMaskContainer = element.querySelector<HTMLElement>(
".composer-overlay-corner-masks",
);
if (!composer || !cornerMaskContainer) return false;
const overlayRect = element.getBoundingClientRect();
const composerRect = composer.getBoundingClientRect();
const leftMask = getComputedStyle(cornerMaskContainer, "::before");
const rightMask = getComputedStyle(cornerMaskContainer, "::after");
const tolerance = 0.5;
return (
after.content !== "none" &&
before.content !== "none" &&
leftMask.maskImage !== "none" &&
rightMask.maskImage !== "none" &&
Math.abs(
composerRect.left - overlayRect.left - Number.parseFloat(leftMask.left),
) <= tolerance &&
Math.abs(
overlayRect.right -
composerRect.right -
Number.parseFloat(rightMask.right),
) <= tolerance &&
Math.abs(
overlayRect.bottom -
composerRect.bottom -
Number.parseFloat(leftMask.bottom),
) <= tolerance &&
leftMask.bottom === rightMask.bottom
);
});
expect(hasMask).toBe(true);
}
test.describe("composer overlays mask scrolled content", () => {
test("channel timeline rows fade out behind the composer", async ({
page,
}) => {
await installMockBridge(page);
await page.goto("/");
await page.getByTestId(`channel-${CHANNEL}`).click();
await expect(page.getByTestId("message-timeline")).toBeVisible();
await waitForMockLiveSubscription(page, CHANNEL);
for (let i = 0; i < 20; i++) {
await emit(
page,
`Channel filler ${i} — enough text to occupy vertical space so the conversation scrolls and rows pass behind the composer overlay.`,
);
}
await page.waitForTimeout(400);
// Scroll the conversation up so trailing rows sit behind the overlay.
await page.evaluate(() => {
const scroller = document.querySelector<HTMLElement>(
'[data-buzz-conversation-scroll="true"]',
);
if (!scroller) throw new Error("Missing conversation scroll container");
scroller.scrollTop = Math.max(
0,
scroller.scrollHeight - scroller.clientHeight - 220,
);
});
await page.waitForTimeout(300);
await waitForAnimations(page);
await page.screenshot({
path: "test-results/channel-overflow/channel-composer.png",
clip: { x: 300, y: 720 - 280, width: 980, height: 280 },
});
await expectOverlayBottomMask(page.getByTestId("channel-composer-overlay"));
});
test("activity trades composer height without moving the dock", async ({
page,
}) => {
await installMockBridge(page);
await page.goto("/");
await page.getByTestId(`channel-${CHANNEL}`).click();
await waitForMockLiveSubscription(page, CHANNEL);
await waitForMockLiveSubscription(page, CHANNEL, TYPING_KIND);
const overlay = page.getByTestId("channel-composer-overlay");
const input = overlay.getByTestId("message-input");
await input.fill(
"A multiline draft that grows the composer.\nSecond line keeps the natural-height path active.",
);
await waitForAnimations(page);
const quiet = await composerDockGeometry(overlay);
await page.evaluate((channelName) => {
window.__BUZZ_E2E_EMIT_MOCK_TYPING__?.({ channelName });
}, CHANNEL);
await expect(
overlay.getByTestId("channel-composer-activity-row"),
).toBeVisible();
await waitForAnimations(page);
const active = await composerDockGeometry(overlay);
expect(Math.abs(active.dockTop - quiet.dockTop)).toBeLessThanOrEqual(0.5);
expect(Math.abs(active.dockHeight - quiet.dockHeight)).toBeLessThanOrEqual(
0.5,
);
expect(
Math.abs(active.composerTop - quiet.composerTop),
).toBeLessThanOrEqual(0.5);
expect(active.composerBottom).toBeLessThan(quiet.composerBottom - 8);
});
test("reduced motion removes dock geometry transitions", async ({ page }) => {
await page.emulateMedia({ reducedMotion: "reduce" });
await installMockBridge(page);
await page.goto("/");
await page.getByTestId(`channel-${CHANNEL}`).click();
const dock = page
.getByTestId("channel-composer-overlay")
.locator(".composer-dock");
const spacer = dock.locator(".composer-dock-quiet-spacer");
await expect(dock).toHaveCSS("transition-duration", "0s");
await expect(spacer).toHaveCSS("transition-duration", "0s");
});
test("bottom-pinned messages clear a growing composer", async ({ page }) => {
await installMockBridge(page);
await page.goto("/");
await page.getByTestId(`channel-${CHANNEL}`).click();
await expect(page.getByTestId("message-timeline")).toBeVisible();
await waitForMockLiveSubscription(page, CHANNEL);
// Give each message its own second. Same-second messages order by id, so
// the last one emitted is not necessarily the bottom row.
const base = Math.floor(Date.now() / 1000);
let newestMessageId = "";
for (let i = 0; i < 20; i++) {
newestMessageId = (
await emit(page, `Bottom-clearance message ${i}`, null, base + i)
).id;
}
await page.waitForTimeout(300);
await page.evaluate(() => {
const scroller = document.querySelector<HTMLElement>(
'[data-buzz-conversation-scroll="true"]',
);
if (!scroller) throw new Error("Missing conversation scroll container");
scroller.scrollTop = scroller.scrollHeight;
});
await page
.getByTestId("message-input")
.fill(
"A long draft grows the composer and must keep the newest message above it.\nSecond line.\nThird line.",
);
await waitForAnimations(page);
// The timeline re-pins to the bottom on the composer's resize, which can
// land after the animations settle, so poll rather than measure once.
const newestClearsComposer = () =>
page.evaluate((messageId) => {
const composer = document.querySelector<HTMLElement>(
'[data-testid="channel-composer-overlay"] [data-testid="message-composer"]',
);
const newestRow = document.querySelector<HTMLElement>(
`[data-message-id="${CSS.escape(messageId)}"]`,
);
return Boolean(
composer &&
newestRow &&
newestRow.getBoundingClientRect().bottom <=
composer.getBoundingClientRect().top,
);
}, newestMessageId);
await expect.poll(newestClearsComposer).toBe(true);
await page.setViewportSize({ width: 1280, height: 620 });
await expect.poll(newestClearsComposer).toBe(true);
});
test("thread panel replies fade out behind the reply composer", async ({
page,
}) => {
await installMockBridge(page);
await page.goto("/");
await page.getByTestId(`channel-${CHANNEL}`).click();
await expect(page.getByTestId("message-timeline")).toBeVisible();
await waitForMockLiveSubscription(page, CHANNEL);
const root = await emit(page, "Thread root — the discussion begins here.");
for (let i = 0; i < 20; i++) {
await emit(
page,
`Thread reply ${i} — enough text to occupy vertical space so the thread body scrolls and replies pass behind the reply composer.`,
root.id,
);
}
await page.waitForTimeout(400);
const summary = page.locator(
`[data-testid="message-thread-summary"][data-thread-head-id="${root.id}"]`,
);
await expect(summary).toBeVisible();
await summary.click();
const threadPanel = page.getByTestId("message-thread-panel");
await expect(threadPanel).toBeVisible();
await waitForAnimations(page);
// Scroll the thread body up so trailing replies sit behind the overlay.
await page.evaluate(() => {
const scroller = document.querySelector<HTMLElement>(
'[data-testid="message-thread-body"]',
);
if (!scroller) throw new Error("Missing thread body scroll container");
scroller.scrollTop = Math.max(
0,
scroller.scrollHeight - scroller.clientHeight - 220,
);
});
await page.waitForTimeout(300);
await waitForAnimations(page);
await page.screenshot({
path: "test-results/channel-overflow/thread-composer.png",
clip: { x: 1280 - 560, y: 720 - 300, width: 560, height: 300 },
});
await expectOverlayBottomMask(page.getByTestId("thread-composer-overlay"));
await waitForMockLiveSubscription(page, CHANNEL, TYPING_KIND);
await page.evaluate(
({ channelName, createdAt, pubkey, threadHeadId }) => {
window.__BUZZ_E2E_EMIT_MOCK_TYPING__?.({
channelName,
createdAt,
pubkey,
threadHeadId,
});
},
{
channelName: CHANNEL,
createdAt: root.created_at + 1,
pubkey: TEST_IDENTITIES.bob.pubkey,
threadHeadId: root.id,
},
);
const threadOverlay = page.getByTestId("thread-composer-overlay");
const activityRow = threadOverlay.getByTestId("message-typing-indicator");
await expect(activityRow).toBeVisible();
await waitForAnimations(page);
const [composerBounds, activityBounds] = await Promise.all([
threadOverlay.getByTestId("message-composer").boundingBox(),
activityRow.boundingBox(),
]);
expect(composerBounds).not.toBeNull();
expect(activityBounds).not.toBeNull();
expect(activityBounds?.x ?? 0).toBeGreaterThanOrEqual(
(composerBounds?.x ?? 0) - 0.5,
);
expect(
(activityBounds?.x ?? 0) + (activityBounds?.width ?? 0),
).toBeLessThanOrEqual(
(composerBounds?.x ?? 0) + (composerBounds?.width ?? 0) + 0.5,
);
});
});