From f915a84468499dc26d0aaf55c2f1cf2ee9b9515e Mon Sep 17 00:00:00 2001 From: Shakker Date: Mon, 11 May 2026 02:56:23 +0100 Subject: [PATCH] test: tighten qwen video request assertions --- .../qwen/video-generation-provider.test.ts | 78 +++++++++++++++---- 1 file changed, 61 insertions(+), 17 deletions(-) diff --git a/extensions/qwen/video-generation-provider.test.ts b/extensions/qwen/video-generation-provider.test.ts index 07e9c2bdf6e..645673dec4d 100644 --- a/extensions/qwen/video-generation-provider.test.ts +++ b/extensions/qwen/video-generation-provider.test.ts @@ -20,6 +20,39 @@ beforeAll(async () => { installProviderHttpMockCleanup(); +function expectPostJsonRequest( + call: unknown, + expected: { + url: string; + body: Record; + }, +) { + if (!call || typeof call !== "object") { + throw new Error("expected postJsonRequest call object"); + } + const request = call as { + url?: unknown; + headers?: unknown; + body?: unknown; + timeoutMs?: unknown; + fetchFn?: unknown; + allowPrivateNetwork?: unknown; + dispatcherPolicy?: unknown; + }; + expect(request.url).toBe(expected.url); + expect(request.body).toEqual(expected.body); + expect(request.timeoutMs).toBe(120_000); + expect(request.fetchFn).toBe(globalThis.fetch); + expect(request.allowPrivateNetwork).toBe(false); + expect(request.dispatcherPolicy).toBeUndefined(); + expect(request.headers).toBeInstanceOf(Headers); + expect(Array.from((request.headers as Headers).entries())).toEqual([ + ["authorization", "Bearer provider-key"], + ["content-type", "application/json"], + ["x-dashscope-async", "enable"], + ]); +} + describe("qwen video generation provider", () => { it("declares explicit mode capabilities", () => { expectExplicitVideoGenerationCapabilities(buildQwenVideoGenerationProvider()); @@ -39,18 +72,21 @@ describe("qwen video generation provider", () => { audio: true, }); - expect(postJsonRequestMock).toHaveBeenCalledWith( - expect.objectContaining({ - url: "https://dashscope-intl.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis", - body: expect.objectContaining({ - model: "wan2.6-r2v-flash", - input: expect.objectContaining({ - prompt: "animate this shot", - img_url: "https://example.com/ref.png", - }), - }), - }), - ); + expect(postJsonRequestMock).toHaveBeenCalledTimes(1); + expectPostJsonRequest(postJsonRequestMock.mock.calls[0]?.[0], { + url: "https://dashscope-intl.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis", + body: { + model: "wan2.6-r2v-flash", + input: { + prompt: "animate this shot", + img_url: "https://example.com/ref.png", + }, + parameters: { + duration: 6, + enable_audio: true, + }, + }, + }); expectDashscopeVideoTaskPoll(fetchWithTimeoutMock); expectSuccessfulDashscopeVideoResult(result); }); @@ -98,11 +134,19 @@ describe("qwen video generation provider", () => { }, }); - expect(postJsonRequestMock).toHaveBeenCalledWith( - expect.objectContaining({ - url: "https://coding-intl.dashscope.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis", - }), - ); + expect(postJsonRequestMock).toHaveBeenCalledTimes(1); + expectPostJsonRequest(postJsonRequestMock.mock.calls[0]?.[0], { + url: "https://coding-intl.dashscope.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis", + body: { + model: "wan2.6-t2v", + input: { + prompt: "animate this shot", + }, + parameters: { + duration: 5, + }, + }, + }); expectDashscopeVideoTaskPoll(fetchWithTimeoutMock, { baseUrl: "https://coding-intl.dashscope.aliyuncs.com", taskId: "task-2",