|
1 | 1 | // Image runtime tests cover model-backed image routing, auth/profile handling, |
2 | 2 | // provider payload transforms, and MiniMax/Copilot special paths. |
| 3 | +import { MAX_TIMER_TIMEOUT_MS } from "@openclaw/normalization-core/number-coercion"; |
3 | 4 | import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; |
4 | 5 | |
5 | 6 | const hoisted = vi.hoisted(() => ({ |
@@ -831,6 +832,47 @@ describe("describeImageWithModel", () => {
|
831 | 832 | }); |
832 | 833 | }); |
833 | 834 | |
| 835 | +it("clamps oversized image description timeouts before scheduling", async () => { |
| 836 | +const setTimeoutSpy = vi.spyOn(globalThis, "setTimeout"); |
| 837 | +discoverModelsMock.mockReturnValue({ |
| 838 | +find: vi.fn(() => ({ |
| 839 | +provider: "openai", |
| 840 | +id: "gpt-5.4", |
| 841 | +input: ["text", "image"], |
| 842 | +baseUrl: "https://chatgpt.com/backend-api", |
| 843 | +})), |
| 844 | +}); |
| 845 | +completeMock.mockResolvedValue({ |
| 846 | +role: "assistant", |
| 847 | +api: "openai-chatgpt-responses", |
| 848 | +provider: "openai", |
| 849 | +model: "gpt-5.4", |
| 850 | +stopReason: "stop", |
| 851 | +timestamp: Date.now(), |
| 852 | +content: [{ type: "text", text: "codex ok" }], |
| 853 | +}); |
| 854 | + |
| 855 | +const result = await describeImageWithModel({ |
| 856 | +cfg: {}, |
| 857 | +agentDir: "/tmp/openclaw-agent", |
| 858 | +provider: "openai", |
| 859 | +model: "gpt-5.4", |
| 860 | +buffer: Buffer.from("png-bytes"), |
| 861 | +fileName: "image.png", |
| 862 | +mime: "image/png", |
| 863 | +prompt: "Describe the image.", |
| 864 | +timeoutMs: Number.MAX_SAFE_INTEGER, |
| 865 | +}); |
| 866 | + |
| 867 | +expect(result).toEqual({ |
| 868 | +text: "codex ok", |
| 869 | +model: "gpt-5.4", |
| 870 | +}); |
| 871 | +expect(setTimeoutSpy).toHaveBeenCalledWith(expect.any(Function), MAX_TIMER_TIMEOUT_MS); |
| 872 | +const firstCall = requireFirstMockCall(completeMock, "image completion"); |
| 873 | +expect(firstCall[2].timeoutMs).toBe(MAX_TIMER_TIMEOUT_MS); |
| 874 | +}); |
| 875 | + |
834 | 876 | it("places OpenRouter image prompts in user content before images", async () => { |
835 | 877 | discoverModelsMock.mockReturnValue({ |
836 | 878 | find: vi.fn(() => ({ |
|