fix: resume transient original-job collection and guard probe input
This commit is contained in:
@@ -3,7 +3,7 @@ import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { Readable } from "node:stream";
|
||||
import sharp from "sharp";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import * as harness from "../src/index.js";
|
||||
import type { ImageVideoRemote, ImageVideoRecord } from "../src/image-video/contracts.js";
|
||||
|
||||
@@ -111,6 +111,44 @@ describe("durable image video tasks", () => {
|
||||
await new harness.ImageVideoService(f.options).submit("ses_owner", task.id);
|
||||
expect(f.calls).toEqual(["status:accepted_before_crash"]);
|
||||
});
|
||||
it("retries a transient download after restart using the original job's current artifact, at the polling cadence", async () => {
|
||||
const f = await fixture(); const task = await f.service.create("ses_owner", f.draft);
|
||||
await f.service.upload("ses_owner", task.id); await f.service.refresh(task.id); await f.service.submit("ses_owner", task.id);
|
||||
const clock = vi.spyOn(Date, "now").mockReturnValue(2_000_000_000_000);
|
||||
const downloaded: string[] = []; let queries = 0;
|
||||
f.remote.status = r => { f.calls.push(`status:${r.jobId ?? "missing"}`); queries++; return Promise.resolve({ state: "succeeded", artifactUrl: `https://public.example/${String(queries)}.mp4` }); };
|
||||
const collect = (url: string) => {
|
||||
downloaded.push(url);
|
||||
if (downloaded.length === 1) return Promise.reject(new harness.HarnessError("I2V_TRANSFER_TRANSIENT", "Temporary download timeout"));
|
||||
return Promise.resolve({ videoSeconds: 10, audioSeconds: 10, width: 720, height: 1280, fps: 24, decoded: true as const, sha256: "a".repeat(64), visualReview: "pending" as const, audioReview: "pending" as const });
|
||||
};
|
||||
try {
|
||||
const initial = new harness.ImageVideoService({ ...f.options, collect });
|
||||
expect(await initial.refresh(task.id)).toMatchObject({ state: "validating", jobId: "remote_job_1" });
|
||||
const restored = new harness.ImageVideoService({ ...f.options, collect });
|
||||
await restored.refresh(task.id); expect(downloaded).toHaveLength(1);
|
||||
clock.mockReturnValue(2_000_000_029_999); await restored.refresh(task.id); expect(downloaded).toHaveLength(1);
|
||||
clock.mockReturnValue(2_000_000_030_000);
|
||||
expect(await restored.refresh(task.id)).toMatchObject({ state: "ready", jobId: "remote_job_1" });
|
||||
await restored.submit("ses_owner", task.id);
|
||||
expect(downloaded).toEqual(["https://public.example/1.mp4", "https://public.example/2.mp4"]);
|
||||
expect(f.calls.filter(call => call.startsWith("status:"))).toEqual(["status:remote_job_1", "status:remote_job_1"]);
|
||||
expect(f.calls.filter(call => call === "submit")).toHaveLength(1);
|
||||
} finally { clock.mockRestore(); }
|
||||
});
|
||||
it("keeps deterministic invalid media terminal across restart with no false ready or second generation", async () => {
|
||||
const f = await fixture(); const task = await f.service.create("ses_owner", f.draft);
|
||||
await f.service.upload("ses_owner", task.id); await f.service.refresh(task.id); await f.service.submit("ses_owner", task.id);
|
||||
f.remote.status = () => Promise.resolve({ state: "succeeded", artifactUrl: "https://public.example/invalid.mp4" });
|
||||
let collections = 0;
|
||||
const collect = () => { collections++; return Promise.reject(new harness.HarnessError("I2V_INVALID_MP4", "Invalid MP4")); };
|
||||
expect((await new harness.ImageVideoService({ ...f.options, collect }).refresh(task.id)).state).toBe("failed");
|
||||
const restored = new harness.ImageVideoService({ ...f.options, collect });
|
||||
expect(await restored.refresh(task.id)).toMatchObject({ state: "failed", jobId: "remote_job_1" });
|
||||
await restored.submit("ses_owner", task.id);
|
||||
expect(collections).toBe(1); expect(f.calls.filter(call => call === "submit")).toHaveLength(1);
|
||||
await expect(restored.media(task.id, "video")).rejects.toMatchObject({ code: "I2V_MEDIA_NOT_FOUND" });
|
||||
});
|
||||
it.each(["task", "hash", "stale", "future", "malformed", "empty_job", "version", "extra_field", "conflicting_job"] as const)("quarantines a %s receipt without polling it or submitting again", async (kind) => {
|
||||
const f = await fixture(); const task = await f.service.create("ses_owner", f.draft);
|
||||
await f.service.upload("ses_owner", task.id); await f.service.refresh(task.id);
|
||||
|
||||
Reference in New Issue
Block a user