mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-11-16 22:57:53 +08:00
119 lines
3.5 KiB
Go
119 lines
3.5 KiB
Go
package config
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
func TestLoadConfigOptional_CodexHeaderDefaults(t *testing.T) {
|
|
dir := t.TempDir()
|
|
configPath := filepath.Join(dir, "config.yaml")
|
|
configYAML := []byte(`
|
|
codex-header-defaults:
|
|
user-agent: " my-codex-client/1.0 "
|
|
beta-features: " feature-a,feature-b "
|
|
`)
|
|
if err := os.WriteFile(configPath, configYAML, 0o600); err != nil {
|
|
t.Fatalf("failed to write config: %v", err)
|
|
}
|
|
|
|
cfg, err := LoadConfigOptional(configPath, false)
|
|
if err != nil {
|
|
t.Fatalf("LoadConfigOptional() error = %v", err)
|
|
}
|
|
|
|
if got := cfg.CodexHeaderDefaults.UserAgent; got != "my-codex-client/1.0" {
|
|
t.Fatalf("UserAgent = %q, want %q", got, "my-codex-client/1.0")
|
|
}
|
|
if got := cfg.CodexHeaderDefaults.BetaFeatures; got != "feature-a,feature-b" {
|
|
t.Fatalf("BetaFeatures = %q, want %q", got, "feature-a,feature-b")
|
|
}
|
|
if cfg.Codex.DisableCodexCloaking {
|
|
t.Fatal("DisableCodexCloaking = true, want default false")
|
|
}
|
|
}
|
|
|
|
func TestLoadConfigOptional_CodexOptions(t *testing.T) {
|
|
dir := t.TempDir()
|
|
configPath := filepath.Join(dir, "config.yaml")
|
|
configYAML := []byte(`
|
|
codex:
|
|
disable-codex-cloaking: true
|
|
optimize-multi-agent-v2: true
|
|
`)
|
|
if err := os.WriteFile(configPath, configYAML, 0o600); err != nil {
|
|
t.Fatalf("failed to write config: %v", err)
|
|
}
|
|
|
|
cfg, err := LoadConfigOptional(configPath, false)
|
|
if err != nil {
|
|
t.Fatalf("LoadConfigOptional() error = %v", err)
|
|
}
|
|
|
|
if !cfg.Codex.DisableCodexCloaking {
|
|
t.Fatal("DisableCodexCloaking = false, want true")
|
|
}
|
|
if !cfg.Client.Codex.OptimizeMultiAgentV2 {
|
|
t.Fatalf("OptimizeMultiAgentV2 = false, want true")
|
|
}
|
|
}
|
|
|
|
func TestLoadConfigOptional_CodexModelLevelCooling(t *testing.T) {
|
|
dir := t.TempDir()
|
|
configPath := filepath.Join(dir, "config.yaml")
|
|
configYAML := []byte(`
|
|
codex:
|
|
model-level-cooling: true
|
|
`)
|
|
if err := os.WriteFile(configPath, configYAML, 0o600); err != nil {
|
|
t.Fatalf("failed to write config: %v", err)
|
|
}
|
|
|
|
cfg, err := LoadConfigOptional(configPath, false)
|
|
if err != nil {
|
|
t.Fatalf("LoadConfigOptional() error = %v", err)
|
|
}
|
|
|
|
if !cfg.Codex.ModelLevelCooling {
|
|
t.Fatalf("ModelLevelCooling = false, want true")
|
|
}
|
|
|
|
defaultCfg, errDefault := ParseConfigBytes([]byte(`{}`))
|
|
if errDefault != nil {
|
|
t.Fatalf("ParseConfigBytes() error = %v", errDefault)
|
|
}
|
|
if defaultCfg.Codex.ModelLevelCooling {
|
|
t.Fatalf("default ModelLevelCooling = true, want false")
|
|
}
|
|
}
|
|
|
|
func TestParseConfigBytes_CodexSignInWithChatGPTIdentifier(t *testing.T) {
|
|
defaultCfg, errDefault := ParseConfigBytes([]byte("port: 8317\n"))
|
|
if errDefault != nil {
|
|
t.Fatalf("ParseConfigBytes (default) error: %v", errDefault)
|
|
}
|
|
if got := defaultCfg.Codex.EffectiveSignInWithChatGPTIdentifier(); got != "CLIProxyAPI" {
|
|
t.Fatalf("EffectiveSignInWithChatGPTIdentifier (default) = %q, want CLIProxyAPI", got)
|
|
}
|
|
|
|
rawV8 := []byte(`oauth:
|
|
providers:
|
|
codex:
|
|
signin-with-chatgpt-identifier: " CustomSIWCClient/2.0 "
|
|
`)
|
|
if errValidate := ValidateV8Config(rawV8); errValidate != nil {
|
|
t.Fatalf("ValidateV8Config error: %v", errValidate)
|
|
}
|
|
cfg, errParse := ParseConfigBytes(rawV8)
|
|
if errParse != nil {
|
|
t.Fatalf("ParseConfigBytes (v8) error: %v", errParse)
|
|
}
|
|
if cfg.Codex.SignInWithChatGPTIdentifier != "CustomSIWCClient/2.0" {
|
|
t.Fatalf("SignInWithChatGPTIdentifier = %q, want CustomSIWCClient/2.0", cfg.Codex.SignInWithChatGPTIdentifier)
|
|
}
|
|
if got := cfg.Codex.EffectiveSignInWithChatGPTIdentifier(); got != "CustomSIWCClient/2.0" {
|
|
t.Fatalf("EffectiveSignInWithChatGPTIdentifier = %q, want CustomSIWCClient/2.0", got)
|
|
}
|
|
}
|