fix: validate pixverse video response ids

This commit is contained in:
Peter Steinberger
2026-05-28 17:52:04 -04:00
parent 1fd73947d1
commit 912e9dd0a6
2 changed files with 27 additions and 3 deletions

View File

@@ -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: {

View File

@@ -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");
}