From 993c24c8b9d35fee2a9b7c17c1dd0171590c8ef4 Mon Sep 17 00:00:00 2001 From: Jon Saad-Falcon <41205309+jonsaadfalcon@users.noreply.github.com> Date: Mon, 22 Jun 2026 19:12:10 -0700 Subject: [PATCH] test(server): make TestTraceRecording hermetic (env-independent) (#583) TestTraceRecording relied on the ambient ~/.openjarvis/config.toml leaving traces.enabled at its default, so it failed on any machine with traces disabled locally (passing in CI only because the runner has no config file). Pass an explicit traces-enabled config with a tmp db_path so the tests are environment-independent and parallel-safe under pytest -n auto. Relates to #582. --- tests/server/test_routes.py | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/tests/server/test_routes.py b/tests/server/test_routes.py index aa6c4812..d0392596 100644 --- a/tests/server/test_routes.py +++ b/tests/server/test_routes.py @@ -790,8 +790,25 @@ class TestCreateApp: # --------------------------------------------------------------------------- +def _traces_enabled_config(tmp_path): + """A config with traces explicitly enabled, isolated to *tmp_path*. + + ``create_app`` only builds a trace store when ``config.traces.enabled`` is + true (server/app.py). Relying on the ambient ``load_config()`` made these + tests fail on any machine whose ``~/.openjarvis/config.toml`` disables + traces; pinning an explicit config + tmp db keeps them hermetic and + parallel-safe under ``pytest -n auto``. + """ + from openjarvis.core.config import JarvisConfig + + cfg = JarvisConfig() + cfg.traces.enabled = True + cfg.traces.db_path = str(tmp_path / "traces.db") + return cfg + + class TestTraceRecording: - def test_agent_completion_creates_trace(self): + def test_agent_completion_creates_trace(self, tmp_path): """A non-streaming agent completion records exactly one trace. The collector is the single writer: it saves directly and also @@ -810,9 +827,10 @@ class TestTraceRecording: "test-model", agent=agent, bus=EventBus(record_history=False), + config=_traces_enabled_config(tmp_path), ) store = app.state.trace_store - assert store is not None, "traces enabled by default → store should exist" + assert store is not None, "traces explicitly enabled → store should exist" assert store.count() == 0 client = TestClient(app) @@ -831,10 +849,10 @@ class TestTraceRecording: assert trace.query == "What is 2+2?" assert trace.result == "traced reply" - def test_streaming_completion_creates_trace(self): + def test_streaming_completion_creates_trace(self, tmp_path): """A streamed completion (no agent) records the assembled response.""" engine = _make_engine() - app = create_app(engine, "test-model") + app = create_app(engine, "test-model", config=_traces_enabled_config(tmp_path)) store = app.state.trace_store assert store is not None assert store.count() == 0