feat(inception): the doors — create_project/decide_project_inception take the decision, enter_project asks until decided, REST inception endpoints, _INSTRUCTIONS (#2882, milestone 297 step 4)
CI & Build / Python lint (push) Successful in 3s
CI & Build / Plugin hooks (push) Successful in 11s
CI & Build / integration (push) Successful in 26s
CI & Build / TypeScript typecheck (push) Successful in 35s
CI & Build / Python tests (push) Failing after 45s
CI & Build / Build & push image (push) Skipped
CI & Build / Python lint (push) Successful in 3s
CI & Build / Plugin hooks (push) Successful in 11s
CI & Build / integration (push) Successful in 26s
CI & Build / TypeScript typecheck (push) Successful in 35s
CI & Build / Python tests (push) Failing after 45s
CI & Build / Build & push image (push) Skipped
- MCP create_project(..., exclude_always_on_rulebooks, subscribe_rulebooks, design_system_id (0 unstated / -1 none / n), seed_systems): any inception arg → inception.decide(via="mcp") after the create; none → undecided with an inception_hint. New decide_project_inception(project_id, …) records or re-records; nothing given = an inherit-all decision, stated. - enter_project carries `inception` ONLY for the caller's own, undecided project: inception_ask() = the project's current defaults + what to ask the operator once + the exact call (the #2683 ask shape). Absent otherwise. - REST: POST /api/projects accepts `inception` (validated before the create); POST /api/projects/<id>/inception decides/re-decides; GET …/inception/defaults is the card's payload; GET project already carries inception via to_dict. - _INSTRUCTIONS: ORIENT names the ask; START a project names the questions — never create a project bare by default (product behaviour, P#119). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -391,3 +391,81 @@ def test_enter_project_registered_in_register():
|
||||
|
||||
register(mcp)
|
||||
assert "enter_project" in mcp.names
|
||||
|
||||
|
||||
# --- milestone 297: the inception doors ---------------------------------------
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_create_project_without_inception_args_stays_undecided():
|
||||
p = fake_project(id=5, title="P", inception=None)
|
||||
with patch("scribe.mcp.tools.projects.projects_svc.create_project", AsyncMock(return_value=p)), \
|
||||
patch("scribe.mcp.tools.projects.inception_svc.decide", AsyncMock()) as decide:
|
||||
out = await create_project(title="P")
|
||||
decide.assert_not_awaited()
|
||||
assert "inception_hint" in out and "inception_effects" not in out
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_create_project_with_inception_args_decides_via_mcp():
|
||||
p = fake_project(id=5, title="P", inception=None)
|
||||
decided = {"inception": {"via": "mcp", "choices": {}}, "effects": {"systems_seeded": []}}
|
||||
with patch("scribe.mcp.tools.projects.projects_svc.create_project", AsyncMock(return_value=p)), \
|
||||
patch("scribe.mcp.tools.projects.inception_svc.decide", AsyncMock(return_value=decided)) as decide:
|
||||
out = await create_project(title="P", exclude_always_on_rulebooks=[1], design_system_id=-1, seed_systems=True)
|
||||
kw = decide.await_args.kwargs
|
||||
assert decide.await_args.args[1] == 5 and kw["via"] == "mcp"
|
||||
assert kw["choices"] == {"exclude_always_on_rulebooks": [1], "subscribe_rulebooks": [],
|
||||
"design_system_id": None, "seed_systems": True}
|
||||
assert out["inception"]["via"] == "mcp" and "inception_effects" in out
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_decide_project_inception_tool_records_an_inherit_all_decision_when_given_nothing():
|
||||
from scribe.mcp.tools.projects import decide_project_inception
|
||||
decided = {"inception": {"via": "mcp"}, "effects": {}}
|
||||
with patch("scribe.mcp.tools.projects.inception_svc.decide", AsyncMock(return_value=decided)) as decide:
|
||||
out = await decide_project_inception(project_id=5)
|
||||
assert decide.await_args.kwargs["choices"] == {}
|
||||
assert out["project_id"] == 5 and out["inception"]["via"] == "mcp"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_enter_project_carries_the_inception_ask_only_for_an_undecided_own_project():
|
||||
applicable = {"rules": [], "project_rules": [], "truncated": False,
|
||||
"subscribed_rulebooks": [], "excluded_always_on": []}
|
||||
ask = {"defaults": {}, "ask": "decide", "call": "decide_project_inception(...)"}
|
||||
|
||||
async def run(project):
|
||||
with patch("scribe.mcp.tools.projects.projects_svc.get_project", AsyncMock(return_value=project)), \
|
||||
patch("scribe.mcp.tools.projects.rulebooks_svc.get_applicable_rules", AsyncMock(return_value=applicable)), \
|
||||
patch("scribe.mcp.tools.projects.milestones_svc.get_project_milestone_summary", AsyncMock(return_value=[])), \
|
||||
patch("scribe.mcp.tools.projects.notes_svc.list_notes", AsyncMock(side_effect=[([], 0), ([], 0)])), \
|
||||
patch("scribe.mcp.tools.projects.systems_svc.list_systems", AsyncMock(return_value=[])), \
|
||||
patch("scribe.mcp.tools.projects.systems_tools.bootstrap_systems_ask", AsyncMock(return_value=None)), \
|
||||
patch("scribe.mcp.tools.projects.inception_svc.inception_ask", AsyncMock(return_value=ask)) as asked:
|
||||
return await enter_project(project_id=5), asked
|
||||
|
||||
# Own + undecided → the ask rides along.
|
||||
out, asked = await run(fake_project(id=5, title="P", user_id=7, inception=None))
|
||||
assert out["inception"] == ask and asked.await_count == 1
|
||||
# Decided → absent, and the ask is not even built.
|
||||
out, asked = await run(fake_project(id=5, title="P", user_id=7, inception={"via": "legacy"}))
|
||||
assert "inception" not in out and asked.await_count == 0
|
||||
# Someone else's (shared) project, undecided → not this caller's to decide.
|
||||
out, asked = await run(fake_project(id=5, title="P", user_id=8, inception=None))
|
||||
assert "inception" not in out and asked.await_count == 0
|
||||
|
||||
|
||||
def test_inception_routes_and_tool_are_registered():
|
||||
from scribe.app import create_app
|
||||
from scribe.mcp.server import build_mcp_server
|
||||
rules = {r.rule for r in create_app().url_map.iter_rules()}
|
||||
assert "/api/projects/<int:project_id>/inception" in rules
|
||||
assert "/api/projects/<int:project_id>/inception/defaults" in rules
|
||||
mcp = build_mcp_server()
|
||||
assert mcp._tool_manager.get_tool("decide_project_inception") is not None
|
||||
tool = mcp._tool_manager.get_tool("create_project")
|
||||
for name in ("exclude_always_on_rulebooks", "subscribe_rulebooks", "design_system_id", "seed_systems"):
|
||||
assert name in tool.parameters.get("properties", {}), name
|
||||
|
||||
|
||||
Reference in New Issue
Block a user