fix: validate pixverse video response ids · openclaw/openclaw@912e9dd
steipete
·
2026-05-29
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -224,6 +224,30 @@ describe("pixverse video generation provider", () => {
|
224 | 224 | }); |
225 | 225 | }); |
226 | 226 | |
| 227 | +it("rejects fractional video ids before polling", async () => { |
| 228 | +postJsonRequestMock.mockResolvedValue({ |
| 229 | +response: { |
| 230 | +json: async () => ({ |
| 231 | +ErrCode: 0, |
| 232 | +ErrMsg: "success", |
| 233 | +Resp: { video_id: 123.5 }, |
| 234 | +}), |
| 235 | +}, |
| 236 | +release: vi.fn(async () => {}), |
| 237 | +}); |
| 238 | + |
| 239 | +const provider = buildPixVerseVideoGenerationProvider(); |
| 240 | +await expect( |
| 241 | +provider.generateVideo({ |
| 242 | +provider: "pixverse", |
| 243 | +model: "pixverse/v6", |
| 244 | +prompt: "a quiet city street at sunrise", |
| 245 | +cfg: {}, |
| 246 | +}), |
| 247 | +).rejects.toThrow("PixVerse video generation response missing video_id"); |
| 248 | +expect(fetchWithTimeoutMock).not.toHaveBeenCalled(); |
| 249 | +}); |
| 250 | + |
227 | 251 | it("uploads local image input before submitting image-to-video", async () => { |
228 | 252 | postMultipartRequestMock.mockResolvedValue({ |
229 | 253 | response: { |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -193,23 +193,23 @@ async function readPixVerseJson<T>(response: Pick<Response, "json">, label: stri
|
193 | 193 | } |
194 | 194 | |
195 | 195 | function readPixVerseVideoId(payload: PixVerseVideoCreateResponse): number { |
196 | | -const videoId = asFiniteNumber(payload.video_id); |
| 196 | +const videoId = asSafeIntegerInRange(payload.video_id, { min: 0 }); |
197 | 197 | if (videoId == null) { |
198 | 198 | throw new Error("PixVerse video generation response missing video_id"); |
199 | 199 | } |
200 | 200 | return videoId; |
201 | 201 | } |
202 | 202 | |
203 | 203 | function readPixVerseImageId(payload: PixVerseUploadImageResponse): number { |
204 | | -const imageId = asFiniteNumber(payload.img_id); |
| 204 | +const imageId = asSafeIntegerInRange(payload.img_id, { min: 0 }); |
205 | 205 | if (imageId == null) { |
206 | 206 | throw new Error("PixVerse image upload response missing img_id"); |
207 | 207 | } |
208 | 208 | return imageId; |
209 | 209 | } |
210 | 210 | |
211 | 211 | function readPixVerseStatus(payload: PixVerseVideoResultResponse): number { |
212 | | -const status = asFiniteNumber(payload.status); |
| 212 | +const status = asSafeIntegerInRange(payload.status, { min: 0 }); |
213 | 213 | if (status == null) { |
214 | 214 | throw new Error("PixVerse video status response missing status"); |
215 | 215 | } |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。