Skip to content

armgit / fuobe

Public Imported from GitHub
0

The open creative studio on ComfyUI: images, video, 3D and audio on open weights, on your own GPU or the cloud. Camera motions, effects, apps, Cinema, Layers, Image to 3D and an AI agent.

Restore 13: review fixes: the cloud reference goes to the first piece, gated LoRAs' reason and readiness, visitor estimates, the board's join

Claude3f54b0121f62
diff --git a/scripts/comfy/library.spec.mjs b/scripts/comfy/library.spec.mjs
index f6ac2184..167822a1 100644
--- a/scripts/comfy/library.spec.mjs
+++ b/scripts/comfy/library.spec.mjs
@@ -2820,7 +2820,7 @@ export const SPEC = [
'first window (the provider removes that branch). image = an optional reference picture at frame_idx -1 (a second IC-LoRA guide; removed without one). deinterlace keeps one field ' +
'(fieldWidth x fieldHeight, nearest rows: no blending; ComfyUI has no fieldmatch/yadif/decimate node), removed when off. Stage 2 (Restore to 4K): the same graph on the restored clip ' +
'with the Detail Refine IC-LoRA, a 2x canvas and 1024x576 tiles. A single generation of a whole clip past 97 frames streams: streaming on the guide and tileFrames 97 on the sampler ' +
- '(the card\'s other long-clip path; no reference picture there). Needs the ComfyUI-LTXVideo pack. Not validated here: the pack is not installed on this server.',
+ '(the card\'s other long-clip path; no reference picture there). Needs the ComfyUI-LTXVideo pack.',
},
// ---- Shorts Studio / Mixed Media: trim, segment, restyle ------------------------
diff --git a/src/components/restore/hooks.ts b/src/components/restore/hooks.ts
index 701526d8..86627f36 100644
--- a/src/components/restore/hooks.ts
+++ b/src/components/restore/hooks.ts
@@ -36,7 +36,8 @@ export interface RestoreEstimate {
dropped: number;
steps: number;
resolution?: string;
- hfToken: boolean;
+ /** The gated Restore IC-LoRA is within reach (a token, or a copy Fuobe holds); left out for a visitor. */
+ loraReady?: boolean;
notes: string[];
}
diff --git a/src/components/restore/restore-tool.tsx b/src/components/restore/restore-tool.tsx
index eb2f3a10..9f457371 100644
--- a/src/components/restore/restore-tool.tsx
+++ b/src/components/restore/restore-tool.tsx
@@ -197,7 +197,7 @@ export function RestoreTool({ tabs }: { tabs?: React.ReactNode }) {
)}
</div>
</Panel>
- {est && !est.hfToken && (
+ {est?.loraReady === false && (
<Panel>
<div className="flex gap-3">
<KeyRound className="mt-0.5 size-4 shrink-0 text-brand-text" aria-hidden />
diff --git a/src/lib/catalog/plan.ts b/src/lib/catalog/plan.ts
index ca6654b3..b18bc382 100644
--- a/src/lib/catalog/plan.ts
+++ b/src/lib/catalog/plan.ts
@@ -12,7 +12,7 @@ import type {
} from "./types";
import { billedClipSeconds, editClipsProblem, sourceSeconds } from "./clip-windows";
import { chainGapProblem, chainTiming, FIRST_AT_ZERO, frameTimes, keyframeChain, MAX_KEYFRAMES, spread } from "./keyframes";
-import { cloudPath, fitLoras, localOnly, loraCapacity, needsToken, routeLoraField, triggerOf } from "./loras";
+import { cloudPath, fitLoras, gated, localOnly, loraCapacity, needsToken, routeLoraField, triggerOf } from "./loras";
import { anglesPrompt, anglesWords, ANGLES_ORIGINAL } from "./open-tools";
import { askedSize, clipWords, numFramesValue, sizeValue } from "./payload";
import { characterScale, CINEMA_CROP, soulKind, soulMegapixels, soulRecipe, soulSize, type SoulOverlay } from "./soul";
@@ -942,6 +942,8 @@ export function routeLoras(route: Pick<ModelRoute, "provider" | "map" | "loraEnd
const field = routeLoraField(route);
const why = (l: LoraRef) => {
if (localOnly(l)) return "it is licensed for your GPU only, and Settings → Models & licences keeps such LoRAs off the cloud";
+ // An optional gated LoRA (Relight, DoP's Slow motion); only a model's own gated adapter goes to the cloud, as Fuobe's copy.
+ if (gated(l) && !l.hostedUrl && !l.adapter) return "it is in a gated Hugging Face repo, so it runs only on your GPU";
if (!cloudPath(l) && !needsToken(l.url) && !l.own) return "no URL to send to the LoRA endpoint";
if (!field) return "this route takes no LoRAs";
return field.shape === "experts" ? "this API takes one LoRA per expert" : `this API takes up to ${loraCapacity(field)} LoRAs`;
diff --git a/src/lib/catalog/restore.ts b/src/lib/catalog/restore.ts
index 76811238..13aa0c26 100644
--- a/src/lib/catalog/restore.ts
+++ b/src/lib/catalog/restore.ts
@@ -450,7 +450,7 @@ export function planRestore(input: RestorePlanInput): RestorePlan {
}
// Cloud: frame-exact pieces, each restored in one untiled pass; a piece after the first starts from the last restored
- // frame of the one before (fal's image_url, the first frame of the video).
+ // frame of the one before (fal's image_url, the first frame of the video), and the first from the reference picture.
const resolution = input.resolution && (RESTORE.cloudResolutions as readonly string[]).includes(input.resolution) ? input.resolution : RESTORE.cloudResolution;
const shape = cloudShape(source.width, source.height);
const [cw, ch] = CLOUD_SIZES[resolution][shape];
@@ -483,13 +483,15 @@ export function planRestore(input: RestorePlanInput): RestorePlan {
}
const seconds = r6((p.frames ?? Math.round((p.end - p.start) * fps)) / fps);
const lone = n === 1;
+ // The reference picture is the first piece's first frame (fal's image_url); later pieces start from the hand-off.
+ const first = i === 0 && input.reference ? { images: [input.reference] } : undefined;
const request: GenerationRequest = {
...own(lone),
modelId: RESTORE.model,
engine: "cloud",
op: "restore-video",
...words,
- ...(whole ? { inputs: { video: source.url } } : {}),
+ ...(whole || first ? { inputs: { ...(whole ? { video: source.url } : {}), ...first } } : {}),
params: { aspectRatio: shape, resolution, fps, duration: seconds, sourceDuration: seconds, ...seed },
step: label(i, n, "restore"),
};
@@ -534,11 +536,13 @@ function thenUpscale(steps: PlanStep[], final: string, input: RestorePlanInput):
}
/** The open join: the windows share one size and frame rate, so they're joined packet by packet (no decode, no resize). */
+export const RESTORE_OPEN_JOIN = "oss-join-encoded";
+
function joinEncoded(steps: PlanStep[], keys: string[], key: string, who: Pick<GenerationRequest, "feature" | "batchTitle" | "title">, what: string): string {
if (keys.length === 1) return keys[0];
steps.push({
key,
- request: { ...who, modelId: "oss-join-encoded", op: "concat", step: { label: what, index: 1000, of: 1000 } },
+ request: { ...who, modelId: RESTORE_OPEN_JOIN, op: "concat", step: { label: what, index: 1000, of: 1000 } },
after: keys,
chain: keys.map(() => ({ slot: "videos" as const })),
});
diff --git a/src/server/gpu/tools.ts b/src/server/gpu/tools.ts
index d0ce961f..6f19d618 100644
--- a/src/server/gpu/tools.ts
+++ b/src/server/gpu/tools.ts
@@ -7,7 +7,7 @@ import { PATH_MODELS } from "@/lib/catalog/cinema";
import { dualEngine, onEngine, runsOn } from "@/lib/catalog/engines";
import { FRAMES_MODELS } from "@/lib/catalog/keyframes";
import { REMOVE_TOOLS } from "@/lib/catalog/remove-object";
-import { RESTORE } from "@/lib/catalog/restore";
+import { RESTORE, RESTORE_OPEN_JOIN } from "@/lib/catalog/restore";
import { libraryEntry, loraEntry, loraRef, needsToken } from "@/lib/catalog/loras";
import { ANGLES_2511_LORA } from "@/lib/catalog/open-tools";
import { presetRoutes, recipeRoute } from "@/lib/catalog/preset-recipes";
@@ -205,14 +205,14 @@ export const STUDIO_ROWS: StudioRowDef[] = [
{ href: "/video-tools/join", label: "Join clips", group: "Video tools", config: S.JOIN_CLIPS_STUDIO },
{ href: "/video-tools/colors", label: "Match colors", group: "Video tools", config: S.VIDEO_COLOR_MATCH_STUDIO },
// Restore & colourise (archive-restore): the tiled-fusion graph with the gated Restore IC-LoRA (the graph loads it
- // itself), then the windows joined and the sound put back. "Restore to 4K"'s Detail Refine LoRA is an option, not listed.
+ // itself), then the windows joined packet by packet (the join planRestore runs) and the sound put back. "Restore to 4K"'s Detail Refine LoRA is an option, not listed.
{
href: "/video-tools/restore",
label: "Restore & colourise",
group: "Video tools",
steps: [
{ modelId: RESTORE.model, op: "restore-video", loras: [loraRef(loraEntry(RESTORE.loras.restore.key)!)] },
- { modelId: REMOVE_TOOLS.open.join, op: "concat" },
+ { modelId: RESTORE_OPEN_JOIN, op: "concat" },
{ modelId: REMOVE_TOOLS.open.mux, op: "mux" },
],
},
diff --git a/src/server/loras.ts b/src/server/loras.ts
index 567269a0..6a1def03 100644
--- a/src/server/loras.ts
+++ b/src/server/loras.ts
@@ -114,6 +114,31 @@ const hfToken = () => getSetting("huggingfaceDownloadToken");
/** Whether a Hugging Face token is set (gated downloads need one). */
export const hasHfToken = (): boolean => !!hfToken();
+/**
+ * Whether a gated Hugging Face LoRA is within reach for a run on `target`: with the token always; without it, when
+ * Fuobe already holds what the run uses: a live copy on the provider (cloud), or the file on this machine (ComfyUI's
+ * LoRA folder; for the cloud also Fuobe's own cache, which mirrorCivitai copies from). A file on disk counts at its
+ * pinned size: hashing 1.7 GB for every estimate is too slow, and the copy itself is still checked against the hash.
+ */
+export function gatedFileReady(file: string, target: MirrorTarget): boolean {
+ if (hfToken()) return true;
+ if (target !== "comfyui") {
+ const cached = getCopy(file, target);
+ if (cached?.hostedUrl && Date.now() - cached.createdAt < MIRROR_TTL_MS[target]) return true;
+ }
+ const size = loraByFile(file)?.sizeBytes;
+ const dirs = target === "comfyui" ? [getSetting("comfyLorasDir")] : [getSetting("comfyLorasDir"), LORA_CACHE_DIR];
+ return dirs.some((d) => {
+ if (!d) return false;
+ try {
+ const p = lorasPath(d, file);
+ return fs.existsSync(p) && (!size || fs.statSync(p).size === size);
+ } catch {
+ return false;
+ }
+ });
+}
+
/** A URL as it may be shown or stored: never with a token in it (the civitai key or the Hugging Face token). */
export function redact(text: string, token = civitaiKey()): string {
let out = text.replace(/([?&]token=)[^&\s"']+/gi, "$1•••");
diff --git a/src/server/restore.ts b/src/server/restore.ts
index 6ff39a9c..f05acb6a 100644
--- a/src/server/restore.ts
+++ b/src/server/restore.ts
@@ -25,11 +25,12 @@ import { ACCESS_PLACE } from "@/lib/model-access";
import { createPipeline } from "./chains";
import { llmText, llmTextBackend } from "./enhance";
import { previewChained } from "./generations";
-import { gatedHint, hasHfToken } from "./loras";
+import { gatedFileReady, gatedHint } from "./loras";
import { isOffered, offeredModel } from "./model-access";
import { localLabel, localWhat, probeLocal } from "./llm";
import { engineMode, getSetting } from "./settings";
import { probeSource, ShortsError } from "./shorts";
+import { tenant } from "./tenant";
/**
* Video tools → Restore & colourise (Fuobe Restore, package archive-restore): plans, prices and starts a run
@@ -146,6 +147,15 @@ export async function writeRestorePrompt(body: z.infer<typeof PromptSchema>): Pr
// ---------------------------------------------------------------------------
// Plan, price, run
+/**
+ * Whether the gated LoRAs this run uses are within reach: a Hugging Face token, or what Fuobe already holds (a live
+ * copy on fal for the cloud; the files in ComfyUI's LoRA folder on the GPU, the Detail Refine one too for Restore to 4K).
+ */
+function gatedReady(engine: Engine, refine?: boolean): boolean {
+ if (engine === "cloud") return gatedFileReady(RESTORE.loras.restore.file, "fal");
+ return gatedFileReady(RESTORE.loras.restore.file, "comfyui") && (!refine || gatedFileReady(RESTORE.loras.refine.file, "comfyui"));
+}
+
function planInput(body: z.infer<typeof RestoreBodySchema>, info: Awaited<ReturnType<typeof probeSource>> | Record<string, never>, prompt: string, probed: boolean): { input: RestorePlanInput; notes: string[] } {
const engine = body.engine;
const src = {
@@ -173,7 +183,9 @@ function planInput(body: z.infer<typeof RestoreBodySchema>, info: Awaited<Return
if (body.upscale) notes.push(`Then upscaled with ${RESTORE_UPSCALE.cloud.label}, priced in`);
}
if (body.reference) notes.push(engine === "open" ? "Your reference picture goes to every window at frame_idx −1 (true colours, faces, signs)" : "In the cloud your picture is the first frame: give the clip's first frame already in colour");
- if (!hasHfToken()) notes.push(GATED_NOTE);
+ // The token and the copies are the owner's: a visitor (priced as on its own GPU) is never told about them, and
+ // Fuobe never downloads onto a visitor's ComfyUI.
+ if (!tenant() && !gatedReady(engine, engine === "open" && body.refine)) notes.push(GATED_NOTE);
if (src.hasAudio) notes.push("Your clip's own sound is put back on the result");
return {
notes,
@@ -225,8 +237,11 @@ export interface RestoreEstimate {
dropped: number;
steps: number;
resolution?: string;
- /** A Hugging Face token is set (the gated LoRA downloads with it). */
- hfToken: boolean;
+ /**
+ * The gated Restore IC-LoRA is within reach: a Hugging Face token is set, or Fuobe already holds a copy the run can
+ * use. Left out for a visitor: the owner's token and copies are none of its business.
+ */
+ loraReady?: boolean;
notes: string[];
}
@@ -247,7 +262,7 @@ export function estimateRestore(body: z.infer<typeof RestoreEstimateSchema>): Re
dropped: plan.dropped,
steps: plan.steps.length,
...(input.resolution ? { resolution: input.resolution } : {}),
- hfToken: hasHfToken(),
+ ...(tenant() ? {} : { loraReady: gatedReady(body.engine, body.engine === "open" && body.refine) }),
notes,
};
}
@@ -270,9 +285,10 @@ export async function createRestore(body: z.infer<typeof RestoreBodySchema>): Pr
}
const { input } = planInput({ ...body, negative }, info, prompt, true);
const plan = planRestore(input);
- // The cloud carries the gated Restore IC-LoRA as Fuobe's copy, made with the Hugging Face token: without one, every piece
- // would fail at submit, so the run is refused before anything starts (a placeholder run needs no file).
- if (body.engine === "cloud" && !hasHfToken() && !price(plan.steps).demo) {
+ // The cloud carries the gated Restore IC-LoRA as Fuobe's copy, made with the Hugging Face token: with neither a token nor
+ // a copy to send (a live one on fal, or the file on this machine), every piece would fail at submit, so the run is
+ // refused before anything starts (a placeholder run needs no file).
+ if (body.engine === "cloud" && !gatedReady("cloud") && !price(plan.steps).demo) {
throw new ShortsError(`${gatedHint("Lightricks' Restore IC-LoRA", RESTORE.loras.restore.page)}. A cloud run gets Fuobe's copy of the file, never your token`, 422);
}
let p: ReturnType<typeof createPipeline>;
diff --git a/tests/eval-api.test.ts b/tests/eval-api.test.ts
index cdafa0f1..4fce4435 100644
--- a/tests/eval-api.test.ts
+++ b/tests/eval-api.test.ts
@@ -4,6 +4,7 @@ import path from "node:path";
import { afterAll, beforeAll, describe, expect, it, vi } from "vitest";
import { getModel, getPreset } from "@/lib/catalog";
import { planGeneration, routeLoras } from "@/lib/catalog/plan";
+import { loraEntry, loraRef } from "@/lib/catalog/loras";
/** The REST seams the evaluation harness (scripts/eval) needs: a recipe's LoRAs on POST /api/generations, and a preview that says which ones run. */
@@ -131,6 +132,15 @@ describe("the preview says what the route runs", () => {
expect(routeLoras({ provider: "replicate" }, [hf]).applied).toEqual([]);
});
+ it("routeLoras: an optional gated LoRA is left off a cloud route as gated; a model's own gated adapter goes (as Fuobe's copy)", () => {
+ const ltx = { provider: "fal" as const, map: { loras: { shape: "items" as const, key: "loras", required: true } }, loraEndpoint: "fal-ai/ltx-2.3-22b/reference-video-to-video/lora" };
+ const slow = loraRef(loraEntry("ltx-2-5-22b-lora-slow-motion-control-1-0")!);
+ const restore = { ...loraRef(loraEntry("ltx-2-5-22b-ic-lora-restore-1-0")!), adapter: true as const };
+ const r = routeLoras(ltx, [slow, restore]);
+ expect(r.dropped).toEqual([{ file: slow.file, reason: "it is in a gated Hugging Face repo, so it runs only on your GPU" }]);
+ expect(r.applied).toEqual([restore]);
+ });
+
it("returns the endpoint, the final prompt and the LoRAs on the open engine (demo mode, no ComfyUI here)", async () => {
const r = await post({ ...soul, loras: [hf, local] });
expect(r.status).toBe(200);
diff --git a/tests/gpu-requirements.test.ts b/tests/gpu-requirements.test.ts
index bab06f7a..7ad05704 100644
--- a/tests/gpu-requirements.test.ts
+++ b/tests/gpu-requirements.test.ts
@@ -108,10 +108,13 @@ describe("requirements.json", () => {
expect(index.packs["ComfyUI-ThinkSound_Wrapper"].isolated).toBe(true);
});
- // 26 KB gzipped since Restore & colourise's graph and pack (o/archive-restore): the library was at 24.8 KB before it.
- it("stays within its size budget (200 KB, 26 KB gzipped)", () => {
- expect(Buffer.byteLength(text)).toBeLessThanOrEqual(200 * 1024);
- expect(zlib.gzipSync(text).length).toBeLessThanOrEqual(26 * 1024);
+ // Raised together with Restore & colourise's graph and pack (o/archive-restore), which took the index from 202.1 to
+ // 204.4 KB (24.9 to 25.3 KB gzipped), leaving the old 200 KB / 25 KB no room. Each graph adds about 1-2.5 KB raw and
+ // 0.2-0.5 KB gzipped, so 216 KB / 27 KB leaves room for the next few graphs (n7-3's among them) while still catching a
+ // build that bloats it. The server parses it once per change, and /api/gpu/requirements serves it compressed.
+ it("stays within its size budget (216 KB, 27 KB gzipped)", () => {
+ expect(Buffer.byteLength(text)).toBeLessThanOrEqual(216 * 1024);
+ expect(zlib.gzipSync(text).length).toBeLessThanOrEqual(27 * 1024);
});
});
diff --git a/tests/lora-fetch.test.ts b/tests/lora-fetch.test.ts
index c4544207..24f36fdc 100644
--- a/tests/lora-fetch.test.ts
+++ b/tests/lora-fetch.test.ts
@@ -8,20 +8,20 @@ import type { LoraRef } from "@/lib/catalog/types";
// The route's GET opts out of prerendering with connection(), which needs a request scope.
vi.mock("next/server", () => ({ connection: async () => {} }));
-// The library pins each file's SHA256: two entries are pinned to the small stand-in files these tests serve.
+// The library pins each file's SHA256: three entries are pinned to the small stand-in files these tests serve.
vi.mock("@/lib/catalog/lora-library.generated", async (importOriginal) => {
const real = await importOriginal<typeof import("@/lib/catalog/lora-library.generated")>();
const { createHash } = await import("node:crypto");
const body = (s: string) => Buffer.from(s.repeat(64));
const pin = (s: string) => ({ sha256: createHash("sha256").update(body(s)).digest("hex"), sizeBytes: body(s).length });
- const fake: Record<string, ReturnType<typeof pin>> = { awportrait: pin("awportrait"), y2k: pin("y2k-style") };
+ const fake: Record<string, ReturnType<typeof pin>> = { awportrait: pin("awportrait"), y2k: pin("y2k-style"), "ltx-2-5-22b-ic-lora-refine-details-1-0": pin("refine-details") };
return { ...real, LORA_LIBRARY: real.LORA_LIBRARY.map((e) => (fake[e.key] ? { ...e, ...fake[e.key] } : e)) };
});
// The downloader reads the civitai key and the LoRA folder from the settings table: a throwaway data folder.
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "fuobe-lora-fetch-"));
process.env.FUOBE_DATA_DIR = dir;
-const { downloadLora, ensureLorasOnComfy, prepareCloudLoras, listLoraCopies, lorasPath, redact, LORA_CACHE_DIR } = await import("@/server/loras");
+const { downloadLora, ensureLorasOnComfy, gatedFileReady, prepareCloudLoras, listLoraCopies, lorasPath, redact, LORA_CACHE_DIR } = await import("@/server/loras");
const { setSetting } = await import("@/server/settings");
const { db } = await import("@/server/db");
afterAll(() => fs.rmSync(dir, { recursive: true, force: true }));
@@ -345,6 +345,43 @@ describe("Before a cloud run", () => {
setSetting("huggingfaceDownloadToken", "");
});
+ it("with the token, a gated adapter whose bytes match the pin is copied to fal once, recorded with its licence, and reused without the token", async () => {
+ // The Detail Refine IC-LoRA stands in (the mock pins it to a small file); sent as a model's own adapter.
+ const refine = { ...loraRef(loraEntry("ltx-2-5-22b-ic-lora-refine-details-1-0")!), adapter: true as const };
+ const body = bytes("refine-details");
+ const HF = "hf_secret0123456789abcdef";
+ setSetting("huggingfaceDownloadToken", HF);
+ expect(gatedFileReady(refine.file, "fal")).toBe(true);
+ net = network({
+ [refine.url!]: (c) =>
+ c.method === "HEAD"
+ ? new Response(null, { status: 302, headers: { "x-linked-etag": `"${sha(body)}"`, "x-linked-size": String(body.length), "x-repo-commit": "4912c478" } })
+ : new Response(new Uint8Array(body), { status: 200, headers: { "content-length": String(body.length) } }),
+ });
+ const up = upload();
+ const [sent] = (await prepareCloudLoras([refine], "fal", up.fn))!;
+ expect(sent.hostedUrl).toBe(`https://v3.fal.media/files/${refine.file}`);
+ expect(up.sent).toEqual([{ name: refine.file, size: body.length }]);
+ for (const c of net.calls) expect(c.url).not.toContain(HF);
+ const copy = listLoraCopies().find((c) => c.file === refine.file && c.target === "fal")!;
+ expect(copy).toMatchObject({ sourceUrl: refine.url, hostedUrl: sent.hostedUrl, sha256: sha(body), sizeBytes: body.length });
+ expect(copy.licence?.hosting).toBe("a gated Hugging Face file, downloaded once with your token; its licence allows hosted use (the research's snapshot)");
+ expect(JSON.stringify(copy)).not.toContain(HF);
+ // The next run, token removed: the live copy is used, nothing is fetched or sent again, and it counts as ready.
+ setSetting("huggingfaceDownloadToken", "");
+ net.restore();
+ net = network({});
+ const [again] = (await prepareCloudLoras([refine], "fal", up.fn))!;
+ expect(again.hostedUrl).toBe(sent.hostedUrl);
+ expect(up.sent).toHaveLength(1);
+ expect(net.calls).toEqual([]);
+ expect(gatedFileReady(refine.file, "fal")).toBe(true);
+ // Replicate has no copy, but the file downloaded for fal sits in Fuobe's cache at its pinned size; without it, nothing.
+ expect(gatedFileReady(refine.file, "replicate")).toBe(true);
+ fs.rmSync(LORA_CACHE_DIR, { recursive: true, force: true });
+ expect(gatedFileReady(refine.file, "replicate")).toBe(false);
+ });
+
it("mirrors the pinned bytes, not a same-named file of other bytes in the LoRA folder", async () => {
setSetting("civitaiKey", KEY);
setSetting("comfyLorasDir", folder);
diff --git a/tests/model-access-listings.test.ts b/tests/model-access-listings.test.ts
index 907d0d2e..09fc4430 100644
--- a/tests/model-access-listings.test.ts
+++ b/tests/model-access-listings.test.ts
@@ -96,8 +96,9 @@ describe("Models & licences in listings and picks", () => {
expect(list.models.length).toBeGreaterThan(300);
// The library's 118 LoRAs (Fuobe Try-On's try-on LoRA, the Storyboard's next-scene LoRA, and since O11 Fuobe Angles'
// Multiple-angles and Fuobe Speak's FusioniX among them), the preset LoRA map's files that aren't library files, and
- // MiniMax H3's four (Akatz Labs' swap LoRA V1.5 and V1 and Person Remover V1, lightx2v's H3 Turbo), each once.
- expect(list.loras.length).toBe(174);
+ // MiniMax H3's four (Akatz Labs' swap LoRA V1.5 and V1 and Person Remover V1, lightx2v's H3 Turbo), and Fuobe Restore's
+ // two gated IC-LoRAs (Lightricks' Restore and Detail Refine), each once.
+ expect(list.loras.length).toBe(176);
expect(list.loras.find((l) => l.file === "next-scene_lora-v2-3000.safetensors")).toMatchObject({ group: "adapter", on: true, licence: { name: "MIT", class: "commercial" } });
expect(list.loras.find((l) => l.file === "qwen-edit-2509-multiple-angles-dx8152.safetensors")).toMatchObject({ group: "adapter", on: true, licence: { name: "Apache-2.0", class: "commercial" } });
expect(list.loras.find((l) => l.file === "Wan2.1_I2V_14B_FusionX_LoRA.safetensors")).toMatchObject({ group: "adapter", on: true });
diff --git a/tests/restore-api.test.ts b/tests/restore-api.test.ts
index 5089a29b..1d2796b4 100644
--- a/tests/restore-api.test.ts
+++ b/tests/restore-api.test.ts
@@ -6,6 +6,19 @@ import type { Generation } from "@/lib/catalog/types";
vi.setConfig({ testTimeout: 120_000 });
+// A switch that stops a run at the pipeline, so a paid cloud run's guard can be passed without submitting anything.
+const pipelineStop = vi.hoisted(() => ({ on: false }));
+vi.mock("@/server/chains", async (original) => {
+ const m = await original<typeof import("@/server/chains")>();
+ return {
+ ...m,
+ createPipeline: (...a: Parameters<typeof m.createPipeline>) => {
+ if (pipelineStop.on) throw new Error("stopped before the pipeline");
+ return m.createPipeline(...a);
+ },
+ };
+});
+
// /api/restore end to end in demo mode (no keys, no ComfyUI, no LLM): a run on either engine becomes one pipeline of
// ordinary generations the mock provider runs through; estimates with a fal key price the real LTX-2.3 route.
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "fuobe-restore-"));
@@ -17,6 +30,8 @@ const { setSetting } = await import("@/server/settings");
const gens = await import("@/server/generations");
const { saveFile } = await import("@/server/storage");
const { db } = await import("@/server/db");
+const { RESTORE } = await import("@/lib/catalog/restore");
+const { loraByFile } = await import("@/lib/catalog/loras");
const createRoute = await import("@/app/api/restore/route");
const estimateRoute = await import("@/app/api/restore/estimate/route");
const promptRoute = await import("@/app/api/restore/prompt/route");
@@ -52,9 +67,9 @@ const src = { duration: 12, fps: 16, width: 72, height: 128, hasAudio: true };
const body = (over: Record<string, unknown> = {}) => ({ engine: "open", source: { url: clip, name: "reel.mp4", ...src }, prompt: "a harbour in the 1930s, natural colour", ...over });
describe("Restore: estimates", () => {
- it("the GPU is free: three windows, the canvas, the tiles, the gated download said while no HF token is set", async () => {
+ it("the GPU is free: three windows, the canvas, the tiles, the gated download said while no HF token or file is there", async () => {
const e = await (await estimateRoute.POST(json(body()))).json();
- expect(e).toMatchObject({ engine: "open", pieces: 3, costUsd: 0, canvas: { width: 1088, height: 1920 }, hfToken: false, dropped: 7 });
+ expect(e).toMatchObject({ engine: "open", pieces: 3, costUsd: 0, canvas: { width: 1088, height: 1920 }, loraReady: false, dropped: 7 });
expect(e.notes.join(" ")).toMatch(/LTX-2.5 22B distilled with tiled latent fusion/);
expect(e.notes.join(" ")).toMatch(/gated on Hugging Face/);
const four = await (await estimateRoute.POST(json(body({ refine: true })))).json();
@@ -98,6 +113,56 @@ describe("Restore: estimates", () => {
expect(r.status).toBe(422);
expect((await r.json()).error).toMatch(/gated Hugging Face repo: accept its licence on https:\/\/huggingface\.co\/Lightricks\/LTX-2\.5-22b-IC-LoRA-Restore .*Settings → LoRAs.*never your token/);
expect((db().prepare("SELECT COUNT(*) AS n FROM generations").get() as { n: number }).n).toBe(before);
+ expect((await (await estimateRoute.POST(json(body({ engine: "cloud" })))).json()).loraReady).toBe(false);
+ });
+
+ it("with no token, a copy Fuobe already holds is enough: a live one on fal, or the file on this machine at its pinned size", async () => {
+ setSetting("huggingfaceDownloadToken", "");
+ const file = RESTORE.loras.restore.file;
+ const count = () => (db().prepare("SELECT COUNT(*) AS n FROM generations").get() as { n: number }).n;
+ // A live copy on fal: the run starts, and nothing asks for a token.
+ db().prepare("INSERT INTO lora_mirrors (file, target, source_url, version, hosted_url, sha256, size_bytes, licence_json, created_at) VALUES (?, 'fal', ?, NULL, ?, NULL, NULL, NULL, ?)")
+ .run(file, RESTORE.loras.restore.page, "https://v3.fal.media/files/restore.safetensors", Date.now());
+ try {
+ const e = await (await estimateRoute.POST(json(body({ engine: "cloud" })))).json();
+ expect(e.loraReady).toBe(true);
+ expect(e.notes.join(" ")).not.toMatch(/gated on Hugging Face/);
+ // The run is let through to the pipeline, which stops it here (a real submit would reach fal with the test key).
+ pipelineStop.on = true;
+ const before = count();
+ const r = await createRoute.POST(json(body({ engine: "cloud" })));
+ expect((await r.json()).error).toBe("stopped before the pipeline");
+ expect(count()).toBe(before);
+ } finally {
+ pipelineStop.on = false;
+ db().prepare("DELETE FROM lora_mirrors WHERE file = ?").run(file);
+ }
+ // An expired copy is no copy.
+ db().prepare("INSERT INTO lora_mirrors (file, target, source_url, version, hosted_url, sha256, size_bytes, licence_json, created_at) VALUES (?, 'fal', ?, NULL, ?, NULL, NULL, NULL, ?)")
+ .run(file, RESTORE.loras.restore.page, "https://v3.fal.media/files/restore.safetensors", Date.now() - 8 * 86_400_000);
+ try {
+ expect((await (await estimateRoute.POST(json(body({ engine: "cloud" })))).json()).loraReady).toBe(false);
+ } finally {
+ db().prepare("DELETE FROM lora_mirrors WHERE file = ?").run(file);
+ }
+ // The file in ComfyUI's LoRA folder at its pinned size (sparse, so nothing is written): ready on both engines;
+ // a file of another size isn't.
+ const loras = fs.mkdtempSync(path.join(dir, "loras-"));
+ setSetting("comfyLorasDir", loras);
+ try {
+ const size = loraByFile(file)!.sizeBytes!;
+ const fd = fs.openSync(path.join(loras, file), "w");
+ fs.ftruncateSync(fd, size);
+ fs.closeSync(fd);
+ expect((await (await estimateRoute.POST(json(body({ engine: "cloud" })))).json()).loraReady).toBe(true);
+ expect((await (await estimateRoute.POST(json(body()))).json()).loraReady).toBe(true);
+ // Restore to 4K needs the Detail Refine file too.
+ expect((await (await estimateRoute.POST(json(body({ refine: true })))).json()).loraReady).toBe(false);
+ fs.truncateSync(path.join(loras, file), 1024);
+ expect((await (await estimateRoute.POST(json(body()))).json()).loraReady).toBe(false);
+ } finally {
+ setSetting("comfyLorasDir", "");
+ }
});
});
diff --git a/tests/restore-signup.test.ts b/tests/restore-signup.test.ts
index 530fefb4..da67d7c8 100644
--- a/tests/restore-signup.test.ts
+++ b/tests/restore-signup.test.ts
@@ -25,6 +25,7 @@ const access = await import("@/lib/guest-access");
const { setSetting } = await import("@/server/settings");
const estimate = await import("@/app/api/restore/estimate/route");
const { PromptSchema } = await import("@/server/restore");
+const { planRestore } = await import("@/lib/catalog/restore");
const { STUDIO_ROWS, studioTool, toolFor } = await import("@/server/gpu/tools");
const { loadIndex } = await import("@/server/gpu/index-file");
afterAll(() => {
@@ -118,6 +119,24 @@ describe("the estimate route: a visitor's price is its own GPU's", () => {
const owner = await estimate.POST(call("/api/restore/estimate", { engine: "open", source }, auth.createSession().value));
expect(await owner.json()).toMatchObject({ demo: true, costUsd: 0 });
});
+
+ it("never tells a visitor whether the owner set a Hugging Face token, nor asks it to add one", async () => {
+ process.env.FUOBE_PUBLIC_SIGNUP = "1";
+ setSetting("huggingfaceDownloadToken", "");
+ const account = auth.createSession(newAccount().id).value;
+ for (const [who, cookie] of [
+ ["guest", undefined],
+ ["account", account],
+ ] as const) {
+ const e = await (await estimate.POST(call("/api/restore/estimate", { engine: "open", source, refine: true }, cookie))).json();
+ expect(e, who).not.toHaveProperty("loraReady");
+ expect(e.notes.join(" "), who).not.toMatch(/gated on Hugging Face|Settings → LoRAs/);
+ }
+ // The owner, with no token and no copy, is told what to set up.
+ const owner = await (await estimate.POST(call("/api/restore/estimate", { engine: "open", source }, auth.createSession().value))).json();
+ expect(owner.loraReady).toBe(false);
+ expect(owner.notes.join(" ")).toMatch(/gated on Hugging Face/);
+ });
});
describe("the prompt writer's body stays under the sign-in proxy's 4 MB", () => {
@@ -142,6 +161,13 @@ describe("the GPU pre-flight board", () => {
for (const wf of t.workflows) expect(idx.workflows[wf], wf).toBeDefined();
expect(t.loras).toEqual([expect.objectContaining({ file: "ltx-2.5-22b-ic-lora-restore-1.0.safetensors", download: "hf-gated" })]);
expect(toolFor("studio:/video-tools/restore")?.workflows).toEqual(t.workflows);
+ // The row checks the graphs a run uses: a multi-window GPU plan with its sound (windows, join, sound back).
+ const plan = planRestore({ engine: "open", title: "R", prompt: "p", negative: "n", source: { url: "/api/files/a.mp4", duration: 12, frames: 192, fps: 16, width: 640, height: 480, hasAudio: true } });
+ const used = new Map(plan.steps.map((s) => [`${s.request.modelId}|${s.request.op}`, { modelId: s.request.modelId, op: s.request.op! }]));
+ expect(used.size).toBe(3);
+ const planned = studioTool({ href: "/video-tools/restore", label: "x", group: "Video tools", steps: [...used.values()] })!;
+ expect(new Set(t.workflows)).toEqual(new Set(planned.workflows));
+ expect(t.workflows).toContain("video-concat-encoded");
// The graph's node pack is pinned, so the board can say what to install.
expect(Object.keys(idx.workflows["video-restore-ltx25-tiled"].packs)).toContain("ComfyUI-LTXVideo");
expect(idx.packs["ComfyUI-LTXVideo"]).toMatchObject({ commit: "220e1d45aa0469f518e982102fca4dca92a61862" });
diff --git a/tests/restore.test.ts b/tests/restore.test.ts
index 7608bd56..ee13b0ac 100644
--- a/tests/restore.test.ts
+++ b/tests/restore.test.ts
@@ -27,6 +27,7 @@ import { THEN_UPSCALE, UPSCALE_FIRST_STEPS } from "@/lib/catalog/upscale-first";
import { VIDEO_UPSCALE_STUDIO } from "@/lib/studios";
import type { ComfyWorkflow } from "@/lib/comfy";
import { getModel, getPreset } from "@/lib/catalog";
+import { withChainInputs } from "@/server/generations";
import { onEngine } from "@/lib/catalog/engines";
import { estimateCost, planGeneration } from "@/lib/catalog/plan";
import { convertEngine, defaultModelForNode, describeNode, inputPorts, nodeEngine, outputType, paletteItems, type CanvasGraph, type CanvasNode } from "@/lib/catalog/canvas";
@@ -231,6 +232,22 @@ describe("Restore & colourise: the pipeline", () => {
expect(plan.steps.find((s) => s.key === "final")!.request.modelId).toBe("merge-audio-video");
});
+ it("cloud: the reference picture is the first piece's first frame (fal's image_url); later pieces start from the hand-off", () => {
+ const ref = "/api/files/ref.png";
+ const plan = planRestore({ engine: "cloud", title: "Restored", source: { ...source, frames: 240, duration: 10 }, ...words, reference: ref });
+ const r0 = plan.steps.find((s) => s.key === "restore0")!;
+ expect(r0.request.inputs).toEqual({ images: [ref] });
+ // The cut piece arrives through the chain, beside the picture.
+ expect(withChainInputs({ ...r0.request, chain: r0.chain }, ["/api/files/cut0.mp4"]).inputs).toEqual({ images: [ref], video: "/api/files/cut0.mp4" });
+ for (const k of ["restore1", "restore2"]) expect(plan.steps.find((s) => s.key === k)!.request.inputs, k).toBeUndefined();
+ // A clip of one whole piece: the clip and the picture together.
+ const whole = planRestore({ engine: "cloud", title: "R", source: { url: "/api/files/a.mp4", duration: 97 / 24, frames: 97, fps: 24, width: 1280, height: 720, hasAudio: false }, ...words, reference: ref });
+ expect(whole.steps[0].request.inputs).toEqual({ video: "/api/files/a.mp4", images: [ref] });
+ // Without one, nothing is added.
+ const none = planRestore({ engine: "cloud", title: "Restored", source: { ...source, frames: 240, duration: 10 }, ...words });
+ expect(none.steps.find((s) => s.key === "restore0")!.request.inputs).toBeUndefined();
+ });
+
it("cloud: a clip of one whole piece runs as it is; its shape picks the tier's size", () => {
const plan = planRestore({ engine: "cloud", title: "R", source: { url: "/api/files/a.mp4", duration: 97 / 24, frames: 97, fps: 24, width: 1280, height: 720, hasAudio: false }, ...words });
expect(plan.steps.map((s) => s.key)).toEqual(["restore0"]);
diff --git a/workflows/comfyui/manifest.json b/workflows/comfyui/manifest.json
index 118ca45b..4424f844 100644
--- a/workflows/comfyui/manifest.json
+++ b/workflows/comfyui/manifest.json
@@ -12335,7 +12335,7 @@
"vramGb": 24,
"license": "LTX-2.x Community License (LTX-2.5 22B distilled, its video VAE, and Lightricks' Restore and Detail Refine IC-LoRAs, both gated on Hugging Face: free under US$10M annual revenue); Gemma 4 text encoder packaged by Lightricks; ComfyUI-LTXVideo nodes under the LTX-2 Community License (its LICENSE file)",
"validated": false,
- "notes": "Built from the Restore IC-LoRA card's recipe (Hugging Face Lightricks/LTX-2.5-22b-IC-LoRA-Restore at 79245e1, read as data) and the node definitions of ComfyUI-LTXVideo at 220e1d4 (its LTX-2.5_V2V_TiledFusion_Upscale example wires the same nodes): the window (windowStart, windowFrames: 8n+1, at most 97) read at the clip's own rate, lanczos to the canvas (canvasWidth x canvasHeight: 1440x1088 for 4:3, 1920x1088 for 16:9), the frame-aligned IC-LoRA guide at downscale 1, LTXVTiledFusionSampler with 960x544 tiles at 50% overlap and the 8 distilled sigmas (euler, cfg 1), tiled decode, silent H.264 (the pipeline puts the sound back after the join). video2 = the window before's saved frames; its last 17 (prefixFrom) go in as LTXVAddGuide at frame 0, and prefixFrames (17) drops them from this window's output; absent on the first window (the provider removes that branch). image = an optional reference picture at frame_idx -1 (a second IC-LoRA guide; removed without one). deinterlace keeps one field (fieldWidth x fieldHeight, nearest rows: no blending; ComfyUI has no fieldmatch/yadif/decimate node), removed when off. Stage 2 (Restore to 4K): the same graph on the restored clip with the Detail Refine IC-LoRA, a 2x canvas and 1024x576 tiles. A single generation of a whole clip past 97 frames streams: streaming on the guide and tileFrames 97 on the sampler (the card's other long-clip path; no reference picture there). Needs the ComfyUI-LTXVideo pack. Not validated here: the pack is not installed on this server.",
+ "notes": "Built from the Restore IC-LoRA card's recipe (Hugging Face Lightricks/LTX-2.5-22b-IC-LoRA-Restore at 79245e1, read as data) and the node definitions of ComfyUI-LTXVideo at 220e1d4 (its LTX-2.5_V2V_TiledFusion_Upscale example wires the same nodes): the window (windowStart, windowFrames: 8n+1, at most 97) read at the clip's own rate, lanczos to the canvas (canvasWidth x canvasHeight: 1440x1088 for 4:3, 1920x1088 for 16:9), the frame-aligned IC-LoRA guide at downscale 1, LTXVTiledFusionSampler with 960x544 tiles at 50% overlap and the 8 distilled sigmas (euler, cfg 1), tiled decode, silent H.264 (the pipeline puts the sound back after the join). video2 = the window before's saved frames; its last 17 (prefixFrom) go in as LTXVAddGuide at frame 0, and prefixFrames (17) drops them from this window's output; absent on the first window (the provider removes that branch). image = an optional reference picture at frame_idx -1 (a second IC-LoRA guide; removed without one). deinterlace keeps one field (fieldWidth x fieldHeight, nearest rows: no blending; ComfyUI has no fieldmatch/yadif/decimate node), removed when off. Stage 2 (Restore to 4K): the same graph on the restored clip with the Detail Refine IC-LoRA, a 2x canvas and 1024x576 tiles. A single generation of a whole clip past 97 frames streams: streaming on the guide and tileFrames 97 on the sampler (the card's other long-clip path; no reference picture there). Needs the ComfyUI-LTXVideo pack.",
"validationError": "HTTP 400: missing_node_type: Node 'the archive clip as the frame-aligned IC-LoRA reference (downscale 1, untiled encode); use_streaming only for a whole clip past 97 frames' not found. The custom node may not be installed. (Node ID '#guide')"
},
{