Files
FabledGrimoire/tests/test_mcp_tool_planning.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.2 KiB
Python

from unittest.mock import AsyncMock, patch
import pytest
from tests.helpers import fake_task
pytestmark = pytest.mark.usefixtures("_bind_user")
@pytest.fixture(autouse=True)
def _no_plan_gate():
"""The plan gate reads the database; the tests that are about it re-patch it."""
with patch("scribe.mcp.tools.tasks.dedup_svc.plan_gate", AsyncMock(return_value=None)):
yield
@pytest.mark.asyncio
async def test_start_planning_tool_delegates_to_service():
payload = {"milestone": {"id": 5}, "applicable_rules": [], "project_rules": [],
"applicable_rules_truncated": False, "project_goal": "", "open_task_count": 0}
with patch("scribe.mcp.tools.tasks.planning_svc.start_planning",
AsyncMock(return_value=payload)) as mock:
from scribe.mcp.tools.tasks import start_planning
out = await start_planning(project_id=3, title="Plan it")
assert out["milestone"]["id"] == 5
# No body and no steps reach the service as None, so it seeds the template
# and takes the single-milestone path.
assert mock.call_args.kwargs == {
"user_id": 7, "project_id": 3, "title": "Plan it", "body": None, "steps": None,
}
@pytest.mark.asyncio
async def test_start_planning_returns_the_plan_that_already_covers_it():
"""A session that cannot see the existing plan makes a second one. It is
handed the first instead, and nothing is created."""
match = {"duplicate": True, "existing_id": 12}
svc = AsyncMock()
with patch("scribe.mcp.tools.tasks.dedup_svc.plan_gate",
AsyncMock(return_value=match)) as gate, \
patch("scribe.mcp.tools.tasks.dedup_svc.find_duplicate_note", AsyncMock()) as steps, \
patch("scribe.mcp.tools.tasks.planning_svc.start_planning", svc):
from scribe.mcp.tools.tasks import start_planning
out = await start_planning(project_id=3, title="Metadata", body="design",
steps=[{"title": "Resolve editions", "body": "via providers"}])
assert out is match
svc.assert_not_awaited()
steps.assert_not_awaited()
# The candidate is judged by its steps as well as its design.
assert gate.call_args.args[:3] == (7, 3, "Metadata")
assert "design" in gate.call_args.args[3]
assert "Resolve editions\nvia providers" in gate.call_args.args[3]
@pytest.mark.asyncio
async def test_force_creates_the_plan_without_asking_the_gate():
gate = AsyncMock(return_value={"duplicate": True})
with patch("scribe.mcp.tools.tasks.dedup_svc.plan_gate", gate), \
patch("scribe.mcp.tools.tasks.planning_svc.start_planning",
AsyncMock(return_value={"milestone": {"id": 5}})) as svc:
from scribe.mcp.tools.tasks import start_planning
out = await start_planning(project_id=3, title="Metadata", force=True)
assert out["milestone"]["id"] == 5
svc.assert_awaited_once()
gate.assert_not_awaited()
@pytest.mark.asyncio
async def test_get_task_augments_plan_with_rules():
applicable = {"rules": [{"id": 1, "title": "r"}], "truncated": False,
"project_rules": [{"id": 3, "title": "own"}]}
with patch("scribe.mcp.tools.tasks.notes_svc.get_note_for_user",
AsyncMock(return_value=(fake_task(task_kind="plan", id=9, project_id=3), "owner"))), \
patch("scribe.mcp.tools.tasks.rulebooks_svc.get_applicable_rules",
AsyncMock(return_value=applicable)):
from scribe.mcp.tools.tasks import get_task
out = await get_task(task_id=9)
assert out["applicable_rules"] == [{"id": 1, "title": "r"}]
assert out["project_rules"] == [{"id": 3, "title": "own"}]
assert "subscribed_rulebooks" not in out
assert out["applicable_rules_truncated"] is False
@pytest.mark.asyncio
async def test_get_task_work_kind_has_no_rules():
with patch("scribe.mcp.tools.tasks.notes_svc.get_note_for_user",
AsyncMock(return_value=(fake_task(task_kind="work", id=9, project_id=3), "owner"))), \
patch("scribe.mcp.tools.tasks.rulebooks_svc.get_applicable_rules",
AsyncMock()) as mock_rules:
from scribe.mcp.tools.tasks import get_task
out = await get_task(task_id=9)
assert "applicable_rules" not in out
assert not mock_rules.called