Files
OpenJarvis/tests/telemetry/test_store.py
T
Jon Saad-FalconandClaude Opus 4.6 301e9cd2d4 Implement OpenJarvis v1.0 — all five pillars, SDK, benchmarks, Docker
Complete implementation across six development phases (v0.1 through v1.0):

- Core: Registry system, config, event bus, types (Phase 0)
- Intelligence + Inference: Model routing, Ollama/vLLM/llama.cpp/Cloud engines (Phase 1)
- Memory: SQLite/FAISS/ColBERT/BM25/Hybrid backends, document ingest, context injection (Phase 2)
- Agents: Simple/Orchestrator/Custom/OpenClaw agents, tool system (Phase 3)
- Learning: HeuristicRouter, reward functions, GRPO stub, telemetry aggregation (Phase 4)
- SDK: Jarvis class, OpenClaw protocol/transport, benchmarks, Docker deployment (Phase 5)

520 tests passing, 8 skipped (optional deps). Ruff lint clean.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-17 00:52:48 +00:00

83 lines
2.5 KiB
Python

"""Tests for the telemetry SQLite store."""
from __future__ import annotations
import time
from pathlib import Path
from openjarvis.core.events import EventBus, EventType
from openjarvis.core.types import TelemetryRecord
from openjarvis.telemetry.store import TelemetryStore
class TestTelemetryStore:
def test_creates_table(self, tmp_path: Path) -> None:
store = TelemetryStore(tmp_path / "test.db")
rows = store._fetchall()
assert rows == []
store.close()
def test_record_values(self, tmp_path: Path) -> None:
store = TelemetryStore(tmp_path / "test.db")
rec = TelemetryRecord(
timestamp=time.time(),
model_id="qwen3:8b",
engine="ollama",
prompt_tokens=10,
completion_tokens=5,
total_tokens=15,
latency_seconds=0.5,
cost_usd=0.001,
)
store.record(rec)
rows = store._fetchall()
assert len(rows) == 1
assert rows[0][2] == "qwen3:8b" # model_id column
store.close()
def test_bus_subscription(self, tmp_path: Path) -> None:
store = TelemetryStore(tmp_path / "test.db")
bus = EventBus()
store.subscribe_to_bus(bus)
rec = TelemetryRecord(
timestamp=time.time(),
model_id="test-model",
engine="vllm",
)
bus.publish(EventType.TELEMETRY_RECORD, {"record": rec})
rows = store._fetchall()
assert len(rows) == 1
assert rows[0][2] == "test-model"
store.close()
def test_close_and_reopen(self, tmp_path: Path) -> None:
db_path = tmp_path / "test.db"
store = TelemetryStore(db_path)
rec = TelemetryRecord(timestamp=time.time(), model_id="m1", engine="e1")
store.record(rec)
store.close()
store2 = TelemetryStore(db_path)
rows = store2._fetchall()
assert len(rows) == 1
store2.close()
def test_metadata_json_roundtrip(self, tmp_path: Path) -> None:
store = TelemetryStore(tmp_path / "test.db")
rec = TelemetryRecord(
timestamp=time.time(),
model_id="m1",
engine="e1",
metadata={"key": "value", "nested": [1, 2, 3]},
)
store.record(rec)
import json
rows = store._fetchall()
meta = json.loads(rows[0][-1]) # metadata is last column
assert meta["key"] == "value"
assert meta["nested"] == [1, 2, 3]
store.close()