b255a0f90e
Renames src/fabledassistant -> src/scribe and all imports, plus the default DB name and DB user/password (fabled -> scribe) in config + compose. 952 refs / 154 files. Reverses the old 'internal name stays fabledassistant' convention. Code-only: live databases are still physically named 'fabledassistant'. Deployed environments must set POSTGRES_DB / POSTGRES_USER (or rename the DB) since the defaults now resolve to 'scribe'. Repo (FabledScribe), git host (fabledsword), MCP (fabled-git) and the image name (fabledscribe) are intentionally unchanged. ruff check src/ clean locally; CI (typecheck + pytest) is the gate. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
67 lines
2.4 KiB
Python
67 lines
2.4 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
|
|
assert _task_row(n) == {
|
|
"id": 5, "title": "Wire reminders", "status": "in_progress", "priority": "none",
|
|
}
|
|
|
|
|
|
@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, "_upcoming_events", AsyncMock(return_value=["evt"])), \
|
|
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"],
|
|
"upcoming_events": ["evt"],
|
|
"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, "_upcoming_events", 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"]
|