File size: 2,555 Bytes
cd16ba1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
05863a5
 
 
 
 
 
 
 
 
 
 
 
 
 
00fa796
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
def test_status_badge_covers_every_status():
    """t() defaults to English outside a Streamlit runtime (see dashboard/i18n.py::t
    docstring), so the English label is what a pytest-run assertion can check."""
    from dashboard.continuity_view import _status_badge
    labels = {"new": "New", "ongoing": "Ongoing", "escalated": "Escalated", "resolved": "Resolved", "stale": "Stale"}
    for status, label in labels.items():
        html = _status_badge(status)
        assert "<span" in html
        assert label in html


def test_partition_threads_groups_open_before_closed_and_preserves_order():
    from dashboard.continuity_view import _partition_threads

    threads = [
        {"thread_id": "a", "status": "resolved"},
        {"thread_id": "b", "status": "ongoing"},
        {"thread_id": "c", "status": "new"},
        {"thread_id": "d", "status": "stale"},
        {"thread_id": "e", "status": "escalated"},
    ]
    open_threads, closed_threads = _partition_threads(threads)
    assert [t["thread_id"] for t in open_threads] == ["b", "c", "e"]
    assert [t["thread_id"] for t in closed_threads] == ["a", "d"]


def test_partition_threads_empty_list():
    from dashboard.continuity_view import _partition_threads
    assert _partition_threads([]) == ([], [])


def test_render_swallows_threads_db_failure(monkeypatch, capsys):
    """A threads_db failure (e.g. 'database is locked' on the shared HF Space)
    must not abort rendering the rest of the page -- render() logs and returns,
    matching dashboard/verdict.py::_render_brief_diff's fail-closed pattern."""
    from dashboard import continuity_view

    def _boom(ticker):
        raise RuntimeError("database is locked")

    monkeypatch.setattr("storage.threads_db.list_all_threads", _boom)
    continuity_view.render({"ticker": "AAPL"})  # must not raise
    assert "database is locked" in capsys.readouterr().err


def test_render_compact_forwards_to_explained_header(monkeypatch):
    """compact=True must reach the header markup, not just be accepted and dropped."""
    from dashboard import continuity_view
    monkeypatch.setattr("storage.threads_db.list_all_threads", lambda ticker: [])
    captured = {}
    original = continuity_view.st.markdown

    def _spy(html, **kwargs):
        captured.setdefault("html", []).append(html)
        return original(html, **kwargs)

    monkeypatch.setattr(continuity_view.st, "markdown", _spy)
    continuity_view.render({"ticker": "AAPL"}, compact=True)
    assert any("margin:4px 0 10px" in html for html in captured["html"])