Files
wehub-resource-sync 4b6817381b
Benchmark image — build + push to ECR (any adapter) / build + push (push) Waiting to run
CI / quality (ubuntu-latest) (push) Waiting to run
CI / test (tools-runtime) (push) Waiting to run
CI / test (e2e-general) (push) Waiting to run
CI / test (cli-runtime) (push) Waiting to run
CI / test (e2e-provider-and-openclaw) (push) Waiting to run
CI / test (integrations-and-misc) (push) Waiting to run
CI / coverage-report (push) Blocked by required conditions
CI / test-kubernetes (push) Waiting to run
CI / should-run-thorough (push) Waiting to run
CI / test-thorough (cloudwatch-demo) (push) Blocked by required conditions
CI / test-thorough (flink-ecs) (push) Blocked by required conditions
CI / test-thorough (upstream-lambda) (push) Blocked by required conditions
CI / test-thorough (prefect-ecs-fargate) (push) Blocked by required conditions
CodeQL / Analyze (python) (push) Waiting to run
Release / build-binaries (zip, opensre.exe, onefile, windows-latest, windows-x64) (push) Blocked by required conditions
Release / publish-release (push) Blocked by required conditions
Release / publish-main-release (push) Blocked by required conditions
Release / prepare (push) Waiting to run
Release / verify (push) Blocked by required conditions
Release / build-python-dist (push) Blocked by required conditions
Release / build-binaries (tar.gz, opensre, onedir, macos-15-intel, darwin-x64) (push) Blocked by required conditions
Release / build-binaries (tar.gz, opensre, onedir, macos-latest, darwin-arm64) (push) Blocked by required conditions
Release / build-binaries (tar.gz, opensre, onedir, ubuntu-22.04, linux-x64) (push) Blocked by required conditions
Release / build-binaries (tar.gz, opensre, onedir, ubuntu-22.04-arm, linux-arm64) (push) Blocked by required conditions
Synthetic Deterministic Tests / Synthetic offline (deterministic) (push) Waiting to run
Interactive Shell Live (PR + post-merge) / turn-checks (no-LLM) (push) Waiting to run
Interactive Shell Live (PR + post-merge) / turn-live shard ${{ matrix.shard_index }} (push) Waiting to run
CI (OpenClaw E2E) / openclaw test (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:10:45 +08:00

66 lines
2.2 KiB
Python

"""Tests for the inline turn spinner in runtime.core.state."""
from __future__ import annotations
import re
import time
from surfaces.interactive_shell.runtime.core.state import SpinnerState
_GLYPHS = SpinnerState._SPINNER_FRAMES
def _glyph(spinner: SpinnerState) -> str:
rendered = spinner.inline_spinner_ansi()
match = re.search("|".join(map(re.escape, _GLYPHS)), rendered)
assert match is not None, f"no spinner glyph in {rendered!r}"
return match.group(0)
def test_spinner_frame_is_a_function_of_elapsed_time_not_call_count() -> None:
"""Regression: the glyph must animate no matter how often it is rendered.
prompt_toolkit evaluates the prompt message callable several times per
render pass. A per-call frame counter advanced exactly one full cycle per
visible render (10 evals x 10 frames), so the on-screen glyph never
changed. Deriving the frame from elapsed time makes repeated evaluations
idempotent and guarantees the animation advances between renders.
"""
spinner = SpinnerState()
spinner.start()
# Repeated evaluations inside one render pass: same frame every time.
first = _glyph(spinner)
assert all(_glyph(spinner) == first for _ in range(10))
# A frame interval later the glyph must have advanced.
spinner.started_at -= SpinnerState._FRAME_INTERVAL_S * 1.01
assert _glyph(spinner) != first
# Over a full cycle of elapsed time, every frame is visited in order.
spinner.start()
seen = []
for step in range(len(_GLYPHS)):
spinner.started_at = time.monotonic() - step * SpinnerState._FRAME_INTERVAL_S * 1.001
seen.append(_glyph(spinner))
assert seen == list(_GLYPHS)
def test_spinner_renders_elapsed_seconds_and_cancel_hint() -> None:
spinner = SpinnerState()
spinner.start()
spinner.started_at = time.monotonic() - 8.2
rendered = spinner.inline_spinner_ansi()
assert "(8s)" in rendered
assert "esc to cancel" in rendered
def test_spinner_empty_when_not_streaming() -> None:
spinner = SpinnerState()
assert spinner.inline_spinner_ansi() == ""
spinner.start()
spinner.stop()
assert spinner.inline_spinner_ansi() == ""