Skip to content

~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.

test(connected): fail cleanup-probe setup when an active-research leak predates the test (#6791)

LearningCircuit09c94da72412
diff --git a/tests/connected/conftest.py b/tests/connected/conftest.py
index 5f4e2e1c6e..912de4ac94 100644
--- a/tests/connected/conftest.py
+++ b/tests/connected/conftest.py
@@ -104,11 +104,15 @@ def register_connected_user(case: ConnectedUser):
return response
-def connected_user_cleanup_probe() -> Generator[list[str], None, None]:
- usernames: list[str] = []
- yield usernames
-
+def _assert_probe_cleanup(usernames: list[str]) -> None:
+ """Teardown half of ``connected_user_cleanup_probe``.
+
+ Lives at module level so tests can drive both probe phases directly
+ (see ``tests/connected/test_cleanup_probe_attribution.py``): every
+ per-user store the fixture's consumer could have touched must be
+ empty for the consumer's username, and the process-wide
+ active-research registry must not leak (#5591).
+ """
assert len(usernames) == 1
username = usernames[0]
@@ -177,6 +181,28 @@ def connected_user_cleanup_probe() -> Generator[list[str], None, None]:
)
+def connected_user_cleanup_probe() -> Generator[list[str], None, None]:
+ # The probe only runs through ``connected_user``, so an entry leaked by
+ # an earlier test that never requested this fixture would survive until
+ # the next ``connected_user`` teardown and be attributed to that
+ # unrelated test (#5591). Fail setup instead: contamination visible
+ # here predates the current test.
+ from local_deep_research.web.research_state import get_active_research_ids
+
+ preexisting_active_research = get_active_research_ids()
+ assert not preexisting_active_research, (
+ f"active research registry not empty before test start; the leak "
+ f"predates this test (left by an earlier test): "
+ f"{preexisting_active_research}"
+ )
+
+ usernames: list[str] = []
+ yield usernames
+
+ _assert_probe_cleanup(usernames)
+
+
@pytest.fixture
def connected_user(
app,
diff --git a/tests/connected/test_cleanup_probe_attribution.py b/tests/connected/test_cleanup_probe_attribution.py
new file mode 100644
index 0000000000..b90a17d1bc
--- /dev/null
+++ b/tests/connected/test_cleanup_probe_attribution.py
@@ -0,0 +1,75 @@
+"""Phase attribution for ``connected_user_cleanup_probe`` (#5591).
+
+The probe's active-research check runs only through ``connected_user``, so
+an entry leaked by an earlier test that never requested this fixture used
+to survive until the next ``connected_user`` teardown and be reported
+against that unrelated test as ``active research leak after connected
+test``. Probe setup now fails first when the registry is already dirty —
+the contamination predates the current test — while teardown still
+attributes entries created while the fixture consumer ran to that test.
+"""
+
+from __future__ import annotations
+
+import pytest
+
+from local_deep_research.web import research_state
+from tests.connected.conftest import _assert_probe_cleanup
+
+#: A distinctive id for registry entries seeded by these tests.
+SEEDED_ID = "cleanup-probe-attribution-seed"
+
+
[email protected](autouse=True)
+def _clean_active_research_registry():
+ """Keep the registry free of this file's seeded entry, pass or fail.
+
+ Every test here asserts on the registry's contents, so an entry leaked
+ by an earlier test on the same worker would either make these tests
+ pass vacuously or fail them with the wrong wording. Refuse to start on
+ a dirty registry instead, naming the leak as pre-existing.
+ """
+ research_state.remove_active_research(SEEDED_ID)
+ leaked = list(research_state.get_active_research_ids())
+ assert not leaked, (
+ f"active research registry already dirty before this test "
+ f"(leak predates it, left by an earlier test): {leaked}"
+ )
+ yield
+ research_state.remove_active_research(SEEDED_ID)
+
+
+def test_setup_attributes_pre_existing_leak_to_an_earlier_test(request):
+ """A dirty registry at probe setup must fail setup, not the next test.
+
+ The seeded entry was ``set_active_research`` here — before the probe
+ fixture even started — so the failure message must say the leak
+ predates this test. ``getfixturevalue`` triggers probe setup inside
+ the ``raises`` block; if the setup guard were missing, the fixture
+ would instantiate cleanly and ``DID NOT RAISE`` fails this test.
+ """
+ research_state.set_active_research(SEEDED_ID, {"status": "running"})
+
+ with pytest.raises(AssertionError, match="predates this test"):
+ request.getfixturevalue("connected_user_cleanup_probe")
+
+
+def test_teardown_still_attributes_entries_created_during_the_test():
+ """An entry created after probe setup stays the consumer's fault.
+
+ Drives the shared teardown half directly with the consumer's username
+ registered, mirroring what pytest does when the fixture's consumer
+ finishes. The existing failure wording is load-bearing triage text
+ and must be retained.
+ """
+ research_state.set_active_research(SEEDED_ID, {"status": "running"})
+
+ with pytest.raises(
+ AssertionError, match="active research leak after connected test"
+ ):
+ _assert_probe_cleanup(["probe_attribution_user"])
+
+
+def test_teardown_passes_with_an_empty_registry():
+ """Sanity: a clean registry (and untouched per-user stores) is quiet."""
+ _assert_probe_cleanup(["probe_attribution_user"])