- Export ApplyBedrockCCCompat() in GatewayService, called after channel model mapping to ensure mapped model ID is used for Opus 4.7+ detection - Add sanitizeBedrockCCFields(): remove service_tier/interface_geo/ context_management, inject max_tokens/anthropic_version defaults - Add sanitizeBedrockCCBetaTokens(): filter anthropic_beta to keep only Bedrock-supported tokens, reusing autoInjectBedrockBetaTokens and filterBedrockBetaTokens for consistent rules - Remove unsupported beta tokens (interleaved-thinking, context-management) from whitelist based on AWS official docs - Simplify IsBedrockCCCompatEnabled() to check boolean toggle directly, applying CC compat to all accounts regardless of platform - Add unit tests for IsBedrockCCCompatEnabled (8 cases), sanitizeBedrockCCFields (8 cases), sanitizeBedrockCCBetaTokens (7 cases) - Update bedrock beta policy tests for removed auto-injection
74 lines
1.8 KiB
Go
74 lines
1.8 KiB
Go
package service
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestChannel_IsBedrockCCCompatEnabled_Enabled(t *testing.T) {
|
|
c := &Channel{
|
|
FeaturesConfig: map[string]any{
|
|
featureKeyBedrockCCCompat: true,
|
|
},
|
|
}
|
|
require.True(t, c.IsBedrockCCCompatEnabled("bedrock"))
|
|
}
|
|
|
|
func TestChannel_IsBedrockCCCompatEnabled_AppliesToAllPlatforms(t *testing.T) {
|
|
c := &Channel{
|
|
FeaturesConfig: map[string]any{
|
|
featureKeyBedrockCCCompat: true,
|
|
},
|
|
}
|
|
require.True(t, c.IsBedrockCCCompatEnabled("anthropic"))
|
|
require.True(t, c.IsBedrockCCCompatEnabled("openai"))
|
|
require.True(t, c.IsBedrockCCCompatEnabled(""))
|
|
}
|
|
|
|
func TestChannel_IsBedrockCCCompatEnabled_Disabled(t *testing.T) {
|
|
c := &Channel{
|
|
FeaturesConfig: map[string]any{
|
|
featureKeyBedrockCCCompat: false,
|
|
},
|
|
}
|
|
require.False(t, c.IsBedrockCCCompatEnabled("bedrock"))
|
|
}
|
|
|
|
func TestChannel_IsBedrockCCCompatEnabled_NilFeaturesConfig(t *testing.T) {
|
|
c := &Channel{FeaturesConfig: nil}
|
|
require.False(t, c.IsBedrockCCCompatEnabled("bedrock"))
|
|
}
|
|
|
|
func TestChannel_IsBedrockCCCompatEnabled_NilChannel(t *testing.T) {
|
|
var c *Channel
|
|
require.False(t, c.IsBedrockCCCompatEnabled("bedrock"))
|
|
}
|
|
|
|
func TestChannel_IsBedrockCCCompatEnabled_WrongType(t *testing.T) {
|
|
c := &Channel{
|
|
FeaturesConfig: map[string]any{
|
|
featureKeyBedrockCCCompat: "yes",
|
|
},
|
|
}
|
|
require.False(t, c.IsBedrockCCCompatEnabled("bedrock"))
|
|
}
|
|
|
|
func TestChannel_IsBedrockCCCompatEnabled_OldMapFormat(t *testing.T) {
|
|
c := &Channel{
|
|
FeaturesConfig: map[string]any{
|
|
featureKeyBedrockCCCompat: map[string]any{"bedrock": true},
|
|
},
|
|
}
|
|
require.False(t, c.IsBedrockCCCompatEnabled("bedrock"))
|
|
}
|
|
|
|
func TestChannel_IsBedrockCCCompatEnabled_MissingKey(t *testing.T) {
|
|
c := &Channel{
|
|
FeaturesConfig: map[string]any{
|
|
"other_feature": true,
|
|
},
|
|
}
|
|
require.False(t, c.IsBedrockCCCompatEnabled("bedrock"))
|
|
}
|