feat(plans): milestone-as-plan-container; retire kind=plan (T3)
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>
This commit is contained in:
@@ -5,7 +5,7 @@ import pytest
|
||||
|
||||
from scribe.mcp._context import _user_id_ctx
|
||||
from scribe.mcp.tools.milestones import (
|
||||
list_milestones, create_milestone, update_milestone,
|
||||
list_milestones, get_milestone, create_milestone, update_milestone,
|
||||
)
|
||||
|
||||
|
||||
@@ -57,6 +57,64 @@ async def test_create_milestone_empty_description_becomes_none():
|
||||
assert mock.call_args.kwargs["description"] is None
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_create_milestone_passes_body_through():
|
||||
"""The milestone-as-plan body is forwarded to the service."""
|
||||
m = _fake_ms(id=5)
|
||||
mock = AsyncMock(return_value=m)
|
||||
with patch("scribe.mcp.tools.milestones.milestones_svc.create_milestone", mock):
|
||||
await create_milestone(project_id=1, title="t", body="## Goal\n\nship")
|
||||
assert mock.call_args.kwargs["body"] == "## Goal\n\nship"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_create_milestone_empty_body_becomes_none():
|
||||
m = _fake_ms()
|
||||
mock = AsyncMock(return_value=m)
|
||||
with patch("scribe.mcp.tools.milestones.milestones_svc.create_milestone", mock):
|
||||
await create_milestone(project_id=1, title="t", body="")
|
||||
assert mock.call_args.kwargs["body"] is None
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_update_milestone_sends_body():
|
||||
m = _fake_ms()
|
||||
mock = AsyncMock(return_value=m)
|
||||
with patch("scribe.mcp.tools.milestones.milestones_svc.update_milestone", mock):
|
||||
await update_milestone(project_id=1, milestone_id=5, body="new plan")
|
||||
assert mock.call_args.kwargs == {"body": "new plan"}
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_milestone_returns_body_steps_and_rules():
|
||||
m = _fake_ms(id=5, project_id=3, body="## Goal")
|
||||
step = MagicMock()
|
||||
step.to_dict.return_value = {"id": 9, "title": "step 1", "status": "todo"}
|
||||
applicable = {"rules": [{"id": 1, "title": "r"}], "truncated": False,
|
||||
"subscribed_rulebooks": [{"id": 2, "title": "rb"}]}
|
||||
with patch("scribe.mcp.tools.milestones.milestones_svc.get_milestone",
|
||||
AsyncMock(return_value=m)), \
|
||||
patch("scribe.mcp.tools.milestones.milestones_svc.get_milestone_progress",
|
||||
AsyncMock(return_value={"total": 1, "completed": 0, "pct": 0.0})), \
|
||||
patch("scribe.mcp.tools.milestones.notes_svc.list_notes",
|
||||
AsyncMock(return_value=([step], 1))), \
|
||||
patch("scribe.mcp.tools.milestones.rulebooks_svc.get_applicable_rules",
|
||||
AsyncMock(return_value=applicable)):
|
||||
out = await get_milestone(milestone_id=5)
|
||||
assert out["milestone"]["body"] == "## Goal"
|
||||
assert out["milestone"]["total"] == 1
|
||||
assert out["steps"] == [{"id": 9, "title": "step 1", "status": "todo"}]
|
||||
assert out["applicable_rules"] == [{"id": 1, "title": "r"}]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_milestone_raises_when_not_found():
|
||||
with patch("scribe.mcp.tools.milestones.milestones_svc.get_milestone",
|
||||
AsyncMock(return_value=None)):
|
||||
with pytest.raises(ValueError, match="milestone 999 not found"):
|
||||
await get_milestone(milestone_id=999)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_update_milestone_only_sends_non_default_fields():
|
||||
m = _fake_ms()
|
||||
|
||||
@@ -14,13 +14,13 @@ def _bind_user():
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_start_planning_tool_delegates_to_service():
|
||||
payload = {"task": {"id": 5}, "applicable_rules": [], "subscribed_rulebooks": [],
|
||||
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["task"]["id"] == 5
|
||||
assert out["milestone"]["id"] == 5
|
||||
assert mock.call_args.kwargs == {"user_id": 7, "project_id": 3, "title": "Plan it"}
|
||||
|
||||
|
||||
|
||||
@@ -4,17 +4,19 @@ import pytest
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_start_planning_creates_plan_task_and_returns_rules():
|
||||
fake_note = MagicMock()
|
||||
fake_note.to_dict.return_value = {"id": 5, "title": "Plan it", "task_kind": "plan"}
|
||||
async def test_start_planning_creates_milestone_and_returns_rules():
|
||||
# start_planning now creates a MILESTONE (the plan container), not a
|
||||
# kind=plan task; its body holds the seeded design template.
|
||||
fake_milestone = MagicMock()
|
||||
fake_milestone.to_dict.return_value = {"id": 5, "title": "Plan it", "status": "active"}
|
||||
applicable = {
|
||||
"rules": [{"id": 1, "title": "dev is home", "statement": "...",
|
||||
"topic_title": "git-workflow", "rulebook_title": "FabledSword family"}],
|
||||
"truncated": False,
|
||||
"subscribed_rulebooks": [{"id": 2, "title": "FabledSword family"}],
|
||||
}
|
||||
with patch("scribe.services.planning.notes_svc.create_note",
|
||||
AsyncMock(return_value=fake_note)) as mock_create, \
|
||||
with patch("scribe.services.planning.milestones_svc.create_milestone",
|
||||
AsyncMock(return_value=fake_milestone)) as mock_create, \
|
||||
patch("scribe.services.planning.rulebooks_svc.get_applicable_rules",
|
||||
AsyncMock(return_value=applicable)), \
|
||||
patch("scribe.services.planning.notes_svc.list_notes",
|
||||
@@ -24,14 +26,13 @@ async def test_start_planning_creates_plan_task_and_returns_rules():
|
||||
from scribe.services.planning import start_planning
|
||||
out = await start_planning(user_id=7, project_id=3, title="Plan it")
|
||||
|
||||
# Created a plan-task (status set => task, kind=plan)
|
||||
# Created a milestone with the seeded plan-body template.
|
||||
kwargs = mock_create.call_args.kwargs
|
||||
assert kwargs["task_kind"] == "plan"
|
||||
assert kwargs["status"] == "todo"
|
||||
assert kwargs["project_id"] == 3
|
||||
assert kwargs["status"] == "active"
|
||||
assert "## Goal" in kwargs["body"] # seeded template
|
||||
# Returned shape
|
||||
assert out["task"]["id"] == 5
|
||||
assert out["milestone"]["id"] == 5
|
||||
assert out["applicable_rules"][0]["title"] == "dev is home"
|
||||
assert out["subscribed_rulebooks"] == [{"id": 2, "title": "FabledSword family"}]
|
||||
assert out["open_task_count"] == 3
|
||||
|
||||
Reference in New Issue
Block a user