feat(gateway): 未知模型缺价发结构化告警——成本账缺项可观测(CR-M2-1)

This commit is contained in:
Yaojia Wang
2026-07-08 12:56:00 +02:00
parent 9ee7c7b000
commit 32451a9bd0
2 changed files with 36 additions and 0 deletions

View File

@@ -0,0 +1,29 @@
"""pricing 单元测试CR-M2-1未知模型缺价应可观测"""
from __future__ import annotations
import structlog
from ww_llm_gateway.pricing import cost_minor
def test_known_model_computes_positive_cost() -> None:
# Arrange / Act
cost, currency = cost_minor("deepseek", "deepseek-chat", 1_000_000, 1_000_000)
# Assert
assert cost > 0
assert currency == "USD"
def test_unknown_model_warns_and_still_returns_zero_cost() -> None:
# CR-M2-1未知 (provider, model) 成本仍计 0照常记账但必须发结构化 warning
# 点名该 model——缺价条目应在成本账路径可见而非静默吞成 0。
with structlog.testing.capture_logs() as logs:
cost, currency = cost_minor("mystery", "ghost-model", 1000, 2000)
assert cost == 0
assert currency == "USD"
warning = next(entry for entry in logs if entry["event"] == "pricing_unknown_model")
assert warning["log_level"] == "warning"
assert warning["provider"] == "mystery"
assert warning["model"] == "ghost-model"