fix: prefer generated video metadata for billing

This commit is contained in:
2026-05-20 00:11:28 +08:00
parent 69d23efb57
commit 11a2c13e4a
4 changed files with 318 additions and 14 deletions
+94
View File
@@ -76,6 +76,100 @@ func TestVideoBillingEstimateUsesFiveSecondUnitsAndDynamicWeights(t *testing.T)
if got, want := line["quantity"], 3; got != want {
t.Fatalf("video quantity = %v, want %v", got, want)
}
if got, want := line["durationSource"], "preprocessed_request"; got != want {
t.Fatalf("video duration source = %v, want %v", got, want)
}
if got, want := line["audioSource"], "preprocessed_request"; got != want {
t.Fatalf("video audio source = %v, want %v", got, want)
}
}
func TestVideoBillingPrefersGeneratedDuration(t *testing.T) {
service := &Service{}
candidate := store.RuntimeModelCandidate{
ModelName: "video-model",
BaseBillingConfig: map[string]any{
"video": map[string]any{"basePrice": 100},
},
}
items := service.billings(context.Background(), nil, "videos.generations", map[string]any{
"duration": 12,
"resolution": "720p",
}, candidate, clients.Response{
Result: map[string]any{
"data": []any{map[string]any{"type": "video", "duration": 6.6}},
},
}, false)
line := firstBillingLine(t, items)
if got, want := floatFromAny(line["durationSeconds"]), 7.0; got != want {
t.Fatalf("video generated duration = %v, want %v", got, want)
}
if got, want := floatFromAny(line["durationUnitCount"]), 2.0; got != want {
t.Fatalf("video generated duration units = %v, want %v", got, want)
}
if got, want := floatFromAny(line["amount"]), 200.0; got != want {
t.Fatalf("video generated duration amount = %v, want %v", got, want)
}
if got, want := line["durationSource"], "generated_video"; got != want {
t.Fatalf("video duration source = %v, want %v", got, want)
}
}
func TestVideoBillingPrefersGeneratedAudio(t *testing.T) {
service := &Service{}
candidate := store.RuntimeModelCandidate{
ModelName: "video-model",
BaseBillingConfig: map[string]any{
"video": map[string]any{
"basePrice": 100,
"audioWeights": map[string]any{"true": 2, "false": 0.5},
"voiceSpecifiedWeights": map[string]any{"true": 4},
},
},
}
items := service.billings(context.Background(), nil, "videos.generations", map[string]any{
"audio": false,
"duration": 5,
}, candidate, clients.Response{
Result: map[string]any{
"data": []any{map[string]any{"type": "video", "has_audio": true}},
},
}, false)
line := firstBillingLine(t, items)
if got, want := floatFromAny(line["amount"]), 200.0; got != want {
t.Fatalf("video generated audio amount = %v, want %v", got, want)
}
if got, want := line["audio"], true; got != want {
t.Fatalf("video generated audio = %v, want %v", got, want)
}
if got, want := line["audioSource"], "generated_video"; got != want {
t.Fatalf("video audio source = %v, want %v", got, want)
}
items = service.billings(context.Background(), nil, "videos.generations", map[string]any{
"audio": true,
"duration": 5,
"voice_id": "voice-a",
}, candidate, clients.Response{
Result: map[string]any{
"data": []any{map[string]any{"type": "video", "hasAudio": false}},
},
}, false)
line = firstBillingLine(t, items)
if got, want := floatFromAny(line["amount"]), 50.0; got != want {
t.Fatalf("video generated no-audio amount = %v, want %v", got, want)
}
if got, want := line["audio"], false; got != want {
t.Fatalf("video generated no-audio = %v, want %v", got, want)
}
if got, want := line["audioSource"], "generated_video"; got != want {
t.Fatalf("video no-audio source = %v, want %v", got, want)
}
}
func TestVideoBillingEstimateSupportsServerMainStyleDynamicKeys(t *testing.T) {