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:
@@ -5,26 +5,23 @@ calling convention meets the service's: an agent cannot omit an argument, so
|
||||
"leave unchanged", "clear" and "set" have to be encoded in the value. Getting
|
||||
that mapping wrong is silent — the call succeeds and changes the wrong thing.
|
||||
"""
|
||||
from unittest.mock import AsyncMock, MagicMock, patch
|
||||
from unittest.mock import AsyncMock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
from scribe.services.design_systems import DesignSystemCycle
|
||||
from tests.helpers import design_token_stub, fake_record
|
||||
|
||||
|
||||
pytestmark = pytest.mark.usefixtures("_bind_user")
|
||||
|
||||
|
||||
def _fake_system():
|
||||
s = MagicMock()
|
||||
s.to_dict.return_value = {"id": 1, "title": "FabledSword", "parent_id": None}
|
||||
return s
|
||||
def _fake_design_system():
|
||||
return fake_record(id=1, title="FabledSword", parent_id=None)
|
||||
|
||||
|
||||
def _fake_token():
|
||||
t = MagicMock()
|
||||
t.to_dict.return_value = {"id": 9, "name": "--fs-obsidian"}
|
||||
return t
|
||||
return fake_record(id=9, name="--fs-obsidian")
|
||||
|
||||
|
||||
# --- create -----------------------------------------------------------------
|
||||
@@ -35,7 +32,7 @@ async def test_creating_without_a_parent_passes_none_not_zero():
|
||||
system id — there is no system 0, so the create would fail an ACL check for
|
||||
a record that cannot exist."""
|
||||
with patch("scribe.mcp.tools.design_systems.ds_svc") as svc:
|
||||
svc.create_design_system = AsyncMock(return_value=_fake_system())
|
||||
svc.create_design_system = AsyncMock(return_value=_fake_design_system())
|
||||
from scribe.mcp.tools.design_systems import create_design_system
|
||||
await create_design_system(title="FabledSword")
|
||||
assert svc.create_design_system.await_args.kwargs["parent_id"] is None
|
||||
@@ -44,7 +41,7 @@ async def test_creating_without_a_parent_passes_none_not_zero():
|
||||
@pytest.mark.asyncio
|
||||
async def test_creating_with_a_parent_passes_it_through():
|
||||
with patch("scribe.mcp.tools.design_systems.ds_svc") as svc:
|
||||
svc.create_design_system = AsyncMock(return_value=_fake_system())
|
||||
svc.create_design_system = AsyncMock(return_value=_fake_design_system())
|
||||
from scribe.mcp.tools.design_systems import create_design_system
|
||||
await create_design_system(title="Scribe", parent_id=4)
|
||||
assert svc.create_design_system.await_args.kwargs["parent_id"] == 4
|
||||
@@ -65,7 +62,7 @@ async def test_create_raises_when_the_parent_is_not_writable():
|
||||
async def test_update_with_parent_id_zero_leaves_the_parent_alone():
|
||||
"""The common case — renaming a system must not silently re-root it."""
|
||||
with patch("scribe.mcp.tools.design_systems.ds_svc") as svc:
|
||||
svc.update_design_system = AsyncMock(return_value=_fake_system())
|
||||
svc.update_design_system = AsyncMock(return_value=_fake_design_system())
|
||||
from scribe.mcp.tools.design_systems import update_design_system
|
||||
await update_design_system(design_system_id=1, title="Renamed")
|
||||
fields = svc.update_design_system.await_args.kwargs
|
||||
@@ -79,7 +76,7 @@ async def test_update_with_parent_id_minus_one_clears_it():
|
||||
None, which is the value the service reads as "become a root" — where
|
||||
omitting the key means "leave alone"."""
|
||||
with patch("scribe.mcp.tools.design_systems.ds_svc") as svc:
|
||||
svc.update_design_system = AsyncMock(return_value=_fake_system())
|
||||
svc.update_design_system = AsyncMock(return_value=_fake_design_system())
|
||||
from scribe.mcp.tools.design_systems import update_design_system
|
||||
await update_design_system(design_system_id=1, parent_id=-1)
|
||||
assert svc.update_design_system.await_args.kwargs["parent_id"] is None
|
||||
@@ -88,7 +85,7 @@ async def test_update_with_parent_id_minus_one_clears_it():
|
||||
@pytest.mark.asyncio
|
||||
async def test_update_with_a_positive_parent_id_sets_it():
|
||||
with patch("scribe.mcp.tools.design_systems.ds_svc") as svc:
|
||||
svc.update_design_system = AsyncMock(return_value=_fake_system())
|
||||
svc.update_design_system = AsyncMock(return_value=_fake_design_system())
|
||||
from scribe.mcp.tools.design_systems import update_design_system
|
||||
await update_design_system(design_system_id=1, parent_id=4)
|
||||
assert svc.update_design_system.await_args.kwargs["parent_id"] == 4
|
||||
@@ -161,16 +158,11 @@ async def test_resolve_returns_serialised_tokens_with_their_provenance():
|
||||
resolution was built to preserve."""
|
||||
from scribe.services.design_cascade import resolve_tokens
|
||||
|
||||
class _T:
|
||||
def __init__(self, name, value_by_mode):
|
||||
self.name, self.value_by_mode = name, value_by_mode
|
||||
self.group_name = self.purpose = None
|
||||
self.order_index = 0
|
||||
|
||||
resolved = resolve_tokens(
|
||||
2, {1: None, 2: 1},
|
||||
{1: [_T("--fs-accent", {"base": "#6b2118"})],
|
||||
2: [_T("--fs-accent", {"base": "#5b4a8a"})]},
|
||||
{1: [design_token_stub("--fs-accent", {"base": "#6b2118"})],
|
||||
2: [design_token_stub("--fs-accent", {"base": "#5b4a8a"})]},
|
||||
)
|
||||
with patch("scribe.mcp.tools.design_systems.ds_svc") as svc:
|
||||
svc.resolve_design_system = AsyncMock(return_value=resolved)
|
||||
|
||||
Reference in New Issue
Block a user