91 lines
2.4 KiB
JavaScript
91 lines
2.4 KiB
JavaScript
const assert = require("node:assert/strict");
|
|
|
|
const {
|
|
DEFAULT_IMAGE_EXPECTED_DURATION_MS,
|
|
DEFAULT_VIDEO_EXPECTED_DURATION_MS,
|
|
PROGRESS_SOURCE_ESTIMATED,
|
|
PROGRESS_SOURCE_REAL,
|
|
formatTaskProgressPayload,
|
|
getExpectedDurationMs,
|
|
parseTaskParams,
|
|
} = require("../src/taskProgressContract");
|
|
|
|
const createdAt = "2026-06-10T08:00:00.000Z";
|
|
|
|
{
|
|
const payload = formatTaskProgressPayload({
|
|
id: 101,
|
|
status: "completed",
|
|
progress: 0,
|
|
created_at: createdAt,
|
|
params_json: "{}",
|
|
result_url: "https://oss.example/result.png",
|
|
});
|
|
|
|
assert.equal(payload.taskId, 101);
|
|
assert.equal(payload.progress, 100);
|
|
assert.equal(payload.progressSource, PROGRESS_SOURCE_REAL);
|
|
assert.equal(payload.stage, "\u5b8c\u6210");
|
|
assert.equal(payload.startedAt, createdAt);
|
|
assert.equal(payload.resultUrl, "https://oss.example/result.png");
|
|
}
|
|
|
|
{
|
|
const payload = formatTaskProgressPayload({
|
|
id: 102,
|
|
status: "running",
|
|
progress: 43,
|
|
progress_source: PROGRESS_SOURCE_REAL,
|
|
created_at: createdAt,
|
|
params_json: JSON.stringify({ model: "kling-3.0-dashscope", duration: 5 }),
|
|
type: "video",
|
|
});
|
|
|
|
assert.equal(payload.progress, 43);
|
|
assert.equal(payload.progressSource, PROGRESS_SOURCE_REAL);
|
|
assert.equal(payload.stage, "\u751f\u6210\u4e2d");
|
|
assert.equal(payload.expectedDurationMs, 300_000);
|
|
}
|
|
|
|
{
|
|
const payload = formatTaskProgressPayload({
|
|
id: 103,
|
|
status: "running",
|
|
progress: 0,
|
|
created_at: createdAt,
|
|
params_json: JSON.stringify({
|
|
requestedModel: "nano-banana-pro",
|
|
referenceUrls: ["https://oss.example/a.png", "https://oss.example/b.png"],
|
|
}),
|
|
type: "image",
|
|
});
|
|
|
|
assert.equal(payload.progressSource, PROGRESS_SOURCE_ESTIMATED);
|
|
assert.equal(payload.stage, "\u5df2\u63d0\u4ea4");
|
|
assert.equal(payload.expectedDurationMs, 250_000);
|
|
}
|
|
|
|
{
|
|
const expectedDurationMs = getExpectedDurationMs({
|
|
type: "video",
|
|
params_json: JSON.stringify({ model: "kling-3.0-dashscope", duration: 10 }),
|
|
});
|
|
|
|
assert.equal(expectedDurationMs, 400_000);
|
|
}
|
|
|
|
{
|
|
assert.deepEqual(parseTaskParams("{bad json"), {});
|
|
assert.deepEqual(parseTaskParams({ model: "gpt-image-2" }), { model: "gpt-image-2" });
|
|
assert.equal(
|
|
getExpectedDurationMs({ type: "image", params_json: "{}" }),
|
|
DEFAULT_IMAGE_EXPECTED_DURATION_MS,
|
|
);
|
|
assert.equal(
|
|
getExpectedDurationMs({ type: "video", params_json: "{}" }),
|
|
DEFAULT_VIDEO_EXPECTED_DURATION_MS,
|
|
);
|
|
}
|
|
|
|
console.log("task progress contract tests passed");
|