Files
writer-work-flow/packages/llm_gateway/tests/test_pricing.py

30 lines
1.0 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""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"