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.

Skills W2: tests for the Katana and Captions lifts and a dry run that ends after the save

Claude66f292f801b0
diff --git a/src/server/recipes.ts b/src/server/recipes.ts
index 510c769c..cabb748d 100644
--- a/src/server/recipes.ts
+++ b/src/server/recipes.ts
@@ -809,11 +809,14 @@ declare global {
}
const DRAFT_TTL_MS = 6 * 60 * 60_000;
+const DRAFT_MAX = 200;
-/** What drafts' checks found, by recipe (kept a few hours, in memory: the server's own word, never the browser's). */
+/** What drafts' checks found, by recipe (the newest few hundred for a few hours, in memory: the server's own word, never the browser's). */
function draftChecks(): Map<string, DraftChecks> {
const m = (globalThis.__fuobeDraftChecks ??= new Map());
for (const [k, v] of m) if (Date.now() - v.at > DRAFT_TTL_MS) m.delete(k);
+ // Oldest first (a Map keeps insertion order; a check of the same recipe is set again, so it moves to the end).
+ while (m.size > DRAFT_MAX) m.delete(m.keys().next().value!);
return m;
}
@@ -883,6 +886,7 @@ export async function checkDraft(input: unknown, level: "plan" | "demo", title =
const key = draftKey(recipe);
const { checks, verified } = await checkEngines({ name: "draft", title }, recipe, level, engines, draftChecks().get(key)?.verified);
const entry = draftChecks().get(key);
+ draftChecks().delete(key);
draftChecks().set(key, { verified: { ...entry?.verified, ...verified }, at: Date.now(), ...(entry?.saved && { saved: entry.saved }) });
if (entry?.saved) adoptChecks(entry.saved, recipe, verified);
return { ok: allPassed(checks), engines: checks, ready: engines.filter((e) => !!verified[e]?.plan) };
@@ -917,6 +921,7 @@ export async function saveDraft(input: DraftSave): Promise<RecipeView> {
deleteSkill(input.name);
throw e;
}
+ draftChecks().delete(key);
draftChecks().set(key, { verified: { ...known, ...verified }, at: Date.now(), saved: input.name });
return recipeView(input.name);
}
diff --git a/tests/recipe-builder.test.ts b/tests/recipe-builder.test.ts
index 2ba30286..724aa1e7 100644
--- a/tests/recipe-builder.test.ts
+++ b/tests/recipe-builder.test.ts
@@ -220,6 +220,25 @@ describe("draftFromGenerations", () => {
expect(mixed.refusals).toEqual([expect.objectContaining({ id: "dub-film", reason: expect.stringContaining("on its own") })]);
});
+ it("lifts a Katana job and a captioned video to their tools", () => {
+ row({ id: "kat-final", feature: "katana", kind: "video", op: "concat", request: { feature: "katana", modelId: "join-clips", op: "concat" }, outputs: [{ url: clip, kind: "video" }] });
+ const now = Date.now();
+ db()
+ .prepare("INSERT INTO katana_jobs (id, data_json, created_at, updated_at) VALUES (?, ?, ?, ?)")
+ .run("kat1", JSON.stringify({ title: "edit", engine: "cloud", reference: clip, photos: [photo], instructions: "keep the jacket", motionModel: "kling-o3", segments: [{ start: 0, end: 5 }, { start: 5, end: 9 }], keepAudio: true, batchId: "kb", steps: { final: "kat-final" }, final: "final" }), now, now);
+ const kat = builder.draftFromGenerations(["kat-final"]).draft!;
+ expect(kat.recipe.steps).toEqual([expect.objectContaining({ kind: "tool", tool: "katana", input: { reference: clip, photos: [photo], instructions: "keep the jacket", segment_seconds: 5, motion_model: "kling-o3", keep_audio: true } })]);
+ expect(kat.candidates.map((c) => [c.type, c.example])).toEqual([
+ ["video", clip],
+ ["image", photo],
+ ["text", "keep the jacket"],
+ ]);
+
+ row({ id: "cap-burn", feature: "captions", kind: "video", op: "captions", request: { feature: "captions", modelId: "veed-subtitles", op: "captions", inputs: { video: clip }, params: { sourceLanguage: "en", targetLanguage: "Spanish" } }, outputs: [{ url: clip, kind: "video" }] });
+ const cap = builder.draftFromGenerations(["cap-burn"]).draft!;
+ expect(cap.recipe.steps).toEqual([expect.objectContaining({ kind: "tool", tool: "add_captions", input: { video: clip, spoken_language: "English", translate_to: "Spanish" } })]);
+ });
+
it("links results handed on by hand (the composer's Animate) into a chain", async () => {
const [a] = gens.createGenerations({ feature: "image", modelId: "nano-banana-pro", op: "t2i", prompt: "a brass desk lamp", params: { numOutputs: 2 } });
await settle([a.id]);
@@ -352,6 +371,19 @@ describe("choices, body, check and save", () => {
expect(() => skills.createSkill({ name: "draft", title: "Draft", description: "x", body: "x" })).toThrow(/reserved/);
});
+ it("writes a dry run still going when the draft was saved into the saved skill", async () => {
+ const p = await turntable();
+ const { draft } = builder.draftFromGenerations([p.byKey.scene.id]);
+ const recipe = lib.buildRecipe(draft!, { varies: { [draft!.candidates.find((c) => c.kind === "text")!.id]: true } });
+ await recipes.checkDraft(recipe, "plan");
+ const dry = recipes.checkDraft(recipe, "demo");
+ const view = await recipes.saveDraft({ name: "scene-early", title: "Scene", description: "A scene.", body: "# Scene", recipe });
+ expect(view.recipe.verified?.cloud?.plan).toBeTruthy();
+ expect(view.recipe.verified?.cloud?.dryRun ?? null).toBeNull();
+ expect((await dry).ok).toBe(true);
+ expect(recipes.recipeView("scene-early").recipe.verified?.cloud?.dryRun).toBeTruthy();
+ });
+
it("refuses to save a recipe whose plan fails, and keeps no half-made skill", async () => {
const bad = { fuobeRecipe: 1, params: [], steps: [{ key: "a", kind: "generate", request: { feature: "image", modelId: "no-such-model", prompt: "x" } }] };
const res = await saveRoute.POST(json({ name: "broken-draft", title: "Broken", description: "x", body: "x", recipe: bad }));