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 & colourise: an account runs it on its own GPU

Adarsh4b781ff1133c
diff --git a/src/app/api/restore/estimate/route.ts b/src/app/api/restore/estimate/route.ts
index d4ad71cd..c3341961 100644
--- a/src/app/api/restore/estimate/route.ts
+++ b/src/app/api/restore/estimate/route.ts
@@ -1,6 +1,6 @@
-import { estimateRestore, RestoreEstimateSchema } from "@/server/restore";
+import { estimateRestore, estimateRestoreSteps, RestoreEstimateSchema } from "@/server/restore";
import { body, handle } from "@/server/shorts-schemas";
-import { priceAs } from "@/server/visitor";
+import { poolPricedCheck } from "@/server/tool-runs";
/** The price, the windows or pieces and the notes for the current settings, before anything runs ("Free" on your GPU). */
async function post(request: Request) {
@@ -10,7 +10,10 @@ async function post(request: Request) {
});
}
-/** A visitor (public sign-up) gets the price of its run on its own GPU, never a demo (src/server/visitor.ts). */
+/**
+ * Priced as the asker's run would go: a visitor's on its own GPU, never a demo; with its place and the price check's
+ * answer on this install's GPUs when the run would go there (poolPricedCheck).
+ */
export async function POST(request: Request) {
- return priceAs(request, () => post(request));
+ return poolPricedCheck(request, () => post(request), (raw) => estimateRestoreSteps(RestoreEstimateSchema.parse(raw)));
}
diff --git a/src/app/api/restore/route.ts b/src/app/api/restore/route.ts
index 1d6a8794..45618f6f 100644
--- a/src/app/api/restore/route.ts
+++ b/src/app/api/restore/route.ts
@@ -1,16 +1,45 @@
-import { createRestore, RestoreBodySchema } from "@/server/restore";
+import { bodyTooBig, guestRun, onceForAccount, runAccountTool, toolViewer } from "@/server/account-tool-run";
+import { createRestore, planRestoreRun, RestoreBodySchema, restoreSteps, startRestore, type RestoreRun } from "@/server/restore";
import { body, handle, once } from "@/server/shorts-schemas";
/**
* Restore & colourise a clip (Fuobe Restore): the prompt is written first when none is given; windows or pieces are
- * joined and the sound put back. The owner's only on a public studio: it plans with the studio's own AI helpers and
- * chains its steps on the server, so guests and accounts get own-gpu-tool from the proxy (src/proxy.ts).
+ * joined and the sound put back. The owner's run as always. An account's runs on its own GPU, with its own files, after
+ * the checks every tool run gets (src/server/account-tool-run.ts): its prompt is its own words or Fuobe's offline
+ * template, never the studio's AI helper. A guest signs up first.
*/
-export async function POST(request: Request) {
+async function post(request: Request) {
return handle(async () => {
const input = await body(request, RestoreBodySchema, "Add the clip to restore and pick an engine");
- // A repeated requestId (a second click on Restore) gets the run the first one started.
- const result = await once("restore", input.requestId, () => createRestore(input));
- return Response.json(result, { status: 201 });
+ const viewer = toolViewer(request);
+ if (viewer.kind !== "account") {
+ // A repeated requestId (a second click on Restore) gets the run the first one started.
+ const result = await once("restore", input.requestId, () => createRestore(input));
+ return Response.json(result, { status: 201 });
+ }
+ let run: RestoreRun | null = null;
+ return onceForAccount(
+ viewer.account,
+ "restore",
+ input.requestId,
+ () =>
+ runAccountTool(request, viewer.account, {
+ tool: "restore",
+ files: [input.source.url, input.reference],
+ plan: async () => restoreSteps((run = await planRestoreRun(input))),
+ start: () => startRestore(run!),
+ }),
+ ({ value, gpuWarning }) => Response.json({ ...value, ...(gpuWarning && { gpuWarning }) }, { status: 201 }),
+ );
}, request);
}
+
+export async function POST(request: Request) {
+ const viewer = toolViewer(request);
+ if (viewer.kind === "guest") return guestRun();
+ if (viewer.kind === "account") {
+ const big = bodyTooBig(request);
+ if (big) return big;
+ }
+ return post(request);
+}
diff --git a/src/lib/guest-access.ts b/src/lib/guest-access.ts
index 14b2c9a4..170b176a 100644
--- a/src/lib/guest-access.ts
+++ b/src/lib/guest-access.ts
@@ -314,6 +314,9 @@ export const ACCOUNT_TOOL_RUNS: readonly RegExp[] = [
// Translate & dub: a dub, and voicing one language of the account's own dub (src/server/dub.ts).
/^\/api\/audio-tools$/,
/^\/api\/dub(\/[^/]+\/voice)?$/,
+ // Restore & colourise: its windows, joins and sound on the account's own GPU, with its own words or Fuobe's offline
+ // template for the prompt. The prompt writer (/api/restore/prompt) stays the owner's: it uses the studio's AI helper.
+ /^\/api\/restore$/,
];
/**
diff --git a/src/server/pool-own-setup.ts b/src/server/pool-own-setup.ts
index 7ef266b0..9faa7144 100644
--- a/src/server/pool-own-setup.ts
+++ b/src/server/pool-own-setup.ts
@@ -3,6 +3,7 @@ import type { GenerationRequest, ModelDef } from "@/lib/catalog/types";
import { MODELS } from "@/lib/catalog/models";
import { directRunFeatures } from "@/lib/catalog/genjutsu";
import { ENHANCE_FEATURES, REGEN_MODEL, wantsH3TwoK } from "@/lib/catalog/regenerate";
+import { RESTORE } from "@/lib/catalog/restore";
import { wantsVoiceFirst } from "@/lib/av/voice-first";
import { ownSetupOnly, type OwnSetup } from "@/lib/own-setup";
import { controlSetup } from "@/lib/own-setup-controls";
@@ -16,7 +17,7 @@ import { poolOnWorkers, poolTakes } from "./hosted";
* What a run on this install's GPUs needs instead, in the "own setup" shape (src/lib/own-setup.ts): the visitor's own GPU
* or key. Two sources, one shape:
* - the static items (ownSetupOnly): a model, or a mode or option of it with an id of its own (MiniMax H3 at 2K,
- * Kandinsky 6.0 Pro, Regenerate, Genjutsu's makers, "Clean the voice first");
+ * Kandinsky 6.0 Pro, Regenerate, Genjutsu's makers, "Clean the voice first", Restore & colourise);
* - what this install's GPUs can't run right now (a model none of them holds, a lane none serves, a card too small or
* of the wrong kind): `needsGpu`, with the memory its workflow needs when the index says.
* The pool gate (hosted-run.ts poolGate) refuses with it, the price check says its label, and GET /api/status sends the
@@ -29,6 +30,8 @@ export function requestSetupIds(req: Pick<GenerationRequest, "modelId" | "op" |
const extra = req.params?.extra ?? {};
if (wantsH3TwoK(req.modelId, req.params?.resolution)) ids.push("regenerate:h3-2k");
if (req.modelId === REGEN_MODEL && req.feature && ENHANCE_FEATURES.has(req.feature)) ids.push("regenerate:enhance");
+ // Restore & colourise's windows: the tool's own setup (its gated IC-LoRA, on the visitor's own GPU).
+ if (req.modelId === RESTORE.model) ids.push("video-tools:restore");
// A model setting whose value has an id of its own (Kandinsky 6.0 at Pro): the one table the pickers read too.
for (const [param, v] of Object.entries(extra)) {
const id = typeof v === "string" || typeof v === "number" ? controlSetup(req.modelId, param, v) : undefined;
diff --git a/src/server/restore.ts b/src/server/restore.ts
index f05acb6a..877086f0 100644
--- a/src/server/restore.ts
+++ b/src/server/restore.ts
@@ -20,7 +20,7 @@ import {
type Size,
} from "@/lib/catalog/restore";
import type { PlanStep } from "@/lib/catalog/shorts";
-import type { Engine, Generation } from "@/lib/catalog/types";
+import type { Engine, Generation, GenerationRequest } from "@/lib/catalog/types";
import { ACCESS_PLACE } from "@/lib/model-access";
import { createPipeline } from "./chains";
import { llmText, llmTextBackend } from "./enhance";
@@ -291,11 +291,61 @@ export async function createRestore(body: z.infer<typeof RestoreBodySchema>): Pr
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);
}
+ return startRestore({ plan, prompt, negative: input.negative, by });
+}
+
+// ---------------------------------------------------------------------------
+// An account's run (public sign-up)
+
+/** A run planned before it starts: its steps, and the words they use. */
+export interface RestoreRun {
+ plan: ReturnType<typeof planRestore>;
+ prompt: string;
+ negative: string;
+ by: PromptAnswer["by"] | "you";
+}
+
+/**
+ * An account's run in the cloud would carry the gated Restore IC-LoRA, which is never sent to a provider on the
+ * account's own key (src/server/loras.ts): it runs on the account's own GPU.
+ */
+export const RESTORE_ON_OWN_GPU = "Restore & colourise runs on your own GPU. Switch the engine to open source to run it.";
+
+/**
+ * An account's run, planned as its own GPU runs it (src/server/account-tool-run.ts): the prompt is the account's own
+ * words, or Fuobe's offline template filled with its hint. The studio's AI helper is never asked.
+ */
+export async function planRestoreRun(body: z.infer<typeof RestoreBodySchema>): Promise<RestoreRun> {
+ if (body.engine === "cloud") throw new ShortsError(RESTORE_ON_OWN_GPU, 422);
+ mustMatchMode(body.engine);
+ mustBeOffered(body.engine);
+ const info = await probeSource(body.source.url);
+ const typed = body.prompt?.trim();
+ const offline = typed ? null : offlineRestorePrompt(body.hint);
+ const prompt = typed || offline!.prompt;
+ const { input } = planInput({ ...body, negative: body.negative?.trim() || offline?.negative }, info, prompt, true);
+ return { plan: planRestore(input), prompt, negative: input.negative, by: typed ? "you" : "offline" };
+}
+
+/** A planned run's steps as the requests they make, with how many earlier steps each waits for (account-tool-run.ts). */
+export const restoreSteps = (run: Pick<RestoreRun, "plan">): { request: GenerationRequest; deps: number }[] =>
+ run.plan.steps.map((s) => ({ request: withChain(s), deps: s.after?.length ?? 0 }));
+
+/** The steps an estimate's settings would run (with the estimate's stand-in prompt), for a price check. */
+export function estimateRestoreSteps(body: z.infer<typeof RestoreEstimateSchema>): { request: GenerationRequest; deps: number }[] {
+ mustMatchMode(body.engine);
+ mustBeOffered(body.engine);
+ const { input } = planInput(body as z.infer<typeof RestoreBodySchema>, {}, body.prompt?.trim() || offlineRestorePrompt(body.hint).prompt, false);
+ return restoreSteps({ plan: planRestore(input) });
+}
+
+/** Start a planned run as one pipeline. Returns the finished video's generation and the words used. */
+export function startRestore(run: RestoreRun): { final: Generation; items: Generation[]; prompt: string; negative: string; by: RestoreRun["by"] } {
let p: ReturnType<typeof createPipeline>;
try {
- p = createPipeline(plan.steps);
+ p = createPipeline(run.plan.steps);
} catch (e) {
throw new ShortsError((e as Error).message, 422);
}
- return { final: p.byKey[plan.final], items: p.items, prompt, negative: input.negative, by };
+ return { final: p.byKey[run.plan.final], items: p.items, prompt: run.prompt, negative: run.negative, by: run.by };
}
diff --git a/tests/hosted-video-audio-tools.test.ts b/tests/hosted-video-audio-tools.test.ts
index 5e5ccecd..ed281cbf 100644
--- a/tests/hosted-video-audio-tools.test.ts
+++ b/tests/hosted-video-audio-tools.test.ts
@@ -45,7 +45,10 @@ const routes = {
turnaroundEstimate: await import("@/app/api/turnaround/estimate/route"),
audio: await import("@/app/api/audio-tools/route"),
dub: await import("@/app/api/dub/route"),
+ restoreEstimate: await import("@/app/api/restore/estimate/route"),
+ restore: await import("@/app/api/restore/route"),
};
+const { ownSetupLabel, ownSetupOnly } = await import("@/lib/own-setup");
const { db } = await import("@/server/db");
const { resetRates } = await import("@/server/rate");
const billing = await import("@/server/billing");
@@ -210,6 +213,43 @@ describe("hosted runs on: an account with no GPU of its own runs them on this in
});
});
+describe("hosted runs on: a tool that runs on a visitor's own setup only", () => {
+ beforeEach(hostedOn);
+ const restore = (f: Files) => ({ engine: "open", source: { url: f.clip, name: "old.mp4", ...src } });
+
+ it("Restore & colourise: its price check says its setup's label, and Run opens that setup with nothing held or made", async () => {
+ const setup = ownSetupOnly("video-tools:restore")!;
+ const f = await filesOf("none");
+ const check = await routes.restoreEstimate.POST(json("/api/restore/estimate", "POST", restore(f), "none"));
+ expect(check.status, await check.clone().text()).toBe(200);
+ const priced = (await check.json()) as { place?: string; quote?: Record<string, unknown> };
+ expect(priced.place).toBe("pool");
+ expect(priced.quote).toMatchObject({ allowed: false, text: ownSetupLabel(setup), ownSetup: setup });
+ const before = reserves();
+ const since = Date.now();
+ const r = await routes.restore.POST(json("/api/restore", "POST", restore(f), "none"));
+ expect(r.status, await r.clone().text()).toBe(403);
+ expect(await r.json()).toMatchObject({ code: "connect-gpu", error: ownSetupLabel(setup), ownSetup: setup });
+ expect(reserves()).toBe(before);
+ expect(places("none", since)).toEqual([]);
+ });
+
+ it("Restore & colourise: an account whose own GPU answers runs it there, with no place in its price check", async () => {
+ const f = await filesOf("gpu");
+ const check = await routes.restoreEstimate.POST(json("/api/restore/estimate", "POST", restore(f), "gpu"));
+ expect(((await check.json()) as { place?: string }).place).toBeUndefined();
+ db().prepare("UPDATE generations SET status = 'canceled' WHERE status IN ('queued', 'running')").run();
+ const before = reserves();
+ const since = Date.now();
+ const r = await send(() => routes.restore.POST(json("/api/restore", "POST", restore(f), "gpu")));
+ expect(r.status, await r.clone().text()).toBe(201);
+ expect(reserves()).toBe(before);
+ const made = places("gpu", since);
+ expect(made.length).toBeGreaterThan(0);
+ expect(made.every((p) => p === "own")).toBe(true);
+ });
+});
+
describe("hosted runs off: as today", () => {
it("no price check names a place, and an account with no GPU of its own is asked to connect one", async () => {
// Its files were uploaded while hosted runs were on (with them off, it can't upload any).
diff --git a/tests/pool-own-setup.test.ts b/tests/pool-own-setup.test.ts
index 8f5a1aa0..a3d43cb5 100644
--- a/tests/pool-own-setup.test.ts
+++ b/tests/pool-own-setup.test.ts
@@ -5,6 +5,7 @@ import { modelOwnSetup, poolOwnSetup, poolRulesOf, poolRunsModel, presetOwnSetup
import { poolRunState, type HostedCheck } from "@/lib/hosted";
import { needsGpu, poolOwnSetups, requestOwnSetup, requestSetupIds } from "@/server/pool-own-setup";
import { loadIndex } from "@/server/gpu/index-file";
+import { planRestore, RESTORE } from "@/lib/catalog/restore";
/**
* What runs on a visitor's own setup only, as the hosted runs see it: the static items a request asks for (a model, or a
@@ -27,6 +28,15 @@ describe("a request's own setup", () => {
expect(requestOwnSetup({ feature: "video", modelId: H3, op: "t2v", params: { resolution: "2K" }, engine: "open" })).toEqual(ownSetupOnly("regenerate:h3-2k"));
expect(requestOwnSetup({ feature: "video", modelId: "oss-h3-regenerate", op: "upscale-video", params: {}, engine: "open" })).toEqual(ownSetupOnly("oss-h3-regenerate"));
});
+
+ it("asks Restore & colourise's windows by the tool's own id, and none of its joins", () => {
+ 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 windows = plan.steps.filter((s) => s.request.modelId === RESTORE.model);
+ expect(windows.length).toBeGreaterThan(0);
+ for (const s of windows) expect(requestOwnSetup({ ...s.request, engine: "open" })).toEqual(ownSetupOnly("video-tools:restore"));
+ for (const s of plan.steps.filter((x) => x.request.modelId !== RESTORE.model)) expect(requestSetupIds(s.request)).not.toContain("video-tools:restore");
+ expect(ownSetupOnly("video-tools:restore")).toMatchObject({ need: "gpu" });
+ });
});
describe("the open models this install's GPUs can't run right now", () => {
diff --git a/tests/restore-account.test.ts b/tests/restore-account.test.ts
new file mode 100644
index 00000000..23728296
--- /dev/null
+++ b/tests/restore-account.test.ts
@@ -0,0 +1,197 @@
+import fs from "node:fs";
+import path from "node:path";
+import { afterAll, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
+import { startFakeComfy, type FakeComfy } from "./helpers/fake-comfy-runner";
+import { tempDir } from "./helpers/temp-dir";
+
+vi.mock("next/server", async (importOriginal) => ({ ...(await importOriginal<typeof import("next/server")>()), connection: async () => {} }));
+
+/**
+ * Restore & colourise for a signed-in account (public sign-up): its run goes to the account's own ComfyUI (a stand-in
+ * here) as one batch of its own steps, with only its own clip; the prompt is its own words or Fuobe's offline template,
+ * and the studio's ComfyUI and AI helper are never reached. A guest signs up first; an account with no GPU is asked to
+ * connect one before anything is made; the cloud engine says to switch to the open engine.
+ */
+const dir = tempDir("fuobe-restore-account-");
+process.env.FUOBE_DATA_DIR = dir;
+process.env.COMFYUI_URL = "http://owner-comfy.test:8188";
+process.env.OLLAMA_URL = "http://owner-llm.test:11434";
+process.env.FUOBE_PUBLIC_SIGNUP = "1";
+delete process.env.FUOBE_PASSWORD;
+delete process.env.FUOBE_ALLOW_PRIVATE_URLS;
+delete process.env.FUOBE_HOSTED_RUNS;
+globalThis.__fuobeTestDiskFree = 1e13;
+
+// Plain fetch is the install's own ComfyUI, its LLM or anything else: recorded, so a test sees that nothing reached them.
+const realFetch = globalThis.fetch;
+const fetched: string[] = [];
+globalThis.fetch = (async (input: RequestInfo | URL, init?: RequestInit) => {
+ const url = new URL(String(input instanceof Request ? input.url : input));
+ if (url.hostname === "127.0.0.1") return realFetch(input, init);
+ fetched.push(url.toString());
+ if (url.host !== "owner-comfy.test:8188") return new Response("not stubbed", { status: 599 });
+ if (url.pathname === "/system_stats") return Response.json({ system: { comfyui_version: "owner", ram_total: 1 }, devices: [] });
+ return Response.json({});
+}) as typeof fetch;
+
+const auth = await import("@/server/auth");
+const restoreRoute = await import("@/app/api/restore/route");
+const estimateRoute = await import("@/app/api/restore/estimate/route");
+const uploadsRoute = await import("@/app/api/uploads/route");
+const gpuRoute = await import("@/app/api/account/gpu/route");
+const access = await import("@/lib/guest-access");
+const { getGeneration } = await import("@/server/generations");
+const { db } = await import("@/server/db");
+const { resetRates } = await import("@/server/rate");
+const { clearAccountLoras } = await import("@/server/account-loras");
+const { setSetting } = await import("@/server/settings");
+const { saveFile } = await import("@/server/storage");
+const { runAsTenant } = await import("@/server/tenant");
+const { RESTORE_ON_OWN_GPU } = await import("@/server/restore");
+const { offlineRestorePrompt, RESTORE } = await import("@/lib/catalog/restore");
+
+const CLIP = fs.readFileSync(path.join(__dirname, "fixtures/shorts-12s.mp4"));
+
+let fake: FakeComfy;
+let a = "";
+let c = "";
+const cookies: Record<string, string> = {};
+beforeAll(async () => {
+ fake = await startFakeComfy({ loras: [], delayMs: 0, output: "video" });
+ globalThis.__fuobeTestGpuPort = fake.port;
+ auth.setPassword("install password");
+ // The owner's AI helper is set up: an account's run must still never use it.
+ setSetting("enhanceProvider", "ollama");
+ for (const [k, email] of [
+ ["a", "[email protected]"],
+ ["c", "[email protected]"],
+ ] as const) {
+ const id = auth.createAccount(email, "long enough").id;
+ cookies[k] = `${auth.SESSION_COOKIE}=${auth.createSession(id).value}`;
+ if (k === "a") a = id;
+ else c = id;
+ }
+ // A links its own ComfyUI; C has neither a GPU nor a key.
+ expect((await gpuRoute.PUT(json("/api/account/gpu", "PUT", { url: fake.url }, "a"))).status).toBe(200);
+});
+afterAll(async () => {
+ globalThis.fetch = realFetch;
+ globalThis.__fuobeTestGpuPort = undefined;
+ globalThis.__fuobeTestDiskFree = undefined;
+ await fake.close();
+});
+beforeEach(() => {
+ resetRates();
+ clearAccountLoras(a);
+ db().prepare("UPDATE generations SET status = 'canceled' WHERE status IN ('queued', 'running') AND json_extract(request_json, '$.account') IS NOT NULL").run();
+});
+
+function json(url: string, method: string, body: unknown, who?: string): Request {
+ const text = JSON.stringify(body);
+ return new Request(`http://localhost:3000${url}`, {
+ method,
+ headers: { host: "localhost:3000", "content-type": "application/json", "content-length": String(Buffer.byteLength(text)), ...(who && { cookie: cookies[who] }) },
+ body: text,
+ });
+}
+
+async function upload(who: string, data: Buffer, type: string, name: string): Promise<string> {
+ const r = await uploadsRoute.POST(new Request("http://localhost:3000/api/uploads", { method: "POST", headers: { host: "localhost:3000", cookie: cookies[who], "content-type": type, "x-file-name": name, "content-length": String(data.length) }, body: new Uint8Array(data) }));
+ expect(r.status, await r.clone().text()).toBe(201);
+ return ((await r.json()) as { url: string }).url;
+}
+
+/** Send a run; a LoRA its ComfyUI lacks is put there (the 409 names it), then it is sent again. */
+async function start(send: () => Promise<Response>): Promise<Response> {
+ let r = await send();
+ if (r.status === 409) {
+ const j = (await r.clone().json()) as { code: string; fix?: { items: { file: string }[] } };
+ if (j.code === "comfy_missing_model" && j.fix) {
+ fake.opts.loras = [...(fake.opts.loras ?? []), ...j.fix.items.map((i) => i.file)];
+ clearAccountLoras(a);
+ r = await send();
+ }
+ }
+ return r;
+}
+
+/** What the studio reads of its own ComfyUI and AI helper to say whether they answer: never a job or a call to them. */
+const notStatus = (u: string) => !/\/(system_stats|api\/tags)$/.test(u);
+const count = () => (db().prepare("SELECT COUNT(*) AS n FROM generations").get() as { n: number }).n;
+const source = (url: string) => ({ url, name: "old.mp4", duration: 12, fps: 16, width: 72, height: 128, hasAudio: true });
+
+describe("Restore & colourise for an account", () => {
+ it("runs on its own ComfyUI as one batch of its own steps, with Fuobe's offline prompt; nothing of the studio's is reached", async () => {
+ const clip = await upload("a", CLIP, "video/mp4", "old.mp4");
+ fetched.length = 0;
+ const hint = "a market in 1923";
+ const r = await start(() => restoreRoute.POST(json("/api/restore", "POST", { engine: "open", source: source(clip), hint, requestId: "restore-run-1" }, "a")));
+ expect(r.status, await r.clone().text()).toBe(201);
+ const body = (await r.json()) as { final: { id: string }; items: { id: string; batchId: string | null }[]; prompt: string; by: string };
+ expect(body.by).toBe("offline");
+ expect(body.prompt).toBe(offlineRestorePrompt(hint).prompt);
+ expect(new Set(body.items.map((g) => g.batchId)).size).toBe(1);
+ for (const { id } of body.items) {
+ const g = getGeneration(id)!;
+ expect(g.request.account, id).toBe(a);
+ expect(g.provider, id).toBe("comfyui");
+ }
+ expect(body.items.some(({ id }) => getGeneration(id)!.modelId === RESTORE.model)).toBe(true);
+ expect(getGeneration(body.final.id)!.request.feature).toBe(RESTORE.feature);
+ expect(fetched.filter(notStatus)).toEqual([]);
+ // A repeat of the same request id gets the first run.
+ const n = count();
+ const again = await restoreRoute.POST(json("/api/restore", "POST", { engine: "open", source: source(clip), hint, requestId: "restore-run-1" }, "a"));
+ expect(((await again.json()) as { final: { id: string } }).final.id).toBe(body.final.id);
+ expect(count()).toBe(n);
+ });
+
+ it("keeps the account's own words when it wrote the prompt", async () => {
+ const clip = await upload("a", CLIP, "video/mp4", "old2.mp4");
+ const r = await start(() => restoreRoute.POST(json("/api/restore", "POST", { engine: "open", source: source(clip), prompt: "a harbour at dawn, natural colour" }, "a")));
+ expect(r.status, await r.clone().text()).toBe(201);
+ const body = (await r.json()) as { prompt: string; by: string };
+ expect(body).toMatchObject({ prompt: "a harbour at dawn, natural colour", by: "you" });
+ });
+
+ it("says to switch to the open engine for a cloud run, before anything is made", async () => {
+ const clip = await upload("a", CLIP, "video/mp4", "old3.mp4");
+ const n = count();
+ const r = await restoreRoute.POST(json("/api/restore", "POST", { engine: "cloud", source: source(clip) }, "a"));
+ expect(r.status).toBe(422);
+ expect((await r.json()).error).toBe(RESTORE_ON_OWN_GPU);
+ expect(count()).toBe(n);
+ });
+
+ it("takes only its own clip", async () => {
+ const n = count();
+ const r = await restoreRoute.POST(json("/api/restore", "POST", { engine: "open", source: source("/api/files/uploads/someone-else.mp4") }, "a"));
+ expect(r.status).toBeGreaterThanOrEqual(400);
+ expect(count()).toBe(n);
+ });
+
+ it("asks an account with neither a GPU nor a key to connect one, before anything is made", async () => {
+ const clip = runAsTenant({ kind: "account", id: c }, () => saveFile({ data: CLIP, contentType: "video/mp4", source: "upload", name: "c.mp4" }).url);
+ const n = count();
+ const r = await restoreRoute.POST(json("/api/restore", "POST", { engine: "open", source: source(clip) }, "c"));
+ expect(r.status, await r.clone().text()).toBe(403);
+ expect(r.headers.get(access.CONNECT_GPU_HEADER)).toBe("1");
+ expect((await r.json()).code).toBe("connect-gpu");
+ expect(count()).toBe(n);
+ });
+
+ it("gives a guest the sign-up card", async () => {
+ const r = await restoreRoute.POST(json("/api/restore", "POST", { engine: "open", source: source("/api/files/uploads/x.mp4") }));
+ expect(r.status).toBe(401);
+ expect(r.headers.get(access.GUEST_HEADER)).toBe("1");
+ });
+
+ it("prices an account's run on its own GPU, with the hosted runs off as today", async () => {
+ const r = await estimateRoute.POST(json("/api/restore/estimate", "POST", { engine: "open", source: source("/api/files/uploads/x.mp4") }, "a"));
+ expect(r.status, await r.clone().text()).toBe(200);
+ const e = await r.json();
+ expect(e).toMatchObject({ engine: "open", demo: false, costUsd: 0 });
+ expect(e).not.toHaveProperty("place");
+ expect(e).not.toHaveProperty("loraReady");
+ });
+});
diff --git a/tests/restore-signup.test.ts b/tests/restore-signup.test.ts
index 1e5b110b..5fd0df99 100644
--- a/tests/restore-signup.test.ts
+++ b/tests/restore-signup.test.ts
@@ -4,9 +4,9 @@ import { tempDir } from "./helpers/temp-dir";
/**
* Restore & colourise under the owner's public sign-up rules (docs/public-signup.md): its price
- * check is open to guests and accounts and priced for their own GPU, never a demo; its run and its prompt writer plan
- * with the studio's own AI helpers and chain on the server, so a guest or an account gets own-gpu-tool (with or
- * without a GPU); the owner's are unchanged. The GPU pre-flight board has its row, on graphs the requirement index knows.
+ * check is open to guests and accounts and priced for their own GPU, never a demo; its run is open to accounts (a guest
+ * signs up first); its prompt writer uses the studio's own AI helper, so a guest or an account gets own-gpu-tool (with
+ * or without a GPU); the owner's are unchanged. The GPU pre-flight board has its row, on graphs the requirement index knows.
*/
const dir = tempDir("fuobe-restore-signup-");
@@ -72,21 +72,35 @@ describe("the proxy: Restore & colourise as main treats a tool", () => {
expect(passed(proxy(req("/video-tools/restore", { cookie })))).toBe(true);
});
- it("opens the price check to guests and accounts; the run and the writer get own-gpu-tool, with or without a GPU", async () => {
+ it("opens the price check to guests and accounts, and the run to accounts; a guest's run signs up first", async () => {
+ process.env.FUOBE_PUBLIC_SIGNUP = "1";
+ const bare = auth.createSession(newAccount().id).value;
+ const withGpu = newAccount();
+ auth.setAccountGpu(withGpu.id, { url: "https://gpu.example" });
+ const gpu = auth.createSession(withGpu.id).value;
+ for (const cookie of [undefined, bare, gpu]) expect(passed(proxy(req("/api/restore/estimate", { method: "POST", cookie }))), String(cookie)).toBe(true);
+ const guest = proxy(req("/api/restore", { method: "POST" }));
+ expect(guest.status).toBe(401);
+ expect(guest.headers.get(access.GUEST_HEADER)).toBe("1");
+ expect(passed(proxy(req("/api/restore", { method: "POST", cookie: gpu })))).toBe(true);
+ // Neither a GPU nor a key of its own: asked to connect one, as for every tool.
+ const none = proxy(req("/api/restore", { method: "POST", cookie: bare }));
+ expect(none.status).toBe(403);
+ expect(none.headers.get(access.CONNECT_GPU_HEADER)).toBe("1");
+ });
+
+ it("keeps the prompt writer the owner's: it uses the studio's AI helper", async () => {
process.env.FUOBE_PUBLIC_SIGNUP = "1";
const bare = auth.createSession(newAccount().id).value;
const withGpu = newAccount();
auth.setAccountGpu(withGpu.id, { url: "https://gpu.example" });
const gpu = auth.createSession(withGpu.id).value;
for (const cookie of [undefined, bare, gpu]) {
- expect(passed(proxy(req("/api/restore/estimate", { method: "POST", cookie }))), String(cookie)).toBe(true);
- for (const p of RUNS) {
- const r = proxy(req(p, { method: "POST", cookie }));
- expect(r.status, p).toBe(403);
- expect(r.headers.get(access.CONNECT_GPU_HEADER), p).toBeNull();
- expect(r.headers.get(access.GUEST_HEADER), p).toBeNull();
- expect(await r.json(), p).toEqual({ error: access.OWN_GPU_TOOL_MESSAGE, code: "own-gpu-tool" });
- }
+ const r = proxy(req("/api/restore/prompt", { method: "POST", cookie }));
+ expect(r.status).toBe(403);
+ expect(r.headers.get(access.CONNECT_GPU_HEADER)).toBeNull();
+ expect(r.headers.get(access.GUEST_HEADER)).toBeNull();
+ expect(await r.json()).toEqual({ error: access.OWN_GPU_TOOL_MESSAGE, code: "own-gpu-tool" });
}
});