Files
OpenJarvis/tests/core/test_config.py
T
Jon Saad-FalconandClaude Opus 4.6 8d538cd1b0 Add orchestrator training, channels, LiteLLM engine, and simplify learning taxonomy
Major changes across parallel sessions:

- Add orchestrator SFT & GRPO training subpackage (learning/orchestrator/)
  with episode types, multi-objective reward, prompt registry, policy model,
  RL environment, and registered learning policies
- Add structured THOUGHT/TOOL/INPUT/FINAL_ANSWER mode to OrchestratorAgent
- Add 15 channel backends (Discord, Slack, Telegram, Email, Webhook, IRC,
  Matrix, Teams, WhatsApp, Signal, Mattermost, BlueBubbles, Feishu,
  Google Chat, Webchat) with channel tools and config
- Add LiteLLM engine backend for unified LLM provider access
- Add RLM agent and REPL tool
- Remove ToolLearningPolicy — learning taxonomy now only targets
  Intelligence (LM weights/routing) and Agents (logic/ICL/tool strategies)
- Rename SFTPolicy to SFTRouterPolicy (backward-compat alias kept)
- Remove OpenClaw agent infrastructure (openclaw*.py, openclaw_bridge.py)
- Fix async streaming tests (asyncio.run vs deprecated get_event_loop)
- Fix server channel route tests (pytest.importorskip for optional fastapi)
- Track uv.lock for reproducibility
- Update CLAUDE.md and docs to reflect all changes

1676 tests pass, 37 skipped.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 18:32:32 +00:00

148 lines
4.8 KiB
Python

"""Tests for configuration, hardware detection, and engine recommendation."""
from __future__ import annotations
from pathlib import Path
from openjarvis.core.config import (
ChannelConfig,
EngineConfig,
GpuInfo,
HardwareInfo,
JarvisConfig,
SecurityConfig,
generate_default_toml,
load_config,
recommend_engine,
)
class TestDefaults:
def test_jarvis_config_defaults(self) -> None:
cfg = JarvisConfig()
assert cfg.engine.default == "ollama"
assert cfg.memory.default_backend == "sqlite"
assert cfg.telemetry.enabled is True
def test_engine_config_defaults(self) -> None:
ec = EngineConfig()
assert ec.ollama_host == "http://localhost:11434"
assert ec.vllm_host == "http://localhost:8000"
class TestRecommendEngine:
def test_no_gpu(self) -> None:
hw = HardwareInfo(platform="linux")
assert recommend_engine(hw) == "llamacpp"
def test_apple_silicon(self) -> None:
hw = HardwareInfo(
platform="darwin",
gpu=GpuInfo(vendor="apple", name="Apple M2 Max"),
)
assert recommend_engine(hw) == "ollama"
def test_nvidia_datacenter(self) -> None:
hw = HardwareInfo(
platform="linux",
gpu=GpuInfo(vendor="nvidia", name="NVIDIA A100-SXM4-80GB", vram_gb=80),
)
assert recommend_engine(hw) == "vllm"
def test_nvidia_consumer(self) -> None:
hw = HardwareInfo(
platform="linux",
gpu=GpuInfo(vendor="nvidia", name="NVIDIA GeForce RTX 4090", vram_gb=24),
)
assert recommend_engine(hw) == "ollama"
def test_amd(self) -> None:
hw = HardwareInfo(
platform="linux",
gpu=GpuInfo(vendor="amd", name="Radeon RX 7900 XTX"),
)
assert recommend_engine(hw) == "vllm"
class TestTomlLoading:
def test_load_missing_file_uses_defaults(self, tmp_path: Path) -> None:
cfg = load_config(tmp_path / "nonexistent.toml")
assert isinstance(cfg, JarvisConfig)
# engine default is derived from detected hardware — just ensure it's a string
assert isinstance(cfg.engine.default, str)
def test_load_overrides(self, tmp_path: Path) -> None:
toml_file = tmp_path / "config.toml"
toml_file.write_text(
'[engine]\ndefault = "vllm"\n\n[memory]\ndefault_backend = "faiss"\n'
)
cfg = load_config(toml_file)
assert cfg.engine.default == "vllm"
assert cfg.memory.default_backend == "faiss"
class TestGenerateToml:
def test_contains_engine_section(self) -> None:
hw = HardwareInfo(
platform="linux",
cpu_brand="Intel Xeon",
cpu_count=16,
ram_gb=64.0,
gpu=GpuInfo(vendor="nvidia", name="NVIDIA H100", vram_gb=80),
)
toml = generate_default_toml(hw)
assert "[engine]" in toml
assert 'default = "vllm"' in toml
assert "H100" in toml
class TestSecurityConfig:
def test_security_config_defaults(self) -> None:
sc = SecurityConfig()
assert sc.enabled is True
assert sc.scan_input is True
assert sc.scan_output is True
assert sc.mode == "warn"
assert sc.secret_scanner is True
assert sc.pii_scanner is True
assert sc.enforce_tool_confirmation is True
def test_security_config_on_jarvis_config(self) -> None:
cfg = JarvisConfig()
assert isinstance(cfg.security, SecurityConfig)
def test_security_config_loads_from_toml(self, tmp_path: Path) -> None:
toml_file = tmp_path / "config.toml"
toml_file.write_text('[security]\nmode = "block"\nscan_input = false\n')
cfg = load_config(toml_file)
assert cfg.security.mode == "block"
assert cfg.security.scan_input is False
def test_security_config_in_default_toml(self) -> None:
output = generate_default_toml(HardwareInfo())
assert "[security]" in output
class TestChannelConfig:
def test_channel_config_defaults(self) -> None:
cc = ChannelConfig()
assert cc.enabled is False
assert cc.default_agent == "simple"
def test_channel_config_on_jarvis_config(self) -> None:
cfg = JarvisConfig()
assert isinstance(cfg.channel, ChannelConfig)
def test_channel_config_loads_from_toml(self, tmp_path: Path) -> None:
toml_file = tmp_path / "config.toml"
toml_file.write_text(
'[channel]\nenabled = true\ndefault_channel = "telegram"\n'
)
cfg = load_config(toml_file)
assert cfg.channel.enabled is True
assert cfg.channel.default_channel == "telegram"
def test_channel_config_in_default_toml(self) -> None:
output = generate_default_toml(HardwareInfo())
assert "[channel]" in output