refactor(tests): one definition each for the copied fixtures and fakes (#2825, milestone 296 area 1)
CI & Build / Python lint (push) Successful in 3s
CI & Build / Plugin hooks (push) Successful in 8s
CI & Build / integration (push) Successful in 24s
CI & Build / TypeScript typecheck (push) Successful in 32s
CI & Build / Python tests (push) Successful in 54s
CI & Build / Build & push image (push) Successful in 18s
CI & Build / Python lint (push) Successful in 3s
CI & Build / Plugin hooks (push) Successful in 8s
CI & Build / integration (push) Successful in 24s
CI & Build / TypeScript typecheck (push) Successful in 32s
CI & Build / Python tests (push) Successful in 54s
CI & Build / Build & push image (push) Successful in 18s
The shape ledger showed the same test scaffolding defined over and over: _bind_user x12 (byte-identical), _dispose_engine x10 in three wordings, _no_supersession x3, _make_mock_session x7 in three subsets, a get-or-create User helper x2 (+3 inlined), and fifteen hand-rolled MagicMock note factories each re-explaining the same "an auto-MagicMock attribute is truthy" hazard (note 2109). Now: conftest.py carries _bind_user / _dispose_engine / _no_supersession as opt-in fixtures (pytestmark = usefixtures(...) per module, so unit tests pay nothing), and tests/helpers.py carries make_mock_session(), ensure_user() and fake_note(**attrs) — the hazard documented once, real values on every attribute the product reads. Call sites were rewritten by AST so titles with dashes and commas survived; the three SimpleNamespace _note stand-ins that only feed a single function stay local. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -15,38 +15,10 @@ shared record would be findable by wording and invisible by meaning.
|
||||
from unittest.mock import AsyncMock, MagicMock, patch
|
||||
|
||||
import pytest
|
||||
from tests.helpers import fake_note
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def _no_supersession():
|
||||
"""The auto-inject menu now asks which of its lines are superseded (#278).
|
||||
|
||||
That is a real database call on a path these tests exercise without one.
|
||||
Stubbed to "nothing superseded" — the ordinary state — rather than hidden
|
||||
behind a try/except in the product, which would make the code lie about
|
||||
what it does. The label's own behaviour is covered in
|
||||
tests/test_supersession_ranking.py.
|
||||
"""
|
||||
with patch("scribe.services.plugin_context.superseded_ids",
|
||||
AsyncMock(return_value=set())):
|
||||
yield
|
||||
|
||||
|
||||
|
||||
def _note(id=1, user_id=7, title="A note", note_type="note",
|
||||
is_task=False, task_kind="work"):
|
||||
n = MagicMock()
|
||||
n.id = id
|
||||
n.user_id = user_id
|
||||
n.title = title
|
||||
n.body = "body"
|
||||
n.tags = []
|
||||
# Real values, not auto-attributes: the menu reads these to label each line,
|
||||
# and a MagicMock is truthy — every record would render as a task (note 2109).
|
||||
n.is_task = is_task
|
||||
n.task_kind = task_kind
|
||||
n.note_type = note_type
|
||||
return n
|
||||
pytestmark = pytest.mark.usefixtures("_no_supersession")
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@@ -148,7 +120,7 @@ async def test_injected_menu_attributes_another_users_note():
|
||||
menu line is the only provenance the agent sees, so it has to name them."""
|
||||
from scribe.services import plugin_context
|
||||
|
||||
mine, theirs = _note(1, user_id=7, title="Mine"), _note(2, user_id=9, title="Theirs")
|
||||
mine, theirs = fake_note(id=1, title="Mine", user_id=7), fake_note(id=2, title="Theirs", user_id=9)
|
||||
with patch.object(plugin_context, "semantic_search_notes",
|
||||
AsyncMock(return_value=[(0.9, theirs), (0.88, mine)])), \
|
||||
patch.object(plugin_context, "get_autoinject_config",
|
||||
@@ -176,11 +148,11 @@ async def test_injected_menu_labels_the_record_kind():
|
||||
from scribe.services import plugin_context
|
||||
|
||||
hits = [
|
||||
(0.92, _note(1, title="debounce — rate-limit a callback", note_type="snippet")),
|
||||
(0.91, _note(2, title="Release checklist", note_type="process")),
|
||||
(0.90, _note(3, title="Auth token expiry", is_task=True, task_kind="issue")),
|
||||
(0.89, _note(4, title="Ship the drafter", is_task=True)),
|
||||
(0.88, _note(5, title="Why we dropped CalDAV")),
|
||||
(0.92, fake_note(id=1, title="debounce — rate-limit a callback", note_type="snippet")),
|
||||
(0.91, fake_note(id=2, title="Release checklist", note_type="process")),
|
||||
(0.90, fake_note(id=3, title="Auth token expiry", is_task=True, task_kind="issue")),
|
||||
(0.89, fake_note(id=4, title="Ship the drafter", is_task=True)),
|
||||
(0.88, fake_note(id=5, title="Why we dropped CalDAV")),
|
||||
]
|
||||
with patch.object(plugin_context, "semantic_search_notes",
|
||||
AsyncMock(return_value=hits)), \
|
||||
|
||||
Reference in New Issue
Block a user