Skip to content

Keep each test's process state its own, wait for the applied reading in round_trip, and refuse assertions that rest on a sleep - #5988

Merged
max-sixty merged 19 commits into
mainfrom
test-isolation
Nov 15, 2026
Merged

max-sixty merged 19 commits into
mainfrom
test-isolation

Conversation

@max-sixty

@max-sixty max-sixty commented Nov 14, 2026 •

Copy link
Copy Markdown
Owner

Three changes to how the suite isolates tests and waits, from a review of recent flakes.

Process state. Nothing writes the pytest process's environment directly now. pytest_configure sets the run-wide conditions once through a MonkeyPatch (failing harness programs on PATH, the headless shell as LEAF_BROWSER_EXECUTABLE, Linux fonts, SIGINT), and tests use monkeypatch. The website's restore() no longer sets LEAF_PAGE_COMMIT; the container's main does, so isolated_session drops the reset b45b8e1 added. A teardown hook fails any test that leaves the environment, working directory or SIGINT/SIGTERM/SIGHUP handlers changed, and a command a test runs through CliRunner keeps the signal handlers it takes (leaf wait, leaf page events) to that run. Layer caches are per test through monkeypatch.setattr instead of cleared after.

round_trip. Since #5899 the page adopts the server's reading a task after the answer, so tests that read page state right after round_trip saw stale state (#5943 and #5949 fixed seven one by one). The traffic ledger now counts received and applied states, and round_trip also waits until every received state has finished applying. postEvent counts acked once the answer's body is read; its headers still decide at once. The two one-shot reads those PRs replaced are back. Two tests hold that application on purpose (behind a held Markdown import, and held zero-delay timers), and end their trip at the answer through a new delivered.

Sleeps. test_no_assertion_rests_on_a_sleep refuses a sleep followed by an assertion. The 79 such sleeps in nine files now wait for rendered, an ordered later event, or the page clock run past the runtime's own preview timers (PREVIEW_TIMERS, read through __lfCheckApi); each pattern was checked against a product change that brings the bug back.

tests/AGENTS.md, "Fixtures", states the isolation rule.

Max asked for this. Codex reviewed it twice, and its findings are fixed. A full-suite dispatch on an earlier commit found four failures this change caused, all fixed since: the two held applications, leaf page events taking SIGTERM, and a finger landing on a panel still opening (macOS). Its other failures also fail on main, in main's own runs or run locally, except three macOS ones that pass here under --cpu-throttle 10. Focused tests, pnpm run test:runtime and pnpm run check pass.

This was written by Claude Code on behalf of max-sixty

…he chart and contents tests

Twelve checks in `test_charts.py` and `test_contents_and_glosses.py` slept
200 to 600 ms and then asserted that a preview had not shown, had not gone, or
still said the same point. A preview decides on timers (preview.js: `DWELL`,
200 ms, for a pointer's rest and for its leaving; `HOLD`, 500 ms, for a finger
where the engine sends no long press), so on a slower machine the decision
lands after the sleep and each absence check passes with the bug present.

Each test whose check waits on one of those timers now opens its page with
Playwright's clock installed. In place of the sleep, `waited_out` waits for
`rendered` (the input has been taken in), runs the clock 600 ms forward (every
preview timer has fired), and waits for `rendered` again (what those timers
decided has been drawn). The contents test does the same three steps inline.

| Test | Slept | Now waits for |
|---|---|---|
| `test_a_chart_says_the_value_under_the_pointer_and_the_keyboard`, pointer back on the point Escape put away | 300 ms | `waited_out` |
| the same, redraw after Escape | 300 ms | `rendered` after the new drawing, since the redraw decides in its own task |
| `test_a_finger_held_on_a_chart_reads_the_point_under_it`, before the long press | 600 ms | `waited_out` |
| `test_a_reading_stays_as_the_pointer_crosses_empty_drawing_toward_it` | 300 ms | `waited_out` |
| `test_a_reading_stays_while_the_pointer_crosses_onto_it_past_the_chart` | 400 ms | `waited_out` |
| `test_a_reading_stays_over_words_its_chart_shares_a_box_with` | 400 ms | `waited_out` |
| `test_a_reading_holds_a_pointer_that_slides_onto_it_over_one_paragraph` | 500 ms | `waited_out` |
| `test_a_reading_keeps_clear_of_the_card_its_chart_stands_in`, a placement read | 200 ms | `rendered` |
| `test_a_held_reading_kept_in_a_gap_stays_as_the_window_resizes`, slide into the gap | 300 ms | `waited_out` |
| the same, resize | 400 ms | `resized`, then `waited_out` |
| `test_a_chart_s_author_picks_which_marks_say_their_values_and_their_words` | 300 ms | `waited_out` |
| `test_each_contents_row_marks_where_its_section_s_threads_on_me_and_changes_stand`, hover on a row with nothing to count | 400 ms | the same three steps |

