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.
TypeScript ai-videocomfyuicreative-toolsgenerative-aiideogramimage-generationimage-to-3dimage-to-videoltx-videominimax-h3nextjsopen-sourceopen-weightsqwen-imagetext-to-imagevideo-generationwan
FLUX 3 Klein: browser check of the Image studio picker, Edit with ten images, the Train dialog and Settings
Clauded2489157d4b7
diff --git a/src/lib/catalog/models.ts b/src/lib/catalog/models.tsindex 8259fe95..b4c1de75 100644--- a/src/lib/catalog/models.ts+++ b/src/lib/catalog/models.ts@@ -81,7 +81,7 @@ const KLEIN_PROMPT_HELPER: NonNullable<ModelOptions["controls"]>[number] = {label: "Prompt helper",values: ["on", "off"],default: "on",- labels: { on: "On · writes the full caption (BFL's advice)", off: "Off · your words as typed" },+ labels: { on: "On · writes a full caption", off: "Off · your words as typed" },};type OpenSpec = Omit<ModelDef, "engine" | "badges"> & { badges?: ModelDef["badges"] };diff --git a/tests/e2e/flux3-klein.mjs b/tests/e2e/flux3-klein.mjsnew file mode 100644index 00000000..0078e234--- /dev/null+++ b/tests/e2e/flux3-klein.mjs@@ -0,0 +1,299 @@+// nm10-flux3-klein in the browser (no run reaches a GPU or fal): FLUX 3 Klein in the Image studio's model menu on both engines,+// in its "Best for this studio" list on your GPU beside Ideogram 4 and Qwen-Image 2.1, with its price before the run ($0.009 an+// image at 1K in the cloud, Free on your GPU) and its Prompt helper under Options; the Edit studio taking an image and nine+// references for it (ten in all); the Train dialog's FLUX 3 Klein target ($4.30 for 1,000 steps on fal, Free on your GPU, the+// licence as information); and both rows in Settings → Models & licences, switched on. Each page at 1440 and 390 px, light and+// dark, without sideways scroll. The API prices are checked through the preview route: with a fal key ($0.009 at 1K, $0.048 at+// 2K with a LoRA on the /lora twin), else as fal's "connect" answer.+// Usage: node tests/e2e/flux3-klein.mjs [appUrl] [--shots <dir>]+// Nothing is sent: Generate is never pressed. Exits 1 on a failed check.+import fs from "node:fs";+import path from "node:path";+import zlib from "node:zlib";+import { launch } from "./_browser.mjs";++const argv = process.argv.slice(2);+const app = (argv.find((a) => !a.startsWith("--") && argv[argv.indexOf(a) - 1] !== "--shots") ?? "http://localhost:3000").replace(/\/$/, "");+const shots = argv.includes("--shots") ? argv[argv.indexOf("--shots") + 1] : undefined;+if (shots) fs.mkdirSync(shots, { recursive: true });++const failures = [];+const check = (label, ok, extra = "") => {+ console.log(`${ok ? "ok " : "FAIL"} ${label.padEnd(84)}${extra ? ` ${extra}` : ""}`);+ if (!ok) failures.push(label);+};+const flat = (s) => String(s ?? "").replace(/\s+/g, " ").trim();+const status = await (await fetch(`${app}/api/status`)).json().catch(() => ({}));+const fal = !!status.providers?.fal?.configured;+const comfy = !!status.providers?.comfyui?.configured;+const demo = status.demoMode === "on";++/** A small solid PNG (no fixture needed): `seed` picks its colour. */+function png(seed, w = 64, h = 48) {+ const crc = (buf) => {+ let c = ~0;+ for (const b of buf) {+ c ^= b;+ for (let k = 0; k < 8; k++) c = (c >>> 1) ^ (0xedb88320 & -(c & 1));+ }+ return ~c >>> 0;+ };+ const chunk = (type, data) => {+ const len = Buffer.alloc(4);+ len.writeUInt32BE(data.length);+ const td = Buffer.concat([Buffer.from(type), data]);+ const c = Buffer.alloc(4);+ c.writeUInt32BE(crc(td));+ return Buffer.concat([len, td, c]);+ };+ const ihdr = Buffer.alloc(13);+ ihdr.writeUInt32BE(w, 0);+ ihdr.writeUInt32BE(h, 4);+ ihdr[8] = 8;+ ihdr[9] = 2;+ const row = Buffer.alloc(1 + w * 3);+ for (let x = 0; x < w; x++) row.set([(seed * 47) % 256, (seed * 91) % 256, (seed * 13) % 256], 1 + x * 3);+ const raw = Buffer.concat(Array.from({ length: h }, () => row));+ return Buffer.concat([Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]), chunk("IHDR", ihdr), chunk("IDAT", zlib.deflateSync(raw)), chunk("IEND", Buffer.alloc(0))]);+}++async function upload(buf, name) {+ const form = new FormData();+ form.append("file", new Blob([buf], { type: "image/png" }), name);+ const res = await fetch(`${app}/api/uploads`, { method: "POST", body: form });+ if (!res.ok) throw new Error(`upload failed: ${res.status}`);+ return (await res.json()).url;+}++const browser = await launch();+const contextFor = async (engine, width = 1440, colorScheme = "light") => {+ const context = await browser.newContext({ viewport: { width, height: width < 500 ? 844 : 900 }, colorScheme, ...(width < 500 && { isMobile: true, hasTouch: true }) });+ await context.addInitScript((e) => {+ try {+ localStorage.setItem("fuobe.engine", e);+ } catch {}+ }, engine);+ const page = await context.newPage();+ page.setDefaultTimeout(60_000);+ return { context, page };+};+const composer = (page) => page.locator("[data-composer]").first();+const shoot = (page, name) => (shots ? page.screenshot({ path: path.join(shots, name) }) : undefined);+const noSideways = (page) => page.evaluate(() => document.documentElement.scrollWidth <= window.innerWidth + 1);+const openStudio = async (page, where) => {+ await page.goto(`${app}/${where}`, { waitUntil: "load" });+ await composer(page).waitFor({ timeout: 60_000 });+ await page.waitForTimeout(1200);+};+/** Open the model menu from the keyboard; returns its search box. */+const openMenu = async (page) => {+ // On a phone the desktop toolbar's button is in the page but hidden: the visible one.+ const button = page.locator('button[aria-label^="Model: "][aria-label$="Change model"]:visible').first();+ const search = page.getByPlaceholder(/^Search( (all )?models)?/);+ // A page that is still settling (a dev server compiling it) can swallow the first key: try again.+ for (let i = 0; i < 3; i++) {+ await button.waitFor({ state: "visible", timeout: 60_000 });+ await button.focus();+ await page.keyboard.press("Enter");+ if (await search.waitFor({ timeout: 10_000 }).then(() => true, () => false)) return search;+ }+ await search.waitFor();+ return search;+};+/** Pick a model from the open menu by searching for it (arrows, then Enter). */+const pick = async (page, query, id) => {+ const search = page.getByPlaceholder(/^Search( (all )?models)?/);+ await search.fill(query);+ const row = page.locator(`[cmdk-item][data-value$=":${id}"]`).first();+ await row.waitFor({ timeout: 15_000 });+ const text = flat(await row.innerText());+ let picked = false;+ for (let i = 0; i < 12 && !picked; i++) {+ picked = (await row.getAttribute("data-selected")) === "true";+ if (!picked) await page.keyboard.press("ArrowDown");+ }+ await page.keyboard.press("Enter");+ await page.waitForTimeout(900);+ return { text, picked };+};++try {+ // ---- The prices, through the preview route (what the composer and the server agree on).+ const preview = async (body) => (await fetch(`${app}/api/generations?preview=1`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(body) })).json();+ const run = { feature: "image", op: "t2i", prompt: "a fox in snow" };+ const lora = [{ file: "klein-style.safetensors", url: "https://huggingface.co/example/klein-style/resolve/main/klein-style.safetensors", strength: 0.8 }];+ const at1k = await preview({ ...run, modelId: "flux-3-klein", params: { aspectRatio: "1:1", resolution: "1K" } });+ const loras2k = await preview({ ...run, modelId: "flux-3-klein", params: { aspectRatio: "1:1", resolution: "2K" }, loras: lora });+ const local = await preview({ ...run, modelId: "oss-flux3-klein", params: { aspectRatio: "1:1", resolution: "2K" } });+ if (fal) {+ check("api: FLUX 3 Klein at 1K costs $0.009 an image", at1k.costUsd === 0.009 && !at1k.demo, JSON.stringify(at1k.costUsd));+ check("api: with a LoRA at 2K it goes to /lora at $0.012 a megapixel ($0.048)", loras2k.costUsd === 0.048 && loras2k.route?.endpoint === "blackforestlabs/flux-3/klein/text-to-image/lora", `${loras2k.costUsd} ${loras2k.route?.endpoint ?? loras2k.error}`);+ } else if (demo) {+ check("api: without a fal key a FLUX 3 Klein run is a free demo", at1k.demo === true && at1k.costUsd === 0, JSON.stringify(at1k));+ } else {+ check("api: without a fal key the cloud asks to connect fal.ai", /Connect fal\.ai/.test(at1k.error ?? ""), at1k.error ?? JSON.stringify(at1k));+ }+ if (comfy) check("api: on your GPU it is free, on flux3-klein-t2i", local.costUsd === 0 && local.route?.endpoint === "flux3-klein-t2i", `${local.costUsd} ${local.route?.endpoint ?? local.error}`);++ // An element with five photos, for the Train dialog.+ const photos = [];+ for (let i = 0; i < 5; i++) photos.push(await upload(png(i + 1, 640, 640), `klein-ref-${i}.png`));+ const elRes = await fetch(`${app}/api/elements`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ name: "Klein Test", kind: "character", references: photos }) });+ const element = await elRes.json();+ check("api: an element to train", elRes.ok && !!element.id, elRes.ok ? element.id : JSON.stringify(element));++ for (const width of [1440, 390]) {+ for (const scheme of ["light", "dark"]) {+ const tag = `${width} ${scheme}`;++ // ---- Image studio, both engines.+ for (const [engine, id] of [["open", "oss-flux3-klein"], ["cloud", "flux-3-klein"]]) {+ const { context, page } = await contextFor(engine, width, scheme);+ await openStudio(page, "image");+ await openMenu(page);+ if (engine === "open") {+ // Best for this studio, on your GPU: Ideogram 4, Qwen-Image 2.1, then FLUX 3 Klein.+ const best = page.locator('[cmdk-group]').filter({ hasText: "Best for this studio" }).first();+ await best.waitFor({ timeout: 15_000 });+ const names = (await best.locator("[cmdk-item]").evaluateAll((els) => els.map((e) => e.getAttribute("data-value") ?? ""))).map((v) => v.split(":").pop());+ // The studio's default leads (Qwen-Image 2.1 when no caption writer is set up for Ideogram 4).+ check(`${tag} open: Best for this studio: Ideogram 4 and Qwen-Image 2.1, then FLUX 3 Klein`, names.slice(0, 2).sort().join(",") === "oss-ideogram-4,oss-qwen-image-21" && names[2] === "oss-flux3-klein", names.join(","));+ }+ const { text, picked } = await pick(page, "Klein", id);+ if (engine === "cloud") check(`${tag} cloud: the menu lists FLUX 3 Klein with its price`, /FLUX 3 Klein/.test(text) && /<\$0\.01\/image|\$0\.009/.test(text), text);+ else check(`${tag} open: the menu lists FLUX 3 Klein, Free on your GPU`, /FLUX 3 Klein/.test(text) && /\bFree\b/.test(text) && /16-24 GB GPU/.test(text), text);+ check(`${tag} ${engine}: the keyboard reaches the FLUX 3 Klein row`, picked);+ await composer(page).getByRole("textbox").first().fill("A man walking his dog, afternoon sun");+ await page.waitForFunction(() => /\bFree\b|Demo|≈ \$|Connect/.test(document.querySelector("[data-composer]")?.textContent ?? ""), null, { timeout: 20_000 }).catch(() => {});+ const t = flat(await composer(page).innerText());+ check(`${tag} ${engine}: the composer runs FLUX 3 Klein`, /FLUX 3 Klein/.test(t), t.slice(0, 100));+ if (engine === "open") {+ check(`${tag} open: Free before the run`, comfy ? /\bFree\b/.test(t) : /Demo|Free/.test(t), (t.match(/Demo|≈ \$[\d.]+|\bFree\b/) ?? ["no price"])[0]);+ // The Prompt helper under Options (on a phone, in the Settings sheet).+ let scope = composer(page);+ if (width < 500) {+ const settings = composer(page).getByRole("button", { name: /^Settings:/ }).first();+ await settings.focus();+ await page.keyboard.press("Enter");+ scope = page.getByRole("dialog").first();+ await scope.waitFor({ timeout: 10_000 });+ }+ const options = scope.getByRole("button", { name: /^Options/ }).first();+ await options.focus();+ await page.keyboard.press("Enter");+ const helper = page.getByRole("combobox", { name: "Prompt helper" });+ await helper.waitFor({ timeout: 10_000 });+ const hbox = await helper.boundingBox();+ check(`${tag} open: Options shows the Prompt helper, on by default`, /On · writes a full caption/.test(flat(await helper.innerText())), flat(await helper.innerText()));+ // The words read in full: the text is no wider than the box that shows it.+ const cut = await helper.evaluate((b) => {+ const v = b.querySelector('[data-slot="select-value"]') ?? b;+ const r = document.createRange();+ r.selectNodeContents(v);+ return { text: Math.round(r.getBoundingClientRect().width * 10) / 10, box: Math.round(v.getBoundingClientRect().width * 10) / 10 };+ });+ check(`${tag} open: the Prompt helper's words aren't cut off`, cut.text <= cut.box + 0.5, `${cut.text} px of text in ${cut.box} px`);+ check(`${tag} open: the Prompt helper fits the screen`, !!hbox && hbox.x >= 0 && hbox.x + hbox.width <= width + 1, hbox ? `${Math.round(hbox.x)}+${Math.round(hbox.width)}` : "no box");+ await shoot(page, `klein-options-${width}-${scheme}.png`);+ await page.keyboard.press("Escape");+ await page.keyboard.press("Escape");+ if (width < 500) await page.keyboard.press("Escape");+ } else {+ // fal's $0.009 reads "≈ <$0.01" in the composer.+ const price = /≈ <?\$0\.0\d|Demo|Connect fal/;+ check(`${tag} cloud: its price (or fal's connect step) shows before the run`, price.test(t), (t.match(/Demo|Connect[^.]*|≈ <?\$[\d.]+/) ?? ["no price"])[0]);+ }+ check(`${tag} ${engine}: no sideways scroll on the Image studio`, await noSideways(page));+ await shoot(page, `klein-image-${engine}-${width}-${scheme}.png`);+ await context.close();+ }++ // ---- Edit studio on your GPU: the image and nine references.+ {+ const { context, page } = await contextFor("open", width, scheme);+ await openStudio(page, "edit");+ await openMenu(page);+ await pick(page, "Klein", "oss-flux3-klein");+ const inputs = () => composer(page).locator('input[type="file"]');+ await inputs().first().setInputFiles({ name: "photo.png", mimeType: "image/png", buffer: png(20, 320, 240) });+ await page.waitForTimeout(800);+ for (let i = 0; i < 9; i++) {+ await inputs().last().setInputFiles({ name: `ref-${i}.png`, mimeType: "image/png", buffer: png(30 + i) });+ await page.waitForTimeout(500);+ }+ await page.waitForFunction(() => !/Uploading/.test(document.querySelector("[data-composer]")?.textContent ?? ""), null, { timeout: 30_000 }).catch(() => {});+ const removable = await composer(page).getByRole("button", { name: /^Remove reference \d+/ }).count();+ check(`${tag} edit: FLUX 3 Klein takes the image and 9 references`, removable === 9, `${removable} references`);+ const addRef = await composer(page).getByText("Add ref", { exact: true }).count();+ check(`${tag} edit: no "Add ref" once ten are in`, addRef === 0, `${addRef}`);+ await composer(page).getByRole("textbox").first().fill("Put the people of the references around a table in the first image");+ await page.waitForTimeout(800);+ const t = flat(await composer(page).innerText());+ check(`${tag} edit: Free on your GPU before the run`, comfy ? /\bFree\b/.test(t) : /Demo|Free/.test(t), (t.match(/Demo|≈ \$[\d.]+|\bFree\b/) ?? ["no price"])[0]);+ check(`${tag} edit: no sideways scroll with ten images`, await noSideways(page));+ await shoot(page, `klein-edit-10-${width}-${scheme}.png`);+ await context.close();+ }++ // ---- The Train dialog: FLUX 3 Klein under More models.+ if (element.id) {+ const { context, page } = await contextFor("open", width, scheme);+ await page.goto(`${app}/elements/${element.id}`, { waitUntil: "load" });+ const train = page.getByRole("button", { name: /^Train$/ }).first();+ await train.waitFor({ timeout: 60_000 });+ await train.click();+ const dialog = page.getByRole("dialog").first();+ await dialog.waitFor();+ const more = dialog.getByRole("button", { name: /More models/ }).first();+ await more.waitFor({ timeout: 20_000 });+ check(`${tag} train: More models names FLUX 3 Klein`, /FLUX 3 Klein/.test(flat(await more.innerText())), flat(await more.innerText()));+ await more.focus();+ await page.keyboard.press("Enter");+ const klein = dialog.getByRole("region", { name: "FLUX 3 Klein" }).or(dialog.locator('section[aria-label="FLUX 3 Klein"]')).first();+ await klein.waitFor({ timeout: 10_000 });+ await klein.scrollIntoViewIfNeeded();+ const k = flat(await klein.innerText());+ check(`${tag} train: Klein Base LoRA on both engines`, /FLUX 3 Image Klein Base LoRA/.test(k), k.slice(0, 120));+ check(`${tag} train: the licence is information`, /Licence: FLUX Kommunity License v1\.0 .*check its revenue tiers/.test(k), (k.match(/Licence:[^·]*·[^·]*/) ?? [""])[0]);+ check(`${tag} train: Cloud at $4.30, 1,000 steps`, /Cloud \$4\.30/.test(k) && /1,000 steps/.test(k), k.match(/Cloud[^]*?steps/)?.[0]?.slice(0, 120));+ check(`${tag} train: Your GPU is Free`, /Your GPU Free/.test(k));+ check(`${tag} train: says it is not blanket permission for commercial fine-tuning`, /not blanket permission for commercial fine-tuning/.test(k));+ const box = await klein.boundingBox();+ check(`${tag} train: the section fits the screen`, !!box && box.x >= 0 && box.x + box.width <= width + 1, box ? `${Math.round(box.x)}+${Math.round(box.width)}` : "no box");+ check(`${tag} train: no sideways scroll`, await noSideways(page));+ await shoot(page, `klein-train-${width}-${scheme}.png`);+ await context.close();+ }++ // ---- Settings → Models & licences: both rows, switched on.+ {+ const { context, page } = await contextFor("cloud", width, scheme);+ await page.goto(`${app}/settings/models`, { waitUntil: "load" });+ const find = page.getByRole("searchbox", { name: "Search names or licences" }).or(page.getByLabel("Search names or licences")).first();+ await find.waitFor({ timeout: 60_000 });+ await find.fill("Klein");+ await page.waitForTimeout(800);+ for (const [id, want] of [+ ["oss-flux3-klein", /FLUX Kommunity License v1\.0/],+ ["flux-3-klein", /Paid API · fal\.ai[\s\S]*Weights: FLUX Kommunity License v1\.0/],+ ]) {+ const sw = page.locator(`#model-${id}`);+ await sw.waitFor({ timeout: 15_000 });+ const row = sw.locator("xpath=ancestor::li[1]");+ const rowText = flat(await row.innerText());+ check(`${tag} settings: ${id} is listed with its licence`, want.test(rowText), rowText.slice(0, 160));+ check(`${tag} settings: ${id} starts on`, (await sw.getAttribute("aria-checked")) === "true" || (await sw.getAttribute("data-state")) === "checked");+ }+ check(`${tag} settings: no sideways scroll`, await noSideways(page));+ await shoot(page, `klein-settings-${width}-${scheme}.png`);+ await context.close();+ }+ }+ }+} finally {+ await browser.close();+ if (failures.length) {+ console.log(`\n${failures.length} check(s) failed`);+ process.exitCode = 1;+ } else console.log("\nall checks passed");+}