From 75bdb9c1480655b1fad8e3c13d09b06eaf87e9c7 Mon Sep 17 00:00:00 2001 From: Bryan Van Deusen Date: Sun, 9 Aug 2026 15:55:56 -0400 Subject: [PATCH] =?UTF-8?q?test(systems):=20fix=20two=20mock=20bugs=20in?= =?UTF-8?q?=20the=20seam=20tests=20=E2=80=94=20unset=20.id=20on=20the=20fa?= =?UTF-8?q?ke,=20shared=20to=5Fdict=20dict=20leaking=20across=20creates?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Runs 3562/3565: _fake_system never sets .id so the dup-gate assertion compared a MagicMock to 7; and a shared to_dict return_value dict let the tagged create's mutation leak into the orphan create's response. Co-Authored-By: Claude Fable 5 --- tests/test_mcp_tool_systems.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/test_mcp_tool_systems.py b/tests/test_mcp_tool_systems.py index 3656b8a..73c10a1 100644 --- a/tests/test_mcp_tool_systems.py +++ b/tests/test_mcp_tool_systems.py @@ -106,6 +106,7 @@ async def test_untagged_hint_zero_systems_prompts_first_create_and_fails_open(): @pytest.mark.asyncio async def test_create_system_same_normalized_name_is_duplicate_gated(): existing = _fake_system(sid=7, name="Scrape Pipeline") + existing.id = 7 existing.name = "Scrape Pipeline" with patch("scribe.mcp.tools.systems.current_user_id", return_value=1), \ patch("scribe.mcp.tools.systems.systems_svc") as svc: @@ -150,7 +151,10 @@ async def test_create_task_untagged_in_project_carries_the_question(): @pytest.mark.asyncio async def test_create_task_tagged_shows_systems_and_projectless_gets_neither(): - note = MagicMock(); note.id = 61; note.to_dict.return_value = {"id": 61} + note = MagicMock(); note.id = 61 + # Fresh dict per call — a shared return_value dict lets the first create's + # mutation leak into the second create's response. + note.to_dict.side_effect = lambda: {"id": 61} tagged_sys = MagicMock(); tagged_sys.to_dict.return_value = {"id": 4, "name": "plugin-hooks"} with patch("scribe.mcp.tools.tasks.current_user_id", return_value=1), \ patch("scribe.mcp.tools.tasks.notes_svc") as notes_svc, \