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
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>
182 lines
7.5 KiB
Python
182 lines
7.5 KiB
Python
"""Tests for fable_*_milestone tools."""
|
|
from unittest.mock import AsyncMock, MagicMock, patch
|
|
|
|
import pytest
|
|
|
|
from scribe.mcp.tools.milestones import (
|
|
list_milestones, get_milestone, create_milestone, update_milestone,
|
|
)
|
|
from tests.helpers import fake_milestone, fake_task
|
|
|
|
|
|
pytestmark = pytest.mark.usefixtures("_bind_user")
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def _no_plan_gate():
|
|
"""The plan gate reads the database; these tests are about what reaches
|
|
the service. The gate's own tests re-patch it."""
|
|
with patch("scribe.mcp.tools.milestones.dedup_svc.plan_gate",
|
|
AsyncMock(return_value=None)):
|
|
yield
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_list_milestones_returns_dict_with_progress():
|
|
rows = [{"id": 1, "title": "MS1", "status": "active", "total": 2}]
|
|
with patch(
|
|
"scribe.mcp.tools.milestones.milestones_svc.get_project_milestone_summary",
|
|
AsyncMock(return_value=rows),
|
|
):
|
|
out = await list_milestones(project_id=1)
|
|
assert out["milestones"] == rows
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_create_milestone_passes_through():
|
|
m = fake_milestone(id=5)
|
|
mock = AsyncMock(return_value=m)
|
|
with patch("scribe.mcp.tools.milestones.milestones_svc.create_milestone", mock):
|
|
out = await create_milestone(project_id=1, title="new", description="d")
|
|
assert out["id"] == 5
|
|
assert mock.call_args.kwargs["project_id"] == 1
|
|
assert mock.call_args.kwargs["title"] == "new"
|
|
assert mock.call_args.kwargs["description"] == "d"
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_create_milestone_empty_description_becomes_none():
|
|
m = fake_milestone()
|
|
mock = AsyncMock(return_value=m)
|
|
with patch("scribe.mcp.tools.milestones.milestones_svc.create_milestone", mock):
|
|
await create_milestone(project_id=1, title="t", description="")
|
|
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_milestone(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_milestone()
|
|
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_create_milestone_returns_the_active_plan_that_already_covers_it():
|
|
match = {"duplicate": True, "existing_id": 4}
|
|
create = AsyncMock()
|
|
with patch("scribe.mcp.tools.milestones.dedup_svc.plan_gate",
|
|
AsyncMock(return_value=match)) as gate, \
|
|
patch("scribe.mcp.tools.milestones.milestones_svc.create_milestone", create):
|
|
out = await create_milestone(project_id=1, title="t", description="d", body="b")
|
|
assert out is match
|
|
create.assert_not_awaited()
|
|
assert gate.call_args.args[:3] == (7, 1, "t")
|
|
assert gate.call_args.args[3] == "d\n\nb"
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_create_milestone_skips_the_gate_when_forced_or_done():
|
|
"""force: the caller read the match. done: a record of past work is not a
|
|
plan competing with an open one."""
|
|
gate = AsyncMock(return_value={"duplicate": True})
|
|
create = AsyncMock(return_value=fake_milestone(id=6))
|
|
with patch("scribe.mcp.tools.milestones.dedup_svc.plan_gate", gate), \
|
|
patch("scribe.mcp.tools.milestones.milestones_svc.create_milestone", create):
|
|
assert (await create_milestone(project_id=1, title="t", force=True))["id"] == 6
|
|
assert (await create_milestone(project_id=1, title="t", status="done"))["id"] == 6
|
|
gate.assert_not_awaited()
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_update_milestone_sends_body():
|
|
m = fake_milestone()
|
|
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_milestone(id=5, project_id=3, body="## Goal")
|
|
step = fake_task(id=9, title="step 1", milestone_id=5, body="a long step body")
|
|
applicable = {"rules": [{"id": 1, "title": "r"}], "truncated": False,
|
|
"project_rules": [{"id": 3, "title": "own"}]}
|
|
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 [(s["id"], s["title"], s["status"]) for s in out["steps"]] == [(9, "step 1", "todo")]
|
|
# A step's body is get_task's job; its placement is not.
|
|
assert "body" not in out["steps"][0]
|
|
assert out["steps"][0]["milestone_title"] == m.title
|
|
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_milestone()
|
|
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, status="done")
|
|
args, kwargs = mock.call_args
|
|
assert args == (7, 5)
|
|
assert kwargs == {"status": "done"}
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_update_milestone_order_index_negative_is_omitted():
|
|
"""order_index=-1 sentinel means leave unchanged."""
|
|
m = fake_milestone()
|
|
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, order_index=-1)
|
|
assert "order_index" not in mock.call_args.kwargs
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_update_milestone_order_index_zero_is_explicit():
|
|
"""order_index=0 is a real value (top of list), not a sentinel."""
|
|
m = fake_milestone()
|
|
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, order_index=0)
|
|
assert mock.call_args.kwargs["order_index"] == 0
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_update_milestone_raises_when_not_found():
|
|
with patch(
|
|
"scribe.mcp.tools.milestones.milestones_svc.update_milestone",
|
|
AsyncMock(return_value=None),
|
|
):
|
|
with pytest.raises(ValueError, match="milestone 999 not found"):
|
|
await update_milestone(project_id=1, milestone_id=999, title="x")
|