
















@@ -1,17 +1,22 @@
11import * as providerAuth from "openclaw/plugin-sdk/provider-auth-runtime";
22import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
33import { installPinnedHostnameTestHooks } from "../../src/media-understanding/audio.test-helpers.js";
4-import { buildMinimaxImageGenerationProvider } from "./image-generation-provider.js";
4+import {
5+buildMinimaxImageGenerationProvider,
6+buildMinimaxPortalImageGenerationProvider,
7+} from "./image-generation-provider.js";
5869installPinnedHostnameTestHooks();
710811describe("minimax image-generation provider", () => {
912beforeEach(() => {
1013vi.clearAllMocks();
14+vi.stubEnv("MINIMAX_API_HOST", "");
1115});
12161317afterEach(() => {
1418vi.restoreAllMocks();
19+vi.unstubAllEnvs();
1520});
16211722function mockMinimaxApiKey() {
@@ -41,6 +46,10 @@ describe("minimax image-generation provider", () => {
4146return fetchMock;
4247}
434849+function expectImageGenerationUrl(fetchMock: ReturnType<typeof vi.fn>, url: string) {
50+expect(fetchMock).toHaveBeenCalledWith(url, expect.any(Object));
51+}
52+4453it("generates PNG buffers through the shared provider HTTP path", async () => {
4554mockMinimaxApiKey();
4655const fetchMock = mockSuccessfulMinimaxImageResponse();
@@ -81,7 +90,7 @@ describe("minimax image-generation provider", () => {
8190});
8291});
839284-it("uses the configured provider base URL origin", async () => {
93+it("keeps the dedicated global image endpoint when text config uses the global API host", async () => {
8594mockMinimaxApiKey();
8695const fetchMock = mockSuccessfulMinimaxImageResponse();
8796@@ -102,36 +111,118 @@ describe("minimax image-generation provider", () => {
102111},
103112});
104113105-expect(fetchMock).toHaveBeenCalledWith(
106-"https://api.minimax.io/v1/image_generation",
107-expect.any(Object),
108-);
114+expectImageGenerationUrl(fetchMock, "https://api.minimax.io/v1/image_generation");
109115});
110116111-it("does not allow private-network routing just because a custom base URL is configured", async () => {
117+it("does not inherit unrelated MiniMax text endpoint hosts for image generation", async () => {
112118mockMinimaxApiKey();
113-const fetchMock = vi.fn();
114-vi.stubGlobal("fetch", fetchMock);
119+const fetchMock = mockSuccessfulMinimaxImageResponse();
115120116121const provider = buildMinimaxImageGenerationProvider();
117-await expect(
118-provider.generateImage({
119-provider: "minimax",
120-model: "image-01",
121-prompt: "draw a cat",
122-cfg: {
123-models: {
124-providers: {
125-minimax: {
126-baseUrl: "http://127.0.0.1:8080/anthropic",
127-models: [],
128-},
122+await provider.generateImage({
123+provider: "minimax",
124+model: "image-01",
125+prompt: "draw a cat",
126+cfg: {
127+models: {
128+providers: {
129+minimax: {
130+baseUrl: "https://api.minimax.chat/anthropic",
131+models: [],
129132},
130133},
131134},
132-}),
133-).rejects.toThrow("Blocked hostname or private/internal/special-use IP address");
135+},
136+});
137+138+expectImageGenerationUrl(fetchMock, "https://api.minimax.io/v1/image_generation");
139+});
140+141+it("uses the dedicated CN image endpoint when CN API host is configured", async () => {
142+vi.stubEnv("MINIMAX_API_HOST", "https://api.minimaxi.com/anthropic");
143+mockMinimaxApiKey();
144+const fetchMock = mockSuccessfulMinimaxImageResponse();
145+146+const provider = buildMinimaxImageGenerationProvider();
147+await provider.generateImage({
148+provider: "minimax",
149+model: "image-01",
150+prompt: "draw a cat",
151+cfg: {},
152+});
153+154+expectImageGenerationUrl(fetchMock, "https://api.minimaxi.com/v1/image_generation");
155+});
156+157+it("infers the dedicated CN image endpoint from MiniMax provider config", async () => {
158+mockMinimaxApiKey();
159+const fetchMock = mockSuccessfulMinimaxImageResponse();
160+161+const provider = buildMinimaxImageGenerationProvider();
162+await provider.generateImage({
163+provider: "minimax",
164+model: "image-01",
165+prompt: "draw a cat",
166+cfg: {
167+models: {
168+providers: {
169+minimax: {
170+baseUrl: "https://api.minimaxi.com/anthropic",
171+models: [],
172+},
173+},
174+},
175+},
176+});
177+178+expectImageGenerationUrl(fetchMock, "https://api.minimaxi.com/v1/image_generation");
179+});
180+181+it("infers the dedicated CN image endpoint from MiniMax Portal provider config", async () => {
182+mockMinimaxApiKey();
183+const fetchMock = mockSuccessfulMinimaxImageResponse();
184+185+const provider = buildMinimaxPortalImageGenerationProvider();
186+await provider.generateImage({
187+provider: "minimax-portal",
188+model: "image-01",
189+prompt: "draw a cat",
190+cfg: {
191+models: {
192+providers: {
193+"minimax-portal": {
194+baseUrl: "api.minimaxi.com/anthropic",
195+models: [],
196+},
197+},
198+},
199+},
200+});
201+202+expectImageGenerationUrl(fetchMock, "https://api.minimaxi.com/v1/image_generation");
203+});
204+205+it("ignores private custom text endpoints for image generation", async () => {
206+mockMinimaxApiKey();
207+const fetchMock = mockSuccessfulMinimaxImageResponse();
208+209+const provider = buildMinimaxImageGenerationProvider();
210+await provider.generateImage({
211+provider: "minimax",
212+model: "image-01",
213+prompt: "draw a cat",
214+cfg: {
215+models: {
216+providers: {
217+minimax: {
218+baseUrl: "http://127.0.0.1:8080/anthropic",
219+models: [],
220+},
221+},
222+},
223+},
224+});
134225135-expect(fetchMock).not.toHaveBeenCalled();
226+expectImageGenerationUrl(fetchMock, "https://api.minimax.io/v1/image_generation");
136227});
137228});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。