Files
OpenJarvis/tests/learning/test_router_stubs.py
T
Jon Saad-FalconandClaude Opus 4.6 323d7ff032 Add TOML config system for eval suites, pillar-aligned config, and documentation
- 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>
2026-02-24 03:34:05 +00:00

72 lines
2.2 KiB
Python

"""Tests for RouterPolicy and QueryAnalyzer ABCs (canonical location)."""
from __future__ import annotations
import pytest
from openjarvis.core.types import RoutingContext
from openjarvis.learning._stubs import QueryAnalyzer, RouterPolicy
from openjarvis.learning.router import DefaultQueryAnalyzer
class _DummyRouter(RouterPolicy):
def select_model(self, context: RoutingContext) -> str:
return "test-model"
class _DummyAnalyzer(QueryAnalyzer):
def analyze(
self, query: str, **kwargs: object,
) -> RoutingContext:
return RoutingContext(
query=query, query_length=len(query),
)
class TestRouterPolicy:
def test_abc_cannot_instantiate(self) -> None:
with pytest.raises(TypeError):
RouterPolicy() # type: ignore[abstract]
def test_concrete_implementation(self) -> None:
router = _DummyRouter()
ctx = RoutingContext(query="hello")
assert router.select_model(ctx) == "test-model"
class TestQueryAnalyzer:
def test_abc_cannot_instantiate(self) -> None:
with pytest.raises(TypeError):
QueryAnalyzer() # type: ignore[abstract]
def test_concrete_implementation(self) -> None:
analyzer = _DummyAnalyzer()
ctx = analyzer.analyze("hello world")
assert ctx.query == "hello world"
assert ctx.query_length == 11
class TestDefaultQueryAnalyzer:
def test_analyze_basic(self) -> None:
analyzer = DefaultQueryAnalyzer()
ctx = analyzer.analyze("Hello world")
assert ctx.query == "Hello world"
assert ctx.query_length == 11
assert ctx.has_code is False
assert ctx.has_math is False
def test_analyze_code_query(self) -> None:
analyzer = DefaultQueryAnalyzer()
ctx = analyzer.analyze("def hello(): pass")
assert ctx.has_code is True
def test_analyze_math_query(self) -> None:
analyzer = DefaultQueryAnalyzer()
ctx = analyzer.analyze("solve the integral of x^2")
assert ctx.has_math is True
def test_analyze_with_urgency(self) -> None:
analyzer = DefaultQueryAnalyzer()
ctx = analyzer.analyze("quick question", urgency=0.9)
assert ctx.urgency == 0.9