refactor(tests): per-model fakes, FakeMCP and session mocks come from tests/helpers (#2825, milestone 296 area 1, batch 2)
CI & Build / Python lint (push) Successful in 4s
CI & Build / Plugin hooks (push) Successful in 8s
CI & Build / integration (push) Successful in 24s
CI & Build / TypeScript typecheck (push) Successful in 33s
CI & Build / Python tests (push) Failing after 36s
CI & Build / Build & push image (push) Skipped
CI & Build / Python lint (push) Successful in 4s
CI & Build / Plugin hooks (push) Successful in 8s
CI & Build / integration (push) Successful in 24s
CI & Build / TypeScript typecheck (push) Successful in 33s
CI & Build / Python tests (push) Failing after 36s
CI & Build / Build & push image (push) Skipped
Second pass over the tests/ ledger after bbee0d0. fake_record(**attrs) is the
one MagicMock-with-real-attributes builder (to_dict mirrors them; the
note-2109 hazard documented once); fake_note/fake_task/fake_snippet/
fake_project/fake_milestone/fake_system/fake_rulebook/fake_topic/fake_rule
carry each model's ordinary defaults on top of it, replacing 14 per-file
factories (two rulebook trios in tool-vs-service wordings, _fake_task, _fake_ms,
_fake_project, _plan_note, _fake_snippet, two _snippet adapters now one-liners
over fake_snippet). FakeMCP replaces the five closure-over-a-list registrar
fakes (+ _Recorder); loc() and design_token_stub() replace the paired _loc /
_token / _T stand-ins; every hand-built async_session mock (9 helper defs and
14 inline copies) now starts from make_mock_session(). Call sites rewritten by
AST with each file's former defaults made explicit, so behaviour is unchanged.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -7,6 +7,7 @@ from scribe.mcp.tools.projects import (
|
||||
list_projects, get_project, create_project,
|
||||
update_project, enter_project,
|
||||
)
|
||||
from tests.helpers import FakeMCP, fake_project
|
||||
|
||||
|
||||
pytestmark = pytest.mark.usefixtures("_bind_user")
|
||||
@@ -56,22 +57,9 @@ def _no_bootstrap():
|
||||
yield mock
|
||||
|
||||
|
||||
def _fake_project(design_system_id=None, **overrides) -> MagicMock:
|
||||
p = MagicMock()
|
||||
base = {"id": 1, "title": "P", "description": "", "goal": "",
|
||||
"status": "active", "color": None}
|
||||
base.update(overrides)
|
||||
p.to_dict.return_value = base
|
||||
# Explicit, because a bare MagicMock hands back a truthy auto-attribute —
|
||||
# which would route every project in this file through the design-system
|
||||
# branch and out to a real database.
|
||||
p.design_system_id = design_system_id
|
||||
return p
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_list_projects_wraps_in_dict():
|
||||
rows = [_fake_project(id=1), _fake_project(id=2)]
|
||||
rows = [fake_project(id=1), fake_project(id=2)]
|
||||
with patch(
|
||||
"scribe.mcp.tools.projects.projects_svc.list_projects",
|
||||
AsyncMock(return_value=rows),
|
||||
@@ -82,7 +70,7 @@ async def test_list_projects_wraps_in_dict():
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_project_enriches_with_milestone_summary():
|
||||
p = _fake_project(id=5, title="found")
|
||||
p = fake_project(id=5, title="found")
|
||||
milestone_summary = [{"id": 10, "title": "MS", "task_count": 3}]
|
||||
applicable_payload = {
|
||||
"rules": [], "truncated": False, "subscribed_rulebooks": [],
|
||||
@@ -107,7 +95,7 @@ async def test_get_project_includes_applicable_rules_and_subscribed_rulebooks():
|
||||
"""The augmented get_project response includes applicable_rules and
|
||||
subscribed_rulebooks pulled from services/rulebooks.get_applicable_rules.
|
||||
"""
|
||||
p = _fake_project(id=3, title="Fabled Assistant")
|
||||
p = fake_project(id=3, title="Fabled Assistant")
|
||||
milestone_summary = []
|
||||
applicable_payload = {
|
||||
"rules": [
|
||||
@@ -147,7 +135,7 @@ async def test_get_project_raises_when_not_found():
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_create_project_passes_color_empty_as_none():
|
||||
p = _fake_project()
|
||||
p = fake_project()
|
||||
mock = AsyncMock(return_value=p)
|
||||
with patch("scribe.mcp.tools.projects.projects_svc.create_project", mock):
|
||||
await create_project(title="P", color="")
|
||||
@@ -156,7 +144,7 @@ async def test_create_project_passes_color_empty_as_none():
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_update_project_only_sends_non_default_fields():
|
||||
p = _fake_project()
|
||||
p = fake_project()
|
||||
mock = AsyncMock(return_value=p)
|
||||
with patch("scribe.mcp.tools.projects.projects_svc.update_project", mock):
|
||||
await update_project(project_id=1, status="archived")
|
||||
@@ -179,7 +167,7 @@ async def test_update_project_raises_when_not_found():
|
||||
async def test_enter_project_composes_full_context():
|
||||
"""enter_project pulls project + rules + milestone summary + open tasks +
|
||||
recent notes in one composed call."""
|
||||
p = _fake_project(id=5, title="P")
|
||||
p = fake_project(id=5, title="P")
|
||||
applicable_payload = {
|
||||
"rules": [{"id": 1, "title": "r1", "statement": "s",
|
||||
"topic_title": "t", "rulebook_title": "rb"}],
|
||||
@@ -239,7 +227,7 @@ async def test_enter_project_surfaces_the_systems_vocabulary():
|
||||
days after the feature landed — one System, nothing tagged since July 28
|
||||
(#2546's audit). Trimmed to id/name/first-line: it rides on every session
|
||||
start, and the full charter is get_system's job."""
|
||||
p = _fake_project(id=5)
|
||||
p = fake_project(id=5)
|
||||
sys1 = MagicMock()
|
||||
sys1.id = 3
|
||||
sys1.name = "retrieval"
|
||||
@@ -294,7 +282,7 @@ async def test_enter_project_carries_the_bootstrap_ask_when_it_fires():
|
||||
|
||||
ask = "This project has 282 records and NO Systems modelled — ..."
|
||||
with contextlib.ExitStack() as stack:
|
||||
for cm in _enter_project_stubs(_fake_project(id=5)):
|
||||
for cm in _enter_project_stubs(fake_project(id=5)):
|
||||
stack.enter_context(cm)
|
||||
stack.enter_context(patch(
|
||||
"scribe.mcp.tools.projects.systems_tools.bootstrap_systems_ask",
|
||||
@@ -315,7 +303,7 @@ async def test_enter_project_never_asks_bootstrap_once_a_vocabulary_exists(
|
||||
sys1 = MagicMock()
|
||||
sys1.id = 3; sys1.name = "retrieval"; sys1.description = ""
|
||||
with contextlib.ExitStack() as stack:
|
||||
for cm in _enter_project_stubs(_fake_project(id=5)):
|
||||
for cm in _enter_project_stubs(fake_project(id=5)):
|
||||
stack.enter_context(cm)
|
||||
stack.enter_context(patch(
|
||||
"scribe.mcp.tools.projects.systems_svc.list_systems",
|
||||
@@ -336,7 +324,7 @@ async def test_enter_project_fires_the_coverage_seed_on_the_owner(
|
||||
enter stays fast."""
|
||||
import contextlib
|
||||
|
||||
project = _fake_project(id=5)
|
||||
project = fake_project(id=5)
|
||||
project.user_id = 42 # explicit: the OWNER, not the caller (ctx uid=7)
|
||||
with contextlib.ExitStack() as stack:
|
||||
for cm in _enter_project_stubs(project):
|
||||
@@ -357,7 +345,7 @@ async def test_enter_project_hands_back_the_design_system_when_the_project_has_o
|
||||
system binds the same way a rule does. Before this it was reachable only by
|
||||
an agent that already knew to call resolve_design_system — so the standards
|
||||
were present in the store and absent from the work."""
|
||||
p = _fake_project(id=5, design_system_id=9)
|
||||
p = fake_project(id=5, design_system_id=9)
|
||||
design = {"id": 9, "title": "App kit", "guidance": [{"title": "House"}],
|
||||
"token_count": 95, "token_groups": ["surface"],
|
||||
"inherits_from": ["House"], "description": ""}
|
||||
@@ -399,14 +387,7 @@ async def test_enter_project_raises_when_project_not_found():
|
||||
def test_enter_project_registered_in_register():
|
||||
"""register(mcp) registers enter_project alongside the existing tools."""
|
||||
from scribe.mcp.tools.projects import register
|
||||
registered: list[str] = []
|
||||
mcp = FakeMCP()
|
||||
|
||||
class FakeMCP:
|
||||
def tool(self, name=None):
|
||||
def decorator(fn):
|
||||
registered.append(name)
|
||||
return fn
|
||||
return decorator
|
||||
|
||||
register(FakeMCP())
|
||||
assert "enter_project" in registered
|
||||
register(mcp)
|
||||
assert "enter_project" in mcp.names
|
||||
|
||||
Reference in New Issue
Block a user