Skip to content

Commit 13171fd

Browse files
matt2eclaude
andcommitted
test(desktop): stop four E2E specs racing scroll settles and focus
Units 2-5 of the 23-30 Oct desktop Playwright flake audit. All four are test-only. origin/main (1eb67bb, now including #8680) hasn't touched these specs since fae3f03. Of the open PRs, #8622 adds an unrelated test at the end of navigation.spec, and #7812 (stale since 10-06) adds tests elsewhere in three of them. #8680 didn't touch them, but it carried navigation:472 mode A's product half (eb88a98), which is not part of this commit. The code confirms each cause, so none is dropped. navigation.spec.ts:472, "composer Buzz chip labels wrap without orphaning their icons" Runs: 11 jobs in the window, 6 after the earlier fixes, and 4 of the 7 main runs that carry every fix. Run 40970053997 (Smoke shard 7) failed all three attempts. Mode A: jobs 122971493553, 123066839967, 123572467962, 123819180597 and retry 2 of 123784825042. Signature: fragmentStep is null at :634. Cause: rows key on renderKey = localKey ?? id. On main, reconcileChannelWindowMessages keeps only pending sends and thread replies from the cache, so a head refetch or live echo after the ack drops the localKey. The key flips and the row remounts, losing the 220 px width the test set in an earlier evaluate. Change: re-land the test half of closed PR #6852, which never merged. Set the width and measure in one expect.poll, and set the width again before each fragment measurement. Mode B: jobs 123573056202, 123784199542, 123784825042 (twice), 123804428893, 123818728963, 123819543461, and 122924164125 (the Infinity variant). Signature: the |tooltipCenter - cursorX| < 1 poll at :667 receives 81.35 or Infinity. In failing attempt 40970053997 the post-send settle (scrollTop 200, 296, 260, 302) took its last step 21 ms or less before focus, and the tooltip read closed 12 ms after it. In the passing retry 40980513346, scrolling had stopped at least 15 ms before focus. Cause: Radix Tooltip 1.2.16 closes when an ancestor of its trigger scrolls (a capture-phase window listener). Reopening by pointer needs a pointermove while hasPointerMoveOpenedRef is false, then the chip provider's 500 ms delay. Any close clears that timer, and only pointerleave resets the flag. useInlineTooltipPosition moves the content only on pointermove and placement. So a scroll after focus can leave the tooltip closed, or open without the fragment offset, and the spec's single mouse.move never recovers it. Change: before focusing the chip, poll until the timeline sits at its floor (scrollHeight - clientHeight - scrollTop <= 1) at the start of one poll, is still there two animation frames later, and its scrollTop hasn't moved. Waiting only for scrollTop to hold for two frames isn't enough: a timeline whose settle hasn't started yet reads as still, and the failing run's last step landed under two frames before focus. The settle's end state is the floor. useVirtualizedBottomSettle scrolls only when Virtua's ResizeObserver reports a layout change, and after the send and the 220 px wrap the timeline sits short of the floor until the settle catches up. Focusing the chip and moving the pointer over it don't change layout. The send's ack does. It removes the row's "Sending…" status, and the confirmed row can lose its header, since a pending row is never shown as a continuation (MessageRow.tsx:167). The send's bottom intent is still armed, so that re-pins the timeline. So before the floor poll, wait for the sent row's message-send-status to reach count 0. If the ack has already landed, that wait is a no-op. The standalone toBeVisible after focus is gone. positionOverFragment asserts data-state matches /open/ instead, because a closing tooltip stays visible through its exit animation. No retry. Wrapping the measure, move and check in toPass, leaving and re-entering the chip on each attempt, would also pass, but it retries around the race instead of removing it. The ack and floor waits close the scroll window. The only other way to scroll under the tooltip was a remount that drops the row's 220 px width (mode A), and #8680's retainAcknowledgedLocalKeys, on this branch's base (1eb67bb), keeps the row's key. So positionOverFragment is a single pass, as on main, plus mode A's width re-set: set the width, measure, move, assert open, then poll the centre with the default timeouts. huddle-transcription.spec.ts:637, "animates the responding agent with the shared speaker ring" Runs: 9 jobs, always Smoke shard 4 attempt 1. Main: 39896948198, 40718743531, 40732061485, 40840949170, 40906253761, 40969965981 and 40983029157. PRs: #8715, #8666. Signature: toBeFocused() at :697 reads inactive for all 14 polls over 5 s. At +3.0 s in the failure video (40983029157, job 123827818084) the caret is in "Message #huddle". Cause: useComposerAutofocus re-runs when `focus` changes. That's focusEnd, which depends on the editor, so it runs again once the editor mounts. It backs off only for input, textarea, select and contentEditable focus, so it takes focus from the focused trigger. Change: wait for message-input to be focused before focusing the trigger. The same spec already does this at :855. scroll-history.spec.ts:1289, "fast middle-page scroll settles with continuous mounted coverage" Runs: 9 jobs in the window. After the fixes: main 40980404335 (Smoke shard 9, job 123819180518), two attempts on #8720, and the brain/native-account-setup branch. Signature: the viewportCoverage poll expects < 100 and receives 200. The failure screenshot shows the timeline at the floor. The 200 px is the bottom spacer (--composer-overlay-height) under the last row. Cause: TimelineMessageList arms useVirtualizedBottomSettle when the channel first positions. Its ResizeObserver then pins to the floor until listenForReaderScroll input or an accepted target cancels it. handleScroll deliberately doesn't cancel, and a prepend delta doesn't settle, so the intent survives the prepend and the spec's scrollTop writes. Virtua's re-measure after the jump pulls the list back down. Change: before the fast scroll, hover the timeline and wheel up 120 px. Then poll until it is more than 32 px from the floor (the timeline's at-bottom band) and scrollTop holds for two frames, so the writes stay the last scroll. custom-emoji.spec.ts:370, "reacting with a custom emoji renders via the loopback media proxy" Runs: main 40787609859 (10-28), main 40983029157 (Smoke shard 3, a run with every fix), and #8241 (agent and auth files only). Signature: the poll at :453 expects the inline "Add reaction" opacity "0" and receives "1". The error context marks button "Open reactions" [active]. Cause: the non-modal Radix Popover returns focus to its trigger when the picker closes. FocusScope does that in a setTimeout(0) after the content unmounts, and the content unmounts after its 100 ms exit animation. That can land after the spec's blur. The action bar is hidden by opacity only, so the trigger takes focus, and group-focus-within/message keeps the button visible. Change: wait for the "Open reactions" trigger to be focused, then blur. The note suggested waiting for em-emoji-picker to reach count 0. That still leaves the setTimeout window open. Focus reaches the trigger only after unmount, so this wait covers both. Verification Not run locally: the Flake Check lane will repeat the touched specs. pnpm typecheck and pnpm check pass. biome's 3 warnings are in untouched files. An ad hoc tsc ran over the four specs, using the desktop tsconfig with only those files, and over HEAD's copies of them. Both gave the same error counts: navigation 7, huddle 17, scroll-history 0, custom-emoji 2. The messages are identical once line numbers are stripped, and all are pre-existing: no Node types, findLast against the ES2022 lib, and the leadingBounds narrowing at navigation:576. With the floor wait in place and the retry dropped, navigation still gives the same 7. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Matt Toohey <[email protected]>
1 parent 1eb67bb commit 13171fd

4 files changed

Lines changed: 108 additions & 39 deletions

File tree

‎desktop/tests/e2e/custom-emoji.spec.ts‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -435,9 +435,11 @@ test("reacting with a custom emoji renders via the loopback media proxy", async
435435
);
436436

437437
const inlineAddReactionButton = row.getByLabel("Add reaction");
438-
// The picker closes with the pointer/focus position depending on animation
439-
// timing. Put the row into a deterministic idle state before checking the
440-
// pill's pre-existing hidden behavior.
438+
// Radix returns focus to "Open reactions" a task after the picker's exit
439+
// animation unmounts it, which keeps the row focus-within. Wait for that
440+
// before blurring, then put the row into a deterministic idle state before
441+
// checking the pill's pre-existing hidden behavior.
442+
await expect(messageReactionTrigger(row)).toBeFocused();
441443
await page.mouse.move(0, 0);
442444
await page.evaluate(() => {
443445
if (document.activeElement instanceof HTMLElement) {

‎desktop/tests/e2e/huddle-transcription.spec.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,9 @@ test("animates the responding agent with the shared speaker ring", async ({
692692
/rounded-squircle-clip/,
693693
);
694694

695+
// The huddle chat's composer takes focus once its editor mounts, even from
696+
// a focused button. Let that land before focusing the trigger.
697+
await expect(page.getByTestId("message-input")).toBeFocused();
695698
const voiceMenuTrigger = page.getByTestId("huddle-agent-voice-menu-trigger");
696699
await voiceMenuTrigger.focus();
697700
await expect(voiceMenuTrigger).toBeFocused();

‎desktop/tests/e2e/navigation.spec.ts‎

Lines changed: 73 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -597,48 +597,85 @@ test("composer Buzz chip labels wrap without orphaning their icons", async ({
597597
await expect(chip).toHaveText("relaytoolsobservabilityconsole-main");
598598
await page.getByTestId("send-message").click();
599599

600-
const sentChip = page.getByTestId("message-row").last().getByRole("button", {
600+
const sentRow = page.getByTestId("message-row").last();
601+
const sentChip = sentRow.getByRole("button", {
601602
name: "Open repository relaytoolsobservabilityconsole-main",
602603
});
603604
await expect(sentChip).toBeVisible();
604605
await expect(sentChip).toHaveClass(/wrapping-inline-chip/);
605-
await sentChip.evaluate((element) => {
606-
const container = element.parentElement;
607-
if (container) container.style.width = "220px";
608-
});
609-
const fragmentMetrics = await sentChip.evaluate((element) => {
610-
const chipStyle = getComputedStyle(element);
611-
const rects = Array.from(element.getClientRects(), (rect) => ({
612-
bottom: rect.bottom,
613-
height: rect.height,
614-
left: rect.left,
615-
right: rect.right,
616-
top: rect.top,
617-
width: rect.width,
618-
})).filter((rect) => rect.width > 0 && rect.height > 0);
619-
const fragmentTops = Array.from(
620-
new Set(rects.map((rect) => Math.round(rect.top))),
621-
).sort((a, b) => a - b);
622-
return {
623-
boxDecorationBreak:
624-
chipStyle.getPropertyValue("box-decoration-break") ||
625-
chipStyle.getPropertyValue("-webkit-box-decoration-break"),
626-
fragmentStep:
627-
fragmentTops.length > 1 ? fragmentTops[1] - fragmentTops[0] : null,
628-
lineHeight: Number.parseFloat(chipStyle.lineHeight),
629-
rects,
630-
};
631-
});
632-
expect(fragmentMetrics.boxDecorationBreak).toBe("clone");
633-
expect(fragmentMetrics.lineHeight).toBe(22);
634-
expect(fragmentMetrics.fragmentStep).toBe(22);
635-
expect(fragmentMetrics.rects.length).toBeGreaterThanOrEqual(2);
606+
// The optimistic message row can be re-created when the relay echo lands,
607+
// dropping any inline style applied before the swap — apply the width and
608+
// measure in one evaluate, polling until the chip settles into wrapped
609+
// fragments with the expected cloned-box metrics.
610+
await expect
611+
.poll(() =>
612+
sentChip.evaluate((element) => {
613+
const container = element.parentElement;
614+
if (container) container.style.width = "220px";
615+
const chipStyle = getComputedStyle(element);
616+
const rects = Array.from(element.getClientRects()).filter(
617+
(rect) => rect.width > 0 && rect.height > 0,
618+
);
619+
const fragmentTops = Array.from(
620+
new Set(rects.map((rect) => Math.round(rect.top))),
621+
).sort((a, b) => a - b);
622+
return {
623+
boxDecorationBreak:
624+
chipStyle.getPropertyValue("box-decoration-break") ||
625+
chipStyle.getPropertyValue("-webkit-box-decoration-break"),
626+
fragmentStep:
627+
fragmentTops.length > 1 ? fragmentTops[1] - fragmentTops[0] : null,
628+
lineHeight: Number.parseFloat(chipStyle.lineHeight),
629+
wrapped: rects.length >= 2,
630+
};
631+
}),
632+
)
633+
.toMatchObject({
634+
boxDecorationBreak: "clone",
635+
fragmentStep: 22,
636+
lineHeight: 22,
637+
wrapped: true,
638+
});
639+
640+
// The send and the wrap settle the timeline at its floor over several
641+
// frames, and Radix closes an open tooltip whenever an ancestor of its
642+
// trigger scrolls. That settle scrolls only when layout changes, and it ends
643+
// at the floor. So focus the chip once the timeline sits at its floor and
644+
// holds there for two frames: a timeline that hasn't started settling yet
645+
// isn't at the floor. The send's ack is one more layout change: it drops
646+
// the row's "Sending…" status, and the confirmed row can lose its header.
647+
// Wait for it first, so the floor the poll sees is the final one.
648+
await expect(sentRow.getByTestId("message-send-status")).toHaveCount(0);
649+
const timeline = page.getByTestId("message-timeline");
650+
await expect
651+
.poll(() =>
652+
timeline.evaluate(
653+
(element) =>
654+
new Promise<boolean>((resolve) => {
655+
const atFloor = () =>
656+
element.scrollHeight - element.clientHeight - element.scrollTop <=
657+
1;
658+
if (!atFloor()) {
659+
resolve(false);
660+
return;
661+
}
662+
const scrollTop = element.scrollTop;
663+
requestAnimationFrame(() =>
664+
requestAnimationFrame(() =>
665+
resolve(atFloor() && element.scrollTop === scrollTop),
666+
),
667+
);
668+
}),
669+
),
670+
)
671+
.toBe(true);
636672

637673
const tooltip = page.getByRole("tooltip");
638674
await sentChip.focus();
639-
await expect(tooltip).toBeVisible();
640675
const positionOverFragment = async (index: number) => {
641676
const fragment = await sentChip.evaluate((element, fragmentIndex) => {
677+
const container = element.parentElement;
678+
if (container) container.style.width = "220px";
642679
const rects = Array.from(element.getClientRects()).filter(
643680
(rect) => rect.width > 0 && rect.height > 0,
644681
);
@@ -653,9 +690,9 @@ test("composer Buzz chip labels wrap without orphaning their icons", async ({
653690
}, index);
654691
if (!fragment) throw new Error(`Expected chip fragment ${index}`);
655692
const cursorX = fragment.left + fragment.width / 2;
656-
const cursorY = fragment.top + fragment.height / 2;
657-
await page.mouse.move(cursorX, cursorY);
658-
await expect(tooltip).toBeVisible();
693+
await page.mouse.move(cursorX, fragment.top + fragment.height / 2);
694+
// A closing tooltip stays visible through its exit animation.
695+
await expect(tooltip).toHaveAttribute("data-state", /open/);
659696
let tooltipCenter = Number.NaN;
660697
await expect
661698
.poll(async () => {

‎desktop/tests/e2e/scroll-history.spec.ts‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1343,6 +1343,33 @@ test("fast middle-page scroll settles with continuous mounted coverage", async (
13431343
)
13441344
.toBeGreaterThan(scrollHeightBeforePrepend + 2_000);
13451345

1346+
// Opening the channel armed the bottom settle, and only reader input
1347+
// cancels it, not the scrollTop writes below. Without a real wheel first,
1348+
// Virtua's next re-measure pins the list back to the floor. Wait until the
1349+
// wheel has left the floor (the timeline's 32 px at-bottom band) and held
1350+
// still for two frames, so the writes below are the last scroll.
1351+
await timeline.hover();
1352+
await page.mouse.wheel(0, -120);
1353+
await expect
1354+
.poll(() =>
1355+
timeline.evaluate(
1356+
(element) =>
1357+
new Promise<number>((resolve) => {
1358+
const scrollTop = element.scrollTop;
1359+
requestAnimationFrame(() =>
1360+
requestAnimationFrame(() =>
1361+
resolve(
1362+
element.scrollTop === scrollTop
1363+
? element.scrollHeight - element.clientHeight - scrollTop
1364+
: 0,
1365+
),
1366+
),
1367+
);
1368+
}),
1369+
),
1370+
)
1371+
.toBeGreaterThan(32);
1372+
13461373
// Simulate a fast trackpad pass through several middle-page ranges, then
13471374
// stop. The final evaluate emits the last scroll event; all coverage samples
13481375
// after it are passive observations.

0 commit comments

Comments
 (0)