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 @@ own import-free module — see services/design_cascade.py.
|
||||
from types import SimpleNamespace
|
||||
|
||||
from scribe.services.design_cascade import ancestry, resolve_tokens, would_cycle
|
||||
from tests.helpers import design_token_stub
|
||||
|
||||
|
||||
# --- ancestry ---------------------------------------------------------------
|
||||
@@ -102,14 +103,6 @@ def test_the_guard_survives_a_hierarchy_that_is_already_corrupt():
|
||||
# because resolve_tokens is pure and duck-typed — which is the whole reason it
|
||||
# lives here rather than inside the service.
|
||||
|
||||
def _token(name, value_by_mode, group_name=None, purpose=None, order_index=0,
|
||||
supersedes=None):
|
||||
return SimpleNamespace(
|
||||
name=name, value_by_mode=value_by_mode, group_name=group_name,
|
||||
purpose=purpose, order_index=order_index, supersedes=supersedes or [],
|
||||
)
|
||||
|
||||
|
||||
# A family (1) and an app inheriting from it (2) — the shape the model exists for.
|
||||
FAMILY, APP = 1, 2
|
||||
PARENTS = {FAMILY: None, APP: FAMILY}
|
||||
@@ -124,7 +117,7 @@ def test_a_system_with_no_tokens_of_its_own_inherits_the_whole_family_set():
|
||||
and the state every app system starts in."""
|
||||
resolved = resolve_tokens(
|
||||
APP, PARENTS,
|
||||
{FAMILY: [_token("--fs-obsidian", {"base": "#14171a"})], APP: []},
|
||||
{FAMILY: [design_token_stub(name="--fs-obsidian", value_by_mode={"base": "#14171a"})], APP: []},
|
||||
)
|
||||
assert [t.name for t in resolved] == ["--fs-obsidian"]
|
||||
assert resolved[0].value_by_mode == {"base": "#14171a"}
|
||||
@@ -138,8 +131,8 @@ def test_the_deepest_system_wins_and_says_what_it_overrode():
|
||||
resolved = _by_name(resolve_tokens(
|
||||
APP, PARENTS,
|
||||
{
|
||||
FAMILY: [_token("--fs-accent", {"base": "#6b2118"})],
|
||||
APP: [_token("--fs-accent", {"base": "#5b4a8a"})],
|
||||
FAMILY: [design_token_stub(name="--fs-accent", value_by_mode={"base": "#6b2118"})],
|
||||
APP: [design_token_stub(name="--fs-accent", value_by_mode={"base": "#5b4a8a"})],
|
||||
},
|
||||
))
|
||||
accent = resolved["--fs-accent"]
|
||||
@@ -158,8 +151,8 @@ def test_overriding_one_mode_leaves_the_others_inherited():
|
||||
resolved = _by_name(resolve_tokens(
|
||||
APP, PARENTS,
|
||||
{
|
||||
FAMILY: [_token("--fs-accent", {"base": "#34a877", "dark": "#34a877"})],
|
||||
APP: [_token("--fs-accent", {"base": "#15803d"})],
|
||||
FAMILY: [design_token_stub(name="--fs-accent", value_by_mode={"base": "#34a877", "dark": "#34a877"})],
|
||||
APP: [design_token_stub(name="--fs-accent", value_by_mode={"base": "#15803d"})],
|
||||
},
|
||||
))
|
||||
accent = resolved["--fs-accent"]
|
||||
@@ -172,7 +165,7 @@ def test_a_token_only_the_app_defines_is_not_an_override():
|
||||
labelled both "overridden here" would misdescribe the first."""
|
||||
resolved = _by_name(resolve_tokens(
|
||||
APP, PARENTS,
|
||||
{FAMILY: [], APP: [_token("--fs-editor-caret", {"base": "#5b4a8a"})]},
|
||||
{FAMILY: [], APP: [design_token_stub(name="--fs-editor-caret", value_by_mode={"base": "#5b4a8a"})]},
|
||||
))
|
||||
caret = resolved["--fs-editor-caret"]
|
||||
assert caret.origin_by_mode == {"base": APP}
|
||||
@@ -183,8 +176,8 @@ def test_is_overridden_in_is_true_only_for_the_system_that_shadowed():
|
||||
resolved = _by_name(resolve_tokens(
|
||||
APP, PARENTS,
|
||||
{
|
||||
FAMILY: [_token("--fs-accent", {"base": "#6b2118"})],
|
||||
APP: [_token("--fs-accent", {"base": "#5b4a8a"})],
|
||||
FAMILY: [design_token_stub(name="--fs-accent", value_by_mode={"base": "#6b2118"})],
|
||||
APP: [design_token_stub(name="--fs-accent", value_by_mode={"base": "#5b4a8a"})],
|
||||
},
|
||||
))
|
||||
accent = resolved["--fs-accent"]
|
||||
@@ -198,9 +191,9 @@ def test_three_levels_stack_nearest_first():
|
||||
resolved = _by_name(resolve_tokens(
|
||||
3, parents,
|
||||
{
|
||||
1: [_token("--fs-bg", {"base": "a"})],
|
||||
2: [_token("--fs-bg", {"base": "b"})],
|
||||
3: [_token("--fs-bg", {"base": "c"})],
|
||||
1: [design_token_stub(name="--fs-bg", value_by_mode={"base": "a"})],
|
||||
2: [design_token_stub(name="--fs-bg", value_by_mode={"base": "b"})],
|
||||
3: [design_token_stub(name="--fs-bg", value_by_mode={"base": "c"})],
|
||||
},
|
||||
))
|
||||
bg = resolved["--fs-bg"]
|
||||
@@ -214,8 +207,8 @@ def test_resolving_the_family_itself_ignores_its_children():
|
||||
resolved = _by_name(resolve_tokens(
|
||||
FAMILY, PARENTS,
|
||||
{
|
||||
FAMILY: [_token("--fs-accent", {"base": "#6b2118"})],
|
||||
APP: [_token("--fs-accent", {"base": "#5b4a8a"})],
|
||||
FAMILY: [design_token_stub(name="--fs-accent", value_by_mode={"base": "#6b2118"})],
|
||||
APP: [design_token_stub(name="--fs-accent", value_by_mode={"base": "#5b4a8a"})],
|
||||
},
|
||||
))
|
||||
assert resolved["--fs-accent"].value_by_mode == {"base": "#6b2118"}
|
||||
@@ -226,7 +219,7 @@ def test_value_for_falls_back_to_the_base_mode():
|
||||
"dark" must yield that rather than nothing — the read rule the storage shape
|
||||
implies."""
|
||||
resolved = _by_name(resolve_tokens(
|
||||
FAMILY, PARENTS, {FAMILY: [_token("--fs-radius-md", {"base": "8px"})]},
|
||||
FAMILY, PARENTS, {FAMILY: [design_token_stub(name="--fs-radius-md", value_by_mode={"base": "8px"})]},
|
||||
))
|
||||
radius = resolved["--fs-radius-md"]
|
||||
assert radius.value_for("dark") == "8px"
|
||||
@@ -236,7 +229,7 @@ def test_value_for_falls_back_to_the_base_mode():
|
||||
def test_value_for_prefers_an_explicit_mode_over_the_fallback():
|
||||
resolved = _by_name(resolve_tokens(
|
||||
FAMILY, PARENTS,
|
||||
{FAMILY: [_token("--fs-bg", {"base": "#f7f5ef", "dark": "#14171a"})]},
|
||||
{FAMILY: [design_token_stub(name="--fs-bg", value_by_mode={"base": "#f7f5ef", "dark": "#14171a"})]},
|
||||
))
|
||||
assert resolved["--fs-bg"].value_for("dark") == "#14171a"
|
||||
|
||||
@@ -248,11 +241,8 @@ def test_metadata_is_inherited_when_the_override_leaves_it_blank():
|
||||
resolved = _by_name(resolve_tokens(
|
||||
APP, PARENTS,
|
||||
{
|
||||
FAMILY: [_token(
|
||||
"--fs-obsidian", {"base": "#14171a"},
|
||||
group_name="surface", purpose="page bg, deepest surface",
|
||||
)],
|
||||
APP: [_token("--fs-obsidian", {"base": "#101317"})],
|
||||
FAMILY: [design_token_stub(name="--fs-obsidian", value_by_mode={"base": "#14171a"}, group_name="surface", purpose="page bg, deepest surface")],
|
||||
APP: [design_token_stub(name="--fs-obsidian", value_by_mode={"base": "#101317"})],
|
||||
},
|
||||
))
|
||||
obsidian = resolved["--fs-obsidian"]
|
||||
@@ -265,8 +255,8 @@ def test_an_override_that_states_metadata_wins_it_too():
|
||||
resolved = _by_name(resolve_tokens(
|
||||
APP, PARENTS,
|
||||
{
|
||||
FAMILY: [_token("--fs-x", {"base": "a"}, purpose="family says")],
|
||||
APP: [_token("--fs-x", {"base": "b"}, purpose="app says")],
|
||||
FAMILY: [design_token_stub(name="--fs-x", value_by_mode={"base": "a"}, purpose="family says")],
|
||||
APP: [design_token_stub(name="--fs-x", value_by_mode={"base": "b"}, purpose="app says")],
|
||||
},
|
||||
))
|
||||
assert resolved["--fs-x"].purpose == "app says"
|
||||
@@ -279,8 +269,8 @@ def test_an_override_at_default_order_keeps_the_familys_position():
|
||||
resolved = _by_name(resolve_tokens(
|
||||
APP, PARENTS,
|
||||
{
|
||||
FAMILY: [_token("--fs-x", {"base": "a"}, order_index=7)],
|
||||
APP: [_token("--fs-x", {"base": "b"})],
|
||||
FAMILY: [design_token_stub(name="--fs-x", value_by_mode={"base": "a"}, order_index=7)],
|
||||
APP: [design_token_stub(name="--fs-x", value_by_mode={"base": "b"})],
|
||||
},
|
||||
))
|
||||
assert resolved["--fs-x"].order_index == 7
|
||||
@@ -290,10 +280,10 @@ def test_the_effective_set_is_ordered_by_group_then_position_with_ungrouped_last
|
||||
resolved = resolve_tokens(
|
||||
FAMILY, PARENTS,
|
||||
{FAMILY: [
|
||||
_token("--fs-z", {"base": "1"}), # ungrouped
|
||||
_token("--fs-b", {"base": "2"}, group_name="text", order_index=1),
|
||||
_token("--fs-a", {"base": "3"}, group_name="surface", order_index=2),
|
||||
_token("--fs-c", {"base": "4"}, group_name="surface", order_index=1),
|
||||
design_token_stub(name="--fs-z", value_by_mode={"base": "1"}), # ungrouped
|
||||
design_token_stub(name="--fs-b", value_by_mode={"base": "2"}, group_name="text", order_index=1),
|
||||
design_token_stub(name="--fs-a", value_by_mode={"base": "3"}, group_name="surface", order_index=2),
|
||||
design_token_stub(name="--fs-c", value_by_mode={"base": "4"}, group_name="surface", order_index=1),
|
||||
]},
|
||||
)
|
||||
assert [t.name for t in resolved] == ["--fs-c", "--fs-a", "--fs-b", "--fs-z"]
|
||||
@@ -306,7 +296,7 @@ def test_resolution_terminates_on_a_corrupt_hierarchy():
|
||||
parents = {1: 2, 2: 1}
|
||||
resolved = _by_name(resolve_tokens(
|
||||
1, parents,
|
||||
{1: [_token("--fs-a", {"base": "one"})], 2: [_token("--fs-b", {"base": "two"})]},
|
||||
{1: [design_token_stub(name="--fs-a", value_by_mode={"base": "one"})], 2: [design_token_stub(name="--fs-b", value_by_mode={"base": "two"})]},
|
||||
))
|
||||
assert set(resolved) == {"--fs-a", "--fs-b"}
|
||||
# Each system contributes exactly once, not endlessly.
|
||||
@@ -326,8 +316,8 @@ def test_supersedes_is_inherited_when_the_override_is_silent_about_it():
|
||||
resolved = _by_name(resolve_tokens(
|
||||
APP, PARENTS,
|
||||
{
|
||||
FAMILY: [_token("--fs-text", {"base": "#e8e4d8"}, supersedes=["#fff", "#ffffff"])],
|
||||
APP: [_token("--fs-text", {"base": "#f0ece0"})],
|
||||
FAMILY: [design_token_stub(name="--fs-text", value_by_mode={"base": "#e8e4d8"}, supersedes=["#fff", "#ffffff"])],
|
||||
APP: [design_token_stub(name="--fs-text", value_by_mode={"base": "#f0ece0"})],
|
||||
},
|
||||
))
|
||||
text = resolved["--fs-text"]
|
||||
@@ -341,8 +331,8 @@ def test_an_override_that_states_its_own_supersedes_replaces_the_list():
|
||||
resolved = _by_name(resolve_tokens(
|
||||
APP, PARENTS,
|
||||
{
|
||||
FAMILY: [_token("--fs-text", {"base": "a"}, supersedes=["#fff", "#ffffff"])],
|
||||
APP: [_token("--fs-text", {"base": "b"}, supersedes=["#fff"])],
|
||||
FAMILY: [design_token_stub(name="--fs-text", value_by_mode={"base": "a"}, supersedes=["#fff", "#ffffff"])],
|
||||
APP: [design_token_stub(name="--fs-text", value_by_mode={"base": "b"}, supersedes=["#fff"])],
|
||||
},
|
||||
))
|
||||
assert resolved["--fs-text"].supersedes == ("#fff",)
|
||||
@@ -352,7 +342,7 @@ def test_a_token_that_supersedes_nothing_resolves_to_an_empty_tuple():
|
||||
"""Most tokens replace nothing. That has to be an empty sequence rather than
|
||||
None, so no caller has to test for two kinds of nothing."""
|
||||
resolved = _by_name(resolve_tokens(
|
||||
FAMILY, PARENTS, {FAMILY: [_token("--fs-radius-md", {"base": "8px"})]},
|
||||
FAMILY, PARENTS, {FAMILY: [design_token_stub(name="--fs-radius-md", value_by_mode={"base": "8px"})]},
|
||||
))
|
||||
assert resolved["--fs-radius-md"].supersedes == ()
|
||||
|
||||
@@ -360,7 +350,7 @@ def test_a_token_that_supersedes_nothing_resolves_to_an_empty_tuple():
|
||||
def test_supersedes_survives_serialisation_as_a_list():
|
||||
resolved = _by_name(resolve_tokens(
|
||||
FAMILY, PARENTS,
|
||||
{FAMILY: [_token("--fs-text", {"base": "#e8e4d8"}, supersedes=["#fff"])]},
|
||||
{FAMILY: [design_token_stub(name="--fs-text", value_by_mode={"base": "#e8e4d8"}, supersedes=["#fff"])]},
|
||||
))
|
||||
assert resolved["--fs-text"].to_dict()["supersedes"] == ["#fff"]
|
||||
|
||||
@@ -372,7 +362,7 @@ def test_the_superseded_literal_need_not_match_the_tokens_own_value():
|
||||
it was turned around."""
|
||||
resolved = _by_name(resolve_tokens(
|
||||
FAMILY, PARENTS,
|
||||
{FAMILY: [_token("--fs-text", {"base": "#e8e4d8"}, supersedes=["#fff"])]},
|
||||
{FAMILY: [design_token_stub(name="--fs-text", value_by_mode={"base": "#e8e4d8"}, supersedes=["#fff"])]},
|
||||
))
|
||||
text = resolved["--fs-text"]
|
||||
assert text.value_by_mode["base"] not in text.supersedes
|
||||
@@ -404,7 +394,7 @@ def test_rationale_cascades_like_purpose_and_is_a_different_question():
|
||||
rationale="equals Moss, aligned by design",
|
||||
order_index=0, supersedes=[],
|
||||
)],
|
||||
APP: [_token("--fs-success", {"base": "#3f5236"})],
|
||||
APP: [design_token_stub(name="--fs-success", value_by_mode={"base": "#3f5236"})],
|
||||
},
|
||||
))
|
||||
token = resolved["--fs-success"]
|
||||
@@ -415,6 +405,6 @@ def test_rationale_cascades_like_purpose_and_is_a_different_question():
|
||||
|
||||
def test_a_token_without_a_rationale_resolves_to_none():
|
||||
resolved = _by_name(resolve_tokens(
|
||||
FAMILY, PARENTS, {FAMILY: [_token("--fs-x", {"base": "1px"})]},
|
||||
FAMILY, PARENTS, {FAMILY: [design_token_stub(name="--fs-x", value_by_mode={"base": "1px"})]},
|
||||
))
|
||||
assert resolved["--fs-x"].rationale is None
|
||||
|
||||
Reference in New Issue
Block a user