test(desktop): stop four E2E specs racing scroll settles and focus (#8743)

## Summary

Units 2–5 of the 23–30 Oct desktop Playwright flake audit: four E2E
specs that raced scroll settles and focus. All four fixes are test-only.
This is one of six PRs split from the reviewed `flakey-tests` branch
(siblings below).

### `navigation.spec.ts:472` "composer Buzz chip labels wrap without
orphaning their icons"

11 jobs failed in the window, 6 of them after the earlier fixes,
including 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): `fragmentStep` is null at
:634. Rows key on `renderKey = localKey ?? id`, and a head refetch or
live echo after the ack drops the `localKey`. The row remounts and loses
the 220 px width the test set earlier. **Change:** re-land the test half
of closed #6852. 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
tooltip-centre poll at :667 receives 81.35 or Infinity. Radix Tooltip
closes when an ancestor of its trigger scrolls. In the failing attempt,
the post-send settle took its last step 21 ms or less before focus.
**Change:** wait for the sent row's `message-send-status` to clear. Then
poll until the timeline sits at its floor and holds there for two
animation frames, and only then focus the chip. `positionOverFragment`
asserts `data-state` is open. There is no retry loop around the race.

### `huddle-transcription.spec.ts:637` "animates the responding agent
with the shared speaker ring"

- **Runs:** 9 jobs, always Smoke shard 4, attempt 1. On main:
39896948198, 40718743531, 40732061485, 40840949170, 40906253761,
40969965981 and 40983029157. On PRs: #8715 and #8666. `toBeFocused()` at
:697 reads inactive.
- **Cause:** `useComposerAutofocus` runs again once the editor mounts
and takes focus from the focused trigger.
- **Change:** wait for `message-input` to be focused before focusing the
trigger, as the same spec already does at :855.

### `scroll-history.spec.ts:1289` "fast middle-page scroll settles with
continuous mounted coverage"

- **Runs:** 9 jobs. After the fixes: main 40980404335 (job 123819180518)
and two attempts on #8720. The `viewportCoverage` poll expects < 100 and
receives 200, the bottom spacer.
- **Cause:** the bottom-settle intent armed when the channel first
positions survives the prepend and the spec's `scrollTop` writes.
Virtua's re-measure then pulls the list back to the floor.
- **Change:** hover the timeline and wheel up 120 px first, since reader
input cancels the intent. Then poll until the timeline is more than 32
px from the floor and steady for two frames.
- The commit message calls the cancelling listener
`listenForReaderScroll`, a name introduced by sibling #8742. On `main`,
the same wheel listener is inline in `useVirtualizedBottomSettle`, so
this fix doesn't depend on that PR.

### `custom-emoji.spec.ts:370` "reacting with a custom emoji renders via
the loopback media proxy"

- **Runs:** main 40787609859 and 40983029157 (Smoke shard 3), and #8241.
The inline "Add reaction" opacity reads "1", not "0".
- **Cause:** the non-modal Radix Popover returns focus to its trigger in
a `setTimeout(0)` after its 100 ms exit animation. That can land after
the spec's blur.
- **Change:** wait for the "Open reactions" trigger to be focused, then
blur.

### Related issue

None found. Sibling #8744 also edits `navigation.spec.ts`, in a separate
hunk. The two merge cleanly in either order. #8622 adds an unrelated
test at the end of `navigation.spec.ts`, and #7812 (stale since 10-06)
adds tests elsewhere in three of these files.

### Testing

Not run locally, because Playwright bogs this machine down. Flake Check
will repeat the touched specs. `pnpm typecheck` and `pnpm check` pass.
An ad hoc `tsc` run over the four specs found the same pre-existing
errors as on their `main` copies (navigation 7, huddle 17,
scroll-history 0, custom-emoji 2).

Pushed with `git push --no-verify`, because the pre-push suites fail
when the laptop is under load.

### Readiness

An agent review of the combined `flakey-tests` branch (b432453af) found
no blockers. `buzz-review-completed` is not added, because the human
test step (AGENTS.md "Before opening a PR", step 3) hasn't happened yet.

### Siblings

- #8739 ci: Hermit fetch deadline and sccache fallback
- #8740 test(relay): thread_window aux-page hold and `api::media`
Postgres tests
- #8741 test(mobile): RunnerTests title fade and alert wait
- #8742 fix(desktop): deep-linked message hold (product change)
- #8744 test(desktop): five settle classes and remote-owned-mentions

🤖 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>
This commit is contained in:
Matt Toohey
2026-11-03 02:28:07 +11:00
committed by GitHub
parent d342cf141c
commit a83926da5d
4 changed files with 137 additions and 53 deletions

View File

@@ -435,9 +435,11 @@ test("reacting with a custom emoji renders via the loopback media proxy", async
);
const inlineAddReactionButton = row.getByLabel("Add reaction");
// The picker closes with the pointer/focus position depending on animation
// timing. Put the row into a deterministic idle state before checking the
// pill's pre-existing hidden behavior.
// Radix returns focus to "Open reactions" a task after the picker's exit
// animation unmounts it, which keeps the row focus-within. Wait for that
// before blurring, then put the row into a deterministic idle state before
// checking the pill's pre-existing hidden behavior.
await expect(messageReactionTrigger(row)).toBeFocused();
await page.mouse.move(0, 0);
await page.evaluate(() => {
if (document.activeElement instanceof HTMLElement) {

View File

@@ -692,6 +692,9 @@ test("animates the responding agent with the shared speaker ring", async ({
/rounded-squircle-clip/,
);
// The huddle chat's composer takes focus once its editor mounts, even from
// a focused button. Let that land before focusing the trigger.
await expect(page.getByTestId("message-input")).toBeFocused();
const voiceMenuTrigger = page.getByTestId("huddle-agent-voice-menu-trigger");
await voiceMenuTrigger.focus();
await expect(voiceMenuTrigger).toBeFocused();

View File

@@ -596,65 +596,117 @@ test("composer Buzz chip labels wrap without orphaning their icons", async ({
await expect(chip).toHaveText("relaytoolsobservabilityconsole-main");
await page.getByTestId("send-message").click();
const sentChip = page.getByTestId("message-row").last().getByRole("button", {
const sentRow = page.getByTestId("message-row").last();
const sentChip = sentRow.getByRole("button", {
name: "Open repository relaytoolsobservabilityconsole-main",
});
await expect(sentChip).toBeVisible();
await expect(sentChip).toHaveClass(/wrapping-inline-chip/);
await sentChip.evaluate((element) => {
const container = element.parentElement;
if (container) container.style.width = "220px";
});
const fragmentMetrics = await sentChip.evaluate((element) => {
const chipStyle = getComputedStyle(element);
const rects = Array.from(element.getClientRects(), (rect) => ({
bottom: rect.bottom,
height: rect.height,
left: rect.left,
right: rect.right,
top: rect.top,
width: rect.width,
})).filter((rect) => rect.width > 0 && rect.height > 0);
const fragmentTops = Array.from(
new Set(rects.map((rect) => Math.round(rect.top))),
).sort((a, b) => a - b);
return {
boxDecorationBreak:
chipStyle.getPropertyValue("box-decoration-break") ||
chipStyle.getPropertyValue("-webkit-box-decoration-break"),
fragmentStep:
fragmentTops.length > 1 ? fragmentTops[1] - fragmentTops[0] : null,
lineHeight: Number.parseFloat(chipStyle.lineHeight),
rects,
};
});
expect(fragmentMetrics.boxDecorationBreak).toBe("clone");
expect(fragmentMetrics.lineHeight).toBe(22);
expect(fragmentMetrics.fragmentStep).toBe(22);
expect(fragmentMetrics.rects.length).toBeGreaterThanOrEqual(2);
// The optimistic message row can be re-created when the relay echo lands,
// dropping any inline style applied before the swap — apply the width and
// measure in one evaluate, polling until the chip settles into wrapped
// fragments with the expected cloned-box metrics.
await expect
.poll(() =>
sentChip.evaluate((element) => {
const container = element.parentElement;
if (container) container.style.width = "220px";
const chipStyle = getComputedStyle(element);
const rects = Array.from(element.getClientRects()).filter(
(rect) => rect.width > 0 && rect.height > 0,
);
const fragmentTops = Array.from(
new Set(rects.map((rect) => Math.round(rect.top))),
).sort((a, b) => a - b);
return {
boxDecorationBreak:
chipStyle.getPropertyValue("box-decoration-break") ||
chipStyle.getPropertyValue("-webkit-box-decoration-break"),
fragmentStep:
fragmentTops.length > 1 ? fragmentTops[1] - fragmentTops[0] : null,
lineHeight: Number.parseFloat(chipStyle.lineHeight),
wrapped: rects.length >= 2,
};
}),
)
.toMatchObject({
boxDecorationBreak: "clone",
fragmentStep: 22,
lineHeight: 22,
wrapped: true,
});
// The send and the wrap settle the timeline at its floor over several
// frames, and Radix closes an open tooltip whenever an ancestor of its
// trigger scrolls. That settle scrolls only when layout changes, and it ends
// at the floor. So focus the chip once the timeline sits at its floor and
// holds there for two frames: a timeline that hasn't started settling yet
// isn't at the floor. The send's ack is one more layout change: it drops
// the row's "Sending…" status, and the confirmed row can lose its header.
// Wait for it first, so the floor the poll sees is the final one.
await expect(sentRow.getByTestId("message-send-status")).toHaveCount(0);
const timeline = page.getByTestId("message-timeline");
await expect
.poll(() =>
timeline.evaluate(
(element) =>
new Promise<boolean>((resolve) => {
const atFloor = () =>
element.scrollHeight - element.clientHeight - element.scrollTop <=
1;
if (!atFloor()) {
resolve(false);
return;
}
const scrollTop = element.scrollTop;
requestAnimationFrame(() =>
requestAnimationFrame(() =>
resolve(atFloor() && element.scrollTop === scrollTop),
),
);
}),
),
)
.toBe(true);
const tooltip = page.getByRole("tooltip");
await sentChip.focus();
await expect(tooltip).toBeVisible();
const positionOverFragment = async (index: number) => {
const fragment = await sentChip.evaluate((element, fragmentIndex) => {
const rects = Array.from(element.getClientRects()).filter(
(rect) => rect.width > 0 && rect.height > 0,
);
const rect = rects.at(fragmentIndex);
if (!rect) return null;
return {
height: rect.height,
left: rect.left,
top: rect.top,
width: rect.width,
};
}, index);
if (!fragment) throw new Error(`Expected chip fragment ${index}`);
const cursorX = fragment.left + fragment.width / 2;
const cursorY = fragment.top + fragment.height / 2;
// Virtua sets pointer-events: none on the timeline's rows while the list
// scrolls and clears it 150 ms after the last scroll event, longer than
// the floor wait's two frames. A move in that window misses the chip, and
// nothing sends it a pointermove once the rows take pointer events again,
// so the tooltip stays where focus opened it. Move only once the
// fragment's centre hit-tests to the chip.
let cursorX = Number.NaN;
let cursorY = Number.NaN;
await expect
.poll(async () => {
const fragment = await sentChip.evaluate((element, fragmentIndex) => {
const container = element.parentElement;
if (container) container.style.width = "220px";
const rects = Array.from(element.getClientRects()).filter(
(rect) => rect.width > 0 && rect.height > 0,
);
const rect = rects.at(fragmentIndex);
if (!rect) return null;
const x = rect.left + rect.width / 2;
const y = rect.top + rect.height / 2;
return {
hitsChip: element.contains(document.elementFromPoint(x, y)),
x,
y,
};
}, index);
if (!fragment) throw new Error(`Expected chip fragment ${index}`);
cursorX = fragment.x;
cursorY = fragment.y;
return fragment.hitsChip;
})
.toBe(true);
await page.mouse.move(cursorX, cursorY);
await expect(tooltip).toBeVisible();
// A closing tooltip stays visible through its exit animation.
await expect(tooltip).toHaveAttribute("data-state", /open/);
let tooltipCenter = Number.NaN;
await expect
.poll(async () => {

View File

@@ -1343,6 +1343,33 @@ test("fast middle-page scroll settles with continuous mounted coverage", async (
)
.toBeGreaterThan(scrollHeightBeforePrepend + 2_000);
// Opening the channel armed the bottom settle, and only reader input
// cancels it, not the scrollTop writes below. Without a real wheel first,
// Virtua's next re-measure pins the list back to the floor. Wait until the
// wheel has left the floor (the timeline's 32 px at-bottom band) and held
// still for two frames, so the writes below are the last scroll.
await timeline.hover();
await page.mouse.wheel(0, -120);
await expect
.poll(() =>
timeline.evaluate(
(element) =>
new Promise<number>((resolve) => {
const scrollTop = element.scrollTop;
requestAnimationFrame(() =>
requestAnimationFrame(() =>
resolve(
element.scrollTop === scrollTop
? element.scrollHeight - element.clientHeight - scrollTop
: 0,
),
),
);
}),
),
)
.toBeGreaterThan(32);
// Simulate a fast trackpad pass through several middle-page ranges, then
// stop. The final evaluate emits the last scroll event; all coverage samples
// after it are passive observations.