30 lines
1.0 KiB
Python
30 lines
1.0 KiB
Python
"""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"
|