|
1 | 1 | // npx vitest run api/providers/__tests__/openai-codex.spec.ts |
2 | 2 |
|
| 3 | +import { Anthropic } from "@anthropic-ai/sdk" |
3 | 4 | import { OpenAiCodexHandler } from "../openai-codex" |
| 5 | +import { openAiCodexOAuthManager } from "../../../integrations/openai-codex/oauth" |
4 | 6 |
|
5 | 7 | describe("OpenAiCodexHandler.getModel", () => { |
6 | 8 | it.each(["gpt-5.1", "gpt-5", "gpt-5.1-codex", "gpt-5-codex", "gpt-5-codex-mini", "gpt-5.3-codex-spark"])( |
@@ -42,3 +44,54 @@ describe("OpenAiCodexHandler.getModel", () => { |
42 | 44 | expect(model.info).toBeDefined() |
43 | 45 | }) |
44 | 46 | }) |
| 47 | + |
| 48 | +describe("OpenAiCodexHandler.createMessage", () => { |
| 49 | + it("should skip URL-sourced images in formatFullConversation (only base64 emits input_image)", async () => { |
| 50 | + const handler = new OpenAiCodexHandler({ apiModelId: "gpt-5.1-codex" }) |
| 51 | + |
| 52 | + vitest.spyOn(openAiCodexOAuthManager, "getAccessToken").mockResolvedValue("test-token") |
| 53 | + vitest.spyOn(openAiCodexOAuthManager, "getAccountId").mockResolvedValue("acct_test") |
| 54 | + |
| 55 | + const capturedInput: any[] = [] |
| 56 | + ;(handler as any).client = { |
| 57 | + responses: { |
| 58 | + create: vitest.fn().mockImplementation(async (body: any) => { |
| 59 | + capturedInput.push(...(body.input ?? [])) |
| 60 | + return { |
| 61 | + async *[Symbol.asyncIterator]() { |
| 62 | + yield { |
| 63 | + type: "response.completed", |
| 64 | + response: { |
| 65 | + id: "r1", |
| 66 | + status: "completed", |
| 67 | + output: [], |
| 68 | + usage: { input_tokens: 1, output_tokens: 1 }, |
| 69 | + }, |
| 70 | + } |
| 71 | + }, |
| 72 | + } |
| 73 | + }), |
| 74 | + }, |
| 75 | + } |
| 76 | + |
| 77 | + const messages: Anthropic.Messages.MessageParam[] = [ |
| 78 | + { |
| 79 | + role: "user", |
| 80 | + content: [ |
| 81 | + { type: "text", text: "Look at this:" }, |
| 82 | + { type: "image", source: { type: "url", url: "https://example.com/img.png" } as any }, |
| 83 | + ], |
| 84 | + }, |
| 85 | + ] |
| 86 | + |
| 87 | + const stream = handler.createMessage("system", messages) |
| 88 | + for await (const _ of stream) { |
| 89 | + // consume |
| 90 | + } |
| 91 | + |
| 92 | + // URL image is skipped; only the text input_text block should be present |
| 93 | + const userMsg = capturedInput.find((item: any) => item.role === "user") |
| 94 | + expect(userMsg?.content).toEqual([{ type: "input_text", text: "Look at this:" }]) |
| 95 | + expect(JSON.stringify(capturedInput)).not.toContain("input_image") |
| 96 | + }) |
| 97 | +}) |
0 commit comments