Sub2API v1.0 - AI API 网关(二开初始版本,基于上游 Wei-Shaw/sub2api)
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
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
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
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")
|
||||
}
|
||||
Reference in New Issue
Block a user