mirror of
https://github.com/open-jarvis/OpenJarvis.git
synced 2026-07-28 05:12:26 +00:00
CI's lint job ran ruff check but never ruff format --check, letting format drift land silently (79 files had drifted from the pinned ruff 0.15.1). Add the ruff format --check step to ci.yml, reformat the 79 drifted files with the pinned ruff (mechanical only — verified AST-identical to before across all files, no logic changes), and add a Makefile whose test target mirrors the actual CI lane. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
65 lines
1.9 KiB
Python
65 lines
1.9 KiB
Python
"""Tests for API server model selection."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from openjarvis.cli.serve import _resolve_server_model
|
|
from openjarvis.core.config import JarvisConfig
|
|
|
|
|
|
class _FakeEngine:
|
|
def __init__(self, models: list[str]) -> None:
|
|
self._models = models
|
|
|
|
def list_models(self) -> list[str]:
|
|
return self._models
|
|
|
|
|
|
def test_server_model_falls_back_to_reachable_ollama_model() -> None:
|
|
cfg = JarvisConfig()
|
|
cfg.server.model = "mlx-community/Qwen2.5-7B-Instruct-4bit"
|
|
cfg.intelligence.default_model = "mlx-community/Qwen2.5-7B-Instruct-4bit"
|
|
cfg.intelligence.fallback_model = "qwen3.5:9b"
|
|
|
|
model = _resolve_server_model(
|
|
None,
|
|
config=cfg,
|
|
engine_name="multi",
|
|
engine=_FakeEngine(["qwen3.5:9b"]),
|
|
all_models={"multi": ["qwen3.5:9b"]},
|
|
)
|
|
|
|
assert model == "qwen3.5:9b"
|
|
|
|
|
|
def test_server_model_prefers_reachable_configured_model() -> None:
|
|
cfg = JarvisConfig()
|
|
cfg.server.model = "mlx-community/Qwen2.5-7B-Instruct-4bit"
|
|
cfg.intelligence.default_model = "qwen3.5:9b"
|
|
cfg.intelligence.fallback_model = "qwen3.5:9b"
|
|
|
|
model = _resolve_server_model(
|
|
None,
|
|
config=cfg,
|
|
engine_name="multi",
|
|
engine=_FakeEngine(["mlx-community/Qwen2.5-7B-Instruct-4bit", "qwen3.5:9b"]),
|
|
all_models={"multi": ["mlx-community/Qwen2.5-7B-Instruct-4bit"]},
|
|
)
|
|
|
|
assert model == "mlx-community/Qwen2.5-7B-Instruct-4bit"
|
|
|
|
|
|
def test_server_model_keeps_explicit_cli_model() -> None:
|
|
cfg = JarvisConfig()
|
|
cfg.server.model = "configured-model"
|
|
cfg.intelligence.fallback_model = "fallback-model"
|
|
|
|
model = _resolve_server_model(
|
|
"explicit-model",
|
|
config=cfg,
|
|
engine_name="multi",
|
|
engine=_FakeEngine(["fallback-model"]),
|
|
all_models={"multi": ["fallback-model"]},
|
|
)
|
|
|
|
assert model == "explicit-model"
|