59 lines
2 KiB
Go
59 lines
2 KiB
Go
package auth
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
cliproxyexecutor "github.com/router-for-me/CLIProxyAPI/v7/sdk/cliproxy/executor"
|
|
coreusage "github.com/router-for-me/CLIProxyAPI/v7/sdk/cliproxy/usage"
|
|
)
|
|
|
|
func TestContextWithRequestedModelAliasIncludesReasoningEffort(t *testing.T) {
|
|
ctx := contextWithRequestedModelAlias(context.Background(), cliproxyexecutor.Options{
|
|
Metadata: map[string]any{
|
|
cliproxyexecutor.RequestedModelMetadataKey: "client-model",
|
|
cliproxyexecutor.ReasoningEffortMetadataKey: "medium",
|
|
cliproxyexecutor.ServiceTierMetadataKey: "auto",
|
|
cliproxyexecutor.GenerateMetadataKey: false,
|
|
},
|
|
}, "fallback-model")
|
|
|
|
if got := coreusage.RequestedModelAliasFromContext(ctx); got != "client-model" {
|
|
t.Fatalf("requested model alias = %q, want %q", got, "client-model")
|
|
}
|
|
if got := coreusage.ReasoningEffortFromContext(ctx); got != "medium" {
|
|
t.Fatalf("reasoning effort = %q, want %q", got, "medium")
|
|
}
|
|
gotServiceTier := coreusage.ServiceTierFromContext(ctx)
|
|
if gotServiceTier != "auto" {
|
|
t.Fatalf("service tier = %q, want %q", gotServiceTier, "auto")
|
|
}
|
|
if got := coreusage.GenerateFromContext(ctx); got {
|
|
t.Fatalf("generate = %v, want false", got)
|
|
}
|
|
}
|
|
|
|
func TestContextWithRequestedModelAliasDefaultsGenerateTrue(t *testing.T) {
|
|
ctx := contextWithRequestedModelAlias(context.Background(), cliproxyexecutor.Options{
|
|
Metadata: map[string]any{
|
|
cliproxyexecutor.RequestedModelMetadataKey: "client-model",
|
|
},
|
|
}, "fallback-model")
|
|
|
|
if got := coreusage.GenerateFromContext(ctx); !got {
|
|
t.Fatalf("generate = %v, want true", got)
|
|
}
|
|
}
|
|
|
|
func TestContextWithRequestedModelAliasPreservesExistingGenerateFalse(t *testing.T) {
|
|
ctx := coreusage.WithGenerate(context.Background(), false)
|
|
ctx = contextWithRequestedModelAlias(ctx, cliproxyexecutor.Options{
|
|
Metadata: map[string]any{
|
|
cliproxyexecutor.RequestedModelMetadataKey: "client-model",
|
|
},
|
|
}, "fallback-model")
|
|
|
|
if got := coreusage.GenerateFromContext(ctx); got {
|
|
t.Fatalf("generate = %v, want false", got)
|
|
}
|
|
}
|