openai_ws_forwarder_retry_payload_test.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package service
  2. import (
  3. "testing"
  4. "github.com/stretchr/testify/require"
  5. )
  6. func TestApplyOpenAIWSRetryPayloadStrategy_KeepPromptCacheKey(t *testing.T) {
  7. payload := map[string]any{
  8. "model": "gpt-5.3-codex",
  9. "prompt_cache_key": "pcache_123",
  10. "include": []any{"reasoning.encrypted_content"},
  11. "text": map[string]any{
  12. "verbosity": "low",
  13. },
  14. "tools": []any{map[string]any{"type": "function"}},
  15. }
  16. strategy, removed := applyOpenAIWSRetryPayloadStrategy(payload, 3)
  17. require.Equal(t, "trim_optional_fields", strategy)
  18. require.Contains(t, removed, "include")
  19. require.NotContains(t, removed, "prompt_cache_key")
  20. require.Equal(t, "pcache_123", payload["prompt_cache_key"])
  21. require.NotContains(t, payload, "include")
  22. require.Contains(t, payload, "text")
  23. }
  24. func TestApplyOpenAIWSRetryPayloadStrategy_AttemptSixKeepsSemanticFields(t *testing.T) {
  25. payload := map[string]any{
  26. "prompt_cache_key": "pcache_456",
  27. "instructions": "long instructions",
  28. "tools": []any{map[string]any{"type": "function"}},
  29. "parallel_tool_calls": true,
  30. "tool_choice": "auto",
  31. "include": []any{"reasoning.encrypted_content"},
  32. "text": map[string]any{"verbosity": "high"},
  33. }
  34. strategy, removed := applyOpenAIWSRetryPayloadStrategy(payload, 6)
  35. require.Equal(t, "trim_optional_fields", strategy)
  36. require.Contains(t, removed, "include")
  37. require.NotContains(t, removed, "prompt_cache_key")
  38. require.Equal(t, "pcache_456", payload["prompt_cache_key"])
  39. require.Contains(t, payload, "instructions")
  40. require.Contains(t, payload, "tools")
  41. require.Contains(t, payload, "tool_choice")
  42. require.Contains(t, payload, "parallel_tool_calls")
  43. require.Contains(t, payload, "text")
  44. }