Vendor OpenClaw source as Adolf fork baseline
Some checks failed
ClawSweeper Dispatch / dispatch (push) Has been cancelled
CodeQL / Security High (actions) (push) Has been cancelled
CodeQL / Security High (channel-runtime-boundary) (push) Has been cancelled
CodeQL / Security High (core-auth-secrets) (push) Has been cancelled
CodeQL / Security High (mcp-process-tool-boundary) (push) Has been cancelled
CodeQL / Security High (network-ssrf-boundary) (push) Has been cancelled
CodeQL / Security High (plugin-trust-boundary) (push) Has been cancelled
CodeQL / Security High (process-exec-boundary) (push) Has been cancelled
Docs Sync Publish Repo / sync-publish-repo (push) Has been cancelled
Docs / docs (push) Has been cancelled
OpenClaw Stable Main Closeout / Resolve stable release closeout inputs (push) Has been cancelled
OpenClaw Stable Main Closeout / Verify stable main closeout (push) Has been cancelled
Workflow Sanity / no-tabs (push) Has been cancelled
Workflow Sanity / actionlint (push) Has been cancelled
Workflow Sanity / generated-doc-baselines (push) Has been cancelled
CI / runner-admission (push) Has been cancelled
CI / preflight (push) Has been cancelled
CI / security-fast (push) Has been cancelled
CI / pnpm-store-warmup (push) Has been cancelled
CI / build-artifacts (push) Has been cancelled
CI / native-i18n (push) Has been cancelled
CI / ${{ matrix.check_name }} (push) Has been cancelled
CI / ${{ matrix.checkName }} (push) Has been cancelled
CI / checks-node-compat-node22 (push) Has been cancelled
CI / check-bundled-channel-config-metadata (push) Has been cancelled
CI / check-dependencies (push) Has been cancelled
CI / check-guards (push) Has been cancelled
CI / check-lint (push) Has been cancelled
CI / check-prod-types (push) Has been cancelled
CI / check-shrinkwrap (push) Has been cancelled
CI / check-test-types (push) Has been cancelled
CI / check-additional-boundaries-a (push) Has been cancelled
CI / check-additional-boundaries-bcd (push) Has been cancelled
CI / check-additional-extension-bundled (push) Has been cancelled
CI / check-additional-extension-channels (push) Has been cancelled
CI / check-additional-extension-package-boundary (push) Has been cancelled
CI / check-additional-runtime-topology-architecture (push) Has been cancelled
CI / check-session-accessor-boundary (push) Has been cancelled
CI / check-session-transcript-reader-boundary (push) Has been cancelled
CI / check-docs (push) Has been cancelled
CI / skills-python (push) Has been cancelled
CI / macos-swift (push) Has been cancelled
CI / ios-build (push) Has been cancelled
CI / ci-timings-summary (push) Has been cancelled
Native App Locale Refresh / Refresh native fa (push) Has been cancelled
Native App Locale Refresh / Refresh native fr (push) Has been cancelled
Native App Locale Refresh / Refresh native hi (push) Has been cancelled
Native App Locale Refresh / Refresh native id (push) Has been cancelled
Native App Locale Refresh / Refresh native it (push) Has been cancelled
Native App Locale Refresh / Refresh native ja-JP (push) Has been cancelled
Control UI Locale Refresh / plan (push) Has been cancelled
Control UI Locale Refresh / Refresh ${{ matrix.locale }} (push) Has been cancelled
Control UI Locale Refresh / Commit control UI locale refresh (push) Has been cancelled
Live Media Runner Image / Build live media runner image (push) Has been cancelled
Native App Locale Refresh / Refresh native ar (push) Has been cancelled
Native App Locale Refresh / Refresh native de (push) Has been cancelled
Native App Locale Refresh / Refresh native es (push) Has been cancelled
Native App Locale Refresh / Refresh native ko (push) Has been cancelled
Native App Locale Refresh / Refresh native nl (push) Has been cancelled
Native App Locale Refresh / Refresh native pl (push) Has been cancelled
Native App Locale Refresh / Refresh native pt-BR (push) Has been cancelled
Native App Locale Refresh / Refresh native ru (push) Has been cancelled
Native App Locale Refresh / Refresh native sv (push) Has been cancelled
Native App Locale Refresh / Refresh native th (push) Has been cancelled
Native App Locale Refresh / Refresh native tr (push) Has been cancelled
Native App Locale Refresh / Refresh native uk (push) Has been cancelled
Native App Locale Refresh / Refresh native vi (push) Has been cancelled
Native App Locale Refresh / Refresh native zh-CN (push) Has been cancelled
Native App Locale Refresh / Refresh native zh-TW (push) Has been cancelled
Native App Locale Refresh / Commit native locale refresh (push) Has been cancelled
Plugin Init Scaffold Validation / Validate provider scaffold (push) Has been cancelled
Plugin NPM Release / preview_plugins_npm (push) Has been cancelled
Plugin NPM Release / Validate release publish approval (push) Has been cancelled
Plugin NPM Release / preview_plugin_pack (push) Has been cancelled
Plugin NPM Release / publish_plugins_npm (push) Has been cancelled
Sandbox Common Smoke / sandbox-common-smoke (push) Has been cancelled
Website Installer Sync / static (push) Has been cancelled
Website Installer Sync / linux-docker (push) Has been cancelled
Website Installer Sync / macos-installer (push) Has been cancelled
Website Installer Sync / windows-installer (push) Has been cancelled
Website Installer Sync / sync-website (push) Has been cancelled
Some checks failed
ClawSweeper Dispatch / dispatch (push) Has been cancelled
CodeQL / Security High (actions) (push) Has been cancelled
CodeQL / Security High (channel-runtime-boundary) (push) Has been cancelled
CodeQL / Security High (core-auth-secrets) (push) Has been cancelled
CodeQL / Security High (mcp-process-tool-boundary) (push) Has been cancelled
CodeQL / Security High (network-ssrf-boundary) (push) Has been cancelled
CodeQL / Security High (plugin-trust-boundary) (push) Has been cancelled
CodeQL / Security High (process-exec-boundary) (push) Has been cancelled
Docs Sync Publish Repo / sync-publish-repo (push) Has been cancelled
Docs / docs (push) Has been cancelled
OpenClaw Stable Main Closeout / Resolve stable release closeout inputs (push) Has been cancelled
OpenClaw Stable Main Closeout / Verify stable main closeout (push) Has been cancelled
Workflow Sanity / no-tabs (push) Has been cancelled
Workflow Sanity / actionlint (push) Has been cancelled
Workflow Sanity / generated-doc-baselines (push) Has been cancelled
CI / runner-admission (push) Has been cancelled
CI / preflight (push) Has been cancelled
CI / security-fast (push) Has been cancelled
CI / pnpm-store-warmup (push) Has been cancelled
CI / build-artifacts (push) Has been cancelled
CI / native-i18n (push) Has been cancelled
CI / ${{ matrix.check_name }} (push) Has been cancelled
CI / ${{ matrix.checkName }} (push) Has been cancelled
CI / checks-node-compat-node22 (push) Has been cancelled
CI / check-bundled-channel-config-metadata (push) Has been cancelled
CI / check-dependencies (push) Has been cancelled
CI / check-guards (push) Has been cancelled
CI / check-lint (push) Has been cancelled
CI / check-prod-types (push) Has been cancelled
CI / check-shrinkwrap (push) Has been cancelled
CI / check-test-types (push) Has been cancelled
CI / check-additional-boundaries-a (push) Has been cancelled
CI / check-additional-boundaries-bcd (push) Has been cancelled
CI / check-additional-extension-bundled (push) Has been cancelled
CI / check-additional-extension-channels (push) Has been cancelled
CI / check-additional-extension-package-boundary (push) Has been cancelled
CI / check-additional-runtime-topology-architecture (push) Has been cancelled
CI / check-session-accessor-boundary (push) Has been cancelled
CI / check-session-transcript-reader-boundary (push) Has been cancelled
CI / check-docs (push) Has been cancelled
CI / skills-python (push) Has been cancelled
CI / macos-swift (push) Has been cancelled
CI / ios-build (push) Has been cancelled
CI / ci-timings-summary (push) Has been cancelled
Native App Locale Refresh / Refresh native fa (push) Has been cancelled
Native App Locale Refresh / Refresh native fr (push) Has been cancelled
Native App Locale Refresh / Refresh native hi (push) Has been cancelled
Native App Locale Refresh / Refresh native id (push) Has been cancelled
Native App Locale Refresh / Refresh native it (push) Has been cancelled
Native App Locale Refresh / Refresh native ja-JP (push) Has been cancelled
Control UI Locale Refresh / plan (push) Has been cancelled
Control UI Locale Refresh / Refresh ${{ matrix.locale }} (push) Has been cancelled
Control UI Locale Refresh / Commit control UI locale refresh (push) Has been cancelled
Live Media Runner Image / Build live media runner image (push) Has been cancelled
Native App Locale Refresh / Refresh native ar (push) Has been cancelled
Native App Locale Refresh / Refresh native de (push) Has been cancelled
Native App Locale Refresh / Refresh native es (push) Has been cancelled
Native App Locale Refresh / Refresh native ko (push) Has been cancelled
Native App Locale Refresh / Refresh native nl (push) Has been cancelled
Native App Locale Refresh / Refresh native pl (push) Has been cancelled
Native App Locale Refresh / Refresh native pt-BR (push) Has been cancelled
Native App Locale Refresh / Refresh native ru (push) Has been cancelled
Native App Locale Refresh / Refresh native sv (push) Has been cancelled
Native App Locale Refresh / Refresh native th (push) Has been cancelled
Native App Locale Refresh / Refresh native tr (push) Has been cancelled
Native App Locale Refresh / Refresh native uk (push) Has been cancelled
Native App Locale Refresh / Refresh native vi (push) Has been cancelled
Native App Locale Refresh / Refresh native zh-CN (push) Has been cancelled
Native App Locale Refresh / Refresh native zh-TW (push) Has been cancelled
Native App Locale Refresh / Commit native locale refresh (push) Has been cancelled
Plugin Init Scaffold Validation / Validate provider scaffold (push) Has been cancelled
Plugin NPM Release / preview_plugins_npm (push) Has been cancelled
Plugin NPM Release / Validate release publish approval (push) Has been cancelled
Plugin NPM Release / preview_plugin_pack (push) Has been cancelled
Plugin NPM Release / publish_plugins_npm (push) Has been cancelled
Sandbox Common Smoke / sandbox-common-smoke (push) Has been cancelled
Website Installer Sync / static (push) Has been cancelled
Website Installer Sync / linux-docker (push) Has been cancelled
Website Installer Sync / macos-installer (push) Has been cancelled
Website Installer Sync / windows-installer (push) Has been cancelled
Website Installer Sync / sync-website (push) Has been cancelled
Adolf is a fork/vendored clone of github.com/openclaw/openclaw (v2026.6.11), free to diverge. Tree copied sans upstream .git; upstream remote added for future syncs. Node pinned to 24 (.nvmrc); engines already require >=22.19. Preserves docs/ARCHITECTURE.md. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LeqyaxJF2nbRXJtae2kNB2
This commit is contained in:
441
extensions/minimax/music-generation-provider.test.ts
Normal file
441
extensions/minimax/music-generation-provider.test.ts
Normal file
@@ -0,0 +1,441 @@
|
||||
// Minimax tests cover music generation provider plugin behavior.
|
||||
import { expectExplicitMusicGenerationCapabilities } from "openclaw/plugin-sdk/provider-test-contracts";
|
||||
import { beforeAll, describe, expect, it, vi } from "vitest";
|
||||
import {
|
||||
getMinimaxProviderHttpMocks,
|
||||
installMinimaxProviderHttpMockCleanup,
|
||||
loadMinimaxMusicGenerationProviderModule,
|
||||
} from "./provider-http.test-helpers.js";
|
||||
|
||||
const {
|
||||
resolveApiKeyForProviderMock,
|
||||
postJsonRequestMock,
|
||||
fetchWithTimeoutMock,
|
||||
resolveProviderHttpRequestConfigMock,
|
||||
} = getMinimaxProviderHttpMocks();
|
||||
|
||||
let buildMinimaxMusicGenerationProvider: Awaited<
|
||||
ReturnType<typeof loadMinimaxMusicGenerationProviderModule>
|
||||
>["buildMinimaxMusicGenerationProvider"];
|
||||
let buildMinimaxPortalMusicGenerationProvider: Awaited<
|
||||
ReturnType<typeof loadMinimaxMusicGenerationProviderModule>
|
||||
>["buildMinimaxPortalMusicGenerationProvider"];
|
||||
|
||||
beforeAll(async () => {
|
||||
({ buildMinimaxMusicGenerationProvider, buildMinimaxPortalMusicGenerationProvider } =
|
||||
await loadMinimaxMusicGenerationProviderModule());
|
||||
});
|
||||
|
||||
installMinimaxProviderHttpMockCleanup();
|
||||
|
||||
function mockMusicGenerationResponse(json: Record<string, unknown>): void {
|
||||
const response = new Response(JSON.stringify(json), {
|
||||
headers: { "content-type": "application/json" },
|
||||
});
|
||||
postJsonRequestMock.mockResolvedValue({
|
||||
response,
|
||||
release: vi.fn(async () => {}),
|
||||
});
|
||||
fetchWithTimeoutMock.mockResolvedValue({
|
||||
headers: new Headers({ "content-type": "audio/mpeg" }),
|
||||
arrayBuffer: async () => Buffer.from("mp3-bytes"),
|
||||
});
|
||||
}
|
||||
|
||||
function mockCallArg(mock: { mock: { calls: unknown[][] } }, index = 0): Record<string, unknown> {
|
||||
const call = mock.mock.calls[index];
|
||||
if (!call) {
|
||||
throw new Error(`expected mock call ${index}`);
|
||||
}
|
||||
return call[0] as Record<string, unknown>;
|
||||
}
|
||||
|
||||
function streamedAudioResponse(bytes: string): Response {
|
||||
return new Response(
|
||||
new ReadableStream({
|
||||
start(controller) {
|
||||
controller.enqueue(new TextEncoder().encode(bytes));
|
||||
controller.close();
|
||||
},
|
||||
}),
|
||||
{ headers: { "content-type": "audio/mpeg" } },
|
||||
);
|
||||
}
|
||||
|
||||
describe("minimax music generation provider", () => {
|
||||
it("declares explicit mode capabilities", () => {
|
||||
expectExplicitMusicGenerationCapabilities(buildMinimaxMusicGenerationProvider());
|
||||
});
|
||||
|
||||
it("streams generated music chunks from MiniMax", async () => {
|
||||
const chunkA = Buffer.from("ID3\x04\x00mp3-a");
|
||||
const chunkB = Buffer.from("mp3-b");
|
||||
postJsonRequestMock.mockResolvedValue({
|
||||
response: new Response(
|
||||
[
|
||||
`data: ${JSON.stringify({ data: { status: 1, audio: chunkA.toString("hex") }, base_resp: { status_code: 0 } })}`,
|
||||
`data: ${JSON.stringify({ data: { status: 1, audio: chunkB.toString("hex") }, base_resp: { status_code: 0 } })}`,
|
||||
`data: ${JSON.stringify({ data: { status: 2, audio: Buffer.concat([chunkA, chunkB]).toString("hex") }, base_resp: { status_code: 0 } })}`,
|
||||
"",
|
||||
].join("\n\n"),
|
||||
{
|
||||
headers: { "content-type": "text/event-stream" },
|
||||
},
|
||||
),
|
||||
release: vi.fn(async () => {}),
|
||||
});
|
||||
|
||||
const provider = buildMinimaxMusicGenerationProvider();
|
||||
const result = await provider.generateMusic({
|
||||
provider: "minimax",
|
||||
model: "",
|
||||
prompt: "upbeat dance-pop with female vocals",
|
||||
cfg: {},
|
||||
lyrics: "our city wakes",
|
||||
durationSeconds: 45,
|
||||
});
|
||||
|
||||
const request = mockCallArg(postJsonRequestMock);
|
||||
expect(request.url).toBe("https://api.minimax.io/v1/music_generation");
|
||||
const body = request.body as Record<string, unknown>;
|
||||
expect(body.model).toBe("music-2.6");
|
||||
expect(body.prompt).toBe("upbeat dance-pop with female vocals");
|
||||
expect(body.prompt).not.toContain("Target duration");
|
||||
expect(body).not.toHaveProperty("duration");
|
||||
expect(body.lyrics).toBe("our city wakes");
|
||||
expect(body.stream).toBe(true);
|
||||
expect(body.output_format).toBe("hex");
|
||||
expect(body.audio_setting).toEqual({
|
||||
sample_rate: 44100,
|
||||
bitrate: 256000,
|
||||
format: "mp3",
|
||||
});
|
||||
expect(request.timeoutMs).toBe(300000);
|
||||
expect(request?.headers).toBeInstanceOf(Headers);
|
||||
const headers = request?.headers as Headers | undefined;
|
||||
expect(headers?.get("content-type")).toBe("application/json");
|
||||
expect(result.tracks).toHaveLength(1);
|
||||
expect(result.tracks[0]?.buffer).toEqual(Buffer.concat([chunkA, chunkB]));
|
||||
expect(result.tracks[0]?.mimeType).toBe("audio/mpeg");
|
||||
expect(result.metadata?.requestedLyrics).toBe(true);
|
||||
expect(result.metadata).not.toHaveProperty("requestedDurationSeconds");
|
||||
});
|
||||
|
||||
it("reports streaming music task failures", async () => {
|
||||
postJsonRequestMock.mockResolvedValue({
|
||||
response: new Response(
|
||||
`data: ${JSON.stringify({
|
||||
base_resp: { status_code: 0 },
|
||||
})}\n\ndata: ${JSON.stringify({
|
||||
base_resp: { status_code: 2013, status_msg: "render rejected" },
|
||||
})}`,
|
||||
{
|
||||
headers: { "content-type": "text/event-stream" },
|
||||
},
|
||||
),
|
||||
release: vi.fn(async () => {}),
|
||||
});
|
||||
|
||||
const provider = buildMinimaxMusicGenerationProvider();
|
||||
|
||||
await expect(
|
||||
provider.generateMusic({
|
||||
provider: "minimax",
|
||||
model: "music-2.6",
|
||||
prompt: "upbeat dance-pop with female vocals",
|
||||
cfg: {},
|
||||
}),
|
||||
).rejects.toThrow("MiniMax music generation failed (2013): render rejected");
|
||||
});
|
||||
|
||||
it("keeps terminal streaming audio when no progressive chunks were sent", async () => {
|
||||
const terminalAudio = Buffer.from("terminal-mp3");
|
||||
postJsonRequestMock.mockResolvedValue({
|
||||
response: new Response(
|
||||
`data: ${JSON.stringify({
|
||||
data: { status: 2, audio: terminalAudio.toString("hex") },
|
||||
base_resp: { status_code: 0 },
|
||||
})}`,
|
||||
{
|
||||
headers: { "content-type": "text/event-stream" },
|
||||
},
|
||||
),
|
||||
release: vi.fn(async () => {}),
|
||||
});
|
||||
|
||||
const provider = buildMinimaxMusicGenerationProvider();
|
||||
const result = await provider.generateMusic({
|
||||
provider: "minimax",
|
||||
model: "music-2.6",
|
||||
prompt: "upbeat dance-pop with female vocals",
|
||||
cfg: {},
|
||||
});
|
||||
|
||||
expect(result.tracks[0]?.buffer).toEqual(terminalAudio);
|
||||
});
|
||||
|
||||
it("rejects streamed generated music that exceeds the configured media cap", async () => {
|
||||
postJsonRequestMock.mockResolvedValue({
|
||||
response: new Response(
|
||||
`data: ${JSON.stringify({
|
||||
data: { status: 2, audio: Buffer.from("too-large").toString("hex") },
|
||||
base_resp: { status_code: 0 },
|
||||
})}`,
|
||||
{
|
||||
headers: { "content-type": "text/event-stream" },
|
||||
},
|
||||
),
|
||||
release: vi.fn(async () => {}),
|
||||
});
|
||||
|
||||
const provider = buildMinimaxMusicGenerationProvider();
|
||||
await expect(
|
||||
provider.generateMusic({
|
||||
provider: "minimax",
|
||||
model: "music-2.6",
|
||||
prompt: "short track",
|
||||
cfg: { agents: { defaults: { mediaMaxMb: 0.000001 } } },
|
||||
}),
|
||||
).rejects.toThrow("MiniMax generated music download exceeds 1 bytes");
|
||||
});
|
||||
|
||||
it("rejects inline generated music that exceeds the configured media cap before decoding", async () => {
|
||||
postJsonRequestMock.mockResolvedValue({
|
||||
response: new Response(
|
||||
JSON.stringify({
|
||||
data: {
|
||||
audio: Buffer.from("too-large").toString("hex"),
|
||||
},
|
||||
base_resp: { status_code: 0 },
|
||||
}),
|
||||
{
|
||||
headers: { "content-type": "application/json" },
|
||||
},
|
||||
),
|
||||
release: vi.fn(async () => {}),
|
||||
});
|
||||
|
||||
const provider = buildMinimaxMusicGenerationProvider();
|
||||
await expect(
|
||||
provider.generateMusic({
|
||||
provider: "minimax",
|
||||
model: "music-2.6",
|
||||
prompt: "short track",
|
||||
cfg: { agents: { defaults: { mediaMaxMb: 0.000001 } } },
|
||||
}),
|
||||
).rejects.toThrow("MiniMax generated music download exceeds 1 bytes");
|
||||
});
|
||||
|
||||
it("downloads tracks when url output is returned in data.audio", async () => {
|
||||
mockMusicGenerationResponse({
|
||||
task_id: "task-url",
|
||||
lyrics: "our city wakes",
|
||||
data: {
|
||||
audio: "https://example.com/url-audio.mp3",
|
||||
},
|
||||
base_resp: { status_code: 0 },
|
||||
});
|
||||
|
||||
const provider = buildMinimaxMusicGenerationProvider();
|
||||
const result = await provider.generateMusic({
|
||||
provider: "minimax",
|
||||
model: "music-2.6",
|
||||
prompt: "upbeat dance-pop with female vocals",
|
||||
cfg: {},
|
||||
lyrics: "our city wakes",
|
||||
});
|
||||
|
||||
expect(fetchWithTimeoutMock).toHaveBeenCalledWith(
|
||||
"https://example.com/url-audio.mp3",
|
||||
{ method: "GET" },
|
||||
120000,
|
||||
fetch,
|
||||
);
|
||||
expect(result.tracks[0]?.buffer.byteLength).toBeGreaterThan(0);
|
||||
expect(result.lyrics).toEqual(["our city wakes"]);
|
||||
expect(result.metadata?.taskId).toBe("task-url");
|
||||
expect(result.metadata?.audioUrl).toBe("https://example.com/url-audio.mp3");
|
||||
});
|
||||
|
||||
it("rejects generated music downloads that exceed the configured media cap", async () => {
|
||||
postJsonRequestMock.mockResolvedValue({
|
||||
response: new Response(
|
||||
JSON.stringify({
|
||||
data: {
|
||||
audio: "https://example.com/too-large.mp3",
|
||||
},
|
||||
base_resp: { status_code: 0 },
|
||||
}),
|
||||
{ headers: { "content-type": "application/json" } },
|
||||
),
|
||||
release: vi.fn(async () => {}),
|
||||
});
|
||||
fetchWithTimeoutMock.mockResolvedValueOnce(streamedAudioResponse("too-large"));
|
||||
|
||||
const provider = buildMinimaxMusicGenerationProvider();
|
||||
await expect(
|
||||
provider.generateMusic({
|
||||
provider: "minimax",
|
||||
model: "music-2.6",
|
||||
prompt: "short track",
|
||||
cfg: { agents: { defaults: { mediaMaxMb: 0.000001 } } },
|
||||
}),
|
||||
).rejects.toThrow("MiniMax generated music download exceeds 1 bytes");
|
||||
});
|
||||
|
||||
it("honors explicit long caller timeouts for request and download fallbacks", async () => {
|
||||
mockMusicGenerationResponse({
|
||||
data: {
|
||||
audio: "https://example.com/long-timeout.mp3",
|
||||
},
|
||||
base_resp: { status_code: 0 },
|
||||
});
|
||||
|
||||
const provider = buildMinimaxMusicGenerationProvider();
|
||||
await provider.generateMusic({
|
||||
provider: "minimax",
|
||||
model: "music-2.6",
|
||||
prompt: "upbeat dance-pop with female vocals",
|
||||
cfg: {},
|
||||
lyrics: "our city wakes",
|
||||
timeoutMs: 600000,
|
||||
});
|
||||
|
||||
expect(mockCallArg(postJsonRequestMock).timeoutMs).toBe(600000);
|
||||
expect(fetchWithTimeoutMock).toHaveBeenCalledWith(
|
||||
"https://example.com/long-timeout.mp3",
|
||||
{ method: "GET" },
|
||||
600000,
|
||||
fetch,
|
||||
);
|
||||
});
|
||||
|
||||
it("applies explicit caller timeouts while reading streaming response bodies", async () => {
|
||||
vi.useFakeTimers();
|
||||
try {
|
||||
let cancelled = false;
|
||||
const stream = new ReadableStream<Uint8Array>({
|
||||
start(controller) {
|
||||
setTimeout(() => {
|
||||
if (cancelled) {
|
||||
return;
|
||||
}
|
||||
controller.enqueue(
|
||||
new TextEncoder().encode(
|
||||
`data: ${JSON.stringify({
|
||||
data: { status: 2, audio: Buffer.from("late-mp3").toString("hex") },
|
||||
base_resp: { status_code: 0 },
|
||||
})}`,
|
||||
),
|
||||
);
|
||||
controller.close();
|
||||
}, 200);
|
||||
},
|
||||
cancel() {
|
||||
cancelled = true;
|
||||
},
|
||||
});
|
||||
postJsonRequestMock.mockResolvedValue({
|
||||
response: new Response(stream, {
|
||||
headers: { "content-type": "text/event-stream" },
|
||||
}),
|
||||
release: vi.fn(async () => {}),
|
||||
});
|
||||
|
||||
const provider = buildMinimaxMusicGenerationProvider();
|
||||
const generation = provider.generateMusic({
|
||||
provider: "minimax",
|
||||
model: "music-2.6",
|
||||
prompt: "upbeat dance-pop with female vocals",
|
||||
cfg: {},
|
||||
timeoutMs: 50,
|
||||
});
|
||||
const expectation = expect(generation).rejects.toThrow(
|
||||
"MiniMax music generation timed out after 50ms",
|
||||
);
|
||||
|
||||
await vi.advanceTimersByTimeAsync(0);
|
||||
await vi.advanceTimersByTimeAsync(50);
|
||||
|
||||
await expectation;
|
||||
expect(cancelled).toBe(true);
|
||||
} finally {
|
||||
vi.useRealTimers();
|
||||
}
|
||||
});
|
||||
|
||||
it("rejects instrumental requests that also include lyrics", async () => {
|
||||
const provider = buildMinimaxMusicGenerationProvider();
|
||||
|
||||
await expect(
|
||||
provider.generateMusic({
|
||||
provider: "minimax",
|
||||
model: "music-2.6",
|
||||
prompt: "driving techno",
|
||||
cfg: {},
|
||||
instrumental: true,
|
||||
lyrics: "do not sing this",
|
||||
}),
|
||||
).rejects.toThrow("cannot use lyrics when instrumental=true");
|
||||
});
|
||||
|
||||
it("uses lyrics optimizer when lyrics are omitted", async () => {
|
||||
mockMusicGenerationResponse({
|
||||
task_id: "task-456",
|
||||
audio_url: "https://example.com/out.mp3",
|
||||
base_resp: { status_code: 0 },
|
||||
});
|
||||
|
||||
const provider = buildMinimaxMusicGenerationProvider();
|
||||
await provider.generateMusic({
|
||||
provider: "minimax",
|
||||
model: "music-2.6",
|
||||
prompt: "upbeat dance-pop",
|
||||
cfg: {},
|
||||
});
|
||||
|
||||
const request = mockCallArg(postJsonRequestMock);
|
||||
const body = request.body as Record<string, unknown>;
|
||||
expect(body.model).toBe("music-2.6");
|
||||
expect(body.lyrics_optimizer).toBe(true);
|
||||
});
|
||||
|
||||
it("routes portal music generation through minimax-portal auth and HTTP config", async () => {
|
||||
mockMusicGenerationResponse({
|
||||
task_id: "task-portal",
|
||||
audio_url: "https://example.com/portal.mp3",
|
||||
base_resp: { status_code: 0 },
|
||||
});
|
||||
|
||||
const provider = buildMinimaxPortalMusicGenerationProvider();
|
||||
await provider.generateMusic({
|
||||
provider: "minimax-portal",
|
||||
model: "",
|
||||
prompt: "cinematic synth theme",
|
||||
cfg: {
|
||||
models: {
|
||||
providers: {
|
||||
minimax: {
|
||||
baseUrl: "https://wrong.example/anthropic",
|
||||
models: [],
|
||||
},
|
||||
"minimax-portal": {
|
||||
baseUrl: "https://api.minimaxi.com/anthropic",
|
||||
models: [],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
expect(mockCallArg(resolveApiKeyForProviderMock).provider).toBe("minimax-portal");
|
||||
const httpConfigParams = mockCallArg(resolveProviderHttpRequestConfigMock);
|
||||
expect(httpConfigParams.baseUrl).toBe("https://api.minimaxi.com");
|
||||
expect(httpConfigParams.provider).toBe("minimax-portal");
|
||||
expect(httpConfigParams.capability).toBe("audio");
|
||||
expect(httpConfigParams.transport).toBe("http");
|
||||
expect(mockCallArg(postJsonRequestMock).url).toBe(
|
||||
"https://api.minimaxi.com/v1/music_generation",
|
||||
);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user