Files
FabledGrimoire/tests/test_services_dashboard.py
T
bvandeusenandClaude Opus 5.5 914f31359c
CI & Build / Python lint (push) Successful in 5s
CI & Build / Plugin hooks (push) Successful in 17s
CI & Build / TypeScript typecheck (push) Successful in 57s
CI & Build / integration (push) Successful in 1m19s
CI & Build / Python tests (push) Successful in 2m2s
CI & Build / Build & push image (push) Successful in 15s
docs(6209): the remaining test files — lessons, reply moment and shape, retrieval specs and scopes, rule doors and judgments, services, snippets, search scope; five tests renamed to their property
Docstrings, section headers and assertion messages drop the record number,
milestone or step that introduced the behaviour, and incident accounts are
restated as the present-tense failure shape. A dead pointer to a design doc
that is not in the repo is removed.

Renamed to the property they check:
  test_the_old_shape_would_be_caught -> test_a_rank_then_scope_query_is_caught
  test_a_ledger_repeat_no_longer_produces_that_case_at_all -> test_a_ledger_repeat_is_counted_not_withheld
  test_the_header_no_longer_promises_once_per_session -> test_the_header_explains_the_seen_marker
  test_the_portal_case_no_longer_stamps_one_canon_onto_a_whole_file -> test_one_canon_is_not_stamped_onto_a_whole_file
  test_the_repos_own_prose_no_longer_defines_with -> test_the_repos_own_prose_does_not_define_with
  test_the_original_regression_create_note_with_content -> test_the_real_server_refuses_content_on_create_note

Fixture and example ids stay: "note 5" in a supersession chain, "rule 156"
in an illustrative question, `#2275` as the hex-versus-citation case,
`#3244` as the example of a bare number, fixed dates in date-filter tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-21 21:44:58 -04:00

90 lines
3.2 KiB
Python

"""build_dashboard composition + helpers (services/dashboard.py).
Query semantics (ranking/caps/owner-scope) are exercised by manual smoke —
the repo's unit tests mock the DB, so SQL isn't executed here. These cover the
pure helpers and the section-isolation contract.
"""
from unittest.mock import AsyncMock, MagicMock, patch
import pytest
def test_task_row_maps_fields():
from scribe.services.dashboard import _task_row
n = MagicMock()
n.id = 5
n.title = "Wire reminders"
n.status = "in_progress"
n.priority = None
# Named, not left to MagicMock: an unset attribute is a truthy Mock, so
# the assertion would pass on a field the row never really carried
# (the reason fake_note exists).
n.task_kind = "spike"
assert _task_row(n) == {
"id": 5, "title": "Wire reminders", "status": "in_progress",
"priority": "none", "task_kind": "spike",
}
def test_task_row_carries_the_kind_so_a_row_can_show_it():
"""The field whose ABSENCE is invisible.
A dashboard row with no task_kind renders no kind badge, which looks
exactly like a list containing no issues and no spikes. The badge is
correct and the payload is short — so the guard belongs on the payload,
where the omission actually was.
"""
from scribe.services.dashboard import _task_row
n = MagicMock()
n.id = 1
n.title = "t"
n.status = "todo"
n.priority = "none"
n.task_kind = "issue"
assert _task_row(n)["task_kind"] == "issue"
@pytest.mark.asyncio
async def test_safe_returns_value_then_empty_on_error():
from scribe.services.dashboard import _safe
async def ok():
return [1, 2, 3]
async def boom():
raise RuntimeError("section blew up")
assert await _safe(ok(), []) == [1, 2, 3]
# a failing section returns the supplied empty default, not an exception
assert await _safe(boom(), []) == []
assert await _safe(boom(), {}) == {}
@pytest.mark.asyncio
async def test_build_dashboard_composes_sections():
import scribe.services.dashboard as dash
with patch.object(dash, "_active_projects", AsyncMock(return_value=["P"])), \
patch.object(dash, "_recently_completed", AsyncMock(return_value=["done"])), \
patch.object(dash, "_open_issues", AsyncMock(return_value=["iss"])), \
patch.object(dash, "_week_stats", AsyncMock(return_value={"open_total": 4})):
out = await dash.build_dashboard(user_id=1)
assert out == {
"active_projects": ["P"],
"recently_completed": ["done"],
"open_issues": ["iss"],
"week_stats": {"open_total": 4},
}
@pytest.mark.asyncio
async def test_build_dashboard_isolates_failing_section():
import scribe.services.dashboard as dash
with patch.object(dash, "_active_projects", AsyncMock(side_effect=RuntimeError("db down"))), \
patch.object(dash, "_recently_completed", AsyncMock(return_value=["done"])), \
patch.object(dash, "_open_issues", AsyncMock(return_value=[])), \
patch.object(dash, "_week_stats", AsyncMock(return_value={})):
out = await dash.build_dashboard(user_id=1)
# failing section degrades to its empty default; others still populate
assert out["active_projects"] == []
assert out["recently_completed"] == ["done"]