Stub llm_core via monkeypatch.setitem so the cross-tenant test does not leak its fake into later test modules
This commit is contained in:
@@ -32,16 +32,20 @@ def _load_extractor():
|
|||||||
return mod
|
return mod
|
||||||
|
|
||||||
|
|
||||||
def _install_llm_stub(facts_json):
|
def _install_llm_stub(monkeypatch, facts_json):
|
||||||
mod = types.ModuleType("src.llm_core")
|
mod = types.ModuleType("src.llm_core")
|
||||||
|
|
||||||
async def llm_call_async(*a, **k):
|
async def llm_call_async(*a, **k):
|
||||||
return facts_json
|
return facts_json
|
||||||
|
|
||||||
mod.llm_call_async = llm_call_async
|
mod.llm_call_async = llm_call_async
|
||||||
|
# Use monkeypatch.setitem so sys.modules is restored at teardown. A raw
|
||||||
|
# assignment here permanently replaced the real src.llm_core with this
|
||||||
|
# stripped stub, leaking "My home is in Lisbon" (and hiding _detect_provider)
|
||||||
|
# into every later-collected test that imports the real module.
|
||||||
src_pkg = sys.modules.get("src") or types.ModuleType("src")
|
src_pkg = sys.modules.get("src") or types.ModuleType("src")
|
||||||
sys.modules["src"] = src_pkg
|
monkeypatch.setitem(sys.modules, "src", src_pkg)
|
||||||
sys.modules["src.llm_core"] = mod
|
monkeypatch.setitem(sys.modules, "src.llm_core", mod)
|
||||||
|
|
||||||
|
|
||||||
class FakeSession:
|
class FakeSession:
|
||||||
@@ -95,7 +99,7 @@ def test_vector_match_from_other_tenant_does_not_drop_users_fact(monkeypatch):
|
|||||||
])
|
])
|
||||||
# The vector store reports user B's new fact as a near-duplicate of a1.
|
# The vector store reports user B's new fact as a near-duplicate of a1.
|
||||||
vec = FakeVector(match_id="a1")
|
vec = FakeVector(match_id="a1")
|
||||||
_install_llm_stub('["My home is in Lisbon"]')
|
_install_llm_stub(monkeypatch, '["My home is in Lisbon"]')
|
||||||
|
|
||||||
memory_extractor = _load_extractor()
|
memory_extractor = _load_extractor()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user