Skip to content

Poll TTY echo mode instead of sleeping in password tests#13305

Merged
williammartin merged 3 commits into
cli:trunkfrom
pdostal:fix/poll-tty-echo-mode-in-password-tests
May 7, 2026
Merged

Poll TTY echo mode instead of sleeping in password tests#13305
williammartin merged 3 commits into
cli:trunkfrom
pdostal:fix/poll-tty-echo-mode-in-password-tests

Conversation

@pdostal

@pdostal pdostal commented Apr 28, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Replace the fixed-duration time.Sleep with a polling loop that checks the actual TTY echo flag before sending password input
  • Eliminates the race condition where huh has not yet disabled echo mode, which caused flaky test failures in slow environments (e.g. isolated build containers)
  • Follow-up to Fix flaky accessible prompter Password test timeout #13304, as suggested by @williammartin

Details

The previous approach used a 100 * time.Microsecond sleep to give huh time to set EchoModeNone on the PTY. This was inherently racy - in constrained environments the sleep was too short, and increasing it was just a less-racy guess.

The new waitForEchoDisabled helper polls the TTY's termios flags every millisecond until ECHO is cleared, with a generous 5-second timeout. This is deterministic - we only proceed once echo mode is actually disabled.

Platform-specific ioctl constants (TCGETS on Linux, TIOCGETA on macOS) are defined in small separate files. golang.org/x/sys is already a dependency.

Changed files

  • internal/prompter/accessible_prompter_test.go - replace sleep with polling, add waitForEchoDisabled helper
  • internal/prompter/echo_test_linux.go - define ioctlGetTermios = unix.TCGETS (new file)
  • internal/prompter/echo_test_darwin.go - define ioctlGetTermios = unix.TIOCGETA (new file)

Copilot AI review requested due to automatic review settings April 28, 2026 17:50
@pdostal pdostal requested a review from a team as a code owner April 28, 2026 17:50
@pdostal pdostal requested a review from williammartin April 28, 2026 17:50
@github-actions github-actions Bot added unmet-requirements external pull request originating outside of the CLI core team needs-triage needs to be reviewed labels Apr 28, 2026
@github-actions

Copy link
Copy Markdown

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

  • None of the referenced issues have the help wanted label

Please update your PR to address the above. 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 if it resolves the issue)

This PR will be automatically closed in 7 days if these requirements are not met.

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

This PR removes a fixed sleep in the accessible prompter password/token tests and replaces it with a deterministic wait that polls the PTY’s echo flag until it’s actually disabled, reducing test flakiness in slow environments.

Changes:

  • Replace time.Sleep before sending password/token input with a waitForEchoDisabled polling helper.
  • Add OS-specific ioctl constants for retrieving termios flags on Linux and macOS.
  • Introduce termios polling via golang.org/x/sys/unix in the tests.

Reviewed changes

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

File Description
internal/prompter/accessible_prompter_test.go Adds waitForEchoDisabled and uses it in Password/AuthToken tests instead of a fixed sleep.
internal/prompter/echo_test_linux.go Adds Linux ioctl constant for IoctlGetTermios.
internal/prompter/echo_test_darwin.go Adds macOS ioctl constant for IoctlGetTermios.

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

Comment thread internal/prompter/echo_linux_test.go
Comment thread internal/prompter/echo_darwin_test.go
Comment thread internal/prompter/accessible_prompter_test.go
Comment thread internal/prompter/accessible_prompter_test.go Outdated
@pdostal pdostal force-pushed the fix/poll-tty-echo-mode-in-password-tests branch from 9afa693 to 119ea9f Compare April 28, 2026 18:02
@github-actions github-actions Bot removed the needs-triage needs to be reviewed label May 3, 2026
@github-actions github-actions Bot closed this May 3, 2026
@williammartin williammartin reopened this May 3, 2026
@github-actions

github-actions Bot commented May 3, 2026

Copy link
Copy Markdown

This pull request appears to be a resubmission of a recently closed PR (#13305) that did not meet the contribution requirements.

Rather than resubmitting, please ensure your contribution:

  1. References an issue with the help wanted label
  2. Includes a detailed description

If you believe this is a different contribution, please comment with details and we'll be happy to reopen.

@github-actions github-actions Bot closed this May 3, 2026
@github-actions github-actions Bot added the needs-triage needs to be reviewed label May 3, 2026
@williammartin

Copy link
Copy Markdown
Member

Oops, didn't triage this in time, but I do want it.

@williammartin williammartin reopened this May 3, 2026
@github-actions github-actions Bot added needs-triage needs to be reviewed unmet-requirements and removed needs-triage needs to be reviewed labels May 3, 2026
@github-actions

github-actions Bot commented May 3, 2026

Copy link
Copy Markdown

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

  • None of the referenced issues have the help wanted label

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)

pdostal and others added 3 commits May 7, 2026 20:20
Replace the fixed-duration sleep with a polling loop that checks the
actual TTY echo flag before sending password input. This eliminates the
race condition where huh has not yet disabled echo mode, which caused
flaky test failures in slow environments.

Follow-up to cli#13304.
- Rename echo_test_{linux,darwin}.go to echo_{linux,darwin}_test.go so
  they are only compiled during tests
- Narrow build tag from !windows to linux || darwin to avoid compile
  failures on other Unix platforms
- Return error from waitForEchoDisabled instead of calling t.Fatal,
  since the function is called from goroutines where FailNow would only
  terminate the calling goroutine
The Go toolchain infers constraints from _darwin/_linux filename suffixes,
but explicit //go:build tags make the constraint visible without relying
on filename conventions, consistent with modern Go style.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@williammartin williammartin force-pushed the fix/poll-tty-echo-mode-in-password-tests branch from 119ea9f to a44721d Compare May 7, 2026 18:24

@williammartin williammartin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks a lot!

@williammartin williammartin enabled auto-merge May 7, 2026 18:25
@williammartin williammartin merged commit b698aa7 into cli:trunk May 7, 2026
11 checks passed
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 ready-for-review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants