mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-06 05:51:15 +08:00
fix: validate byteplus video duration metadata
This commit is contained in:
@@ -177,6 +177,42 @@ describe("byteplus video generation provider", () => {
|
||||
expect(requireBytePlusPostBody()).not.toHaveProperty("duration");
|
||||
});
|
||||
|
||||
it("drops malformed response duration metadata", async () => {
|
||||
postJsonRequestMock.mockResolvedValue({
|
||||
response: {
|
||||
json: async () => ({
|
||||
id: "task_123",
|
||||
}),
|
||||
},
|
||||
release: vi.fn(async () => {}),
|
||||
});
|
||||
fetchWithTimeoutMock
|
||||
.mockResolvedValueOnce({
|
||||
json: async () => ({
|
||||
id: "task_123",
|
||||
status: "succeeded",
|
||||
content: {
|
||||
video_url: "https://example.com/byteplus.mp4",
|
||||
},
|
||||
duration: 1.5,
|
||||
}),
|
||||
})
|
||||
.mockResolvedValueOnce({
|
||||
headers: new Headers({ "content-type": "video/mp4" }),
|
||||
arrayBuffer: async () => Buffer.from("mp4-bytes"),
|
||||
});
|
||||
|
||||
const provider = buildBytePlusVideoGenerationProvider();
|
||||
const result = await provider.generateVideo({
|
||||
provider: "byteplus",
|
||||
model: "seedance-1-0-lite-t2v-250428",
|
||||
prompt: "A lantern floats upward into the night sky",
|
||||
cfg: {},
|
||||
});
|
||||
|
||||
expect(result.metadata).toMatchObject({ duration: undefined });
|
||||
});
|
||||
|
||||
it("reports malformed create JSON with a provider-owned error", async () => {
|
||||
const release = vi.fn(async () => {});
|
||||
postJsonRequestMock.mockResolvedValue({
|
||||
|
||||
@@ -137,6 +137,13 @@ function resolveBytePlusDurationSeconds(value: unknown): number | undefined {
|
||||
});
|
||||
}
|
||||
|
||||
function readBytePlusDurationSeconds(value: unknown): number | undefined {
|
||||
return asSafeIntegerInRange(value, {
|
||||
min: BYTEPLUS_MIN_DURATION_SECONDS,
|
||||
max: BYTEPLUS_MAX_DURATION_SECONDS,
|
||||
});
|
||||
}
|
||||
|
||||
async function pollBytePlusTask(params: {
|
||||
taskId: string;
|
||||
headers: Headers;
|
||||
@@ -396,7 +403,7 @@ export function buildBytePlusVideoGenerationProvider(): VideoGenerationProvider
|
||||
videoUrl,
|
||||
ratio: normalizeOptionalString(completed.ratio),
|
||||
resolution: normalizeOptionalString(completed.resolution),
|
||||
duration: typeof completed.duration === "number" ? completed.duration : undefined,
|
||||
duration: readBytePlusDurationSeconds(completed.duration),
|
||||
},
|
||||
};
|
||||
} finally {
|
||||
|
||||
Reference in New Issue
Block a user