mirror of
https://github.com/open-jarvis/OpenJarvis.git
synced 2026-07-30 19:02:16 +00:00
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>
83 lines
2.7 KiB
Python
83 lines
2.7 KiB
Python
"""Tests for the ``jarvis bench`` CLI commands."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from unittest.mock import MagicMock, patch
|
|
|
|
from click.testing import CliRunner
|
|
|
|
from openjarvis.cli import cli
|
|
|
|
|
|
class TestBenchCLI:
|
|
def test_bench_group_in_help(self):
|
|
result = CliRunner().invoke(cli, ["--help"])
|
|
assert result.exit_code == 0
|
|
assert "bench" in result.output
|
|
|
|
def test_run_help(self):
|
|
result = CliRunner().invoke(cli, ["bench", "run", "--help"])
|
|
assert result.exit_code == 0
|
|
assert "--model" in result.output
|
|
assert "--samples" in result.output
|
|
|
|
def test_run_no_engine_error(self):
|
|
with patch("openjarvis.cli.bench_cmd.get_engine", return_value=None):
|
|
result = CliRunner().invoke(cli, ["bench", "run"])
|
|
assert result.exit_code != 0
|
|
|
|
def test_run_with_mock(self):
|
|
engine = MagicMock()
|
|
engine.engine_id = "mock"
|
|
engine.list_models.return_value = ["test-model"]
|
|
engine.generate.return_value = {
|
|
"content": "Hello",
|
|
"usage": {"prompt_tokens": 5, "completion_tokens": 3, "total_tokens": 8},
|
|
}
|
|
|
|
with patch(
|
|
"openjarvis.cli.bench_cmd.get_engine",
|
|
return_value=("mock", engine),
|
|
):
|
|
result = CliRunner().invoke(cli, ["bench", "run", "-n", "2"])
|
|
assert result.exit_code == 0
|
|
|
|
def test_json_output(self):
|
|
engine = MagicMock()
|
|
engine.engine_id = "mock"
|
|
engine.list_models.return_value = ["test-model"]
|
|
engine.generate.return_value = {
|
|
"content": "Hello",
|
|
"usage": {"prompt_tokens": 5, "completion_tokens": 3, "total_tokens": 8},
|
|
}
|
|
|
|
with patch(
|
|
"openjarvis.cli.bench_cmd.get_engine",
|
|
return_value=("mock", engine),
|
|
):
|
|
result = CliRunner().invoke(
|
|
cli, ["bench", "run", "-n", "2", "--json"],
|
|
)
|
|
assert result.exit_code == 0
|
|
assert "benchmark_count" in result.output
|
|
|
|
def test_output_to_file(self, tmp_path):
|
|
engine = MagicMock()
|
|
engine.engine_id = "mock"
|
|
engine.list_models.return_value = ["test-model"]
|
|
engine.generate.return_value = {
|
|
"content": "Hello",
|
|
"usage": {"prompt_tokens": 5, "completion_tokens": 3, "total_tokens": 8},
|
|
}
|
|
|
|
out_file = tmp_path / "results.jsonl"
|
|
with patch(
|
|
"openjarvis.cli.bench_cmd.get_engine",
|
|
return_value=("mock", engine),
|
|
):
|
|
result = CliRunner().invoke(
|
|
cli, ["bench", "run", "-n", "2", "-o", str(out_file)],
|
|
)
|
|
assert result.exit_code == 0
|
|
assert out_file.exists()
|