mirror of
https://github.com/open-jarvis/OpenJarvis.git
synced 2026-07-30 19:02:16 +00:00
- Remove pynvml from core deps (optional, behind pynvml import guard) - Fix SystemBuilder wiring bugs (agent/tools/telemetry initialization) - Fix LoopGuard hash tracking and ping-pong detection edge cases - Fix OrchestratorAgent/NativeReActAgent tool_calls handling - Fix OpenAI-compat engine streaming and error handling - Fix Ollama engine model listing and health checks - Fix eval display, config parsing, and runner edge cases - Fix guardrails engine scan mode handling - Fix dashboard panel rendering and data formatting - Fix web_search tool error handling - Fix quickstart CLI detection and setup flow - Harden channel tests (WhatsApp, Matrix, IRC, Signal, Teams, etc.) - Harden optimizer, trace judge, and personal synthesizer tests - Add missing test coverage for types, engine, system, and security Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
194 lines
6.7 KiB
Python
194 lines
6.7 KiB
Python
"""Tests for ``jarvis quickstart`` command."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from unittest.mock import MagicMock, patch
|
|
|
|
from click.testing import CliRunner
|
|
|
|
from openjarvis.cli import cli
|
|
|
|
|
|
class TestQuickstartCommand:
|
|
def test_registered(self):
|
|
"""quickstart should be a registered CLI command."""
|
|
runner = CliRunner()
|
|
result = runner.invoke(cli, ["quickstart", "--help"])
|
|
assert result.exit_code == 0
|
|
assert "quickstart" in result.output.lower() or "--help" in result.output
|
|
|
|
def test_happy_path(self, tmp_path):
|
|
"""Full quickstart succeeds when hardware detected and engine healthy."""
|
|
config_path = tmp_path / "config.toml"
|
|
hw = MagicMock()
|
|
hw.platform = "linux"
|
|
hw.cpu_brand = "Test CPU"
|
|
hw.cpu_count = 8
|
|
hw.ram_gb = 32
|
|
hw.gpu = MagicMock(name="Test GPU", vram_gb=24, count=1, vendor="nvidia")
|
|
|
|
with (
|
|
patch("openjarvis.cli.quickstart_cmd.detect_hardware", return_value=hw),
|
|
patch("openjarvis.cli.quickstart_cmd.DEFAULT_CONFIG_PATH", config_path),
|
|
patch("openjarvis.cli.quickstart_cmd.DEFAULT_CONFIG_DIR", tmp_path),
|
|
patch(
|
|
"openjarvis.cli.quickstart_cmd"
|
|
".generate_default_toml",
|
|
return_value="[engine]\n",
|
|
),
|
|
patch(
|
|
"openjarvis.cli.quickstart_cmd"
|
|
".recommend_engine",
|
|
return_value="ollama",
|
|
),
|
|
patch(
|
|
"openjarvis.cli.quickstart_cmd"
|
|
"._check_engine_health",
|
|
return_value=True,
|
|
),
|
|
patch(
|
|
"openjarvis.cli.quickstart_cmd"
|
|
"._check_model_available",
|
|
return_value=True,
|
|
),
|
|
patch(
|
|
"openjarvis.cli.quickstart_cmd"
|
|
"._test_query",
|
|
return_value="Hello!",
|
|
),
|
|
):
|
|
runner = CliRunner()
|
|
result = runner.invoke(cli, ["quickstart"])
|
|
assert result.exit_code == 0
|
|
assert "1/5" in result.output
|
|
assert "5/5" in result.output
|
|
|
|
def test_skips_config_if_exists(self, tmp_path):
|
|
"""Config step is skipped when config already exists."""
|
|
config_path = tmp_path / "config.toml"
|
|
config_path.write_text("[engine]\n")
|
|
hw = MagicMock()
|
|
hw.platform = "linux"
|
|
hw.cpu_brand = "Test CPU"
|
|
hw.cpu_count = 8
|
|
hw.ram_gb = 32
|
|
hw.gpu = None
|
|
|
|
with (
|
|
patch("openjarvis.cli.quickstart_cmd.detect_hardware", return_value=hw),
|
|
patch("openjarvis.cli.quickstart_cmd.DEFAULT_CONFIG_PATH", config_path),
|
|
patch("openjarvis.cli.quickstart_cmd.DEFAULT_CONFIG_DIR", tmp_path),
|
|
patch(
|
|
"openjarvis.cli.quickstart_cmd"
|
|
".generate_default_toml",
|
|
return_value="[engine]\n",
|
|
),
|
|
patch(
|
|
"openjarvis.cli.quickstart_cmd"
|
|
".recommend_engine",
|
|
return_value="ollama",
|
|
),
|
|
patch(
|
|
"openjarvis.cli.quickstart_cmd"
|
|
"._check_engine_health",
|
|
return_value=True,
|
|
),
|
|
patch(
|
|
"openjarvis.cli.quickstart_cmd"
|
|
"._check_model_available",
|
|
return_value=True,
|
|
),
|
|
patch(
|
|
"openjarvis.cli.quickstart_cmd"
|
|
"._test_query",
|
|
return_value="Hello!",
|
|
),
|
|
):
|
|
runner = CliRunner()
|
|
result = runner.invoke(cli, ["quickstart"])
|
|
assert result.exit_code == 0
|
|
assert (
|
|
"already exists" in result.output.lower()
|
|
or "skip" in result.output.lower()
|
|
)
|
|
|
|
def test_force_regenerates_config(self, tmp_path):
|
|
"""--force should regenerate config even if it exists."""
|
|
config_path = tmp_path / "config.toml"
|
|
config_path.write_text("[old]\n")
|
|
hw = MagicMock()
|
|
hw.platform = "linux"
|
|
hw.cpu_brand = "Test CPU"
|
|
hw.cpu_count = 8
|
|
hw.ram_gb = 32
|
|
hw.gpu = None
|
|
|
|
with (
|
|
patch("openjarvis.cli.quickstart_cmd.detect_hardware", return_value=hw),
|
|
patch("openjarvis.cli.quickstart_cmd.DEFAULT_CONFIG_PATH", config_path),
|
|
patch("openjarvis.cli.quickstart_cmd.DEFAULT_CONFIG_DIR", tmp_path),
|
|
patch(
|
|
"openjarvis.cli.quickstart_cmd"
|
|
".generate_default_toml",
|
|
return_value="[engine]\nnew = true\n",
|
|
),
|
|
patch(
|
|
"openjarvis.cli.quickstart_cmd"
|
|
".recommend_engine",
|
|
return_value="ollama",
|
|
),
|
|
patch(
|
|
"openjarvis.cli.quickstart_cmd"
|
|
"._check_engine_health",
|
|
return_value=True,
|
|
),
|
|
patch(
|
|
"openjarvis.cli.quickstart_cmd"
|
|
"._check_model_available",
|
|
return_value=True,
|
|
),
|
|
patch("openjarvis.cli.quickstart_cmd._test_query", return_value="Hello!"),
|
|
):
|
|
runner = CliRunner()
|
|
result = runner.invoke(cli, ["quickstart", "--force"])
|
|
assert result.exit_code == 0
|
|
assert "new = true" in config_path.read_text()
|
|
|
|
def test_engine_not_found(self, tmp_path):
|
|
"""Helpful message when engine is unreachable."""
|
|
config_path = tmp_path / "config.toml"
|
|
hw = MagicMock()
|
|
hw.platform = "linux"
|
|
hw.cpu_brand = "Test CPU"
|
|
hw.cpu_count = 8
|
|
hw.ram_gb = 32
|
|
hw.gpu = None
|
|
|
|
with (
|
|
patch("openjarvis.cli.quickstart_cmd.detect_hardware", return_value=hw),
|
|
patch("openjarvis.cli.quickstart_cmd.DEFAULT_CONFIG_PATH", config_path),
|
|
patch("openjarvis.cli.quickstart_cmd.DEFAULT_CONFIG_DIR", tmp_path),
|
|
patch(
|
|
"openjarvis.cli.quickstart_cmd"
|
|
".generate_default_toml",
|
|
return_value="[engine]\n",
|
|
),
|
|
patch(
|
|
"openjarvis.cli.quickstart_cmd"
|
|
".recommend_engine",
|
|
return_value="ollama",
|
|
),
|
|
patch(
|
|
"openjarvis.cli.quickstart_cmd"
|
|
"._check_engine_health",
|
|
return_value=False,
|
|
),
|
|
):
|
|
runner = CliRunner()
|
|
result = runner.invoke(cli, ["quickstart"])
|
|
assert result.exit_code == 1
|
|
assert (
|
|
"engine" in result.output.lower()
|
|
or "not reachable" in result.output.lower()
|
|
)
|