feat: 合并网关能力与兼容性优化 #15

Merged
wangbo merged 12 commits from codex/gateway-feature-batch-20260721 into main 2026-07-22 01:17:46 +08:00
2 changed files with 32 additions and 3 deletions
Showing only changes of commit 0818f55235 - Show all commits
+7 -3
View File
@@ -17,12 +17,16 @@ type EffectiveBillingConfigInput struct {
func ResolveEffectiveBillingConfig(input EffectiveBillingConfigInput) map[string]any {
config := mergeObjects(input.BaseConfig, nil)
if len(input.InheritedRuleSetConfig) > 0 {
config = mergeObjects(input.InheritedRuleSetConfig, nil)
// Rule sets are allowed to cover only a subset of resource types. Keep
// base-model prices for resources that the inherited rule set does not
// define, while letting the rule set remain authoritative for matching
// top-level keys.
config = mergeObjects(config, input.InheritedRuleSetConfig)
} else if len(input.LegacyPlatformModelConfig) > 0 {
config = mergeObjects(input.LegacyPlatformModelConfig, nil)
config = mergeObjects(config, input.LegacyPlatformModelConfig)
}
if len(input.ModelRuleSetConfig) > 0 {
config = mergeObjects(input.ModelRuleSetConfig, nil)
config = mergeObjects(config, input.ModelRuleSetConfig)
}
return mergeObjects(config, input.Override)
}
@@ -62,6 +62,31 @@ func TestResolveEffectiveBillingConfigAppliesOverrideLast(t *testing.T) {
}
}
func TestResolveEffectiveBillingConfigPreservesBaseResourcesMissingFromRuleSet(t *testing.T) {
config := ResolveEffectiveBillingConfig(EffectiveBillingConfigInput{
BaseConfig: map[string]any{
"music": map[string]any{"basePrice": float64(20)},
"audio": map[string]any{"basePrice": float64(1)},
"video": map[string]any{"basePrice": float64(100)},
},
InheritedRuleSetConfig: map[string]any{
"video": map[string]any{"basePrice": float64(416)},
},
})
assertBillingBasePrice(t, config, "music", 20)
assertBillingBasePrice(t, config, "audio", 1)
assertBillingBasePrice(t, config, "video", 416)
}
func assertBillingBasePrice(t *testing.T, config map[string]any, resource string, want float64) {
t.Helper()
resourceConfig, ok := config[resource].(map[string]any)
if !ok || resourceConfig["basePrice"] != want {
t.Fatalf("%s base price = %#v, want %v", resource, config[resource], want)
}
}
func videoBillingConfig(basePrice float64) map[string]any {
return map[string]any{
"video": map[string]any{"basePrice": basePrice},