openai_codex_astra_image_test.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. package service
  2. import (
  3. "context"
  4. "testing"
  5. "github.com/stretchr/testify/require"
  6. )
  7. func TestBuildCodexModelsManifestForGroupCorrectsOfficialAstraStaleModalities(t *testing.T) {
  8. t.Parallel()
  9. const groupID int64 = 780
  10. account := Account{
  11. ID: 1,
  12. Platform: PlatformOpenAI,
  13. Type: AccountTypeAPIKey,
  14. Credentials: map[string]any{"api_key": "sk-test"},
  15. }
  16. account.SetUpstreamModelMetadataSnapshot(UpstreamModelMetadataSnapshot{
  17. Models: map[string]UpstreamModelMetadata{
  18. "gpt-6-astra": {ID: "gpt-6-astra", InputModalities: []string{"text"}},
  19. },
  20. })
  21. svc := &GatewayService{accountRepo: codexModelsVisibilityAccountRepo{
  22. byGroup: map[int64][]Account{groupID: {account}},
  23. }}
  24. body, err := svc.BuildCodexModelsManifestForGroup(
  25. context.Background(),
  26. &Group{ID: groupID, Platform: PlatformOpenAI},
  27. "",
  28. []string{"gpt-6-astra"},
  29. )
  30. require.NoError(t, err)
  31. models := decodeCodexManifestModels(t, body)
  32. require.Len(t, models, 1)
  33. require.Equal(t, []any{"text", "image"}, models[0]["input_modalities"])
  34. }
  35. func TestBuildCodexModelsManifestForGroupPreservesCompatibleAstraTextOnlyMetadata(t *testing.T) {
  36. t.Parallel()
  37. const groupID int64 = 781
  38. account := Account{
  39. ID: 2,
  40. Platform: PlatformOpenAI,
  41. Type: AccountTypeAPIKey,
  42. Credentials: map[string]any{"api_key": "sk-test", "base_url": "https://relay.example.test/v1"},
  43. }
  44. account.SetUpstreamModelMetadataSnapshot(UpstreamModelMetadataSnapshot{
  45. Models: map[string]UpstreamModelMetadata{
  46. "gpt-6-astra": {ID: "gpt-6-astra", InputModalities: []string{"text"}},
  47. },
  48. })
  49. svc := &GatewayService{accountRepo: codexModelsVisibilityAccountRepo{
  50. byGroup: map[int64][]Account{groupID: {account}},
  51. }}
  52. body, err := svc.BuildCodexModelsManifestForGroup(
  53. context.Background(),
  54. &Group{ID: groupID, Platform: PlatformOpenAI},
  55. "",
  56. []string{"gpt-6-astra"},
  57. )
  58. require.NoError(t, err)
  59. models := decodeCodexManifestModels(t, body)
  60. require.Len(t, models, 1)
  61. require.Equal(t, []any{"text"}, models[0]["input_modalities"])
  62. }