fix(plugins): stop the new spool tests depending on ambient state
CI runs agent-plugin-core/tests and claude-code-plugin/tests in one pytest process. Two things only show up in that combined run, so the suites passed locally and failed on every push. claude-code-plugin/tests/conftest.py sets MEM0_TELEMETRY=false at import, which is process-wide. record() then returns early and every assertion in test_spool_delivery.py saw an empty spool — nine failures, all reported as "recorded nothing" rather than as a disabled feature. The fixture now pins MEM0_TELEMETRY rather than trusting whatever collected first. The fixture also dropped telemetry/memory_core/_harness_id from sys.modules on teardown. That conftest imports memory_core once at collection and calls configure_harness() on it, so a later re-import got a fresh module with default harness config and test_memory_core failed depending on collection order. The fixture now saves and restores those entries instead of deleting them. Verified with CI's exact command rather than the narrower path I had been running: 266 passed, 8 skipped. Claude-Session: https://claude.ai/code/session_01C7tEmH86HAr7GoAAKCEHZb
This commit is contained in:
@@ -25,15 +25,32 @@ pytestmark = pytest.mark.skipif(not HOST_CORE.exists(), reason="claude-code-plug
|
|||||||
|
|
||||||
@pytest.fixture()
|
@pytest.fixture()
|
||||||
def telemetry(tmp_path, monkeypatch):
|
def telemetry(tmp_path, monkeypatch):
|
||||||
|
# CI runs this directory and claude-code-plugin/tests in ONE pytest process,
|
||||||
|
# and that suite's conftest sets MEM0_TELEMETRY=false at import, process-wide.
|
||||||
|
# Without this the whole file silently no-ops: record() returns early and
|
||||||
|
# every assertion sees an empty spool. Do not rely on ambient env.
|
||||||
|
monkeypatch.setenv("MEM0_TELEMETRY", "true")
|
||||||
monkeypatch.setenv("MEM0_CODE_DATA_DIR", str(tmp_path / "data"))
|
monkeypatch.setenv("MEM0_CODE_DATA_DIR", str(tmp_path / "data"))
|
||||||
monkeypatch.syspath_prepend(str(HOST_CORE))
|
monkeypatch.syspath_prepend(str(HOST_CORE))
|
||||||
for name in ("telemetry", "memory_core", "_harness_id"):
|
|
||||||
|
# Save and RESTORE rather than delete. claude-code-plugin/tests/conftest.py
|
||||||
|
# imports memory_core once at collection and calls configure_harness() on it;
|
||||||
|
# dropping the module left a later re-import with default harness config, so
|
||||||
|
# tests in that suite failed depending on collection order.
|
||||||
|
names = ("telemetry", "memory_core", "_harness_id")
|
||||||
|
saved = {name: sys.modules.get(name) for name in names}
|
||||||
|
for name in names:
|
||||||
sys.modules.pop(name, None)
|
sys.modules.pop(name, None)
|
||||||
|
|
||||||
module = importlib.import_module("telemetry")
|
module = importlib.import_module("telemetry")
|
||||||
monkeypatch.setattr(module, "resolve_distinct_id", lambda: ("tester@example.com", ""))
|
monkeypatch.setattr(module, "resolve_distinct_id", lambda: ("tester@example.com", ""))
|
||||||
yield module
|
try:
|
||||||
for name in ("telemetry", "memory_core", "_harness_id"):
|
yield module
|
||||||
sys.modules.pop(name, None)
|
finally:
|
||||||
|
for name in names:
|
||||||
|
sys.modules.pop(name, None)
|
||||||
|
if saved[name] is not None:
|
||||||
|
sys.modules[name] = saved[name]
|
||||||
|
|
||||||
|
|
||||||
def _delivered(payloads):
|
def _delivered(payloads):
|
||||||
|
|||||||
Reference in New Issue
Block a user