From 6c4c1bccfcfb8eda55d01b82a38359ae3afa72b7 Mon Sep 17 00:00:00 2001 From: Bryan Van Deusen Date: Sat, 8 Aug 2026 02:07:14 -0400 Subject: [PATCH] test: stub the auto-inject supersession lookup where there is no database MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit CI on f20c019: nine failures across three files, all on the auto-inject path. Step 3's own tests passed; these are the same shape as the step 2 breakage — a real database call added to a path whose unit tests run without one. Stubbed per file, each saying why, rather than once in conftest. A global stub would hide the dependency from every future test on these paths too, which is the same "make the code lie" trade refused in 984407f, one level up. The auto-inject query is kept separate from the ranker's rather than threaded through, and that is deliberate: `_reserve_slot_for_reuse` runs a SECOND search and can add a hit to the menu, so the final `kept` set is not a subset of what the ranker scored. Labelling whatever actually reached the menu needs its own lookup over that final set — one indexed query on a handful of ids. Refs #278 --- tests/test_note_usage.py | 16 ++++++++++++++++ tests/test_retrieval_scopes.py | 16 ++++++++++++++++ tests/test_services_plugin_context.py | 16 ++++++++++++++++ 3 files changed, 48 insertions(+) diff --git a/tests/test_note_usage.py b/tests/test_note_usage.py index b57f6b3..d223e6d 100644 --- a/tests/test_note_usage.py +++ b/tests/test_note_usage.py @@ -9,6 +9,22 @@ from unittest.mock import AsyncMock, MagicMock, patch import pytest + +@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 + + from scribe.services import note_usage from scribe.services.note_usage import ( empty_usage, diff --git a/tests/test_retrieval_scopes.py b/tests/test_retrieval_scopes.py index 478edce..3f4fa6b 100644 --- a/tests/test_retrieval_scopes.py +++ b/tests/test_retrieval_scopes.py @@ -17,6 +17,22 @@ from unittest.mock import AsyncMock, MagicMock, patch import pytest +@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() diff --git a/tests/test_services_plugin_context.py b/tests/test_services_plugin_context.py index 82b96e1..e45c98e 100644 --- a/tests/test_services_plugin_context.py +++ b/tests/test_services_plugin_context.py @@ -3,6 +3,22 @@ from unittest.mock import AsyncMock, MagicMock, patch import pytest +@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 _rule(rid, title, topic_id): r = MagicMock() r.id, r.title, r.topic_id = rid, title, topic_id