mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-09-21 06:12:17 +03:00
Landed with the design call resolved per the owner's pick — **option 1**: the synced store is now endpoint-agnostic (persistDiscoveredModels and managedModelImport no longer drop non-chat models at write time), and chat selectability moved to read time (auto-pool expansion in autoStrategy applies filterChatSelectableModels; the models-route projection already had its chatOnly filter). Your discovery test now passes end-to-end (3/3): /api/show capabilities persist per connection and image/embedding requests route through the advertising host. Reconciliation notes: conflicted areas merged onto the current tip (adobe discovery import, requestedModel preflight signature, resolvedProvider fast-path coexists with the synced-route override — explicit resolution wins); carried base-red drains (#10055 memoization, #11071 test variants) dropped as already-landed; the managed-model-import exclusion test was propagated to the new contract (image/video models persist; the read filter still hides them from chat pickers — pinned by a new assertion). Full battery: 205/206 focused (the one red is a confirmed periodic-timer timing flake on the loaded devbox — 20/20 isolated), autoCombo vitest 30/30, combo suites 46/46, gates + typecheck clean. Thank you @yourspraveen — the capability probe + routing design was right; it just needed the store contract opened up. Fixes #11087.
124 lines
4.3 KiB
TypeScript
124 lines
4.3 KiB
TypeScript
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import { mkdtempSync } from "node:fs";
|
|
import { tmpdir } from "node:os";
|
|
import { join } from "node:path";
|
|
|
|
process.env.DATA_DIR = mkdtempSync(join(tmpdir(), "omniroute-video-fal-grok-"));
|
|
|
|
const { handleVideoGeneration } = await import("../../open-sse/handlers/videoGeneration.ts");
|
|
const { VIDEO_PROVIDERS } = await import("../../open-sse/config/videoRegistry.ts");
|
|
|
|
function immediateTimeout(callback: (...args: unknown[]) => void, _ms: number, ...args: unknown[]) {
|
|
callback(...args);
|
|
return 0;
|
|
}
|
|
|
|
function jsonResponse(body: unknown, status = 200) {
|
|
return new Response(JSON.stringify(body), {
|
|
status,
|
|
headers: { "content-type": "application/json" },
|
|
});
|
|
}
|
|
|
|
test("VIDEO_PROVIDERS exposes the Fal-hosted Grok video model", () => {
|
|
assert.ok(VIDEO_PROVIDERS["fal-ai"]);
|
|
assert.equal(VIDEO_PROVIDERS["fal-ai"].format, "fal-ai-video");
|
|
assert.ok(
|
|
VIDEO_PROVIDERS["fal-ai"].models.some(
|
|
(model) => model.id === "xai/grok-imagine-video/text-to-video"
|
|
)
|
|
);
|
|
});
|
|
|
|
test("handleVideoGeneration sends the Fal-hosted Grok request and returns the video URL", async () => {
|
|
const originalFetch = globalThis.fetch;
|
|
const originalSetTimeout = globalThis.setTimeout;
|
|
const requests: Array<{ url: string; headers: Record<string, string>; body?: unknown }> = [];
|
|
globalThis.setTimeout = immediateTimeout as typeof globalThis.setTimeout;
|
|
|
|
globalThis.fetch = async (url, options = {}) => {
|
|
const stringUrl = String(url);
|
|
const headers = Object.fromEntries(new Headers(options.headers).entries());
|
|
const body = options.body ? JSON.parse(String(options.body)) : undefined;
|
|
requests.push({ url: stringUrl, headers, body });
|
|
|
|
if (requests.length === 1) {
|
|
return jsonResponse({
|
|
request_id: "fal-grok-1",
|
|
status_url:
|
|
"https://queue.fal.run/xai/grok-imagine-video/text-to-video/requests/fal-grok-1/status",
|
|
response_url:
|
|
"https://queue.fal.run/xai/grok-imagine-video/text-to-video/requests/fal-grok-1",
|
|
});
|
|
}
|
|
if (stringUrl.endsWith("/status")) return jsonResponse({ status: "COMPLETED" });
|
|
return jsonResponse({ video: { url: "https://cdn.example/fal-grok-1.mp4" } });
|
|
};
|
|
|
|
try {
|
|
const result = await handleVideoGeneration({
|
|
body: {
|
|
model: "fal-ai/xai/grok-imagine-video/text-to-video",
|
|
prompt: "a dog walking through a park",
|
|
duration: "8s",
|
|
resolution: "720p",
|
|
generate_audio: true,
|
|
},
|
|
credentials: { apiKey: "fal-key" },
|
|
log: null,
|
|
});
|
|
|
|
assert.equal(requests[0]?.url, "https://queue.fal.run/xai/grok-imagine-video/text-to-video");
|
|
assert.equal(requests[0]?.headers.authorization, "Key fal-key");
|
|
assert.deepEqual(requests[0]?.body, {
|
|
prompt: "a dog walking through a park",
|
|
aspect_ratio: "16:9",
|
|
duration: 8,
|
|
resolution: "720p",
|
|
});
|
|
assert.equal(result.success, true);
|
|
assert.equal(result.data.data[0].url, "https://cdn.example/fal-grok-1.mp4");
|
|
assert.equal(result.data.data[0].format, "mp4");
|
|
} finally {
|
|
globalThis.fetch = originalFetch;
|
|
globalThis.setTimeout = originalSetTimeout;
|
|
}
|
|
});
|
|
|
|
test("handleVideoGeneration rejects Fal video requests without credentials", async () => {
|
|
const result = await handleVideoGeneration({
|
|
body: { model: "fal-ai/xai/grok-imagine-video/text-to-video", prompt: "x" },
|
|
credentials: null,
|
|
log: null,
|
|
});
|
|
|
|
assert.equal(result.success, false);
|
|
assert.equal(result.status, 401);
|
|
assert.match(result.error, /Fal API key is required/);
|
|
});
|
|
|
|
test("handleVideoGeneration rejects malformed Fal video URL payloads", async () => {
|
|
const originalFetch = globalThis.fetch;
|
|
globalThis.fetch = async () => jsonResponse({ video: { url: { nested: "not-a-url" } } });
|
|
|
|
try {
|
|
const result = await handleVideoGeneration({
|
|
body: {
|
|
model: "fal-ai/xai/grok-imagine-video/text-to-video",
|
|
prompt: "a malformed result",
|
|
},
|
|
credentials: { apiKey: "fal-key" },
|
|
log: null,
|
|
});
|
|
|
|
assert.equal(result.success, false);
|
|
assert.equal(result.status, 502);
|
|
// #9982 folded the video path into the provider-neutral mediaGeneration/fal.ts,
|
|
// whose wording is media-kind agnostic ("no media URL").
|
|
assert.match(result.error, /no media URL/);
|
|
} finally {
|
|
globalThis.fetch = originalFetch;
|
|
}
|
|
});
|