Files
OpenJarvis/tests/intelligence/test_intelligence_stubs.py
T
Jon Saad-FalconandClaude Opus 4.6 852259f18b Restructure codebase into 5-pillar architecture with MCP tool management, composition layer, and structured learning
Phase 1: Move RoutingContext to core/types.py, add RouterPolicy and QueryAnalyzer ABCs to intelligence/_stubs.py
Phase 2: Move memory backends to tools/storage/, convert memory/ to backward-compat shims
Phase 3: Add MCPToolAdapter, storage MCP tools, upgrade MCP server to spec 2025-11-25
Phase 4: Add SystemBuilder + JarvisSystem composition layer (system.py)
Phase 5: Add InstrumentedEngine for opt-in telemetry, simplify all agents
Phase 6: Add LearningPolicy ABC taxonomy with SFTPolicy, AgentAdvisorPolicy, ICLUpdaterPolicy
Phase 7: Update config schema (ToolsConfig, MCPConfig, TracesConfig, per-pillar learning policies)

Also: update all docs, README (DSPy-inspired), CLAUDE.md, and add logo assets.
1391 tests pass, 32 skipped. Zero new lint errors. Full backward compatibility via shims.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-22 05:57:13 +00:00

89 lines
3.0 KiB
Python

"""Tests for Intelligence pillar ABCs."""
from __future__ import annotations
import pytest
from openjarvis.core.types import RoutingContext
from openjarvis.intelligence._stubs import QueryAnalyzer, RouterPolicy
from openjarvis.intelligence.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
class TestRoutingContextInCoreTypes:
"""Verify RoutingContext is accessible from core.types."""
def test_import_from_core_types(self) -> None:
from openjarvis.core.types import RoutingContext as RC
ctx = RC(query="test", has_code=True)
assert ctx.query == "test"
assert ctx.has_code is True
def test_backward_compat_import(self) -> None:
"""RoutingContext should still be importable from learning._stubs."""
from openjarvis.learning._stubs import RoutingContext as RC
ctx = RC(query="compat")
assert ctx.query == "compat"
def test_router_policy_backward_compat(self) -> None:
"""RouterPolicy should still be importable from learning._stubs."""
from openjarvis.learning._stubs import RouterPolicy as RP
assert RP is RouterPolicy