Each test protects the same behavior as before. Each kind of wait was checked
against a product change that brings back the forbidden behavior, and the test
failed at the converted check: the chart reading the point Escape put away
again, a row with nothing to count previewing, `onPreview` never keeping a
pointer that crosses onto the reading, the chart dropping its reading in a gap,
a hold timer arming in Chromium, and a redraw restoring the ring. With
`onPreview` broken, `rendered` alone in place of `waited_out` passed, so the
clock run is the part that catches the leaving timer.
Each of these tests slept and then asserted. The behavior each one
protects is unchanged; only what it waits on before asserting changed.

- test_live_samples::test_reading_keys_page_on_from_a_sample_to_its_page
  (300 ms): waits for the sample's answer to `restoreCurrentLocation()`.
  The answer travels the frame's port behind any step the `d` press
  passed on, so a step that Full view should keep inside has reached the
  containing page before scrollY is read.
- test_go_to::test_generated_hints_follow_the_page_while_it_moves
  (200 ms): waits for `rendered`. The settle timer the sleep outlasted
  is gone from the hint session; the chips show only once the map is
  drawn at rest.
- test_render_reactions::test_a_remote_resolve_disarms_the_open_reply_list_it_takes_away
  (100 ms): `rendered`, then `round_trip`, so anything the second digit
  sent has come back before the log is counted.
- test_reading_position::test_live_news_keeps_the_reading_draft_in_the_thread_being_written_in
  (600 ms): the sleep is removed. It waited out Chrome's 500 ms
  `hadRecentInput` credit, which the shift watch no longer reads: the
  page adopting a server reading ends the input's credit, so news shifts
  are judged at once.
- test_render_navigation::test_target_mnemonics_filter_the_generated_map_without_renumbering_hints
  (100 ms): waits for the deferred news to show in the panel, then for
  the next Escape's "Go to cancelled", which the live region speaks after
  anything said as the news showed. The news shows only once the
  notices queued ahead of it retire, about 4 s later, so the 100 ms sleep
  never reached that moment.

Bug-back checks, each reverted:
- Ignoring the open modal in `stepAlong` makes the sample test fail;
  with the same flip and no wait, the read passes.
- A stray post on the second `1` keydown makes the reactions test fail;
  with no wait, the read passes.
- Announcing a background notice shown after a retire makes the
  navigation test fail; the previous version passes with that flip.
- A transient 60 px shift of #reading, triggered by the first server
  reading the page adopts, is reported by the shift watch without the
  sleep.
…ests

Twenty sleeps in test_render_anchors.py, from 150 to 600 ms, stood before
a read of what a pointer move, a press, a script's change to the page's
words, a search match's landing or a thread walk's landing had done. Each
now waits for `rendered`, which returns once every rendering pass the
input queued has run: the hover frame that paints the hand over a mark
(anchor-paint.js, `refreshHover`), the card's placement, the repaint of
the marks and the draft's mark after placement takes in a script's
change, and the walk's glide. The behavior each test protects is
unchanged.

One assertion changed with its wait. The check that a pressed card stays
open read `to_be_visible()` after 500 ms, which a closed card satisfies
while it fades out, and a card that opens again later satisfies too. It
now reads once, after `rendered`, that the card still holds its placement
(`data-lf-thread-placement`), which `close` removes at once.

Bug-back checks, each reverted after the run:

- The hit test's index keeps a re-placed thread's old pieces, and the
  hand paints 20 frames late: the hand-absence read fails. With a 100 ms
  sleep in place of `rendered`, that read passed.
