1f6c592226
The milestone becomes the plan container: a new nullable milestones.body holds the design/intent (Goal/Approach/Verification) and individual steps live as first-class child tasks (milestone_id) instead of checkboxes crammed into one kind=plan task body. start_planning now creates a MILESTONE seeded with the body template (not a kind=plan task) and returns it with applicable rules; a new get_milestone MCP tool reads the plan back (body + steps + rules). kind=plan is hard-retired going forward — start_planning never creates one. The 'plan' task_kind enum value stays valid so the 11 historical plan-tasks remain readable in place; no body-shredding backfill (corpus review showed auto-splitting their checklists into tasks would be lossy: embedded code blocks, a non-binary [~] state, tables, ID-encoded hierarchy). - migration 0066: add milestones.body - model/service/route/MCP: body passthrough on create+update; get_milestone - server _INSTRUCTIONS: "plan" = milestone w/ body + child step-tasks - UI: ProjectView shows/edits a milestone's plan body; start_planning expands the new milestone and opens its plan editor - tests updated to the milestone contract + new body/get_milestone coverage Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
60 lines
2.3 KiB
Python
60 lines
2.3 KiB
Python
from unittest.mock import AsyncMock, MagicMock, patch
|
|
|
|
import pytest
|
|
|
|
from scribe.mcp._context import _user_id_ctx
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def _bind_user():
|
|
token = _user_id_ctx.set(7)
|
|
yield
|
|
_user_id_ctx.reset(token)
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_start_planning_tool_delegates_to_service():
|
|
payload = {"milestone": {"id": 5}, "applicable_rules": [], "subscribed_rulebooks": [],
|
|
"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
|
|
assert mock.call_args.kwargs == {"user_id": 7, "project_id": 3, "title": "Plan it"}
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_get_task_augments_plan_with_rules():
|
|
note = MagicMock()
|
|
note.parent_id = None
|
|
note.project_id = 3
|
|
note.to_dict.return_value = {"id": 9, "task_kind": "plan", "project_id": 3}
|
|
applicable = {"rules": [{"id": 1, "title": "r"}], "truncated": False,
|
|
"subscribed_rulebooks": [{"id": 2, "title": "rb"}]}
|
|
with patch("scribe.mcp.tools.tasks.notes_svc.get_note",
|
|
AsyncMock(return_value=note)), \
|
|
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["subscribed_rulebooks"] == [{"id": 2, "title": "rb"}]
|
|
assert out["applicable_rules_truncated"] is False
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_get_task_work_kind_has_no_rules():
|
|
note = MagicMock()
|
|
note.parent_id = None
|
|
note.project_id = 3
|
|
note.to_dict.return_value = {"id": 9, "task_kind": "work", "project_id": 3}
|
|
with patch("scribe.mcp.tools.tasks.notes_svc.get_note",
|
|
AsyncMock(return_value=note)), \
|
|
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
|