Files
agent/packages/harness/tests/image-video-boundary.test.ts

36 lines
3.4 KiB
TypeScript

import { describe, expect, it } from "vitest";
import * as harness from "../src/index.js";
describe("image video remote boundary", () => {
it("rejects incompatible live tool input types and new required fields before calling them", () => {
expect(harness).toHaveProperty("assertImageVideoArguments");
const schema = { type: "object", properties: { duration_seconds: { type: "number" }, reference_asset_ids: { anyOf: [{ type: "array", items: { type: "string" } }, { type: "null" }] } }, required: ["duration_seconds"] };
expect(() => harness.assertImageVideoArguments(schema, { duration_seconds: 10, reference_asset_ids: ["asset_1"] })).not.toThrow();
expect(() => harness.assertImageVideoArguments(schema, { duration_seconds: "10" })).toThrow();
expect(() => harness.assertImageVideoArguments(schema, { duration_seconds: 10, external_account_id: "unapproved" })).toThrow();
expect(() => harness.assertImageVideoArguments({ ...schema, required: ["new_field"] }, { duration_seconds: 10 })).toThrow();
});
it("accepts signed HTTPS queries privately but rejects credentials, private DNS and localhost", async () => {
expect(harness).toHaveProperty("validateImageVideoUrl");
const result = await harness.validateImageVideoUrl("https://cdn.example/video?token=private", () => Promise.resolve([{ address: "8.8.8.8", family: 4 }]));
expect(result.url.search).toBe("?token=private"); expect(result.address).toBe("8.8.8.8");
for (const url of ["http://cdn.example/v", "https://user:pass@cdn.example/v", "https://127.0.0.1/v", "https://[::ffff:127.0.0.1]/v"]) await expect(harness.validateImageVideoUrl(url)).rejects.toBeDefined();
await expect(harness.validateImageVideoUrl("https://cdn.example/v", () => Promise.resolve([{ address: "192.168.1.2", family: 4 }]))).rejects.toBeDefined();
});
it("classifies a temporary DNS lookup failure as retryable without allowing private results", async () => {
await expect(harness.validateImageVideoUrl("https://cdn.example/video", () => Promise.reject(new Error("EAI_AGAIN")))).rejects.toMatchObject({ code: "I2V_TRANSFER_TRANSIENT" });
await expect(harness.validateImageVideoUrl("https://cdn.example/video", () => Promise.resolve([{ address: "127.0.0.1", family: 4 }]))).rejects.toMatchObject({ code: "BASE_URL_NOT_ALLOWED" });
});
it("extracts only the documented response envelope and rejects malformed or error responses", () => {
expect(harness).toHaveProperty("imageVideoResponse");
expect(harness.imageVideoResponse({ content: [{ type: "text", text: '{"job_id":"j1"}' }] })).toEqual({ job_id: "j1" });
for (const value of [{ isError: true, content: [{ type: "text", text: "token=private" }] }, { content: [{ type: "text", text: "not JSON" }] }, { structuredContent: [] }]) expect(() => harness.imageVideoResponse(value)).toThrow();
});
it("refuses a false-duration or incomplete technical validation instead of releasing a video", () => {
expect(harness).toHaveProperty("parseImageVideoValidation");
const result = { video_seconds: 10, audio_seconds: 10, width: 720, height: 1280, fps: "24", decoded: true, sha256: "a".repeat(64) };
expect(harness.parseImageVideoValidation(result, 10).visualReview).toBe("pending");
for (const changed of [{ video_seconds: 7.292 }, { audio_seconds: 0 }, { decoded: false }, { width: 1280, height: 720 }, { fps: "0" }]) expect(() => harness.parseImageVideoValidation({ ...result, ...changed }, 10)).toThrow();
});
});