Files
xinghuoapi/backend/internal/service/pricing_service_test.go
yangjianbo 1a0d4ed668 feat(openai): 增加 gpt-5.4 模型支持与定价配置
- 接入 gpt-5.4 模型识别与规范化,补充默认模型列表
- 增加 gpt-5.4 输入/缓存命中/输出价格与计费兜底逻辑
- 同步前端模型白名单与 OpenCode 上下文窗口(1050000/128000)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
(cherry picked from commit 924476dcac6181cd0f3ee731ec7b73672ff03793)
2026-03-06 10:16:23 +08:00

68 lines
2.0 KiB
Go

package service
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestGetModelPricing_Gpt53CodexSparkUsesGpt51CodexPricing(t *testing.T) {
sparkPricing := &LiteLLMModelPricing{InputCostPerToken: 1}
gpt53Pricing := &LiteLLMModelPricing{InputCostPerToken: 9}
svc := &PricingService{
pricingData: map[string]*LiteLLMModelPricing{
"gpt-5.1-codex": sparkPricing,
"gpt-5.3": gpt53Pricing,
},
}
got := svc.GetModelPricing("gpt-5.3-codex-spark")
require.Same(t, sparkPricing, got)
}
func TestGetModelPricing_Gpt53CodexFallbackStillUsesGpt52Codex(t *testing.T) {
gpt52CodexPricing := &LiteLLMModelPricing{InputCostPerToken: 2}
svc := &PricingService{
pricingData: map[string]*LiteLLMModelPricing{
"gpt-5.2-codex": gpt52CodexPricing,
},
}
got := svc.GetModelPricing("gpt-5.3-codex")
require.Same(t, gpt52CodexPricing, got)
}
func TestGetModelPricing_OpenAIFallbackMatchedLoggedAsInfo(t *testing.T) {
logSink, restore := captureStructuredLog(t)
defer restore()
gpt52CodexPricing := &LiteLLMModelPricing{InputCostPerToken: 2}
svc := &PricingService{
pricingData: map[string]*LiteLLMModelPricing{
"gpt-5.2-codex": gpt52CodexPricing,
},
}
got := svc.GetModelPricing("gpt-5.3-codex")
require.Same(t, gpt52CodexPricing, got)
require.True(t, logSink.ContainsMessageAtLevel("[Pricing] OpenAI fallback matched gpt-5.3-codex -> gpt-5.2-codex", "info"))
require.False(t, logSink.ContainsMessageAtLevel("[Pricing] OpenAI fallback matched gpt-5.3-codex -> gpt-5.2-codex", "warn"))
}
func TestGetModelPricing_Gpt54UsesStaticFallbackWhenRemoteMissing(t *testing.T) {
svc := &PricingService{
pricingData: map[string]*LiteLLMModelPricing{
"gpt-5.1-codex": &LiteLLMModelPricing{InputCostPerToken: 1.25e-6},
},
}
got := svc.GetModelPricing("gpt-5.4")
require.NotNil(t, got)
require.InDelta(t, 2.5e-6, got.InputCostPerToken, 1e-12)
require.InDelta(t, 1.5e-5, got.OutputCostPerToken, 1e-12)
require.InDelta(t, 2.5e-7, got.CacheReadInputTokenCost, 1e-12)
}