Skip to content

Fix flaky accessible prompter Password test timeout#13304

Merged
williammartin merged 1 commit into
cli:trunkfrom
pdostal:fix/accessible-prompter-password-test-timeout
Apr 28, 2026
Merged

Fix flaky accessible prompter Password test timeout#13304
williammartin merged 1 commit into
cli:trunkfrom
pdostal:fix/accessible-prompter-password-test-timeout

Conversation

@pdostal

@pdostal pdostal commented Apr 28, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Increase beforePasswordSendTimeout from 100 * time.Microsecond (0.1ms) to 100 * time.Millisecond (100ms) in TestAccessiblePrompter
  • The previous 100 microsecond delay was insufficient for huh to disable echo mode on the PTY before input was sent, causing the password to be echoed to the terminal and the subsequent regex assertion to fail
  • This race condition manifests in slow or constrained environments such as network-isolated build containers (e.g. openSUSE OBS)

Details

The TestAccessiblePrompter/Password subtest sends a password to the terminal after a brief delay (beforePasswordSendTimeout) that gives huh time to set EchoModeNone on the PTY. With only 100 microseconds, the echo mode is not yet disabled when input arrives, so the password appears in the terminal output and the assertion that verifies the password is hidden fails:

expect.go:76: Failed to find ["^(\\x1b\\[\\d;]*m)* \\r\\n\\r\\n$"] in "\x1b[m 12345abcdefg\r\n\r\n\r\n": read |0: i/o timeout

Increasing to 100 milliseconds adds negligible overhead (at most 300ms total across the 3 uses of this timeout) while providing sufficient headroom for the PTY echo mode to be configured.

The beforePasswordSendTimeout was set to 100 microseconds, which is
insufficient for huh to disable echo mode on the PTY in slow or
constrained environments (e.g. network-isolated build containers).
Increase to 100 milliseconds to avoid the race condition.
Copilot AI review requested due to automatic review settings April 28, 2026 16:26
@pdostal pdostal requested a review from a team as a code owner April 28, 2026 16:26
@pdostal pdostal requested a review from babakks April 28, 2026 16:26
@github-actions

Copy link
Copy Markdown

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

  • No linked help wanted issue found in PR description

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.

@github-actions github-actions Bot added external pull request originating outside of the CLI core team needs-triage needs to be reviewed labels Apr 28, 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

This PR fixes a flaky TestAccessiblePrompter/Password subtest by increasing the delay used before sending password input, giving the PTY time to have echo disabled before keystrokes are written.

Changes:

  • Increase beforePasswordSendTimeout from 100µs to 100ms to reduce race-related flakes in password/token prompt tests.

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

@williammartin

Copy link
Copy Markdown
Member

No need for an issue.

@williammartin

Copy link
Copy Markdown
Member

I'm gonna approve this because as you say, it's negligible extra cost in test run time. However, do you have a reliable reproduction of this failure? I think I'd prefer to poll the tty to see whether the echo mode has changed instead of having this sleep at all.

Something like:

func waitForEchoDisabled(t *testing.T, tty *os.File, timeout time.Duration) {
    t.Helper()
    deadline := time.Now().Add(timeout)
    for time.Now().Before(deadline) {
        termios, err := unix.IoctlGetTermios(int(tty.Fd()), unix.TIOCGETA)
        require.NoError(t, err)
        if termios.Lflag&unix.ECHO == 0 {
            return
        }
        time.Sleep(time.Millisecond)
    }
    t.Fatal("timed out waiting for echo mode to be disabled")
}

Since this isn't run on windows. Can look into it myself as a follow up if I have time 😬

@williammartin williammartin enabled auto-merge April 28, 2026 16:38
@williammartin williammartin merged commit d762f9e into cli:trunk Apr 28, 2026
21 of 22 checks passed
@pdostal

pdostal commented Apr 28, 2026

Copy link
Copy Markdown
Contributor Author

Hello @williammartin,

thanks for the approval! The failure happens reliably in the Open Build Service (OBS) where we build openSUSE packages - builds run in isolated containers without network access, which tend to be slower and more resource-constrained.

I put together a follow-up PR implementing the polling approach you suggested: #13305. It replaces the sleep with a loop that checks the TTY's termios ECHO flag before sending input, so it's deterministic rather than a timing guess.

pdostal added a commit to pdostal/cli that referenced this pull request Apr 28, 2026
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.
williammartin pushed a commit that referenced this pull request May 7, 2026
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 #13304.
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants