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
Uploads: a guest, or an account with no GPU or key, is asked before the file chooser
Adarsh9a48552bc8d5
diff --git a/src/components/color-grade-view.tsx b/src/components/color-grade-view.tsxindex 6dfb3ae2..0ff7791d 100644--- a/src/components/color-grade-view.tsx+++ b/src/components/color-grade-view.tsx@@ -416,7 +416,7 @@ function Grader() {<h1 className="font-heading text-[22px] leading-none">Color grading</h1><span className="ml-2 hidden rounded-full bg-success/15 px-2 py-0.5 text-[11px] font-medium text-success sm:inline">Free · runs in your browser</span><div className="ml-auto flex items-center gap-2">- {input && <MediaSlot label="Replace" kind={input.kind} value={null} onChange={pick} onFile={pickFile} />}+ {input && <MediaSlot label="Replace" kind={input.kind} value={null} onChange={pick} onFile={pickFile} local />}</div></header><div className="flex min-h-0 flex-1 flex-col gap-3 px-3 pb-3 sm:px-6 lg:flex-row">@@ -436,8 +436,8 @@ function Grader() {<p className="mt-1 text-[13px]">Drop a file, or pick one from your library. Nothing is uploaded until you save.</p></div><div className="flex gap-2">- <MediaSlot label="Image" kind="image" value={null} onChange={pick} onFile={pickFile} size="lg" />- <MediaSlot label="Video" kind="video" value={null} onChange={pick} onFile={pickFile} size="lg" />+ <MediaSlot label="Image" kind="image" value={null} onChange={pick} onFile={pickFile} local size="lg" />+ <MediaSlot label="Video" kind="video" value={null} onChange={pick} onFile={pickFile} local size="lg" /></div><buttontype="button"diff --git a/src/components/studio/attach-menu.tsx b/src/components/studio/attach-menu.tsxindex b3da0520..d2049f55 100644--- a/src/components/studio/attach-menu.tsx+++ b/src/components/studio/attach-menu.tsx@@ -5,6 +5,7 @@ import { useRef, useState } from "react";import { toast } from "sonner";import { Button } from "@/components/ui/button";import { Kbd } from "@/components/ui/kbd";+import { useAskBeforeUpload } from "@/lib/api";import type { MediaKind } from "@/lib/catalog/types";import { useModKey } from "@/lib/keys";import { ACCEPT, LibraryGrid, type SlotValue } from "./media-slot";@@ -37,7 +38,15 @@ export function AttachMenu({ kinds, onFiles, onPick }: { kinds: MediaKind[]; onFconst [open, setOpen] = useState(false);const input = useRef<HTMLInputElement>(null);const mod = useModKey();+ const askFirst = useAskBeforeUpload();+ /** Someone whose upload would be refused gets its card instead of the file chooser: the panel makes way for it. */+ const refused = () => {+ if (!askFirst()) return false;+ setOpen(false);+ return true;+ };const paste = async () => {+ if (refused()) return;try {const files = await clipboardFiles();if (!files.length) return toast("Nothing to paste — copy an image first");@@ -68,7 +77,7 @@ export function AttachMenu({ kinds, onFiles, onPick }: { kinds: MediaKind[]; onF><div className="space-y-3"><div className="grid grid-cols-2 gap-1.5">- <Button variant="secondary" className="h-10 justify-start gap-2" onClick={() => input.current?.click()}>+ <Button variant="secondary" className="h-10 justify-start gap-2" onClick={() => refused() || input.current?.click()}><Upload /> Upload</Button><Button variant="secondary" className="h-10 justify-start gap-2" onClick={paste}>diff --git a/src/components/studio/attachments.ts b/src/components/studio/attachments.tsindex 4f3d12e3..aeb67f69 100644--- a/src/components/studio/attachments.ts+++ b/src/components/studio/attachments.ts@@ -3,6 +3,7 @@import { nanoid } from "nanoid";import { createContext, useCallback, useContext, useEffect, useMemo, useRef } from "react";import { toast } from "sonner";+import { useAskBeforeUpload } from "@/lib/api";import { MAX_KEYFRAMES } from "@/lib/catalog/keyframes";import { acceptedKinds, addFrame, fitAttachments, noRoomMessage, onImageChange, placeAttachment, removeFrame, replaceAttachment } from "@/lib/composer";import type { InputSlot, MediaKind } from "@/lib/catalog/types";@@ -41,7 +42,9 @@ const MAX_AT_ONCE = 8;* Attach files to the studio draft: paste, drop, the "+" menu and the slot tiles all go through* here. Each file is placed once with its local preview, then swapped for the uploaded asset by* id (never re-added if it was removed meanwhile). A file with no room (references full, or a- * model that takes none) is never uploaded: the person is told why instead.+ * model that takes none) is never uploaded: the person is told why instead. Someone whose upload+ * would be refused (a guest, an account with neither its own GPU nor its own key) gets that card+ * at once, before any preview is placed.*/export function useAttach(slots: InputSlot[], refMax: number) {const { config, draft, setDraft } = useStudio();@@ -50,10 +53,12 @@ export function useAttach(slots: InputSlot[], refMax: number) {useEffect(() => {latest.current = draft;});+ const askFirst = useAskBeforeUpload();/** Upload a file: `place` runs once with the local preview, the result replaces it by id. */const start = useCallback((file: File, place: (v: SlotValue) => void, kind?: MediaKind) => {+ if (askFirst()) return;const id = nanoid(8);const entry = { ac: new AbortController(), seen: false };inflight.set(id, entry);@@ -78,7 +83,7 @@ export function useAttach(slots: InputSlot[], refMax: number) {{ signal: entry.ac.signal },);},- [setDraft],+ [setDraft, askFirst],);const kinds = useMemo(() => new Set<MediaKind>(acceptedKinds(slots, config.multiRef)), [slots, config.multiRef]);@@ -113,6 +118,8 @@ export function useAttach(slots: InputSlot[], refMax: number) {const attachFiles = useCallback((files: File[]) => {+ // A paste, a drop on the page or the "+" menu: one card for the lot, and no toast about kinds or room on top.+ if (askFirst()) return;const frames = latest.current.frames;// Frames mode: each still becomes the next frame, up to ten.const usable = files.filter((f) => (frames ? kindOfFile(f) === "image" : kinds.has(kindOfFile(f))));@@ -130,7 +137,7 @@ export function useAttach(slots: InputSlot[], refMax: number) {if (rejected.length) noRoom();for (const i of placed) start(batch[i], place);},- [kinds, start, place, noRoom, slots, config.multiRef, refMax],+ [askFirst, kinds, start, place, noRoom, slots, config.multiRef, refMax],);/** A slot tile: replace its value (an upload it held is cancelled by the reaper). A drawing belongs to the image it was made on. */diff --git a/src/components/studio/audio-controls.tsx b/src/components/studio/audio-controls.tsxindex c89131c0..4b9fa946 100644--- a/src/components/studio/audio-controls.tsx+++ b/src/components/studio/audio-controls.tsx@@ -5,7 +5,7 @@ import Link from "next/link";import { useMemo, useRef, useState } from "react";import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";import { Slider } from "@/components/ui/slider";-import { useElements } from "@/lib/api";+import { useAskBeforeUpload, useElements } from "@/lib/api";import type { GenParams, ModelDef } from "@/lib/catalog/types";import { cn } from "@/lib/utils";import { fileToSlot, type SlotValue } from "./media-slot";@@ -69,6 +69,12 @@ export function VoicePicker({onChange(c);setOpen(false);};+ // Someone whose upload would be refused (a guest, an account with no GPU or key) gets its card, not the file chooser.+ const askFirst = useAskBeforeUpload();+ const upload = () => {+ if (!askFirst()) return file.current?.click();+ setOpen(false);+ };return (<Popover open={open} onOpenChange={setOpen}><PopoverTrigger asChild>@@ -82,7 +88,7 @@ export function VoicePicker({<Section title="Clone a voice"><div className="flex flex-wrap gap-1.5 px-2 pb-1"><VoiceRecorder onRecorded={(v) => pick({ kind: "sample", value: v })} />- <button type="button" onClick={() => file.current?.click()} className={cn(chip, idle)}>+ <button type="button" onClick={upload} className={cn(chip, idle)}><Upload className="size-3.5" /> Upload</button><inputdiff --git a/src/components/studio/frames-strip.tsx b/src/components/studio/frames-strip.tsxindex 6f370523..58d0d7a7 100644--- a/src/components/studio/frames-strip.tsx+++ b/src/components/studio/frames-strip.tsx@@ -4,6 +4,7 @@ import { Loader2, Minus, Plus, TriangleAlert, X } from "lucide-react";import { useId, useRef, useState } from "react";import { toast } from "sonner";import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";+import { useAskBeforeUpload } from "@/lib/api";import { FRAMES_HINT, frameRange, frameRole, frameTimes, KEYFRAME_SNAP, MAX_KEYFRAMES, secondsLabel } from "@/lib/catalog/keyframes";import type { FrameAttachment } from "@/lib/composer";import { cn } from "@/lib/utils";@@ -177,8 +178,10 @@ function FrameTile({const input = useRef<HTMLInputElement>(null);const [over, setOver] = useState(false);const name = index === 0 ? "the start frame" : `frame ${index + 1}`;+ // Someone whose upload would be refused (a guest, an account with no GPU or key) gets its card, not the file chooser.+ const askFirst = useAskBeforeUpload();const take = (f: File | undefined) => {- if (!f) return;+ if (!f || askFirst()) return;if (kindOfFile(f) !== "image") return void toast(wrongKindMessage("image"));onFile(f);};@@ -203,7 +206,7 @@ function FrameTile({<TooltipTrigger asChild><buttontype="button"- onClick={() => input.current?.click()}+ onClick={() => askFirst() || input.current?.click()}aria-label={`Frame ${index + 1}, ${role.toLowerCase()} at ${secondsLabel(time)}: replace`}className={cn("size-full overflow-hidden rounded-xl border bg-muted outline-none focus-visible:ring-2 focus-visible:ring-ring/50", over && "ring-2 ring-primary")}>diff --git a/src/components/studio/media-slot.tsx b/src/components/studio/media-slot.tsxindex 1e04099e..f1c4f12a 100644--- a/src/components/studio/media-slot.tsx+++ b/src/components/studio/media-slot.tsx@@ -6,7 +6,7 @@ import { useRef, useState } from "react";import { toast } from "sonner";import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";-import { useAssets, type Asset } from "@/lib/api";+import { useAskBeforeUpload, useAssets, type Asset } from "@/lib/api";import { toastError } from "@/lib/refusals";import { postFile } from "@/lib/upload";import type { MediaKind } from "@/lib/catalog/types";@@ -211,7 +211,11 @@ function LibraryPicker({ kind, onPick }: { kind: MediaKind; onPick: (v: SlotValu);}-/** A compact attachment tile: empty (dashed, click/drop to upload) or filled (thumbnail + remove). */+/**+ * A compact attachment tile: empty (dashed, click/drop to upload) or filled (thumbnail + remove). Someone whose upload+ * would be refused (a guest, an account with neither its own GPU nor its own key) is asked first instead of getting the+ * file chooser, unless the tile keeps the file in the browser (`local`).+ */export function MediaSlot({label,kind,@@ -220,6 +224,7 @@ export function MediaSlot({required,size = "md",onFile,+ local,slotKey,caption,}: {@@ -231,6 +236,8 @@ export function MediaSlot({size?: "md" | "lg";/** Take over file handling (e.g. to append to a list with a stable id). */onFile?: (f: File) => void;+ /** `onFile` keeps the file in this browser and uploads nothing (Color grading): anyone may pick one. */+ local?: boolean;/** Marks the tile so the composer can point at it ("Add a start frame"). */slotKey?: string;/** Filled, keep the slot's role on the thumbnail ("Target", "Face"), so two photos can be told apart. */@@ -242,6 +249,9 @@ export function MediaSlot({if (onFile) onFile(f);else void fileToSlot(f, onChange, kind);};+ const askFirst = useAskBeforeUpload();+ /** True when the upload would be refused and its card opened instead. */+ const refused = () => !local && askFirst();const input = useRef<HTMLInputElement>(null);const [over, setOver] = useState(false);const dim = size === "lg" ? "size-20" : "size-14";@@ -263,7 +273,7 @@ export function MediaSlot({e.stopPropagation();setOver(false);const f = e.dataTransfer.files?.[0];- if (f) handleFile(f);+ if (f && !refused()) handleFile(f);}}>{value ? (@@ -290,7 +300,7 @@ export function MediaSlot({) : (<buttontype="button"- onClick={() => input.current?.click()}+ onClick={() => refused() || input.current?.click()}aria-label={`${label}${required ? " (required)" : ""}: upload`}className={cn("flex size-full flex-col items-center justify-center gap-0.5 rounded-xl border border-dashed border-border-strong text-muted-foreground transition-colors hover:border-primary hover:bg-brand-faint hover:text-brand-text",diff --git a/src/lib/api.ts b/src/lib/api.tsindex a7cd6fcd..dd5fa043 100644--- a/src/lib/api.ts+++ b/src/lib/api.ts@@ -1229,6 +1229,29 @@ function requestPath(input: RequestInfo | URL): string {}}+/** Opens "Create a free account" on its own (GuestPrompt), e.g. before a guest's file chooser: it could only be refused. */+export function askToSignUp(action: RefusalAction = "upload"): void {+ window.dispatchEvent(new CustomEvent<RefusalDetail>(GUEST_PROMPT_EVENT, { detail: { action } }));+}++/**+ * For a file chooser, a drop or a paste: asks first whoever the upload would refuse, instead of letting them pick a file+ * for nothing. A guest gets "Create a free account", an account with neither its own GPU nor its own key "Connect your+ * GPU or add a key". The function returns true when it asked (the chooser stays shut, the file stays out), and false+ * for anyone the upload takes, and while who is looking isn't known yet (the server's refusal opens the same card).+ */+export function useAskBeforeUpload(): () => boolean {+ const guest = useIsGuest();+ const seen = useStatus().data?.viewer;+ const nowhere = seen?.kind === "account" && !seen.gpu.connected && !seen.keys?.length;+ return useCallback(() => {+ if (guest) askToSignUp("upload");+ else if (nowhere) window.dispatchEvent(new CustomEvent<RefusalDetail>(CONNECT_GPU_EVENT, { detail: { action: "upload" } }));+ else return false;+ return true;+ }, [guest, nowhere]);+}+/*** The card a refusal opens on this page. None on the sign-in page: the visitor is signing in already,* and a wrong password there is the form's own error.diff --git a/tests/e2e/guest-prompt.mjs b/tests/e2e/guest-prompt.mjsindex b0eaffb7..b081f527 100644--- a/tests/e2e/guest-prompt.mjs+++ b/tests/e2e/guest-prompt.mjs@@ -1,11 +1,15 @@-// A refused change shows one card, in the browser. A guest uploads a picture in Color Grading: "Create a free account-// to run this" opens alone (no error toast, no trip to the sign-in page). Its Log in and Sign up free open the sign-in-// page with the card closed, Back closes it too, and a wrong password on the sign-in page is the form's own error.-// The same in a studio with its own fetch helper: a guest presses New canvas in Canvas. A guest's message in Assist opens-// no card (it's the owner's: "Assist runs on the studio owner's AI…" is its toast, as an account's).-// Then an account without its GPU: "Connect your GPU" opens alone, its form inside it, and closes when the page changes.-// None on a message in Assist (it's the owner's, the same toast), and none on New canvas, whose refusal ("Free accounts-// can't save…") is its toast.+// A refused change shows one card, in the browser. A guest presses Face Swap's Target photo: no file chooser opens (the+// upload could only be refused), and "Create a free account to add your own files" opens alone (no error toast, no trip+// to the sign-in page). Its Log in and Sign up free open the sign-in page with the card closed, Back closes it too, and+// a wrong password on the sign-in page is the form's own error. An upload sent anyway is refused with the same card.+// Color Grading runs in the browser: a guest grades a picture of its own there, with no card and no upload.+// A run keeps the run's words: a guest presses Generate in the Image studio ("Create a free account to run this"). A+// guest's message in Assist opens no card (it's the owner's: "Assist runs on the studio owner's AI…" is its toast, as+// an account's).+// Then an account with neither a GPU nor a key: Target photo opens "Connect your GPU or add a key to use your own files"+// instead of the file chooser, its form inside it, closed when the page changes; an upload sent anyway is refused (403)+// with the same card; Color Grading still grades its own picture. None on a message in Assist (it's the owner's, the+// same toast), and its Generate in the Image studio opens "Connect your GPU to run this".// Usage: node tests/e2e/guest-prompt.mjs [appUrl] [--shots <dir>] (the app with a password and FUOBE_PUBLIC_SIGNUP=1).// Signs up one throwaway account. Exits 1 on a failed check.import fs from "node:fs";@@ -25,8 +29,12 @@ const check = (label, ok, extra = "") => {const shot = (page, name) => shots && page.screenshot({ path: path.join(shots, `${name}.png`) });const picture = path.join(root, "public/samples/grade-sample.jpg");-const GUEST_CARD = "Create a free account to run this";-const GPU_CARD = "Connect your GPU to run this";+const FACE_SWAP = "/apps/app-face-swap";+const TARGET = /^Target photo \(required\): upload$/;+const GUEST_CARD = "Create a free account to add your own files";+const GUEST_RUN_CARD = "Create a free account to run this";+const GPU_CARD = "Connect your GPU or add a key to use your own files";+const GPU_RUN_CARD = "Connect your GPU to run this";const browser = await launch();const contextFor = async () => {@@ -44,11 +52,50 @@ const seen = async (page) => ({});const settled = (page) => page.waitForTimeout(1500);-/** Press New canvas in Canvas, and wait for the server's answer. */-async function newCanvas(page) {- await openRoute(page, `${app}/canvas`);- const answered = page.waitForResponse((r) => new URL(r.url()).pathname === "/api/canvases" && r.request().method() === "POST");- await page.getByRole("button", { name: "New canvas" }).first().click();+/** Press a tile: whether the file chooser opened (it gets the picture), and how many uploads the page sent. */+async function press(page, name) {+ let uploads = 0;+ const count = (r) => new URL(r.url()).pathname === "/api/uploads" && r.method() === "POST" && uploads++;+ page.on("request", count);+ const chooser = page.waitForEvent("filechooser", { timeout: 3000 }).catch(() => null);+ await page.getByRole("button", { name }).first().click();+ const opened = await chooser;+ if (opened) await opened.setFiles(picture);+ await page.waitForTimeout(1000);+ page.off("request", count);+ return { chooser: !!opened, uploads };+}++/** An upload sent anyway (as a script would): the server's answer. The page's own fetch, so its card opens. */+const uploadAnyway = (page) =>+ page.evaluate(async () => {+ const r = await fetch("/api/uploads", {+ method: "POST",+ body: new Blob([new Uint8Array([0x89, 0x50, 0x4e, 0x47])], { type: "image/png" }),+ headers: { "Content-Type": "image/png", "X-File-Name": "photo.png" },+ });+ return { status: r.status, guest: r.headers.get("x-fuobe-guest"), gpu: r.headers.get("x-fuobe-connect-gpu") };+ });++/** Grade a picture of one's own in Color Grading: it opens in the grader, with no card and no upload. */+async function gradeOwnPicture(page, who) {+ await openRoute(page, `${app}/color-grade`);+ const pressed = await press(page, "Image: upload");+ await page.locator("canvas").first().waitFor({ timeout: 15_000 }).catch(() => {});+ await settled(page);+ const s = await seen(page);+ check(`${who}: Color Grading opens the file chooser`, pressed.chooser, JSON.stringify(pressed));+ check(`${who}: and grades the picture in the browser (no card, no upload)`, (await page.locator("canvas").count()) > 0 && s.cards.length === 0 && s.errors.length === 0 && pressed.uploads === 0, JSON.stringify({ ...s, ...pressed }));+}++/** Write a prompt in the Image studio and press Generate, once the composer is live, and wait for the run's answer. */+async function generateImage(page) {+ await openRoute(page, `${app}/image`);+ await page.waitForSelector("[data-composer-toolbar]", { timeout: 60_000 });+ await page.waitForFunction(() => Object.keys(document.querySelector("[data-composer-toolbar]") ?? {}).some((k) => k.startsWith("__react")), null, { timeout: 60_000 });+ await page.locator("[data-composer] textarea").fill("A red wool coat on a model, studio light");+ const answered = page.waitForResponse((r) => new URL(r.url()).pathname === "/api/generations" && r.request().method() === "POST");+ await page.getByRole("button", { name: "Generate", exact: true }).click();return answered;}@@ -62,29 +109,21 @@ async function sendInAssist(page) {return answered;}-/** Upload a picture through Color Grading's Image tile, and wait for the server's answer. */-async function uploadPicture(page) {- const answered = page.waitForResponse((r) => r.url().endsWith("/api/uploads") && r.request().method() === "POST");- const [chooser] = await Promise.all([page.waitForEvent("filechooser"), page.getByRole("button", { name: "Image: upload" }).click()]);- await chooser.setFiles(picture);- return answered;-}-try {// ---------------------------------------------------------------------------- // A guest in Color Grading.+ // A guest in Face Swap.{const { context, page } = await contextFor();- await openRoute(page, `${app}/color-grade`);- const res = await uploadPicture(page);- check("the guest's upload is refused (401, marked for the card)", res.status() === 401 && res.headers()["x-fuobe-guest"] === "1", String(res.status()));+ await openRoute(page, `${app}${FACE_SWAP}`);+ const pressed = await press(page, TARGET);+ check("the guest's Target photo opens no file chooser, and uploads nothing", !pressed.chooser && pressed.uploads === 0, JSON.stringify(pressed));await page.getByRole("dialog").waitFor();await settled(page);let s = await seen(page);await shot(page, "1-guest-upload");- check("one card opens: Create a free account", s.cards.length === 1 && s.cards[0] === GUEST_CARD, JSON.stringify(s.cards));+ check("one card opens: Create a free account to add your own files", s.cards.length === 1 && s.cards[0] === GUEST_CARD, JSON.stringify(s.cards));check("no error toast on top of it", s.errors.length === 0, JSON.stringify(s.errors));- check("and no trip to the sign-in page", s.path === "/color-grade", s.path);+ check("and no trip to the sign-in page", s.path === FACE_SWAP, s.path);await page.getByRole("dialog").getByRole("link", { name: "Log in" }).click();await page.waitForURL((u) => u.pathname === "/login");@@ -92,7 +131,7 @@ try {await settled(page);s = await seen(page);await shot(page, "2-log-in");- check("Log in opens the sign-in page, coming back to Color Grading", new URL(page.url()).searchParams.get("next") === "/color-grade", page.url());+ check("Log in opens the sign-in page, coming back to Face Swap", new URL(page.url()).searchParams.get("next") === FACE_SWAP, page.url());check("with the card closed", s.cards.length === 0, JSON.stringify(s.cards));// A wrong password: the form's own error, no card.@@ -107,11 +146,11 @@ try {check("a wrong password is refused", refused.status() === 401, String(refused.status()));check("and is the form's own error, with no card", s.cards.length === 0 && (await page.locator("form .text-destructive").count()) === 1, JSON.stringify(s.cards));- // Keep browsing, upload again, then Back: the card closes with the page.+ // Keep browsing, press Target photo again, then Back: the card closes with the page.await page.getByRole("link", { name: "Keep browsing as a guest" }).click();- await page.waitForURL((u) => u.pathname === "/color-grade");- await page.getByRole("button", { name: "Image: upload" }).waitFor();- await uploadPicture(page);+ await page.waitForURL((u) => u.pathname === FACE_SWAP);+ await page.getByRole("button", { name: TARGET }).waitFor();+ await press(page, TARGET);await page.getByRole("dialog").waitFor();await page.goBack();await page.waitForURL((u) => u.pathname === "/login");@@ -121,30 +160,44 @@ try {// Sign up free: the sign-up form, the card closed.await page.goForward();- await page.waitForURL((u) => u.pathname === "/color-grade");- await page.getByRole("button", { name: "Image: upload" }).waitFor();- await uploadPicture(page);+ await page.waitForURL((u) => u.pathname === FACE_SWAP);+ await page.getByRole("button", { name: TARGET }).waitFor();+ await press(page, TARGET);await page.getByRole("dialog").getByRole("link", { name: "Sign up free" }).click();await page.getByRole("heading", { name: "Create your free account" }).waitFor();await settled(page);s = await seen(page);await shot(page, "4-sign-up");check("Sign up free opens the sign-up form with the card closed", s.path === "/login" && s.cards.length === 0, JSON.stringify(s));++ // An upload sent anyway: the server refuses it, and its card says the same.+ await openRoute(page, `${app}${FACE_SWAP}`);+ const res = await uploadAnyway(page);+ check("the guest's upload is refused (401, marked for the card)", res.status === 401 && res.guest === "1", JSON.stringify(res));+ await page.getByRole("dialog").waitFor();+ await settled(page);+ s = await seen(page);+ check("its card: Create a free account to add your own files, alone", s.cards.length === 1 && s.cards[0] === GUEST_CARD && s.errors.length === 0, JSON.stringify(s));+ await page.keyboard.press("Escape");++ // Color Grading runs in the browser: the guest's own picture, no card.+ await gradeOwnPicture(page, "the guest");+ await shot(page, "5-guest-color-grade");await context.close();}// ---------------------------------------------------------------------------- // A guest in Canvas and Assist: each studio's own fetch helper, the same one card.+ // A guest's run and Assist: a run keeps the run's words; Assist opens no card.{const { context, page } = await contextFor();- const res = await newCanvas(page);- check("the guest's New canvas is refused (401, marked for the card)", res.status() === 401 && res.headers()["x-fuobe-guest"] === "1", String(res.status()));+ const res = await generateImage(page);+ check("the guest's Generate is refused (401, marked for the card)", res.status() === 401 && res.headers()["x-fuobe-guest"] === "1", String(res.status()));await page.getByRole("dialog").waitFor();await settled(page);let s = await seen(page);- await shot(page, "6-guest-new-canvas");- check("Canvas: one card opens: Create a free account", s.cards.length === 1 && s.cards[0] === GUEST_CARD, JSON.stringify(s.cards));- check("Canvas: no error toast on top of it", s.errors.length === 0, JSON.stringify(s.errors));+ await shot(page, "6-guest-generate");+ check("Image: one card opens: Create a free account to run this", s.cards.length === 1 && s.cards[0] === GUEST_RUN_CARD, JSON.stringify(s.cards));+ check("Image: no error toast on top of it", s.errors.length === 0, JSON.stringify(s.errors));// Assist is the owner's: signing up wouldn't let the guest use it, so it gets the account's answer, not the card.const sent = await sendInAssist(page);@@ -158,7 +211,7 @@ try {}// ---------------------------------------------------------------------------- // An account without its GPU: "Connect your GPU", alone, closed when the page changes.+ // An account with neither a GPU nor a key: "Connect your GPU or add a key", alone, closed when the page changes.{const { context, page } = await contextFor();await openRoute(page, `${app}/login?signup=1`);@@ -166,45 +219,56 @@ try {await page.getByPlaceholder("Password (at least 8 characters)").fill("long enough password");await page.getByRole("button", { name: "Sign up", exact: true }).click();await page.waitForURL((u) => u.pathname === "/connect");- await openRoute(page, `${app}/`);- await page.getByRole("link", { name: "Color grading" }).first().click();- await page.waitForURL((u) => u.pathname === "/color-grade");- await page.getByRole("button", { name: "Image: upload" }).waitFor();- const res = await uploadPicture(page);- check("the account's upload is refused until it connects a GPU (403)", res.status() === 403, String(res.status()));+ await openRoute(page, `${app}${FACE_SWAP}`);+ const pressed = await press(page, TARGET);+ check("the account's Target photo opens no file chooser until it has a GPU or a key", !pressed.chooser && pressed.uploads === 0, JSON.stringify(pressed));await page.getByRole("dialog").waitFor();await settled(page);let s = await seen(page);- await shot(page, "5-connect-gpu");- check("one card opens: Connect your GPU", s.cards.length === 1 && s.cards[0] === GPU_CARD, JSON.stringify(s.cards));+ await shot(page, "8-connect-gpu");+ check("one card opens: Connect your GPU or add a key to use your own files", s.cards.length === 1 && s.cards[0] === GPU_CARD, JSON.stringify(s.cards));check("no error toast on top of it", s.errors.length === 0, JSON.stringify(s.errors));const sideways = await page.getByRole("dialog").evaluate((d) => d.scrollWidth - d.clientWidth);check("its form fits inside it (nothing cut off at the right)", sideways <= 0, `${sideways}px`);await page.goBack();- await page.waitForURL((u) => u.pathname === "/");+ await page.waitForURL((u) => u.pathname === "/connect");await settled(page);s = await seen(page);check("Back closes it", s.cards.length === 0, JSON.stringify(s.cards));+ // An upload sent anyway: refused until it connects a GPU or adds a key, with the same card.+ await openRoute(page, `${app}${FACE_SWAP}`);+ const res = await uploadAnyway(page);+ check("the account's upload is refused until it has a GPU or a key (403)", res.status === 403 && res.gpu === "1", JSON.stringify(res));+ await page.getByRole("dialog").waitFor();+ await settled(page);+ s = await seen(page);+ check("its card: Connect your GPU or add a key, alone", s.cards.length === 1 && s.cards[0] === GPU_CARD && s.errors.length === 0, JSON.stringify(s));+ await page.keyboard.press("Escape");++ // Color Grading runs in the browser: no GPU or key needed for its own picture.+ await gradeOwnPicture(page, "the account");+ await shot(page, "9-account-color-grade");+// A message in Assist (its own fetch helper): Assist is the owner's, and a GPU wouldn't change that, so no card.const sent = await sendInAssist(page);check("the account's message in Assist is refused (403, Assist is the owner's)", sent.status() === 403 && !sent.headers()["x-fuobe-connect-gpu"], String(sent.status()));await page.locator("[data-sonner-toast][data-type=error]").first().waitFor();await settled(page);s = await seen(page);- await shot(page, "8-account-assist-send");+ await shot(page, "10-account-assist-send");check("Assist: its own error toast, with no card", s.cards.length === 0 && s.errors.length === 1 && /owner/.test(s.errors[0]), JSON.stringify(s));- // Gone before New canvas, so its toast is counted alone.+ // Gone before Generate, so nothing else is counted with its card.await page.locator("[data-sonner-toast][data-type=error]").first().waitFor({ state: "detached", timeout: 20_000 });- // New canvas: a refusal with no card of its own, so its toast is the one thing shown.- const made = await newCanvas(page);- check("the account's New canvas is refused (403, no card for it)", made.status() === 403 && !made.headers()["x-fuobe-connect-gpu"], String(made.status()));- await page.locator("[data-sonner-toast][data-type=error]").first().waitFor();+ // A run keeps the run's words: "Connect your GPU to run this".+ const made = await generateImage(page);+ check("the account's Generate is refused until it has a GPU or a key (403)", made.status() === 403 && made.headers()["x-fuobe-connect-gpu"] === "1", String(made.status()));+ await page.getByRole("dialog").waitFor();await settled(page);s = await seen(page);- await shot(page, "9-account-new-canvas");- check("Canvas: its own error toast, with no card", s.cards.length === 0 && s.errors.length === 1, JSON.stringify(s));+ await shot(page, "11-account-generate");+ check("Image: one card opens: Connect your GPU to run this", s.cards.length === 1 && s.cards[0] === GPU_RUN_CARD && s.errors.length === 0, JSON.stringify(s));await context.close();}} finally {diff --git a/tests/guest-prompt.test.ts b/tests/guest-prompt.test.tsindex 1637b726..ab062eda 100644--- a/tests/guest-prompt.test.ts+++ b/tests/guest-prompt.test.ts@@ -32,7 +32,7 @@ import { send as shortsSend } from "@/components/shorts/hooks";import { fileToSlot, type SlotValue } from "@/components/studio/media-slot";import { useCreateSwapProject } from "@/components/swap-studio/hooks";import { runGpuCheck } from "@/hooks/use-gpu";-import { assetUsage, CONNECT_GPU_EVENT, enhance, GUEST_PROMPT_EVENT, refusalCard, signInHref, watchGuestRefusals } from "@/lib/api";+import { askToSignUp, assetUsage, CONNECT_GPU_EVENT, enhance, GUEST_PROMPT_EVENT, refusalCard, signInHref, watchGuestRefusals } from "@/lib/api";import { CONNECT_GPU_HEADER, CONNECT_GPU_MESSAGE, CONNECT_GPU_UPLOAD_MESSAGE, GUEST_HEADER, GUEST_LIBRARY_MESSAGE, GUEST_RUN_MESSAGE } from "@/lib/guest-access";import { refusalShown, toastError } from "@/lib/refusals";@@ -116,6 +116,24 @@ describe("a guest's refused upload (an image tile: Face Swap's Target photo)", (});});+describe("askToSignUp", () => {+ it("opens Create a free account about the visitor's own files, with no request sent", () => {+ page("/apps/app-face-swap");+ const sent = vi.fn(server);+ server = sent;+ askToSignUp();+ expect(events).toEqual([GUEST_PROMPT_EVENT]);+ expect(details).toEqual([{ action: "upload" }]);+ expect(sent).not.toHaveBeenCalled();+ });++ it("or about a run", () => {+ page("/image");+ askToSignUp("run");+ expect(details).toEqual([{ action: "run" }]);+ });+});+describe("a guest's refused run", () => {it("opens the card, and the error it throws says the card shows it already", async () => {page("/image");