Skip to content

fix(test): gate switch_picker stability on matcher row count, not preview vscroll - #2729

Merged
max-sixty merged 1 commit into
mainfrom
debug-picker-preview-flake
May 12, 2026
Merged

max-sixty merged 1 commit into
mainfrom
debug-picker-preview-flake

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

Summary

The flake's mechanism was that skim's matcher runs on a separate thread and, under heavy parallel load (the failure first surfaced in a 3641-test nextest run), can lag seconds behind the prompt repaint. The test types feature, skim renders > feature into the query line, but the items list still has both rows. The prior consistency check (display_matches_count, added in #2345) was supposed to detect exactly this and reject "stable" screens with row counts that disagreed with skim's N/M counter — except no_info(true) hides the real counter, so the regex was actually matching the previewer's {vscroll_offset}/{content.len()} indicator (e.g. 1/28). That coincidentally equalled visible_list_rows == 1 in the filtered steady state, so it looked like it worked, but under matcher lag the wait simply timed out at 30 s and wait_for_stable_with_content warned-and-proceeded — capturing the stale unfiltered screen with @ main still visible.

Fix

Replaced the indirect counter-parsing gate with an explicit expected_rows: Option<usize> parameter threaded through the input tuple and wait_for_stable_with_content. Stability now requires visible_list_rows == expected_rows when set, and the timeout path panics with a diagnostic dump (instead of silently proceeding) so a future matcher-lag regression fails at the actual cause rather than at the snapshot assertion downstream.

The four (feature, …) filter tests (uncommitted, log, main_diff, summary) and the four (target, …) selection tests now pass Some(1). Tests that don't depend on a specific row count pass None.

parse_match_count and display_matches_count are deleted — they were checking the wrong thing.

Test plan

  • cargo run -- hook pre-merge --yes — 3666 tests pass.
  • Switch picker suite (19 tests) passes under --test-threads=8.
  • Stress repro: the original flake reproduced ~1/19 in the very first repro attempt under contention, then did not reproduce in 100+ isolated iterations nor 14 iterations under explicit CPU stress. The fix is hypothesis-based but firmly grounded in the captured .snap.new (both rows visible despite the filter) plus skim's source (matcher on a separate thread; previewer's vscroll indicator that the old regex was actually matching). Closes Flaky: test_switch_picker_preview_panel_main_diff on macOS #2334 (which test(switch_picker): gate stability on matcher/display consistency #2345 only accidentally guarded).

… vscroll

Replace the indirect `display_matches_count` consistency check with an
explicit `expected_rows` parameter on `wait_for_stable_with_content` and on
each input tuple. The four `(feature, …)` filter tests now pass `Some(1)`, so
the helper actively waits for skim's matcher to narrow the list before
snapshotting and panics with a diagnostic dump (not warn-and-proceed) if it
never does.

The prior check parsed `\d+/\d+` off the right edge of the screen, intending
to read skim's match counter. But the picker uses `no_info(true)`, so the
real counter is hidden — the regex was actually matching the previewer's
`{vscroll_offset}/{content.len()}` indicator (e.g. `1/28`). That happened to
equal `visible_list_rows == 1` in the steady filtered state, so it appeared
to work, but it offered no real protection during matcher lag: under heavy
parallel load skim's matcher (own thread) lags seconds behind the prompt
repaint, the wait timed out at 30 s, and `wait_for_stable_with_content`
silently warned-and-proceeded, capturing the stale pre-filter screen with
`@ main` still visible.

Closes #2334 (reopened — #2345 only accidentally guarded the steady state).

Co-Authored-By: Claude <[email protected]>
@max-sixty
max-sixty merged commit 3cc6879 into main May 12, 2026
33 checks passed
@max-sixty
max-sixty deleted the debug-picker-preview-flake branch May 12, 2026 00:55
max-sixty added a commit that referenced this pull request May 12, 2026
…nters (#2733)

Two comment-only fixes following #2729 — no behavioral change, no
snapshot change.

- `is_skim_ready` no longer claims skim "displays item count like 1/3";
the picker uses `no_info(true)`, so it doesn't render that.
- The snapshot filter that normalizes the trailing `N/M` on the preview
pane's first line now correctly attributes it to skim's previewer
vertical-scroll indicator (`{vscroll_offset}/{content.len()}`, drawn in
reverse video at the right edge — see
`skim::previewer::Previewer::draw`), rather than the matcher's
matched/total counter. The earlier comment's misattribution is what led
#2345's stability check to parse the wrong thing; #2729 fixed the check,
this fixes the comment so the misunderstanding doesn't resurface. The
filter regex and replacement string are untouched.

Co-authored-by: Claude <[email protected]>
max-sixty added a commit that referenced this pull request May 15, 2026
… row count (#2767)

The `expected_rows: Some(1)` gate (added in #2729) waits for skim's row
list to filter down after the test types its query. But skim's matcher
runs on a separate thread, and under heavy parallel macOS load the row
redraw can lag the matcher by more than the 30s timeout — even though
skim's selection cursor and preview pane have already advanced to the
matched item. The gate then panics with `saw 2`, while the test would
have selected the right item anyway: Enter acts on the cursor, not on
which rows happen to be painted. This is the flake reported on
`test_switch_picker_no_cd_prints_branch_without_switching` (local) and
`test_switch_picker_switch_to_existing_worktree` (CI on #2764).

These three `target`-selection tests don't snapshot the list panel, so
they don't need the filter applied — only the cursor on the right item.
They now gate on the preview-pane text that's emitted once skim's
selection moves to target-branch, which tracks the cursor rather than
the lagging redraw. If selection genuinely never moves, the content gate
still fails loudly, so the diagnostic value of #2729 is preserved.

Reproduced the original flake at ~2/5 with 5 parallel `cargo test
test_switch_picker -- --test-threads=20`. After the fix: 0 occurrences
of the line-528 panic across 48-run focused stress, the original 5×20
recipe, and a 16× pathological run. The `preview_panel_*` snapshot tests
share the same matcher-lag root cause but genuinely need the filter
applied (they snapshot the list); they weren't in scope here and remain
as follow-up.

Also deletes `test_switch_picker_no_cd_suppresses_directive` — a strict
subset of `test_switch_picker_no_cd_prints_branch_without_switching`
(identical setup/env/inputs, both assert exit 0 + empty cd file; the
latter additionally asserts the printed branch name). Same belief, no
coverage lost. Net diff is a reduction.

Co-authored-by: Claude Opus 4.7 (1M context) <[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.

Flaky: test_switch_picker_preview_panel_main_diff on macOS

2 participants