feat(planning): start_planning hands back the active plan that already covers the work (#4079)
CI & Build / Python lint (push) Successful in 5s
CI & Build / Plugin hooks (push) Successful in 13s
CI & Build / integration (push) Successful in 1m10s
CI & Build / TypeScript typecheck (push) Successful in 1m15s
CI & Build / Python tests (push) Failing after 1m22s
CI & Build / Build & push image (push) Skipped
CI & Build / Python lint (push) Successful in 5s
CI & Build / Plugin hooks (push) Successful in 13s
CI & Build / integration (push) Successful in 1m10s
CI & Build / TypeScript typecheck (push) Successful in 1m15s
CI & Build / Python tests (push) Failing after 1m22s
CI & Build / Build & push image (push) Skipped
Step 4 of milestone 415 "An existing plan is found before a new one is made". A session that could not see an existing plan made a second one beside it. start_planning and create_milestone now ask first: an ACTIVE milestone in the project with the same title, or one that reads as the same plan (title, design and steps against milestone embeddings), is returned with its progress and a pointer to create_records(milestone_id=...). Nothing is created; force=true bypasses. - dedup.find_matching_plan / plan_gate / plan_match_response; access-checked before either arm (rule 78), fail-open like the other gates. - Done milestones never block; the semantic arm needs 200+ chars of candidate. - kb_plan_match_threshold (default 0.90) is a setting, in the Settings view, and pinned against the Python default by test_settings_defaults_agree. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01821k5B3Ysecp9fNYs92Kuy
This commit is contained in:
@@ -7,6 +7,13 @@ from tests.helpers import fake_task
|
||||
pytestmark = pytest.mark.usefixtures("_bind_user")
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def _no_plan_gate():
|
||||
"""The plan gate reads the database; the tests that are about it re-patch it."""
|
||||
with patch("scribe.mcp.tools.tasks.dedup_svc.plan_gate", AsyncMock(return_value=None)):
|
||||
yield
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_start_planning_tool_delegates_to_service():
|
||||
payload = {"milestone": {"id": 5}, "applicable_rules": [], "project_rules": [],
|
||||
@@ -23,6 +30,42 @@ async def test_start_planning_tool_delegates_to_service():
|
||||
}
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_start_planning_returns_the_plan_that_already_covers_it():
|
||||
"""The FabledLibrarian failure (milestone 415): a session that could not see
|
||||
the existing plan made a second one. Now it is handed the first, and
|
||||
nothing is created."""
|
||||
match = {"duplicate": True, "existing_id": 12}
|
||||
svc = AsyncMock()
|
||||
with patch("scribe.mcp.tools.tasks.dedup_svc.plan_gate",
|
||||
AsyncMock(return_value=match)) as gate, \
|
||||
patch("scribe.mcp.tools.tasks.dedup_svc.find_duplicate_note", AsyncMock()) as steps, \
|
||||
patch("scribe.mcp.tools.tasks.planning_svc.start_planning", svc):
|
||||
from scribe.mcp.tools.tasks import start_planning
|
||||
out = await start_planning(project_id=3, title="Metadata", body="design",
|
||||
steps=[{"title": "Resolve editions", "body": "via providers"}])
|
||||
assert out is match
|
||||
svc.assert_not_awaited()
|
||||
steps.assert_not_awaited()
|
||||
# The candidate is judged by its steps as well as its design.
|
||||
assert gate.call_args.args[:3] == (7, 3, "Metadata")
|
||||
assert "design" in gate.call_args.args[3]
|
||||
assert "Resolve editions\nvia providers" in gate.call_args.args[3]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_force_creates_the_plan_without_asking_the_gate():
|
||||
gate = AsyncMock(return_value={"duplicate": True})
|
||||
with patch("scribe.mcp.tools.tasks.dedup_svc.plan_gate", gate), \
|
||||
patch("scribe.mcp.tools.tasks.planning_svc.start_planning",
|
||||
AsyncMock(return_value={"milestone": {"id": 5}})) as svc:
|
||||
from scribe.mcp.tools.tasks import start_planning
|
||||
out = await start_planning(project_id=3, title="Metadata", force=True)
|
||||
assert out["milestone"]["id"] == 5
|
||||
svc.assert_awaited_once()
|
||||
gate.assert_not_awaited()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_task_augments_plan_with_rules():
|
||||
applicable = {"rules": [{"id": 1, "title": "r"}], "truncated": False,
|
||||
|
||||
Reference in New Issue
Block a user