mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 18:30:44 +00:00
test: share fal video queue fixtures
This commit is contained in:
@@ -13,17 +13,7 @@ function createMockRequestConfig() {
|
|||||||
describe("fal video generation provider", () => {
|
describe("fal video generation provider", () => {
|
||||||
const fetchGuardMock = vi.fn();
|
const fetchGuardMock = vi.fn();
|
||||||
|
|
||||||
afterEach(() => {
|
function mockFalProviderRuntime() {
|
||||||
vi.restoreAllMocks();
|
|
||||||
fetchGuardMock.mockReset();
|
|
||||||
_setFalVideoFetchGuardForTesting(null);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("declares explicit mode capabilities", () => {
|
|
||||||
expectExplicitVideoGenerationCapabilities(buildFalVideoGenerationProvider());
|
|
||||||
});
|
|
||||||
|
|
||||||
it("submits fal video jobs through the queue API and downloads the completed result", async () => {
|
|
||||||
vi.spyOn(providerAuth, "resolveApiKeyForProvider").mockResolvedValue({
|
vi.spyOn(providerAuth, "resolveApiKeyForProvider").mockResolvedValue({
|
||||||
apiKey: "fal-key",
|
apiKey: "fal-key",
|
||||||
source: "env",
|
source: "env",
|
||||||
@@ -41,43 +31,75 @@ describe("fal video generation provider", () => {
|
|||||||
});
|
});
|
||||||
vi.spyOn(providerHttp, "assertOkOrThrowHttpError").mockResolvedValue(undefined);
|
vi.spyOn(providerHttp, "assertOkOrThrowHttpError").mockResolvedValue(undefined);
|
||||||
_setFalVideoFetchGuardForTesting(fetchGuardMock as never);
|
_setFalVideoFetchGuardForTesting(fetchGuardMock as never);
|
||||||
|
}
|
||||||
|
|
||||||
|
function releasedJson(value: unknown) {
|
||||||
|
return {
|
||||||
|
response: {
|
||||||
|
json: async () => value,
|
||||||
|
},
|
||||||
|
release: vi.fn(async () => {}),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function releasedVideo(params: { contentType: string; bytes: string }) {
|
||||||
|
return {
|
||||||
|
response: {
|
||||||
|
headers: new Headers({ "content-type": params.contentType }),
|
||||||
|
arrayBuffer: async () => Buffer.from(params.bytes),
|
||||||
|
},
|
||||||
|
release: vi.fn(async () => {}),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function mockCompletedFalVideoJob(params: {
|
||||||
|
requestId: string;
|
||||||
|
statusUrl: string;
|
||||||
|
responseUrl: string;
|
||||||
|
videoUrl: string;
|
||||||
|
bytes: string;
|
||||||
|
responseExtras?: Record<string, unknown>;
|
||||||
|
}) {
|
||||||
fetchGuardMock
|
fetchGuardMock
|
||||||
.mockResolvedValueOnce({
|
.mockResolvedValueOnce(
|
||||||
response: {
|
releasedJson({
|
||||||
json: async () => ({
|
request_id: params.requestId,
|
||||||
request_id: "req-123",
|
status_url: params.statusUrl,
|
||||||
status_url: "https://queue.fal.run/fal-ai/minimax/requests/req-123/status",
|
response_url: params.responseUrl,
|
||||||
response_url: "https://queue.fal.run/fal-ai/minimax/requests/req-123",
|
}),
|
||||||
}),
|
)
|
||||||
},
|
.mockResolvedValueOnce(releasedJson({ status: "COMPLETED" }))
|
||||||
release: vi.fn(async () => {}),
|
.mockResolvedValueOnce(
|
||||||
})
|
releasedJson({
|
||||||
.mockResolvedValueOnce({
|
status: "COMPLETED",
|
||||||
response: {
|
response: {
|
||||||
json: async () => ({
|
video: { url: params.videoUrl },
|
||||||
status: "COMPLETED",
|
...params.responseExtras,
|
||||||
}),
|
},
|
||||||
},
|
}),
|
||||||
release: vi.fn(async () => {}),
|
)
|
||||||
})
|
.mockResolvedValueOnce(releasedVideo({ contentType: "video/mp4", bytes: params.bytes }));
|
||||||
.mockResolvedValueOnce({
|
}
|
||||||
response: {
|
|
||||||
json: async () => ({
|
afterEach(() => {
|
||||||
status: "COMPLETED",
|
vi.restoreAllMocks();
|
||||||
response: {
|
fetchGuardMock.mockReset();
|
||||||
video: { url: "https://fal.run/files/video.mp4" },
|
_setFalVideoFetchGuardForTesting(null);
|
||||||
},
|
});
|
||||||
}),
|
|
||||||
},
|
it("declares explicit mode capabilities", () => {
|
||||||
release: vi.fn(async () => {}),
|
expectExplicitVideoGenerationCapabilities(buildFalVideoGenerationProvider());
|
||||||
})
|
});
|
||||||
.mockResolvedValueOnce({
|
|
||||||
response: {
|
it("submits fal video jobs through the queue API and downloads the completed result", async () => {
|
||||||
headers: new Headers({ "content-type": "video/mp4" }),
|
mockFalProviderRuntime();
|
||||||
arrayBuffer: async () => Buffer.from("mp4-bytes"),
|
mockCompletedFalVideoJob({
|
||||||
},
|
requestId: "req-123",
|
||||||
release: vi.fn(async () => {}),
|
statusUrl: "https://queue.fal.run/fal-ai/minimax/requests/req-123/status",
|
||||||
});
|
responseUrl: "https://queue.fal.run/fal-ai/minimax/requests/req-123",
|
||||||
|
videoUrl: "https://fal.run/files/video.mp4",
|
||||||
|
bytes: "mp4-bytes",
|
||||||
|
});
|
||||||
|
|
||||||
const provider = buildFalVideoGenerationProvider();
|
const provider = buildFalVideoGenerationProvider();
|
||||||
const result = await provider.generateVideo({
|
const result = await provider.generateVideo({
|
||||||
@@ -136,62 +158,15 @@ describe("fal video generation provider", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("submits HeyGen video-agent requests without unsupported fal controls", async () => {
|
it("submits HeyGen video-agent requests without unsupported fal controls", async () => {
|
||||||
vi.spyOn(providerAuth, "resolveApiKeyForProvider").mockResolvedValue({
|
mockFalProviderRuntime();
|
||||||
apiKey: "fal-key",
|
mockCompletedFalVideoJob({
|
||||||
source: "env",
|
requestId: "heygen-req-123",
|
||||||
mode: "api-key",
|
statusUrl:
|
||||||
|
"https://queue.fal.run/fal-ai/heygen/v2/video-agent/requests/heygen-req-123/status",
|
||||||
|
responseUrl: "https://queue.fal.run/fal-ai/heygen/v2/video-agent/requests/heygen-req-123",
|
||||||
|
videoUrl: "https://fal.run/files/heygen.mp4",
|
||||||
|
bytes: "heygen-mp4-bytes",
|
||||||
});
|
});
|
||||||
vi.spyOn(providerHttp, "resolveProviderHttpRequestConfig").mockReturnValue({
|
|
||||||
baseUrl: "https://fal.run",
|
|
||||||
allowPrivateNetwork: false,
|
|
||||||
headers: new Headers({
|
|
||||||
Authorization: "Key fal-key",
|
|
||||||
"Content-Type": "application/json",
|
|
||||||
}),
|
|
||||||
dispatcherPolicy: undefined,
|
|
||||||
requestConfig: createMockRequestConfig(),
|
|
||||||
});
|
|
||||||
vi.spyOn(providerHttp, "assertOkOrThrowHttpError").mockResolvedValue(undefined);
|
|
||||||
_setFalVideoFetchGuardForTesting(fetchGuardMock as never);
|
|
||||||
fetchGuardMock
|
|
||||||
.mockResolvedValueOnce({
|
|
||||||
response: {
|
|
||||||
json: async () => ({
|
|
||||||
request_id: "heygen-req-123",
|
|
||||||
status_url:
|
|
||||||
"https://queue.fal.run/fal-ai/heygen/v2/video-agent/requests/heygen-req-123/status",
|
|
||||||
response_url:
|
|
||||||
"https://queue.fal.run/fal-ai/heygen/v2/video-agent/requests/heygen-req-123",
|
|
||||||
}),
|
|
||||||
},
|
|
||||||
release: vi.fn(async () => {}),
|
|
||||||
})
|
|
||||||
.mockResolvedValueOnce({
|
|
||||||
response: {
|
|
||||||
json: async () => ({
|
|
||||||
status: "COMPLETED",
|
|
||||||
}),
|
|
||||||
},
|
|
||||||
release: vi.fn(async () => {}),
|
|
||||||
})
|
|
||||||
.mockResolvedValueOnce({
|
|
||||||
response: {
|
|
||||||
json: async () => ({
|
|
||||||
status: "COMPLETED",
|
|
||||||
response: {
|
|
||||||
video: { url: "https://fal.run/files/heygen.mp4" },
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
},
|
|
||||||
release: vi.fn(async () => {}),
|
|
||||||
})
|
|
||||||
.mockResolvedValueOnce({
|
|
||||||
response: {
|
|
||||||
headers: new Headers({ "content-type": "video/mp4" }),
|
|
||||||
arrayBuffer: async () => Buffer.from("heygen-mp4-bytes"),
|
|
||||||
},
|
|
||||||
release: vi.fn(async () => {}),
|
|
||||||
});
|
|
||||||
|
|
||||||
const provider = buildFalVideoGenerationProvider();
|
const provider = buildFalVideoGenerationProvider();
|
||||||
const result = await provider.generateVideo({
|
const result = await provider.generateVideo({
|
||||||
@@ -223,63 +198,17 @@ describe("fal video generation provider", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("submits Seedance 2 requests with fal schema fields", async () => {
|
it("submits Seedance 2 requests with fal schema fields", async () => {
|
||||||
vi.spyOn(providerAuth, "resolveApiKeyForProvider").mockResolvedValue({
|
mockFalProviderRuntime();
|
||||||
apiKey: "fal-key",
|
mockCompletedFalVideoJob({
|
||||||
source: "env",
|
requestId: "seedance-req-123",
|
||||||
mode: "api-key",
|
statusUrl:
|
||||||
|
"https://queue.fal.run/bytedance/seedance-2.0/fast/text-to-video/requests/seedance-req-123/status",
|
||||||
|
responseUrl:
|
||||||
|
"https://queue.fal.run/bytedance/seedance-2.0/fast/text-to-video/requests/seedance-req-123",
|
||||||
|
videoUrl: "https://fal.run/files/seedance.mp4",
|
||||||
|
bytes: "seedance-mp4-bytes",
|
||||||
|
responseExtras: { seed: 42 },
|
||||||
});
|
});
|
||||||
vi.spyOn(providerHttp, "resolveProviderHttpRequestConfig").mockReturnValue({
|
|
||||||
baseUrl: "https://fal.run",
|
|
||||||
allowPrivateNetwork: false,
|
|
||||||
headers: new Headers({
|
|
||||||
Authorization: "Key fal-key",
|
|
||||||
"Content-Type": "application/json",
|
|
||||||
}),
|
|
||||||
dispatcherPolicy: undefined,
|
|
||||||
requestConfig: createMockRequestConfig(),
|
|
||||||
});
|
|
||||||
vi.spyOn(providerHttp, "assertOkOrThrowHttpError").mockResolvedValue(undefined);
|
|
||||||
_setFalVideoFetchGuardForTesting(fetchGuardMock as never);
|
|
||||||
fetchGuardMock
|
|
||||||
.mockResolvedValueOnce({
|
|
||||||
response: {
|
|
||||||
json: async () => ({
|
|
||||||
request_id: "seedance-req-123",
|
|
||||||
status_url:
|
|
||||||
"https://queue.fal.run/bytedance/seedance-2.0/fast/text-to-video/requests/seedance-req-123/status",
|
|
||||||
response_url:
|
|
||||||
"https://queue.fal.run/bytedance/seedance-2.0/fast/text-to-video/requests/seedance-req-123",
|
|
||||||
}),
|
|
||||||
},
|
|
||||||
release: vi.fn(async () => {}),
|
|
||||||
})
|
|
||||||
.mockResolvedValueOnce({
|
|
||||||
response: {
|
|
||||||
json: async () => ({
|
|
||||||
status: "COMPLETED",
|
|
||||||
}),
|
|
||||||
},
|
|
||||||
release: vi.fn(async () => {}),
|
|
||||||
})
|
|
||||||
.mockResolvedValueOnce({
|
|
||||||
response: {
|
|
||||||
json: async () => ({
|
|
||||||
status: "COMPLETED",
|
|
||||||
response: {
|
|
||||||
video: { url: "https://fal.run/files/seedance.mp4" },
|
|
||||||
seed: 42,
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
},
|
|
||||||
release: vi.fn(async () => {}),
|
|
||||||
})
|
|
||||||
.mockResolvedValueOnce({
|
|
||||||
response: {
|
|
||||||
headers: new Headers({ "content-type": "video/mp4" }),
|
|
||||||
arrayBuffer: async () => Buffer.from("seedance-mp4-bytes"),
|
|
||||||
},
|
|
||||||
release: vi.fn(async () => {}),
|
|
||||||
});
|
|
||||||
|
|
||||||
const provider = buildFalVideoGenerationProvider();
|
const provider = buildFalVideoGenerationProvider();
|
||||||
const result = await provider.generateVideo({
|
const result = await provider.generateVideo({
|
||||||
|
|||||||
Reference in New Issue
Block a user