image_generation_intent_explicit_test.go 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package service
  2. import (
  3. "testing"
  4. "github.com/stretchr/testify/assert"
  5. )
  6. func TestIsExplicitImageGenerationIntent_IgnoresPassiveNamespace(t *testing.T) {
  7. body := []byte(`{
  8. "model": "gpt-5.5",
  9. "input": [{"type":"message","role":"user","content":"hello"}],
  10. "tools": [
  11. {"type":"function","name":"Read"},
  12. {"type":"namespace","name":"image_gen","tools":[{"type":"function","name":"imagegen"}]}
  13. ],
  14. "tool_choice": "auto"
  15. }`)
  16. assert.False(t, IsExplicitImageGenerationIntent("/v1/responses", "gpt-5.5", body),
  17. "passive image_gen namespace should NOT be explicit image intent")
  18. assert.True(t, IsImageGenerationIntent("/v1/responses", "gpt-5.5", body),
  19. "passive image_gen namespace SHOULD be general image intent (for permission check)")
  20. }
  21. func TestIsExplicitImageGenerationIntent_DetectsNativeTool(t *testing.T) {
  22. body := []byte(`{
  23. "model": "gpt-5.5",
  24. "tools": [{"type":"image_generation","model":"gpt-image-2"}],
  25. "tool_choice": "auto"
  26. }`)
  27. assert.True(t, IsExplicitImageGenerationIntent("/v1/responses", "gpt-5.5", body),
  28. "native image_generation tool IS explicit intent")
  29. }
  30. func TestIsExplicitImageGenerationIntent_DetectsImageModel(t *testing.T) {
  31. assert.True(t, IsExplicitImageGenerationIntent("/v1/responses", "gpt-image-2", nil),
  32. "image model IS explicit intent")
  33. }
  34. func TestIsExplicitImageGenerationIntent_DetectsImageEndpoint(t *testing.T) {
  35. assert.True(t, IsExplicitImageGenerationIntent("/v1/images/generations", "gpt-5.5", nil),
  36. "image endpoint IS explicit intent")
  37. }
  38. func TestIsExplicitImageGenerationIntent_DetectsExplicitToolChoice(t *testing.T) {
  39. body := []byte(`{"model":"gpt-5.5","tools":[{"type":"function","name":"Read"}],"tool_choice":"image_generation"}`)
  40. assert.True(t, IsExplicitImageGenerationIntent("/v1/responses", "gpt-5.5", body),
  41. "explicit tool_choice selecting image_generation IS explicit intent")
  42. }
  43. func TestIsExplicitImageGenerationIntent_PlainTextRequest(t *testing.T) {
  44. body := []byte(`{
  45. "model": "gpt-5.5",
  46. "input": "hello",
  47. "tools": [{"type":"function","name":"Read"}]
  48. }`)
  49. assert.False(t, IsExplicitImageGenerationIntent("/v1/responses", "gpt-5.5", body),
  50. "plain text request should NOT be explicit image intent")
  51. }