fix(test): pin monotonic clock in spinner-elapsed test to fix CI flake (#54203)

test_spinner_elapsed_format_is_fixed_width_to_reduce_wrap_jitter derived
_tool_start_time from the live time.monotonic() clock (now - 65.2 / now - 9.2).
monotonic()'s epoch is arbitrary — on a host where monotonic() < 65.2 (fresh
subprocess on a freshly-booted CI runner) the start time went negative, the
(t0 > 0) guard in _render_spinner_text() dropped the '(elapsed)' suffix, and
short.split('(',1)[1] raised IndexError: list index out of range. Deterministic
given a small clock, so it would keep flaking, not clear on rerun.

Pin time.monotonic to a fixed 1000.0 and offset _tool_start_time from it so both
the <60s and >=60s paths always render the elapsed suffix regardless of the
runner's monotonic epoch.

Pre-existing main flake (surfaced in CI test slice 1/8).
This commit is contained in:
Teknium 2026-06-28 04:16:25 -07:00 committed by GitHub
parent 8e356eccea
commit 52a853f5c3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -400,13 +400,20 @@ class TestCLIStatusBar:
cli_obj = _make_cli()
cli_obj._spinner_text = "running tool"
# <60s path
cli_obj._tool_start_time = time.monotonic() - 9.2
short = cli_obj._render_spinner_text()
# Pin the clock: time.monotonic()'s epoch is arbitrary (often near
# boot), so deriving _tool_start_time from the real monotonic clock
# made the test fail on hosts where monotonic() < 65.2 — the start
# time went negative, the (t0 > 0) guard in _render_spinner_text
# dropped the "(elapsed)" suffix entirely, and the split below hit an
# IndexError. A fixed clock keeps both elapsed paths deterministic.
with patch.object(cli_mod.time, "monotonic", return_value=1000.0):
# <60s path
cli_obj._tool_start_time = 1000.0 - 9.2
short = cli_obj._render_spinner_text()
# >=60s path
cli_obj._tool_start_time = time.monotonic() - 65.2
long = cli_obj._render_spinner_text()
# >=60s path
cli_obj._tool_start_time = 1000.0 - 65.2
long = cli_obj._render_spinner_text()
short_elapsed = short.split("(", 1)[1].rstrip(")")
long_elapsed = long.split("(", 1)[1].rstrip(")")