Skip to content

test: settle Tab's scroll before refocusing the diff header in the sideways-reader test - #6279

Merged
max-sixty merged 2 commits into
mainfrom
fix/issue-5883-diff-walk-order
Nov 17, 2026
Merged

max-sixty merged 2 commits into
mainfrom
fix/issue-5883-diff-walk-order

Conversation

@leaf-agent

@leaf-agent leaf-agent commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

test_a_changed_diff_file_keeps_its_sideways_reader failed intermittently because of a race in its setup. It pressed Tab, which starts a scroll glide to the file's comment button, then refocused the first file's header and pressed ArrowRight while that glide was still moving. When the glide carried the header above the window, the keyboard controller's let-go released focus the user couldn't see (letsGo → focusPlace() in browser/runtime/keyboard/controller.js) instead of opening the file. Focus went to <body>, the file stayed closed, and ] walked to app/routes.py's hunk at line 200, which is the end state the CI failures show.

The test now waits for Tab's scroll to settle before refocusing the header, and waits for each ] to land on app/handlers.py's hunk heads at lines 1, 40 and 80 before reading. What it protects hasn't changed: a refreshed file keeps its sideways scroll and its focused row.

Verification: before the change, 3 of 8 local runs failed at the first ]. After it, 6 of 6 runs and 18 of 18 copies under leaf-dev suite flake passed. With the settle placed after the refocus instead, so the glide ends before ArrowRight, the test fails every time, which confirms the cause.

Refs #5883. This settles the diff test it lists. Its other two failures, the Firefox module-load warning and the threads view's u scroll, remain open.

test_a_changed_diff_file_keeps_its_sideways_reader pressed `]` three
times without waiting, then read the focused row. Each step walks from
the row the previous one focused, so the test now waits for focus on
the hunk heads at lines 1, 40 and 80 in turn. The test checks the same
behavior as before (a refreshed file keeps its sideways scroll and
focused row); only the setup states its ordering.

This does not settle the CI failure: on CI the walk ended on
app/routes.py's hunk with no datum row focused, which no local run has
reproduced. If it recurs, the failure now names the press that went past
its hunk instead of a bare `assert None is not None` after all three.

Refs #5883

@leaf-agent leaf-agent left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new waits fail at the first ], not after line 80. The race is in the setup above the walk. In this runner the test failed in 3 of 8 runs at this head, each time at the first press (["app/handlers.py","both",1,1] not focused).

The cause, from tracing a failing run: the click collapses app/handlers.py (both files start open). Then Tab focuses the file's comment button and starts a scroll glide. .focus() moves focus back to the summary, but the glide keeps going and carries the summary above the window (scrollY 1433, summary top between −36 and −18). ArrowRight then reaches the keyboard controller's let-go (letsGo → focusPlace() in browser/runtime/keyboard/controller.js), which releases focus because the user can't see it. So the file never reopens, focus lands on <body>, and ] walks to app/routes.py's hunk at line 200. That is the end state the CI failures show. Runs pass only when ArrowRight arrives before the glide carries the summary out of sight. With scroll_settled(page) between .focus() and ArrowRight, the test fails every time.

Waiting for the Tab glide to settle before .focus() makes the focus the last thing to scroll, so the summary stays in view. With that ordering the test passed 6 of 6 runs and 18 of 18 copies under leaf-dev suite flake. I'm pushing that change and rewriting the description around this cause.

The sideways-reader test pressed Tab and then refocused the first file's header
while Tab's glide to the comment button was still moving. The glide carried the
header above the window, so ArrowRight hit the keyboard controller's let-go for
focus the user can't see: the file stayed closed, focus went to the body, and `]`
walked to app/routes.py's hunk at line 200, the end state the CI failures show.
Waiting for the scroll to settle before the refocus keeps the header in view.
Behavior protected is unchanged: a refreshed file keeps its sideways scroll and
focused row.

Before: 3 of 8 local runs failed at the first `]`. After: 6 of 6 runs and
18 of 18 copies under `leaf-dev suite flake`.
@leaf-agent leaf-agent changed the title test: wait for each hunk step's landing in the diff sideways-reader test test: settle Tab's scroll before refocusing the diff header in the sideways-reader test Nov 17, 2026
@max-sixty
max-sixty merged commit d3656ce into main Nov 17, 2026
6 checks passed
@max-sixty
max-sixty deleted the fix/issue-5883-diff-walk-order branch November 17, 2026 09:43
max-sixty pushed a commit that referenced this pull request Nov 19, 2026
…hout the animated close (#6500)

`test_a_changed_diff_file_keeps_its_sideways_reader` failed
intermittently at its first `]` because its setup acted during an
animated close. The test now focuses the first file's header directly
instead. That removes the race: 10 of 10 local runs and 18 of 18 copies
at `--cpu-throttle 8` pass, against 8 failures in 12 local runs before.

**Cause.** To reach the header, the test clicked it (closing the file),
pressed Tab, refocused the header and pressed `ArrowRight` to reopen it.
A pointer close runs the fold's collapse animation (`--lf-motion-fold`,
[`disclosure.css`](https://github.com/max-sixty/leaf/blob/99ef78526d6bcfe546c389923ed292b36de56226/packages/diff/styles/disclosure.css)).
While the collapse runs, the closing file still has height, so its
sticky header stays pinned at the window's top. Tab scrolls the next
file's comment button into view, and `scroll_settled` returns at once
because the fold doesn't move the scroll. So `focus()` finds the header
on screen and doesn't scroll. When the fold ends, the header sits above
the window: in a captured failure it was at top −36 with `scrollY` still
1433. `ArrowRight` then lets go of focus the user can't see (`letsGo` in
`keyboard/controller.js`) instead of opening the file, and `]` walks
into `app/routes.py`. That is the end state in every CI failure listed
on #5883, including the two after #6279.

**Change.** Both files start open, so focusing the first header and
walking its hunks gives the same starting point. The click, Tab and
`ArrowRight` came with the test's first version (#1624) as setup, not as
the behavior under test. What the test protects is unchanged: a
refreshed file keeps its sideways scroll and its focused row. The
product behaves as designed throughout: a key pressed on a header that
has left the screen lets go of it.

<details><summary>Captured failing sequence (event log in the
page)</summary>

```
keydown Tab         scrollY 972   header top 397   files open [False, True]
scrollend           scrollY 1433  header top 0     (pinned while the fold runs)
keydown ArrowRight  scrollY 1433  header top -36   focus on header
focusout → BODY     (let-go; file stays closed)
keydown ]           focus on BODY → walks to app/routes.py
```

A passing run with the same log shows `document.scrollHeight` shrinking
over several frames after Tab (3362 → 3017) with `scrollY` fixed, which
is the fold collapsing.

</details>

Refs #5883 — automated triage. The issue's other undiagnosed failures,
such as the visual action's `Locator.focus` timeout, are untouched.

Co-authored-by: leaf-agent <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants