loosecanvas / tests /test_friendly_turn_error.py
Joshua Sundance Bailey
fix(ui): HF layout (iframe vh feedback) + selector bug + CI + trust legibility
7094269
Raw
History Blame Contribute Delete
1.19 kB
"""Unit tests for main._friendly_turn_error — the chat-lane turn-error mapper.
The HF Space L4 auto-sleeps, so the first turn after idle hits a waking server
(connection/timeout). Those must read as a reassuring "waking up" note; anything
else gets a generic retry note, and the raw exception text is never surfaced.
"""
from __future__ import annotations
import pytest
from loosecanvas.main import _friendly_turn_error
@pytest.mark.parametrize(
"exc",
[
ConnectionError("Connection refused"),
TimeoutError("timed out"),
RuntimeError("Max retries exceeded with url"),
RuntimeError("HTTP 503 Service Unavailable"),
RuntimeError("failed to connect to localhost:8080"),
],
)
def test_connection_errors_map_to_waking_message(exc: Exception) -> None:
msg = _friendly_turn_error(exc)
assert "wake up" in msg or "waking" in msg.lower()
# Never leak the raw exception text.
assert str(exc) not in msg
def test_other_errors_map_to_generic_retry() -> None:
msg = _friendly_turn_error(ValueError("some internal detail x7y8"))
assert "try again" in msg
assert "x7y8" not in msg # raw exception text not surfaced