mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-07-02 18:24:37 +08:00
Adds a fourth value for the disable-image-generation setting:
- false: inject image_generation (unchanged)
- true: strip everywhere + 404 on /v1/images/* (unchanged)
- chat: strip on non-images endpoints, keep /v1/images/* (unchanged)
- passthrough: never inject and never strip on non-images endpoints
(the client payload is forwarded unchanged); behaves like
"chat" on /v1/images/* endpoints.
image_generation injection (codex executors) is already gated on the Off
mode, and the /v1/images/* 404 gate is already gated on the All mode, so
passthrough only required a change to the payload strip logic in
payload_helpers.go, now expressed via shouldStripImageGeneration().
Closes #3831
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
97 lines
2.4 KiB
Go
97 lines
2.4 KiB
Go
package config
|
|
|
|
import (
|
|
"encoding/json"
|
|
"testing"
|
|
|
|
"gopkg.in/yaml.v3"
|
|
)
|
|
|
|
func TestDisableImageGenerationMode_UnmarshalYAML(t *testing.T) {
|
|
type wrapper struct {
|
|
V DisableImageGenerationMode `yaml:"disable-image-generation"`
|
|
}
|
|
|
|
{
|
|
var w wrapper
|
|
if err := yaml.Unmarshal([]byte("disable-image-generation: false\n"), &w); err != nil {
|
|
t.Fatalf("unmarshal false: %v", err)
|
|
}
|
|
if w.V != DisableImageGenerationOff {
|
|
t.Fatalf("false => %v, want %v", w.V, DisableImageGenerationOff)
|
|
}
|
|
}
|
|
|
|
{
|
|
var w wrapper
|
|
if err := yaml.Unmarshal([]byte("disable-image-generation: true\n"), &w); err != nil {
|
|
t.Fatalf("unmarshal true: %v", err)
|
|
}
|
|
if w.V != DisableImageGenerationAll {
|
|
t.Fatalf("true => %v, want %v", w.V, DisableImageGenerationAll)
|
|
}
|
|
}
|
|
|
|
{
|
|
var w wrapper
|
|
if err := yaml.Unmarshal([]byte("disable-image-generation: chat\n"), &w); err != nil {
|
|
t.Fatalf("unmarshal chat: %v", err)
|
|
}
|
|
if w.V != DisableImageGenerationChat {
|
|
t.Fatalf("chat => %v, want %v", w.V, DisableImageGenerationChat)
|
|
}
|
|
}
|
|
|
|
{
|
|
var w wrapper
|
|
if err := yaml.Unmarshal([]byte("disable-image-generation: passthrough\n"), &w); err != nil {
|
|
t.Fatalf("unmarshal passthrough: %v", err)
|
|
}
|
|
if w.V != DisableImageGenerationPassthrough {
|
|
t.Fatalf("passthrough => %v, want %v", w.V, DisableImageGenerationPassthrough)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestDisableImageGenerationMode_UnmarshalJSON(t *testing.T) {
|
|
{
|
|
var v DisableImageGenerationMode
|
|
if err := json.Unmarshal([]byte("false"), &v); err != nil {
|
|
t.Fatalf("unmarshal false: %v", err)
|
|
}
|
|
if v != DisableImageGenerationOff {
|
|
t.Fatalf("false => %v, want %v", v, DisableImageGenerationOff)
|
|
}
|
|
}
|
|
|
|
{
|
|
var v DisableImageGenerationMode
|
|
if err := json.Unmarshal([]byte("true"), &v); err != nil {
|
|
t.Fatalf("unmarshal true: %v", err)
|
|
}
|
|
if v != DisableImageGenerationAll {
|
|
t.Fatalf("true => %v, want %v", v, DisableImageGenerationAll)
|
|
}
|
|
}
|
|
|
|
{
|
|
var v DisableImageGenerationMode
|
|
if err := json.Unmarshal([]byte(`"chat"`), &v); err != nil {
|
|
t.Fatalf("unmarshal chat: %v", err)
|
|
}
|
|
if v != DisableImageGenerationChat {
|
|
t.Fatalf("chat => %v, want %v", v, DisableImageGenerationChat)
|
|
}
|
|
}
|
|
|
|
{
|
|
var v DisableImageGenerationMode
|
|
if err := json.Unmarshal([]byte(`"passthrough"`), &v); err != nil {
|
|
t.Fatalf("unmarshal passthrough: %v", err)
|
|
}
|
|
if v != DisableImageGenerationPassthrough {
|
|
t.Fatalf("passthrough => %v, want %v", v, DisableImageGenerationPassthrough)
|
|
}
|
|
}
|
|
}
|