Skip to content

Personal AI, On Personal Devices

Python

test(server): fix flaky /metrics assertion, missing the third response state (#804)

havolline1895c00900d44
diff --git a/tests/server/test_api_routes.py b/tests/server/test_api_routes.py
index e21f13d8..330e1b77 100644
--- a/tests/server/test_api_routes.py
+++ b/tests/server/test_api_routes.py
@@ -120,11 +120,22 @@ class TestBudgetRoutes:
class TestMetricsRoute:
- def test_metrics_endpoint(self):
+ def test_metrics_endpoint(self, tmp_path, monkeypatch):
+ """An isolated empty config dir returns the exact no-data response.
+
+ Pinning ``DEFAULT_CONFIG_DIR`` keeps the test independent of the
+ machine's real telemetry database and makes any other response a
+ regression rather than accepting all possible production states.
+ """
+ import openjarvis.core.config as config_mod
+
+ monkeypatch.setattr(config_mod, "DEFAULT_CONFIG_DIR", tmp_path)
+
client = TestClient(_make_app())
resp = client.get("/metrics")
assert resp.status_code == 200
- assert "openjarvis" in resp.text or "No metrics" in resp.text
+ assert resp.text == "# no telemetry data\n"
+ assert resp.headers["content-type"].startswith("text/plain")
class TestSkillRoutes: