Skip to content

test(tui): de-flake near-tail journal-jump scroll assertion#108

Merged
pbean merged 2 commits into
bmad-code-org:mainfrom
dracic:fix/tui-journal-jump-flaky-wait
Jul 10, 2026
Merged

test(tui): de-flake near-tail journal-jump scroll assertion#108
pbean merged 2 commits into
bmad-code-org:mainfrom
dracic:fix/tui-journal-jump-flaky-wait

Conversation

@dracic

@dracic dracic commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

What

De-flake test_journal_jump_near_tail_does_not_chase_growing_log, which intermittently failed in CI with assert 188 == 0. Test-only change.

Why

The jump handler (_jump_to_log_event_scroll_log_to) defers its scroll via a set_timer until the RichLog flushes its lines and grows tall enough to scroll. The test waited on a bare is_vertical_scroll_end, which is trivially true in the pre-flush empty state (scroll_y == max_scroll_y == 0). On a fast capture it sampled anchored = 0 before the deferred scroll landed at the tail; the delayed jump then moved the view to 188, tripping assert 188 == 0.

The 188 was the legit jump landing (old content max), never tail-chasing — the product anchor (_log_follow_tail = False) was already correct. This is a test-synchronization race, not a product bug.

How

  • Gate the wait on max_scroll_y > 0 and is_vertical_scroll_end so anchored is sampled only after content is actually rendered at the tail. This is the tail-variant of the 0 < scroll_y < max_scroll_y guard the sibling test_journal_enter_jumps_to_log_position already uses.
  • Add @pytest.mark.flaky(reruns=2, reruns_delay=1), matching the two sibling journal-jump tests, for the orthogonal exclusive-poll-supersede stall the until docstring documents.

Testing

Ran the target 5× with flaky reruns disabled (-p no:flaky) → 5/5 green, so the wait fix alone is deterministic; the marker is belt-and-suspenders. Ruff check + format clean. No other test in the suite uses the bare-scroll-end wait pattern.

Summary by CodeRabbit

  • Tests
    • Improved a timing-sensitive terminal navigation test to better account for delayed log rendering.
    • Marked the test as flaky to reduce false failures in CI.
    • Strengthened the wait condition so it verifies the log has finished loading and reached the end before continuing.

The jump handler defers its scroll via a set_timer until the RichLog
flushes its lines and grows tall enough to scroll. The test waited on a
bare `is_vertical_scroll_end`, which is trivially true in the pre-flush
empty state (scroll_y == max_scroll_y == 0), so on a fast capture it
sampled anchored=0 before the deferred scroll landed at the tail. The
delayed jump then moved the view to 188, tripping `assert 188 == 0`.

Gate the wait on `max_scroll_y > 0 and is_vertical_scroll_end` so it
samples only after the content is actually rendered at the tail - the
tail-variant of the `0 < scroll_y < max_scroll_y` guard its sibling
jump test already uses. Also add the flaky marker its two sibling
journal-jump tests carry for the orthogonal poll-supersede stall.

No product change; the anchor logic was already correct.
@coderabbitai

coderabbitai Bot commented Jul 9, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@pbean, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 42 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 5fe65e8c-97f8-4955-8715-f1d5201e3208

📥 Commits

Reviewing files that changed from the base of the PR and between ff5ce6c and 3bb17c1.

📒 Files selected for processing (1)
  • tests/test_tui_app.py

Walkthrough

The journal jump test is marked flaky and now waits for the log pane to render scrollable content before checking that it is at the vertical end.

Changes

Journal jump test

Layer / File(s) Summary
Strengthen journal jump synchronization
tests/test_tui_app.py
Marks the near-tail journal jump test as flaky and waits for both non-zero scroll range and vertical-end positioning after the jump.

Estimated code review effort: 1 (Trivial) | ~3 minutes

Poem

I’m a bunny who waits by the log’s bright tail,
For flushed little lines before tests set sail.
With scroll range awake and timing made right,
The journal jump lands at the end just right.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main test-only change: de-flaking the near-tail journal-jump scroll assertion.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

The flush's own scroll_end can satisfy the settled-at-tail wait while one
deferred _scroll_log_to retry is still armed; if that fire landed after the
growth-render it would re-scroll against the grown content and re-flake the
anchor assert. Pause two timer periods so the chain provably drains at the
tail before the anchor is sampled.

@pbean pbean left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Validated end-to-end — approving. Every claim in the description checks out against the code:

  • _scroll_log_to really does defer via a 0.05s set_timer retry chain until the previously-hidden RichLog flushes (dashboard.py:302-317), and Textual's is_vertical_scroll_end is scroll_offset.y == max_scroll_y or not self.size — trivially True on an unflushed/unsized pane, exactly as diagnosed. The failure arithmetic matches too: 201 content lines − 13-row viewport = 188.
  • Product anchor confirmed correct (_log_follow_tail = False at jump; the growth-render preserves scroll_y via clear+rewrite with scroll_end=False), so this was genuinely test synchronization, not product behavior.
  • Sibling parity checks out: both other journal-jump tests carry the same flaky marker, and line 560 was the only bare scroll-end wait in the suite.

I pushed one small hardening commit on-branch (3bb17c1): the new wait can be satisfied by the flush's own scroll_end while one deferred _scroll_log_to retry is still armed (≤50 ms out). If the growth-render from _tick landed before that pending fire, the late fire would re-scroll against the grown content (~194 vs the 188 anchor) — same-shaped flake, just a narrower window. Pausing two timer periods before sampling anchored provably drains the chain at the tail. Pre-existing, not something your change introduced.

One heads-up on the testing methodology: -p no:flaky disables the flaky package, but this repo uses pytest-rerunfailures, whose plugin name is rerunfailures — so your 5× run silently still had reruns armed. -p no:rerunfailures is the flag that does what you intended. I re-ran the target 10× with it genuinely disabled (plus the drain commit): 10/10 green, so your wait fix is indeed deterministic on its own. Siblings green, trunk clean.

@pbean pbean merged commit b7afb1e into bmad-code-org:main Jul 10, 2026
8 checks passed
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