From 52a853f5c37b752fe1256d1ffe358ab68329524d Mon Sep 17 00:00:00 2001 From: Teknium <127238744+teknium1@users.noreply.github.com> Date: Sun, 28 Jun 2026 04:16:25 -0700 Subject: [PATCH] fix(test): pin monotonic clock in spinner-elapsed test to fix CI flake (#54203) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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). --- tests/cli/test_cli_status_bar.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/tests/cli/test_cli_status_bar.py b/tests/cli/test_cli_status_bar.py index 3edc1e94c80..1899f0dd78e 100644 --- a/tests/cli/test_cli_status_bar.py +++ b/tests/cli/test_cli_status_bar.py @@ -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(")")