Skip to content

e2e: diagnose and reduce flakiness in browser login TOTP handling - #1778

Draft
adombeck wants to merge 3 commits into
mainfrom
1777-e2e-browser-login-test-flakily
Draft

e2e: diagnose and reduce flakiness in browser login TOTP handling#1778
adombeck wants to merge 3 commits into
mainfrom
1777-e2e-browser-login-test-flakily

Conversation

@adombeck

@adombeck adombeck commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Tries to fix the e2e browser login test flakiness described in #1777. TOTP-based logins were intermittently failing with no way to tell whether a rejected code was actually wrong, stale, or never made it into the page at all.

See commit messages for details.

adombeck and others added 2 commits August 12, 2026 14:06
generate_totp() only returned the code string, discarding the time
step and generation time it was derived from. Callers had no way to
tell whether a code was rejected because it was stale (submitted too
close to the end of its validity window) or because it was wrong from
the start, which made flaky TOTP failures hard to diagnose.

Introduce TOTPCode, a small dataclass carrying the code alongside its
time step and generation timestamp, with helpers to compute its
remaining validity and age. generate_totp() is kept as a thin wrapper
around the new generate_totp_details() for existing callers.

While here, bump the minimum validity a freshly generated code must
have left from 5 to 10 seconds, giving more headroom to type it in
and have the identity provider validate it before it expires.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Key events sent to the WebKit view are handled asynchronously, so
there was no way to confirm that typed text actually reached the page
before submitting it. A dropped or misdirected key event silently
turned into a wrong TOTP code, indistinguishable from one rejected for
other reasons.

Add run_javascript_sync() to execute JavaScript in the page and block
until it returns or times out, get_focused_input_value() to read the
value of document.activeElement, and wait_for_focused_input_value() to
poll until the field matches an expected value, since the typed text
can lag behind the key events that produced it.

After typing a TOTP code, read the focused input back and compare it
to the expected value; retype once if it doesn't match before giving
up. Also log the code, its time step and remaining validity when it is
submitted, and log the same details when a code is rejected, so a
stale code can be told apart from one that was wrong from the start.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@adombeck adombeck added the e2e-tests This issue is related to end-to-end tests / Run end-to-end tests on this pull request label Aug 12, 2026
The release matrix shares one broker MFA account, but serializing each full e2e
job unnecessarily multiplies the test duration. Acquire a broker-specific,
lease-based R2 lock only while Browser.Login runs so other tests and brokers
remain parallel. The lock is an experiment for an observed correlation, not a
confirmed explanation or guaranteed fix.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@adombeck
adombeck force-pushed the 1777-e2e-browser-login-test-flakily branch from 79cc5aa to 51636c9 Compare August 18, 2026 11:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

e2e-tests This issue is related to end-to-end tests / Run end-to-end tests on this pull request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant