chore: import upstream snapshot with attribution
CI (OpenClaw E2E) / openclaw test (push) Has been cancelled
CI / coverage-report (push) Has been cancelled
CI / test-kubernetes (push) Has been cancelled
CI / should-run-thorough (push) Has been cancelled
CI / test-thorough (cloudwatch-demo) (push) Has been cancelled
CI / test-thorough (flink-ecs) (push) Has been cancelled
CI / test-thorough (upstream-lambda) (push) Has been cancelled
CI / test-thorough (prefect-ecs-fargate) (push) Has been cancelled
Release / build-binaries (zip, opensre.exe, onefile, windows-latest, windows-x64) (push) Has been cancelled
Benchmark image — build + push to ECR (any adapter) / build + push (push) Has been cancelled
CI / quality (ubuntu-latest) (push) Has been cancelled
CI / test (tools-runtime) (push) Has been cancelled
CI / test (e2e-general) (push) Has been cancelled
CI / test (cli-runtime) (push) Has been cancelled
CI / test (e2e-provider-and-openclaw) (push) Has been cancelled
CI / test (integrations-and-misc) (push) Has been cancelled
Release / verify (push) Has been cancelled
Release / build-python-dist (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, macos-15-intel, darwin-x64) (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, macos-latest, darwin-arm64) (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, ubuntu-22.04, linux-x64) (push) Has been cancelled
Release / publish-release (push) Has been cancelled
Release / publish-main-release (push) Has been cancelled
Interactive Shell Live (PR + post-merge) / turn-checks (no-LLM) (push) Has been cancelled
CodeQL / Analyze (python) (push) Has been cancelled
Interactive Shell Live (PR + post-merge) / turn-live shard ${{ matrix.shard_index }} (push) Has been cancelled
Release / prepare (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, ubuntu-22.04-arm, linux-arm64) (push) Has been cancelled
Synthetic Deterministic Tests / Synthetic offline (deterministic) (push) Has been cancelled
CI (OpenClaw E2E) / openclaw test (push) Has been cancelled
CI / coverage-report (push) Has been cancelled
CI / test-kubernetes (push) Has been cancelled
CI / should-run-thorough (push) Has been cancelled
CI / test-thorough (cloudwatch-demo) (push) Has been cancelled
CI / test-thorough (flink-ecs) (push) Has been cancelled
CI / test-thorough (upstream-lambda) (push) Has been cancelled
CI / test-thorough (prefect-ecs-fargate) (push) Has been cancelled
Release / build-binaries (zip, opensre.exe, onefile, windows-latest, windows-x64) (push) Has been cancelled
Benchmark image — build + push to ECR (any adapter) / build + push (push) Has been cancelled
CI / quality (ubuntu-latest) (push) Has been cancelled
CI / test (tools-runtime) (push) Has been cancelled
CI / test (e2e-general) (push) Has been cancelled
CI / test (cli-runtime) (push) Has been cancelled
CI / test (e2e-provider-and-openclaw) (push) Has been cancelled
CI / test (integrations-and-misc) (push) Has been cancelled
Release / verify (push) Has been cancelled
Release / build-python-dist (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, macos-15-intel, darwin-x64) (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, macos-latest, darwin-arm64) (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, ubuntu-22.04, linux-x64) (push) Has been cancelled
Release / publish-release (push) Has been cancelled
Release / publish-main-release (push) Has been cancelled
Interactive Shell Live (PR + post-merge) / turn-checks (no-LLM) (push) Has been cancelled
CodeQL / Analyze (python) (push) Has been cancelled
Interactive Shell Live (PR + post-merge) / turn-live shard ${{ matrix.shard_index }} (push) Has been cancelled
Release / prepare (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, ubuntu-22.04-arm, linux-arm64) (push) Has been cancelled
Synthetic Deterministic Tests / Synthetic offline (deterministic) (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
"""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() == ""
|
||||
Reference in New Issue
Block a user