Files
adolf/extensions/runway/video-generation-provider.test.ts
alvis bedb527145
Some checks failed
ClawSweeper Dispatch / dispatch (push) Has been cancelled
CodeQL / Security High (actions) (push) Has been cancelled
CodeQL / Security High (channel-runtime-boundary) (push) Has been cancelled
CodeQL / Security High (core-auth-secrets) (push) Has been cancelled
CodeQL / Security High (mcp-process-tool-boundary) (push) Has been cancelled
CodeQL / Security High (network-ssrf-boundary) (push) Has been cancelled
CodeQL / Security High (plugin-trust-boundary) (push) Has been cancelled
CodeQL / Security High (process-exec-boundary) (push) Has been cancelled
Docs Sync Publish Repo / sync-publish-repo (push) Has been cancelled
Docs / docs (push) Has been cancelled
OpenClaw Stable Main Closeout / Resolve stable release closeout inputs (push) Has been cancelled
OpenClaw Stable Main Closeout / Verify stable main closeout (push) Has been cancelled
Workflow Sanity / no-tabs (push) Has been cancelled
Workflow Sanity / actionlint (push) Has been cancelled
Workflow Sanity / generated-doc-baselines (push) Has been cancelled
CI / runner-admission (push) Has been cancelled
CI / preflight (push) Has been cancelled
CI / security-fast (push) Has been cancelled
CI / pnpm-store-warmup (push) Has been cancelled
CI / build-artifacts (push) Has been cancelled
CI / native-i18n (push) Has been cancelled
CI / ${{ matrix.check_name }} (push) Has been cancelled
CI / ${{ matrix.checkName }} (push) Has been cancelled
CI / checks-node-compat-node22 (push) Has been cancelled
CI / check-bundled-channel-config-metadata (push) Has been cancelled
CI / check-dependencies (push) Has been cancelled
CI / check-guards (push) Has been cancelled
CI / check-lint (push) Has been cancelled
CI / check-prod-types (push) Has been cancelled
CI / check-shrinkwrap (push) Has been cancelled
CI / check-test-types (push) Has been cancelled
CI / check-additional-boundaries-a (push) Has been cancelled
CI / check-additional-boundaries-bcd (push) Has been cancelled
CI / check-additional-extension-bundled (push) Has been cancelled
CI / check-additional-extension-channels (push) Has been cancelled
CI / check-additional-extension-package-boundary (push) Has been cancelled
CI / check-additional-runtime-topology-architecture (push) Has been cancelled
CI / check-session-accessor-boundary (push) Has been cancelled
CI / check-session-transcript-reader-boundary (push) Has been cancelled
CI / check-docs (push) Has been cancelled
CI / skills-python (push) Has been cancelled
CI / macos-swift (push) Has been cancelled
CI / ios-build (push) Has been cancelled
CI / ci-timings-summary (push) Has been cancelled
Native App Locale Refresh / Refresh native fa (push) Has been cancelled
Native App Locale Refresh / Refresh native fr (push) Has been cancelled
Native App Locale Refresh / Refresh native hi (push) Has been cancelled
Native App Locale Refresh / Refresh native id (push) Has been cancelled
Native App Locale Refresh / Refresh native it (push) Has been cancelled
Native App Locale Refresh / Refresh native ja-JP (push) Has been cancelled
Control UI Locale Refresh / plan (push) Has been cancelled
Control UI Locale Refresh / Refresh ${{ matrix.locale }} (push) Has been cancelled
Control UI Locale Refresh / Commit control UI locale refresh (push) Has been cancelled
Live Media Runner Image / Build live media runner image (push) Has been cancelled
Native App Locale Refresh / Refresh native ar (push) Has been cancelled
Native App Locale Refresh / Refresh native de (push) Has been cancelled
Native App Locale Refresh / Refresh native es (push) Has been cancelled
Native App Locale Refresh / Refresh native ko (push) Has been cancelled
Native App Locale Refresh / Refresh native nl (push) Has been cancelled
Native App Locale Refresh / Refresh native pl (push) Has been cancelled
Native App Locale Refresh / Refresh native pt-BR (push) Has been cancelled
Native App Locale Refresh / Refresh native ru (push) Has been cancelled
Native App Locale Refresh / Refresh native sv (push) Has been cancelled
Native App Locale Refresh / Refresh native th (push) Has been cancelled
Native App Locale Refresh / Refresh native tr (push) Has been cancelled
Native App Locale Refresh / Refresh native uk (push) Has been cancelled
Native App Locale Refresh / Refresh native vi (push) Has been cancelled
Native App Locale Refresh / Refresh native zh-CN (push) Has been cancelled
Native App Locale Refresh / Refresh native zh-TW (push) Has been cancelled
Native App Locale Refresh / Commit native locale refresh (push) Has been cancelled
Plugin Init Scaffold Validation / Validate provider scaffold (push) Has been cancelled
Plugin NPM Release / preview_plugins_npm (push) Has been cancelled
Plugin NPM Release / Validate release publish approval (push) Has been cancelled
Plugin NPM Release / preview_plugin_pack (push) Has been cancelled
Plugin NPM Release / publish_plugins_npm (push) Has been cancelled
Sandbox Common Smoke / sandbox-common-smoke (push) Has been cancelled
Website Installer Sync / static (push) Has been cancelled
Website Installer Sync / linux-docker (push) Has been cancelled
Website Installer Sync / macos-installer (push) Has been cancelled
Website Installer Sync / windows-installer (push) Has been cancelled
Website Installer Sync / sync-website (push) Has been cancelled
Vendor OpenClaw source as Adolf fork baseline
Adolf is a fork/vendored clone of github.com/openclaw/openclaw (v2026.6.11),
free to diverge. Tree copied sans upstream .git; upstream remote added for
future syncs. Node pinned to 24 (.nvmrc); engines already require >=22.19.
Preserves docs/ARCHITECTURE.md.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LeqyaxJF2nbRXJtae2kNB2
2026-07-05 09:36:54 +00:00

