Files
FabledGrimoire/tests/test_list_rows_brief.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

94 lines
4.1 KiB
Python

"""List tools return rows that say what a record is, never what it says.
A list that returns every row's to_dict(), body included, runs a project's todo
list to 93-165k characters, past what an MCP client accepts as a tool result,
so the list arrives as a file to page through — the same failure enter_project
avoids by carrying a summary. A list is for choosing which record to open;
get_task / get_note read one in full.
"""
import json
from datetime import datetime, timezone
from types import SimpleNamespace
from unittest.mock import AsyncMock, patch
import pytest
from scribe.mcp.tools.notes import list_notes
from scribe.mcp.tools.systems import list_system_records
from scribe.mcp.tools.tasks import list_tasks
from scribe.services.notes import brief_row
pytestmark = pytest.mark.usefixtures("_bind_user")
STEP_PLAN = "A step plan paragraph long enough to matter. " * 110 # ~5k chars
WHEN = datetime(2026, 9, 15, tzinfo=timezone.utc)
def _row(nid: int, *, is_task: bool = True, milestone_id: int | None = 415) -> SimpleNamespace:
"""A real-shaped Note: every attribute brief_row or to_dict could read."""
return SimpleNamespace(
id=nid, title=f"Step {nid} — something worth doing", body=STEP_PLAN,
description=None, note_type="note", project_id=2, tags=["retrieval"],
updated_at=WHEN, created_at=WHEN, is_task=is_task,
status="todo" if is_task else None, task_kind="work", priority="high",
milestone_id=milestone_id if is_task else None, parent_id=None, due_date=None,
)
def test_a_task_row_names_what_it_is_and_where_it_sits_but_not_its_body():
row = brief_row(_row(7), {415: "An existing plan is found"})
assert "body" not in row
assert row["milestone_title"] == "An existing plan is found"
assert {"id", "title", "status", "task_kind", "priority", "milestone_id",
"tags", "updated_at", "project_id"} <= set(row)
# Empty optional fields are left off rather than sent as null.
assert not {"description", "parent_id", "due_date"} & set(row)
assert row["updated_at"] == WHEN.isoformat()
def test_a_note_row_carries_no_task_fields():
row = brief_row(_row(8, is_task=False))
assert "body" not in row and "status" not in row and "milestone_title" not in row
def test_a_task_outside_any_milestone_says_so_rather_than_inventing_a_title():
row = brief_row(_row(9, milestone_id=None), {})
assert row["milestone_id"] is None and "milestone_title" not in row
@pytest.mark.asyncio
async def test_a_full_page_of_long_tasks_fits_inline():
"""The ceiling. 100 rows (list_tasks' own limit cap) of ~5k-character step
plans: as to_dict() rows this was over half a million characters."""
rows = [_row(i) for i in range(100)]
with patch("scribe.mcp.tools.tasks.notes_svc.list_notes",
AsyncMock(return_value=(rows, 100))), \
patch("scribe.mcp.tools.tasks.milestones_svc.titles_for",
AsyncMock(return_value={415: "An existing plan is found"})) as titles:
out = await list_tasks(project_id=2, limit=100)
size = len(json.dumps(out))
assert size < 40_000, f"list_tasks page is {size} characters"
assert titles.await_args.args[0] == {415}
assert out["tasks"][0]["milestone_title"] == "An existing plan is found"
@pytest.mark.asyncio
async def test_list_notes_rows_leave_the_body_to_get_note():
rows = [_row(i, is_task=False) for i in range(3)]
with patch("scribe.mcp.tools.notes.notes_svc.list_notes",
AsyncMock(return_value=(rows, 3))):
out = await list_notes(project_id=2)
assert all("body" not in r for r in out["notes"])
@pytest.mark.asyncio
async def test_list_system_records_rows_leave_the_body_to_the_getters():
rows = [_row(1), _row(2, is_task=False)]
with patch("scribe.mcp.tools.systems.systems_svc.list_records_for_system",
AsyncMock(return_value=rows)), \
patch("scribe.mcp.tools.systems.milestones_svc.titles_for",
AsyncMock(return_value={415: "Plan"})):
out = await list_system_records(system_id=3)
assert [r["id"] for r in out["records"]] == [1, 2]
assert all("body" not in r for r in out["records"])