mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-06 05:51:15 +08:00
fix: validate pixverse video response ids
This commit is contained in:
@@ -224,6 +224,30 @@ describe("pixverse video generation provider", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("rejects fractional video ids before polling", async () => {
|
||||
postJsonRequestMock.mockResolvedValue({
|
||||
response: {
|
||||
json: async () => ({
|
||||
ErrCode: 0,
|
||||
ErrMsg: "success",
|
||||
Resp: { video_id: 123.5 },
|
||||
}),
|
||||
},
|
||||
release: vi.fn(async () => {}),
|
||||
});
|
||||
|
||||
const provider = buildPixVerseVideoGenerationProvider();
|
||||
await expect(
|
||||
provider.generateVideo({
|
||||
provider: "pixverse",
|
||||
model: "pixverse/v6",
|
||||
prompt: "a quiet city street at sunrise",
|
||||
cfg: {},
|
||||
}),
|
||||
).rejects.toThrow("PixVerse video generation response missing video_id");
|
||||
expect(fetchWithTimeoutMock).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("uploads local image input before submitting image-to-video", async () => {
|
||||
postMultipartRequestMock.mockResolvedValue({
|
||||
response: {
|
||||
|
||||
@@ -193,7 +193,7 @@ async function readPixVerseJson<T>(response: Pick<Response, "json">, label: stri
|
||||
}
|
||||
|
||||
function readPixVerseVideoId(payload: PixVerseVideoCreateResponse): number {
|
||||
const videoId = asFiniteNumber(payload.video_id);
|
||||
const videoId = asSafeIntegerInRange(payload.video_id, { min: 0 });
|
||||
if (videoId == null) {
|
||||
throw new Error("PixVerse video generation response missing video_id");
|
||||
}
|
||||
@@ -201,7 +201,7 @@ function readPixVerseVideoId(payload: PixVerseVideoCreateResponse): number {
|
||||
}
|
||||
|
||||
function readPixVerseImageId(payload: PixVerseUploadImageResponse): number {
|
||||
const imageId = asFiniteNumber(payload.img_id);
|
||||
const imageId = asSafeIntegerInRange(payload.img_id, { min: 0 });
|
||||
if (imageId == null) {
|
||||
throw new Error("PixVerse image upload response missing img_id");
|
||||
}
|
||||
@@ -209,7 +209,7 @@ function readPixVerseImageId(payload: PixVerseUploadImageResponse): number {
|
||||
}
|
||||
|
||||
function readPixVerseStatus(payload: PixVerseVideoResultResponse): number {
|
||||
const status = asFiniteNumber(payload.status);
|
||||
const status = asSafeIntegerInRange(payload.status, { min: 0 });
|
||||
if (status == null) {
|
||||
throw new Error("PixVerse video status response missing status");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user