feat(plan): start_planning MCP tool + get_task rules augmentation + instructions
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
from unittest.mock import AsyncMock, MagicMock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
from fabledassistant.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 = {"task": {"id": 5}, "applicable_rules": [], "subscribed_rulebooks": [],
|
||||
"applicable_rules_truncated": False, "project_goal": "", "open_task_count": 0}
|
||||
with patch("fabledassistant.mcp.tools.tasks.planning_svc.start_planning",
|
||||
AsyncMock(return_value=payload)) as mock:
|
||||
from fabledassistant.mcp.tools.tasks import start_planning
|
||||
out = await start_planning(project_id=3, title="Plan it")
|
||||
assert out["task"]["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("fabledassistant.mcp.tools.tasks.notes_svc.get_note",
|
||||
AsyncMock(return_value=note)), \
|
||||
patch("fabledassistant.mcp.tools.tasks.rulebooks_svc.get_applicable_rules",
|
||||
AsyncMock(return_value=applicable)):
|
||||
from fabledassistant.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("fabledassistant.mcp.tools.tasks.notes_svc.get_note",
|
||||
AsyncMock(return_value=note)), \
|
||||
patch("fabledassistant.mcp.tools.tasks.rulebooks_svc.get_applicable_rules",
|
||||
AsyncMock()) as mock_rules:
|
||||
from fabledassistant.mcp.tools.tasks import get_task
|
||||
out = await get_task(task_id=9)
|
||||
assert "applicable_rules" not in out
|
||||
assert not mock_rules.called
|
||||
Reference in New Issue
Block a user