from __future__ import annotations import time from blackbox.dashboard.rendering import ( esc, esc_md, fmt_duration, fmt_relative, fmt_time, passes_filter, render_log_html, shorten_paths, tool_call_html, ) from blackbox.models import LogEntry # --------------------------------------------------------------------------- # fmt_time # --------------------------------------------------------------------------- class TestFmtTime: def test_epoch_zero(self) -> None: assert "00:00:00" == fmt_time(0.0) def test_known_timestamp(self) -> None: assert "01:46:40" == fmt_time(1_000_000_000.0) def test_fractional_seconds_truncated(self) -> None: assert "00:00:00" == fmt_time(0.999) # --------------------------------------------------------------------------- # fmt_duration # --------------------------------------------------------------------------- class TestFmtDuration: def test_zero_seconds(self) -> None: assert "0s" == fmt_duration(100.0, 100.0) def test_seconds_only(self) -> None: assert "45s" == fmt_duration(0.0, 45.0) def test_minutes_and_seconds(self) -> None: assert "2m30s" == fmt_duration(0.0, 150.0) def test_hours_and_minutes(self) -> None: assert "1h30m" == fmt_duration(0.0, 5400.0) def test_negative_clamps_to_zero(self) -> None: assert "0s" == fmt_duration(100.0, 50.0) def test_none_finished_uses_current_time(self) -> None: result = fmt_duration(time.time() - 10, None) assert result.endswith("s") def test_exactly_60_seconds(self) -> None: assert "1m00s" == fmt_duration(0.0, 60.0) def test_exactly_one_hour(self) -> None: assert "1h00m" == fmt_duration(0.0, 3600.0) # --------------------------------------------------------------------------- # fmt_relative # --------------------------------------------------------------------------- class TestFmtRelative: def test_just_now(self) -> None: assert "just now" == fmt_relative(time.time()) def test_minutes_ago(self) -> None: assert "5m ago" == fmt_relative(time.time() - 300) def test_hours_ago(self) -> None: assert "2h ago" == fmt_relative(time.time() - 7200) def test_days_ago(self) -> None: assert "3d ago" == fmt_relative(time.time() - 259200) # --------------------------------------------------------------------------- # esc / esc_md # --------------------------------------------------------------------------- class TestEsc: def test_ampersand(self) -> None: assert "a & b" == esc("a & b") def test_angle_brackets(self) -> None: assert "<div>" == esc("