mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-09-11 14:47:58 +08:00
- Add `model-level-cooling` configuration option to Codex settings. - Scope `usage_limit_reached` quota cooldowns to the requested model instead of the entire credential when enabled. - Propagate model-level cooling checks across HTTP, SSE, and WebSocket execution paths. Closes: #5619
94 lines
2.5 KiB
Go
94 lines
2.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_CodexIdentityConfuse(t *testing.T) {
|
|
dir := t.TempDir()
|
|
configPath := filepath.Join(dir, "config.yaml")
|
|
configYAML := []byte(`
|
|
codex:
|
|
identity-confuse: true
|
|
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.IdentityConfuse {
|
|
t.Fatalf("IdentityConfuse = false, want true")
|
|
}
|
|
if !cfg.Codex.DisableCodexCloaking {
|
|
t.Fatal("DisableCodexCloaking = false, want true")
|
|
}
|
|
if !cfg.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")
|
|
}
|
|
}
|