- The hit test reads placement without settling it: the absence reads in
  `_rest_on` fail. With placement's `settle` a no-op, the press made in
  the script's task opens the card, and its read fails.
- The card closes 30 frames after its placement: the keep-open read
  fails, where the old visibility check passed.
- The anchor paint ignores re-placements: the four reads of marks and
  the draft's mark after a script's change fail.
- A search match and the comment box land by the passage's last segment,
  the walk scrolls nothing, or the walk lands and is carried 3000 px away
  20 frames later: every position read fails.

The 50 affected cases pass in Chromium and Firefox, and the 25 Chromium
cases pass at --cpu-throttle 10 and 20.
…fixed sleeps

Forty-two sleeps in `tests/browser/controls/test_previews.py`, from 200 to
700 ms, stood before an assertion or a reading one asserts. On a slower
machine an absence checked after one passes with the bug present, since
the preview that shouldn't show shows late. Each now waits for what
decides it, and the behavior each test protects is unchanged.

| Waited out | Sites | Now |
|---|---|---|
| A pointer's dwell, or the dwell before a preview the pointer left goes (preview.js `DWELL`, `WARM`) | 18, in 12 tests and `_reads` | The page opens on Playwright's clock (`clocked`, installed before navigation); `dwelt` waits for the repaints the input queued, runs the clock past the timer, then waits for the repaints it queued |
| A finger at rest before the long press, past the wait an engine that says nothing reads after (`HOLD`) | 3 | `dwelt(page, HOLD)` |
| A finger's hold, which only the long press ends | 4 | nothing: the page reads no time there |
| Focus a command placed, a redraw giving focus back, a long press's reading | 11 | `rendered` |
| A scroll or a window resize | 6 | `resized` for a resize, then `rendered` |

Three checks change what they read:

- A preview that goes keeps its words in the closed popover, so the
  check that the pointer moving onto Resolve's preview keeps it passed
  on a preview that had gone. It now first checks that the preview
  shows. With `onPreview` always false, the old test passed and the new
  one fails.
- `_reads` lets the last preview go and the warmth after it pass before
  the pointer comes onto the words. Its 400 ms ended inside that warmth,
  since the preview goes a dwell after the pointer leaves it.
- The two taps after a finger's hold no longer hold for a real 600 ms.
  With the panel refusing every click in a run, both fail with and
  without that time, so Chromium still counts the hold into the tap's
  run.

Bug-back checks, each a throwaway product change, reverted:

| Change | Test | Result |
|---|---|---|
| `onPreview` always false | `test_a_control_previews_its_word_and_every_key_that_presses_it` | fails at the new visibility check; the old test passed |
| a mark landing under a still pointer reads (anchor-paint.js) | `test_a_thread_that_lands_under_a_still_pointer_previews_nothing` | fails |
| a titled element previews to a pointer | `test_a_title_stays_its_writers` | fails |
| focus any command places previews | `test_a_walk_s_landing_previews_nothing_and_tab_reads_it` | fails |
| `decide` coalesces nothing | `test_a_window_resize_decides_once_where_a_preview_stands` | fails |
| every engine reads a hold after `HOLD` | `test_a_finger_s_hold_reads_and_its_release_presses_nothing` | fails |
| the panel refuses every click in a run | both tap tests | fail, with and without the 600 ms |

Every changed test passes in Chromium and Firefox, and one per row of
the first table also at `--cpu-throttle 10`.
# Conflicts:
#	tests/conftest.py
#	tests/interact_support.py
leaf-agent
leaf-agent previously approved these changes Nov 14, 2026
leaf-agent
leaf-agent previously approved these changes Nov 14, 2026
leaf-agent
leaf-agent previously approved these changes Nov 15, 2026
leaf-agent
leaf-agent previously approved these changes Nov 15, 2026
leaf-agent
leaf-agent previously approved these changes Nov 15, 2026
leaf-agent
leaf-agent previously approved these changes Nov 15, 2026
# Conflicts:
#	tests/browser/controls/test_live_samples.py
#	tests/browser/controls/test_previews.py
@max-sixty
max-sixty merged commit bbf23f3 into main Nov 15, 2026
5 checks passed
@max-sixty
max-sixty deleted the test-isolation branch November 15, 2026 18:13
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