mirror of
https://github.com/open-jarvis/OpenJarvis.git
synced 2026-07-30 19:02:16 +00:00
- Eval config: TOML-based suite configs defining models x benchmarks matrix, loaded via --config flag. Includes load_eval_config(), expand_suite(), 7 config dataclasses, 3 example configs, and 61 new tests. - Pillar-aligned config: generation params in IntelligenceConfig, nested engine/learning configs, agent objective/system_prompt/context_from_memory, structured learning sub-policies, TOML migration layer. - Documentation: evaluations user guide, evals API reference, updated mkdocs.yml navigation, updated architecture docs. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
113 lines
4.0 KiB
Python
113 lines
4.0 KiB
Python
"""Tests for model resolution fallback chain in jarvis ask."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import importlib
|
|
from unittest import mock
|
|
|
|
from click.testing import CliRunner
|
|
|
|
from openjarvis.cli import cli
|
|
|
|
_ask_mod = importlib.import_module("openjarvis.cli.ask")
|
|
|
|
|
|
def _mock_engine():
|
|
"""Create a mock engine that returns a simple response."""
|
|
engine = mock.MagicMock()
|
|
engine.engine_id = "mock"
|
|
engine.health.return_value = True
|
|
engine.list_models.return_value = ["test-model"]
|
|
engine.generate.return_value = {
|
|
"content": "Hello!",
|
|
"usage": {"prompt_tokens": 5, "completion_tokens": 3, "total_tokens": 8},
|
|
"model": "test-model",
|
|
"finish_reason": "stop",
|
|
}
|
|
return engine
|
|
|
|
|
|
def _patch_engine(engine):
|
|
"""Return context managers that patch engine discovery to use our mock."""
|
|
return (
|
|
mock.patch.object(
|
|
_ask_mod, "get_engine",
|
|
return_value=("mock", engine),
|
|
),
|
|
mock.patch.object(
|
|
_ask_mod, "discover_engines",
|
|
return_value={"mock": engine},
|
|
),
|
|
mock.patch.object(
|
|
_ask_mod, "discover_models",
|
|
return_value={"mock": ["test-model"]},
|
|
),
|
|
mock.patch.object(_ask_mod, "register_builtin_models"),
|
|
mock.patch.object(_ask_mod, "merge_discovered_models"),
|
|
mock.patch.object(_ask_mod, "TelemetryStore"),
|
|
)
|
|
|
|
|
|
class TestAskModelResolution:
|
|
def test_default_model_from_config(self) -> None:
|
|
"""When no -m flag, uses config.intelligence.default_model."""
|
|
engine = _mock_engine()
|
|
patches = _patch_engine(engine)
|
|
with patches[0], patches[1], patches[2], patches[3], patches[4], patches[5]:
|
|
result = CliRunner().invoke(cli, ["ask", "Hello"])
|
|
assert result.exit_code == 0
|
|
assert "Hello!" in result.output
|
|
|
|
def test_explicit_model_flag(self) -> None:
|
|
"""The -m flag directly selects a model, bypassing fallback chain."""
|
|
engine = _mock_engine()
|
|
patches = _patch_engine(engine)
|
|
with patches[0], patches[1], patches[2], patches[3], patches[4], patches[5]:
|
|
result = CliRunner().invoke(
|
|
cli, ["ask", "-m", "test-model", "Hello"],
|
|
)
|
|
assert result.exit_code == 0
|
|
assert "Hello!" in result.output
|
|
|
|
def test_fallback_to_engine_models(self) -> None:
|
|
"""When default_model is empty, falls back to first engine model."""
|
|
engine = _mock_engine()
|
|
patches = _patch_engine(engine)
|
|
with (
|
|
patches[0], patches[1], patches[2], patches[3], patches[4], patches[5],
|
|
mock.patch.object(
|
|
_ask_mod, "load_config",
|
|
) as mock_config,
|
|
):
|
|
cfg = mock_config.return_value
|
|
cfg.telemetry.enabled = False
|
|
cfg.intelligence.default_model = ""
|
|
cfg.intelligence.fallback_model = ""
|
|
cfg.agent.context_from_memory = False
|
|
result = CliRunner().invoke(cli, ["ask", "Hello"])
|
|
assert result.exit_code == 0
|
|
|
|
def test_fallback_to_fallback_model(self) -> None:
|
|
"""When default_model is empty and no engine models, uses fallback_model."""
|
|
engine = _mock_engine()
|
|
patches = _patch_engine(engine)
|
|
# Override discover_models to return empty list
|
|
with (
|
|
patches[0], patches[1],
|
|
mock.patch.object(
|
|
_ask_mod, "discover_models",
|
|
return_value={"mock": []},
|
|
),
|
|
patches[3], patches[4], patches[5],
|
|
mock.patch.object(
|
|
_ask_mod, "load_config",
|
|
) as mock_config,
|
|
):
|
|
cfg = mock_config.return_value
|
|
cfg.telemetry.enabled = False
|
|
cfg.intelligence.default_model = ""
|
|
cfg.intelligence.fallback_model = "fallback-model"
|
|
cfg.agent.context_from_memory = False
|
|
result = CliRunner().invoke(cli, ["ask", "Hello"])
|
|
assert result.exit_code == 0
|