fix(gateway): normalize model alias billing identity
This commit is contained in:
@@ -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{
|
||||
|
||||
Reference in New Issue
Block a user