59 lines
1.7 KiB
Python
59 lines
1.7 KiB
Python
|
|
"""Tests for time-aware model routing."""
|
||
|
|
|
||
|
|
import pytest
|
||
|
|
import sys
|
||
|
|
from pathlib import Path
|
||
|
|
|
||
|
|
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
|
||
|
|
|
||
|
|
from agent.time_aware_routing import (
|
||
|
|
resolve_time_aware_model,
|
||
|
|
get_hour_error_rate,
|
||
|
|
is_off_hours,
|
||
|
|
get_routing_report,
|
||
|
|
)
|
||
|
|
|
||
|
|
|
||
|
|
class TestErrorRates:
|
||
|
|
def test_evening_high_error(self):
|
||
|
|
assert get_hour_error_rate(18) == 9.4
|
||
|
|
assert get_hour_error_rate(19) == 8.1
|
||
|
|
|
||
|
|
def test_morning_low_error(self):
|
||
|
|
assert get_hour_error_rate(9) == 4.0
|
||
|
|
assert get_hour_error_rate(12) == 4.0
|
||
|
|
|
||
|
|
def test_default_for_unknown(self):
|
||
|
|
assert get_hour_error_rate(15) == 4.0
|
||
|
|
|
||
|
|
|
||
|
|
class TestOffHours:
|
||
|
|
def test_evening_is_off_hours(self):
|
||
|
|
assert is_off_hours(20) is True
|
||
|
|
assert is_off_hours(2) is True
|
||
|
|
|
||
|
|
def test_business_hours_not_off(self):
|
||
|
|
assert is_off_hours(9) is False
|
||
|
|
assert is_off_hours(14) is False
|
||
|
|
|
||
|
|
|
||
|
|
class TestRouting:
|
||
|
|
def test_interactive_uses_base_model(self):
|
||
|
|
d = resolve_time_aware_model("my-model", "my-provider", is_cron=False, hour=18)
|
||
|
|
assert d.model == "my-model"
|
||
|
|
assert "Interactive" in d.reason
|
||
|
|
|
||
|
|
def test_cron_low_error_uses_base(self):
|
||
|
|
d = resolve_time_aware_model("cheap-model", is_cron=True, hour=10)
|
||
|
|
assert d.model == "cheap-model"
|
||
|
|
|
||
|
|
def test_cron_high_error_upgrades(self):
|
||
|
|
d = resolve_time_aware_model("cheap-model", is_cron=True, hour=18)
|
||
|
|
assert d.model != "cheap-model"
|
||
|
|
assert d.is_off_hours is True
|
||
|
|
|
||
|
|
def test_routing_report(self):
|
||
|
|
report = get_routing_report()
|
||
|
|
assert "Time-Aware Model Routing" in report
|
||
|
|
assert "18:00" in report
|