322 lines
10 KiB
TypeScript

// Runway tests cover video generation provider plugin behavior.
import {
getProviderHttpMocks,
installProviderHttpMockCleanup,
} from "openclaw/plugin-sdk/provider-http-test-mocks";
import { expectExplicitVideoGenerationCapabilities } from "openclaw/plugin-sdk/provider-test-contracts";
import { beforeAll, describe, expect, it, vi } from "vitest";
const { postJsonRequestMock, fetchWithTimeoutMock } = getProviderHttpMocks();
let buildRunwayVideoGenerationProvider: typeof import("./video-generation-provider.js").buildRunwayVideoGenerationProvider;
beforeAll(async () => {
({ buildRunwayVideoGenerationProvider } = await import("./video-generation-provider.js"));
});
installProviderHttpMockCleanup();
function firstPostJsonRequest() {
const [call] = postJsonRequestMock.mock.calls;
if (!call) {
throw new Error("expected Runway create request");
}
const [request] = call;
if (!request || typeof request !== "object") {
throw new Error("expected Runway create request options");
}
return request as { url?: string; body?: Record<string, unknown> };
}
function firstFetchWithTimeoutCall() {
const [call] = fetchWithTimeoutMock.mock.calls;
if (!call) {
throw new Error("expected Runway poll request");
}
const [url, init, timeoutMs, requestFetch] = call;
if (typeof url !== "string") {
throw new Error("expected Runway poll request URL");
}
if (!init || typeof init !== "object" || Array.isArray(init)) {
throw new Error("expected Runway poll request init");
}
if (typeof timeoutMs !== "number") {
throw new Error("expected Runway poll request timeout");
}
return {
init: init as { method?: string; headers?: unknown },
requestFetch,
timeoutMs,
url,
};
}
function streamedVideoResponse(bytes: string): Response {
return new Response(
new ReadableStream({
start(controller) {
controller.enqueue(new TextEncoder().encode(bytes));
controller.close();
},
}),
{ headers: { "content-type": "video/mp4" } },
);
}
// Response.json keeps object fixtures on the standard Response body path so create/poll
// reads exercise the byte-bounded reader instead of an unbounded res.json().
function streamedJsonResponse(payload: unknown): Response {
return Response.json(payload);
}
function streamedRawResponse(text: string): Response {
return new Response(
new ReadableStream({
start(controller) {
controller.enqueue(new TextEncoder().encode(text));
controller.close();
},
}),
{ headers: { "content-type": "application/json" } },
);
}
describe("runway video generation provider", () => {
it("declares explicit mode capabilities", () => {
expectExplicitVideoGenerationCapabilities(buildRunwayVideoGenerationProvider());
});
it("submits a text-to-video task, polls it, and downloads the output", async () => {
postJsonRequestMock.mockResolvedValue({
response: streamedJsonResponse({
id: "task-1",
}),
release: vi.fn(async () => {}),
});
fetchWithTimeoutMock
.mockResolvedValueOnce(
streamedJsonResponse({
id: "task-1",
status: "SUCCEEDED",
output: ["https://example.com/out.mp4"],
}),
)
.mockResolvedValueOnce({
arrayBuffer: async () => Buffer.from("mp4-bytes"),
headers: new Headers({ "content-type": "video/webm" }),
});
const provider = buildRunwayVideoGenerationProvider();
const result = await provider.generateVideo({
provider: "runway",
model: "gen4.5",
prompt: "a tiny lobster DJ under neon lights",
cfg: {},
durationSeconds: 4,
aspectRatio: "16:9",
});
expect(postJsonRequestMock).toHaveBeenCalledTimes(1);
const createRequest = firstPostJsonRequest();
expect(createRequest.url).toBe("https://api.dev.runwayml.com/v1/text_to_video");
expect(createRequest.body).toEqual({
model: "gen4.5",
promptText: "a tiny lobster DJ under neon lights",
ratio: "1280:720",
duration: 4,
});
const pollCall = firstFetchWithTimeoutCall();
expect(pollCall.url).toBe("https://api.dev.runwayml.com/v1/tasks/task-1");
expect(pollCall.init.method).toBe("GET");
expect(pollCall.init.headers).toBeInstanceOf(Headers);
expect(pollCall.timeoutMs).toBe(120000);
expect(pollCall.requestFetch).toBe(fetch);
expect(result.videos).toHaveLength(1);
const video = result.videos[0];
if (!video) {
throw new Error("expected Runway generated video");
}
expect(video.fileName).toBe("video-1.webm");
const metadata = result.metadata as Record<string, unknown>;
expect(metadata.taskId).toBe("task-1");
expect(metadata.status).toBe("SUCCEEDED");
expect(metadata.endpoint).toBe("/v1/text_to_video");
});
it("rejects generated video downloads that exceed the configured media cap", async () => {
postJsonRequestMock.mockResolvedValue({
response: streamedJsonResponse({ id: "task-too-large" }),
release: vi.fn(async () => {}),
});
fetchWithTimeoutMock
.mockResolvedValueOnce(
streamedJsonResponse({
id: "task-too-large",
status: "SUCCEEDED",
output: ["https://example.com/out.mp4"],
}),
)
.mockResolvedValueOnce(streamedVideoResponse("too-large"));
const provider = buildRunwayVideoGenerationProvider();
await expect(
provider.generateVideo({
provider: "runway",
model: "gen4.5",
prompt: "short video",
cfg: { agents: { defaults: { mediaMaxMb: 0.000001 } } },
}),
).rejects.toThrow("Runway generated video download exceeds 1 bytes");
});
it("does not round malformed duration values into create requests", async () => {
postJsonRequestMock.mockResolvedValue({
response: streamedJsonResponse({ id: "task-duration" }),
release: vi.fn(async () => {}),
});
fetchWithTimeoutMock
.mockResolvedValueOnce(
streamedJsonResponse({
id: "task-duration",
status: "SUCCEEDED",
output: ["https://example.com/out.mp4"],
}),
)
.mockResolvedValueOnce({
arrayBuffer: async () => Buffer.from("mp4-bytes"),
headers: new Headers({ "content-type": "video/mp4" }),
});
const provider = buildRunwayVideoGenerationProvider();
await provider.generateVideo({
provider: "runway",
model: "gen4.5",
prompt: "a tiny lobster DJ under neon lights",
cfg: {},
durationSeconds: 4.5,
aspectRatio: "16:9",
});
expect(postJsonRequestMock).toHaveBeenCalledTimes(1);
expect(firstPostJsonRequest().body?.duration).toBe(5);
});
it("accepts local image buffers by converting them into data URIs", async () => {
postJsonRequestMock.mockResolvedValue({
response: streamedJsonResponse({ id: "task-2" }),
release: vi.fn(async () => {}),
});
fetchWithTimeoutMock
.mockResolvedValueOnce(
streamedJsonResponse({
id: "task-2",
status: "SUCCEEDED",
output: ["https://example.com/out.mp4"],
}),
)
.mockResolvedValueOnce({
arrayBuffer: async () => Buffer.from("mp4-bytes"),
headers: new Headers({ "content-type": "video/mp4" }),
});
const provider = buildRunwayVideoGenerationProvider();
await provider.generateVideo({
provider: "runway",
model: "gen4_turbo",
prompt: "animate this frame",
cfg: {},
inputImages: [{ buffer: Buffer.from("png-bytes"), mimeType: "image/png" }],
aspectRatio: "1:1",
durationSeconds: 6,
});
expect(postJsonRequestMock).toHaveBeenCalledTimes(1);
const request = firstPostJsonRequest();
expect(request.url).toBe("https://api.dev.runwayml.com/v1/image_to_video");
expect(request.body?.promptImage).toMatch(/^data:image\/png;base64,/u);
expect(request.body?.ratio).toBe("960:960");
expect(request.body?.duration).toBe(6);
});
it("requires gen4_aleph for video-to-video", async () => {
const provider = buildRunwayVideoGenerationProvider();
await expect(
provider.generateVideo({
provider: "runway",
model: "gen4.5",
prompt: "restyle this clip",
cfg: {},
inputVideos: [{ url: "https://example.com/input.mp4" }],
}),
).rejects.toThrow("Runway video-to-video currently requires model gen4_aleph.");
expect(postJsonRequestMock).not.toHaveBeenCalled();
});
it("reports malformed create JSON with a provider-owned error", async () => {
const release = vi.fn(async () => {});
postJsonRequestMock.mockResolvedValue({
response: streamedRawResponse("{ not json"),
release,
});
const provider = buildRunwayVideoGenerationProvider();
await expect(
provider.generateVideo({
provider: "runway",
model: "gen4.5",
prompt: "bad create response",
cfg: {},
}),
).rejects.toThrow("Runway video generation failed: malformed JSON response");
expect(release).toHaveBeenCalledOnce();
});
it("rejects status responses missing a task status", async () => {
postJsonRequestMock.mockResolvedValue({
response: streamedJsonResponse({ id: "task-missing-status" }),
release: vi.fn(async () => {}),
});
fetchWithTimeoutMock.mockResolvedValueOnce(
streamedJsonResponse({
id: "task-missing-status",
output: ["https://example.com/out.mp4"],
}),
);
const provider = buildRunwayVideoGenerationProvider();
await expect(
provider.generateVideo({
provider: "runway",
model: "gen4.5",
prompt: "missing status",
cfg: {},
}),
).rejects.toThrow("Runway video status response missing task status");
});
it("rejects malformed completed output URLs", async () => {
postJsonRequestMock.mockResolvedValue({
response: streamedJsonResponse({ id: "task-malformed-output" }),
release: vi.fn(async () => {}),
});
fetchWithTimeoutMock.mockResolvedValueOnce(
streamedJsonResponse({
id: "task-malformed-output",
status: "SUCCEEDED",
output: "https://example.com/out.mp4",
}),
);
const provider = buildRunwayVideoGenerationProvider();
await expect(
provider.generateVideo({
provider: "runway",
model: "gen4.5",
prompt: "malformed output",
cfg: {},
}),
).rejects.toThrow("Runway video generation completed with malformed output URLs");
});
});