fix(gateway): normalize model alias billing identity

This commit is contained in:
2026-05-28 01:19:28 +08:00
parent f5c69b9852
commit 2aeb47d6a5
4 changed files with 185 additions and 16 deletions
@@ -2,6 +2,52 @@ package store
import "testing"
func TestNormalizeModelMatchKeyRemovesWhitespace(t *testing.T) {
got := normalizeModelMatchKey(" doubao-5.0 图像\t编辑\n")
if got != "doubao-5.0图像编辑" {
t.Fatalf("expected whitespace-insensitive model key, got %q", got)
}
}
func TestTaskBillingModelIdentityPrefersSystemAlias(t *testing.T) {
identity := taskBillingModelIdentity(GatewayTask{
Model: "doubao-5.0 图像编辑",
RequestedModel: "doubao-5.0 图像编辑",
ResolvedModel: "doubao-image-real",
Metrics: map[string]any{
"modelAlias": "doubao-5.0图像编辑",
"modelName": "doubao-image-real",
"providerModel": "doubao-provider-image",
},
})
if identity.Model != "doubao-5.0图像编辑" || identity.ResolvedModel != "doubao-5.0图像编辑" {
t.Fatalf("expected persisted model to use system alias, got %+v", identity)
}
if identity.RequestedModel != "doubao-5.0 图像编辑" {
t.Fatalf("expected requested model to preserve original request, got %+v", identity)
}
if identity.ModelName != "doubao-image-real" || identity.ProviderModelName != "doubao-provider-image" {
t.Fatalf("expected model name/provider model to stay available, got %+v", identity)
}
}
func TestTaskBillingModelIdentityFallsBackToBillingLines(t *testing.T) {
identity := taskBillingModelIdentity(GatewayTask{
Model: "front end alias",
Billings: []any{
map[string]any{
"model": "system-model-name",
"modelAlias": "System Model Alias",
},
},
})
if identity.Model != "System Model Alias" || identity.ModelName != "system-model-name" {
t.Fatalf("expected billing lines to provide system model identity, got %+v", identity)
}
}
func TestRuntimeCandidateLoadUsesMaxLimitedMetric(t *testing.T) {
candidate := RuntimeModelCandidate{}
applyRuntimeCandidateLoad(&candidate, runtimeCandidateLoadInput{