Files
FabledScribe/tests/test_mcp_tool_tasks_kind.py
T
bvandeusenandClaude Opus 5 69d93898d9
CI & Build / Python lint (push) Successful in 3s
CI & Build / Plugin hooks (push) Successful in 8s
CI & Build / integration (push) Successful in 29s
CI & Build / TypeScript typecheck (push) Successful in 33s
CI & Build / Python tests (push) Failing after 48s
CI & Build / Build & push image (push) Skipped
fix(tasks): a task's kind is correctable — the Kind select stops lying (#3129)
`kind` was accepted at CREATE on both doors and dropped at UPDATE on both:
update_task had no such parameter, and the REST PATCH allow-list never read
the field. So a task filed under the wrong kind could never be corrected.

The frontend made it worse by looking like it worked. TaskEditorView binds a
Kind select, marks the form dirty, and HAS ALWAYS SENT `kind` in the update
payload — the store even types it. The route ignored it, returned 200, the
view optimistically updated, the toast said "Task saved", and the old value
came back on reload. Silent success, same class as #2709.

Found by trying to re-file #3126 as a spike after deploying 0091. It could
not be done; the task had to be recreated as #3128 and the original
cancelled.

One seam, not two doors. `minted_kind()` lives in services/notes.py because
the REST route cannot import an MCP tool module and a second spelling of the
list is how the doors would come to disagree. Both create and update route
through it, so a bogus kind is now a readable error rather than a
CheckViolationError surfacing as a 500.

TaskKind joins TaskStatus and TaskPriority as a real enum, and update_note
validates task_kind exactly as it already validated those two — the field
had been reaching setattr through the hasattr guard with no validation at
all, unnoticed only because no door ever offered it.

The `-> plan` question #3129 raised is answered in code rather than left
implicit: MINTABLE_KINDS is work/issue/spike, deliberately NARROWER than the
column's CHECK. `plan` stays a valid stored value because historical
plan-tasks carry it and must stay writable; it is simply not a value any
door hands out, and the refusal names start_planning because a caller
reaching for it wants a plan. The whitelist and the policy answer different
questions and are not the same list.

Every new test reads the value BACK. One that only asserted the call
succeeded would have passed against the broken code — the route returned 200
while dropping the field, which is how this survived long enough to be found
by hand.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-27 15:55:04 -04:00

100 lines
3.8 KiB
Python

from unittest.mock import AsyncMock, patch
import pytest
from tests.helpers import fake_note
pytestmark = pytest.mark.usefixtures("_bind_user")
@pytest.mark.asyncio
async def test_create_task_passes_kind():
# kind=plan is retired (plans are milestones); 'issue' exercises passthrough.
mock = AsyncMock(return_value=fake_note(task_kind="issue"))
with patch("scribe.mcp.tools.tasks.notes_svc.create_note", mock):
from scribe.mcp.tools.tasks import create_task
await create_task(title="P", kind="issue")
assert mock.call_args.kwargs["task_kind"] == "issue"
@pytest.mark.asyncio
async def test_list_tasks_passes_kind_filter():
mock = AsyncMock(return_value=([], 0))
with patch("scribe.mcp.tools.tasks.notes_svc.list_notes", mock):
from scribe.mcp.tools.tasks import list_tasks
await list_tasks(kind="plan")
assert mock.call_args.kwargs["task_kind"] == "plan"
@pytest.mark.asyncio
async def test_list_tasks_kind_empty_means_no_filter():
mock = AsyncMock(return_value=([], 0))
with patch("scribe.mcp.tools.tasks.notes_svc.list_notes", mock):
from scribe.mcp.tools.tasks import list_tasks
await list_tasks()
assert mock.call_args.kwargs["task_kind"] is None
@pytest.mark.asyncio
async def test_create_task_passes_spike():
"""The kind a failed rule-check asks for (milestone 312).
Time-boxed, and its output is knowledge rather than a change — filing one
as `work` makes a finished investigation look like an abandoned change.
"""
mock = AsyncMock(return_value=fake_note(task_kind="spike"))
with patch("scribe.mcp.tools.tasks.notes_svc.create_note", mock):
from scribe.mcp.tools.tasks import create_task
await create_task(title="Can the runner be given a bash shell?", kind="spike")
assert mock.call_args.kwargs["task_kind"] == "spike"
@pytest.mark.asyncio
async def test_update_task_can_re_file_a_kind():
"""A task's kind must be CORRECTABLE, not write-once (#3129).
What a piece of work turns out to be is often clear only once it is under
way. Before this, `update_task` had no `kind` parameter at all and the
REST route dropped the field the editor was already sending — the save
reported success and reverted on reload.
"""
mock = AsyncMock(return_value=fake_note(task_kind="spike"))
with patch("scribe.mcp.tools.tasks.notes_svc.update_note", mock):
from scribe.mcp.tools.tasks import update_task
await update_task(task_id=1, kind="spike")
assert mock.call_args.kwargs["task_kind"] == "spike"
@pytest.mark.asyncio
async def test_update_task_leaves_kind_alone_when_not_given():
""""" means leave unchanged, as it does for every other field here."""
mock = AsyncMock(return_value=fake_note())
with patch("scribe.mcp.tools.tasks.notes_svc.update_note", mock):
from scribe.mcp.tools.tasks import update_task
await update_task(task_id=1, title="renamed")
assert "task_kind" not in mock.call_args.kwargs
@pytest.mark.asyncio
async def test_minting_a_plan_is_refused_at_both_doors():
"""`plan` is a valid stored value and NOT a mintable one.
Historical plan-tasks carry it and must stay writable, so the column
keeps accepting it — but plans became milestones in 0066, so no door
hands out a new one. The error names start_planning rather than just
refusing, because a caller reaching for kind='plan' wants a plan.
"""
from scribe.services.notes import minted_kind
with pytest.raises(ValueError, match="start_planning"):
minted_kind("plan")
@pytest.mark.asyncio
async def test_an_unknown_kind_raises_rather_than_defaulting():
"""A silently-corrected kind is the defect this whole fix exists to end."""
from scribe.services.notes import minted_kind
with pytest.raises(ValueError, match="kind must be one of"):
minted_kind("investigation")