Skip to content

Fix flaky TestHuhPrompterMultiSelectWithSearchPersistence on slow architectures#13675

Open
pdostal wants to merge 1 commit into
cli:trunkfrom
pdostal:fix/multi-select-search-race-s390x
Open

Fix flaky TestHuhPrompterMultiSelectWithSearchPersistence on slow architectures#13675
pdostal wants to merge 1 commit into
cli:trunkfrom
pdostal:fix/multi-select-search-race-s390x

Conversation

@pdostal

@pdostal pdostal commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

The test was using a fixed 50ms sleep (waitForOptions()) to wait for an async bubbletea search goroutine before sending the next keystroke. On slow architectures such as s390x under QEMU emulation, the goroutine scheduling and event loop round-trip can exceed 50ms, causing the enter key to arrive while m.loading is still true. In that state the field silently drops all keystrokes, the form never advances, and the 5s overall deadline fires with "form.Run() did not complete in time".

The fix replaces the blind sleep with proper channel-based synchronization. An onSearchDone func() hook is added to multiSelectSearchField (nil in production, set only in tests) and called at the end of applySearchResult. A new test helper waitForSearch(field) wires a one-shot sync.Once-guarded channel into that hook and blocks until it fires - guaranteeing the search is truly complete before the next step is sent, regardless of scheduler timing or machine speed.

Error log

[  770s] --- FAIL: TestHuhPrompterMultiSelectWithSearchPersistence (5.42s)
[  770s]     --- FAIL: TestHuhPrompterMultiSelectWithSearchPersistence/selections_persist_after_changing_search_query (5.31s)                                                                                                      Context
[  770s]         huh_prompter_test.go:478: form.Run() did not complete in time                                                                                                                                                     54,494 tokens
[  770s] FAIL                                                                                                                                                                                                                      5% used
[  770s] FAIL  github.com/cli/cli/v2/internal/prompter  11.841s

@pdostal pdostal requested a review from a team as a code owner June 17, 2026 13:44
@pdostal pdostal requested review from BagToad and Copilot June 17, 2026 13:44
@github-actions

Copy link
Copy Markdown

Thanks for your pull request! Unfortunately, it doesn't meet the requirements for review:

  • No linked help wanted issue found in PR description

Please update your PR to address the above. This PR will be automatically closed in 4 days if these requirements are not met.

Full contribution requirements
  1. Include a detailed description of what this PR does
  2. Link to an issue with the help wanted label (use Fixes #123 or Closes #123)

@github-actions github-actions Bot added external pull request originating outside of the CLI core team needs-triage needs to be reviewed labels Jun 17, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

This PR improves the reliability of Bubble Tea-based prompt tests by replacing fixed sleeps with a deterministic synchronization hook that waits for async search completion.

Changes:

  • Add a test-only onSearchDone callback hook to multiSelectSearchField, invoked when async search results are applied.
  • Extend the test interaction harness to support blocking “wait” steps (waitFn) in addition to time-based delays.
  • Update the multi-select-with-search persistence test to wait for async search completion before submitting.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
internal/prompter/multi_select_with_search.go Adds a callback hook fired on search completion to enable deterministic test synchronization.
internal/prompter/huh_prompter_test.go Adds wait-capable interaction steps and uses them to remove timing flakiness in async search tests.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread internal/prompter/multi_select_with_search.go Outdated
Comment thread internal/prompter/multi_select_with_search.go Outdated
Comment thread internal/prompter/huh_prompter_test.go
Comment thread internal/prompter/multi_select_with_search.go Outdated
@pdostal pdostal force-pushed the fix/multi-select-search-race-s390x branch from 58f5399 to 5c33128 Compare June 17, 2026 13:56
…tures

Replace fixed-duration sleep with a channel-based synchronization hook
so the test waits for the async search to genuinely complete before
sending the next keystroke. The previous 50ms waitForOptions() was too
short on slow architectures such as s390x under QEMU emulation, causing
the enter key to be dropped while the field was still loading.
@pdostal pdostal force-pushed the fix/multi-select-search-race-s390x branch from 5c33128 to 300cae9 Compare June 17, 2026 14:03
@pdostal

pdostal commented Jun 19, 2026

Copy link
Copy Markdown
Contributor Author

Hello @williammartin, I remember we already did similar fixes together, can you help here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

external pull request originating outside of the CLI core team needs-triage needs to be reviewed unmet-requirements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants