补齐 gpt-5.4 fallback 的长上下文计费元信息,\n确保超过 272000 输入 token 时对整次会话应用\n2x 输入与 1.5x 输出计费规则。\n\n同时将官方快照 gpt-5.4-2026-03-05 加入前端\n白名单候选与回归测试,避免 whitelist 模式误拦截。\n\nCo-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> (cherry picked from commit d95497af87f608c6dadcbe7d6e851de9413ae147)
71 lines
2.2 KiB
Go
71 lines
2.2 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)
|
|
require.Equal(t, 272000, got.LongContextInputTokenThreshold)
|
|
require.InDelta(t, 2.0, got.LongContextInputCostMultiplier, 1e-12)
|
|
require.InDelta(t, 1.5, got.LongContextOutputCostMultiplier, 1e-12)
|
|
}
|