(self)
| 227 | assert rs.summary().total_requests == 0 |
| 228 | |
| 229 | def test_persistence_roundtrip(self) -> None: |
| 230 | storage = InMemoryRouteStatsStorage() |
| 231 | rs1 = RouteStats(storage=storage) |
| 232 | rs1.record(RouteRecord(**{ |
| 233 | **_make_record(model="test/model", confidence=0.77).__dict__, |
| 234 | "transport": "anthropic-messages", |
| 235 | "cache_mode": "cache_control", |
| 236 | "cache_family": "anthropic", |
| 237 | "cache_breakpoints": 2, |
| 238 | "route_reasoning": "selected for low latency", |
| 239 | "routing_features_payload": {"step_type": "research"}, |
| 240 | "fallback_chain_payload": [{"model": "fallback/model", "reason": "cost"}], |
| 241 | "candidate_scores_payload": [{"model": "test/model", "score": 0.91}], |
| 242 | "status_code": 502, |
| 243 | "error_code": "connect_error", |
| 244 | "error_stage": "upstream_request", |
| 245 | "error_message": "Upstream unreachable", |
| 246 | })) |
| 247 | rs1.record(_make_record(model="test/model2", tier="REASONING")) |
| 248 | |
| 249 | rs2 = RouteStats(storage=storage) |
| 250 | assert rs2.count == 2 |
| 251 | h = rs2.history() |
| 252 | assert h[0].model == "test/model2" |
| 253 | assert h[0].tier == "COMPLEX" |
| 254 | assert h[1].confidence == 0.77 |
| 255 | assert h[1].transport == "anthropic-messages" |
| 256 | assert h[1].cache_mode == "cache_control" |
| 257 | assert h[1].cache_family == "anthropic" |
| 258 | assert h[1].cache_breakpoints == 2 |
| 259 | assert h[1].route_reasoning == "selected for low latency" |
| 260 | assert h[1].routing_features_payload == {"step_type": "research"} |
| 261 | assert h[1].fallback_chain_payload == [{"model": "fallback/model", "reason": "cost"}] |
| 262 | assert h[1].candidate_scores_payload == [{"model": "test/model", "score": 0.91}] |
| 263 | assert h[1].status_code == 502 |
| 264 | assert h[1].error_code == "connect_error" |
| 265 | assert h[1].error_stage == "upstream_request" |
| 266 | assert h[1].error_message == "Upstream unreachable" |
| 267 | |
| 268 | def test_retention_cleanup(self) -> None: |
| 269 | t = 1_000_000.0 |
nothing calls this directly
no test coverage detected