Files
sub2api/backend/internal/service/image_generation_intent_explicit_test.go
李建琦 6d655c9903
Release / update-version (push) Has been cancelled
Release / build-frontend (push) Has been cancelled
Release / release (push) Has been cancelled
Release / sync-version-file (push) Has been cancelled
CI / shell (push) Canceled after 0s
CI / test (push) Canceled after 0s
CI / frontend (push) Canceled after 0s
CI / golangci-lint (push) Canceled after 0s
Security Scan / backend-security (push) Canceled after 0s
Security Scan / frontend-security (push) Canceled after 0s
Sub2API v1.0 - AI API 网关(二开初始版本,基于上游 Wei-Shaw/sub2api)
2026-08-21 18:30:13 +08:00

64 lines
2.2 KiB
Go

package service
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestIsExplicitImageGenerationIntent_IgnoresPassiveNamespace(t *testing.T) {
body := []byte(`{
"model": "gpt-5.5",
"input": [{"type":"message","role":"user","content":"hello"}],
"tools": [
{"type":"function","name":"Read"},
{"type":"namespace","name":"image_gen","tools":[{"type":"function","name":"imagegen"}]}
],
"tool_choice": "auto"
}`)
assert.False(t, IsExplicitImageGenerationIntent("/v1/responses", "gpt-5.5", body),
"passive image_gen namespace should NOT be explicit image intent")
assert.True(t, IsImageGenerationIntent("/v1/responses", "gpt-5.5", body),
"passive image_gen namespace SHOULD be general image intent (for permission check)")
}
func TestIsExplicitImageGenerationIntent_DetectsNativeTool(t *testing.T) {
body := []byte(`{
"model": "gpt-5.5",
"tools": [{"type":"image_generation","model":"gpt-image-2"}],
"tool_choice": "auto"
}`)
assert.True(t, IsExplicitImageGenerationIntent("/v1/responses", "gpt-5.5", body),
"native image_generation tool IS explicit intent")
}
func TestIsExplicitImageGenerationIntent_DetectsImageModel(t *testing.T) {
assert.True(t, IsExplicitImageGenerationIntent("/v1/responses", "gpt-image-2", nil),
"image model IS explicit intent")
}
func TestIsExplicitImageGenerationIntent_DetectsImageEndpoint(t *testing.T) {
assert.True(t, IsExplicitImageGenerationIntent("/v1/images/generations", "gpt-5.5", nil),
"image endpoint IS explicit intent")
}
func TestIsExplicitImageGenerationIntent_DetectsExplicitToolChoice(t *testing.T) {
body := []byte(`{"model":"gpt-5.5","tools":[{"type":"function","name":"Read"}],"tool_choice":"image_generation"}`)
assert.True(t, IsExplicitImageGenerationIntent("/v1/responses", "gpt-5.5", body),
"explicit tool_choice selecting image_generation IS explicit intent")
}
func TestIsExplicitImageGenerationIntent_PlainTextRequest(t *testing.T) {
body := []byte(`{
"model": "gpt-5.5",
"input": "hello",
"tools": [{"type":"function","name":"Read"}]
}`)
assert.False(t, IsExplicitImageGenerationIntent("/v1/responses", "gpt-5.5", body),
"plain text request should NOT be explicit image intent")
}