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.

Studios: Run says the price, the place in line and the wait, and is off when refused

Adarsh517c19745c73
diff --git a/src/components/recolor/recolor-tool.tsx b/src/components/recolor/recolor-tool.tsx
index 1dad7ed9..05bed4c7 100644
--- a/src/components/recolor/recolor-tool.tsx
+++ b/src/components/recolor/recolor-tool.tsx
@@ -260,6 +260,8 @@ export function RecolorTool({ app }: { app: { name: string; description: string
const go = async () => {
if (blocker || !ready || !frame) return void toast(blocker ?? "Add a photo");
+ // Refused by this studio's GPUs before Run (busy, a limit): its words, and nothing is sent.
+ if (place?.refused) return void toast(place.refused);
// The example photo goes up as the visitor's own picture the first time it runs. A guest is asked to sign up for
// the run itself (they added no file of their own); an account that can't add pictures gets the usual card.
if (example && guest) return askToSignUp("run");
@@ -375,16 +377,16 @@ export function RecolorTool({ app }: { app: { name: string; description: string
size="lg"
className="h-11 w-full rounded-full text-[15px]"
onClick={go}
- disabled={sending || !ready || !frame}
+ disabled={sending || !ready || !frame || !!place?.refused}
aria-describedby="recolor-blocker"
title={place?.send ? `${runLabel} · ${place.send}` : undefined}
>
{sending ? <Loader2 className="size-4 animate-spin" /> : <Palette className="size-4" />}
{runLabel}
</Button>
- {blocker && ready && (
+ {(blocker || place?.refused) && ready && (
<p id="recolor-blocker" className="text-center text-[12px] text-muted-foreground" aria-live="polite">
- {blocker}
+ {blocker ?? place?.refused}
</p>
)}
</div>
diff --git a/src/components/studio/composer.tsx b/src/components/studio/composer.tsx
index de6c4e78..fc179f41 100644
--- a/src/components/studio/composer.tsx
+++ b/src/components/studio/composer.tsx
@@ -19,7 +19,8 @@ import { dualEngine } from "@/lib/catalog/engines";
import { locksByDefault } from "@/lib/catalog/palettes";
import { DEFAULT_LOOK, lookCard } from "@/lib/catalog/soul-cards";
import { formatsOf } from "@/lib/av/formats";
-import { quoteBody, useHostedQuote, useSettled, type RunOn } from "@/lib/hosted";
+import { poolRunState, quoteBody, useHostedQuote, useSettled, type RunOn } from "@/lib/hosted";
+import { PoolNote } from "./pool-note";
import { ExactOrbitControls } from "@/components/exact-orbit-controls";
import { useFlyAround } from "@/components/fly-around-run";
import { exactDefaults, takesExact, type ExactOrbit } from "@/lib/exact-orbit";
@@ -598,8 +599,12 @@ export function Composer({ docked }: { docked: boolean }) {
const hostedHere = !!viewerInfo?.hosted && model?.engine === "open";
const poolPrice = hostedHere && runOn === "pool";
const priceBody = useSettled(poolPrice ? quoteBody(signed.request, runOn) : null);
- const hostedQuote = useHostedQuote(priceBody).data?.quote;
- const priceUnavailable = poolPrice && hostedQuote?.code === "paused";
+ const hostedCheck = useHostedQuote(priceBody).data;
+ const hostedQuote = hostedCheck?.quote;
+ // The price check's answer: refused (busy, a limit, not offered here, paused…), Run is off and says why; otherwise
+ // the price, and where the run would stand in line with the wait.
+ const poolState = poolPrice ? poolRunState(hostedCheck) : null;
+ const poolRefused = !!poolState?.refused;
const resolvesOnServer = mentions.mentioned.length > 0 || !!draft.slots.mask?.ref || !!draft.slots.sketch?.ref;
// Plan with stand-ins for attachments that are missing or still uploading, so the cost and the
@@ -705,7 +710,8 @@ export function Composer({ docked }: { docked: boolean }) {
: undefined;
const presetGpu = presetKey && gpuBadges?.connected ? gpuBadges.presets[presetKey] : undefined;
const gpuBadge = model?.engine === "open" && gpuBadges?.connected ? (presetGpu ?? badgeFor(gpuBadges, { modelId: model.id, op: gpuOp })) : null;
- const gpuSetup = gpuBadge && gpuBadge[0] !== "r" ? gpuBadge : null;
+ // (A run on this studio's GPUs never meets the pre-flight of the account's own GPU.)
+ const gpuSetup = gpuBadge && gpuBadge[0] !== "r" && !poolPrice ? gpuBadge : null;
const gpuRef = presetGpu && presetKey ? `preset:${presetKey}` : model ? `model:${model.id}#${gpuOp ?? Object.keys(gpuBadges?.models ?? {}).find((k) => k.startsWith(`${model.id}#`))?.split("#")[1] ?? ""}` : "";
const openGpuFix = () => {
setGpuRetry(
@@ -733,6 +739,8 @@ export function Composer({ docked }: { docked: boolean }) {
}
if (keyToAdd && model && !create.isPending) return openAddKey(keyToAdd, model.id);
if (!blocker && gpuSetup && !skipGpu && !create.isPending) return openGpuFix();
+ // Refused by the price check (Run is off; Enter in the prompt lands here too): its words, and nothing is sent.
+ if (!blocker && poolRefused && poolState) return void toast(poolState.text, { id: "composer-blocker" });
if (blocker || create.isPending || signature.lock.isPending) {
if (blocker) {
// One blocker toast at a time (pressing Generate again replaces it), gone once a run starts.
@@ -885,7 +893,7 @@ export function Composer({ docked }: { docked: boolean }) {
// On this studio's GPUs: the quote's words (none from the server: free, as the open engine always is).
// An exact orbit runs as a fly-around: its own price.
const exactPrice = exact ? fly.price : "";
- const costText = exactPrice || (poolPrice ? (priceUnavailable ? "Price unavailable" : hostedQuote?.text || ownCostText) : ownCostText);
+ const costText = exactPrice || (poolPrice ? (poolState?.refused ? poolState.text : hostedQuote?.text || ownCostText) : ownCostText);
const payerText = poolPrice ? "" : ownPayerText;
// Attachments: only when something is attached, a required slot is still empty, or none of a "one of these" group is filled (U8).
@@ -1569,7 +1577,7 @@ export function Composer({ docked }: { docked: boolean }) {
{costText && (
<Tooltip>
<TooltipTrigger asChild>
- <span className="shrink-0 text-[12px] font-medium text-muted-foreground tabular-nums">
+ <span className={cn("shrink-0 text-[12px] font-medium text-muted-foreground tabular-nums", poolRefused && "min-w-0 shrink truncate max-sm:hidden")} data-pool-refused={poolRefused || undefined}>
<span className="sm:hidden">{exactPrice ? fly.compactPrice : poolPrice ? costText : costLabel({ demo, cost: cost ?? (engine === "open" && model ? 0 : null), compact: true, unknown: loraPriceUnknown, gpu: gpuRun }, formatCost)}</span>
<span className="hidden sm:inline">
{costText}
@@ -1579,9 +1587,9 @@ export function Composer({ docked }: { docked: boolean }) {
</TooltipTrigger>
<TooltipContent className="max-w-72">
{poolPrice
- ? priceUnavailable
- ? "Runs on this studio's GPUs are paused for a moment. Try again soon, or run on your own GPU."
- : (hostedQuote?.sub ?? "Runs on this studio's GPUs")
+ ? poolState?.refused
+ ? (poolState.sub ?? poolState.text)
+ : [hostedQuote?.sub ?? "Runs on this studio's GPUs", poolState?.wait].filter(Boolean).join(" · ")
: demo
? "Placeholder results are on (Settings), so outputs are free stand-ins"
: cost === 0
@@ -1601,8 +1609,8 @@ export function Composer({ docked }: { docked: boolean }) {
<Button
size="icon"
onClick={submit}
- disabled={create.isPending || signature.lock.isPending || priceUnavailable}
- aria-label={blocker ? `Generate — ${blocker.message}` : "Generate"}
+ disabled={create.isPending || signature.lock.isPending || poolRefused}
+ aria-label={blocker ? `Generate — ${blocker.message}` : poolRefused && poolState ? `Generate — ${poolState.text}` : "Generate"}
aria-busy={create.isPending || signature.lock.isPending || undefined}
// Blocked, it stays the brand colour (paler, the arrow still 3:1 or more): pressing it still says what's missing and points at it.
className={cn("size-10 shrink-0 rounded-full", blocker && "bg-primary/70 hover:bg-primary/80")}
@@ -1647,6 +1655,8 @@ export function Composer({ docked }: { docked: boolean }) {
)}
</p>
)}
+ {/* Folded (docked, not focused), the composer stays one line: the wait shows again once it opens. */}
+ {!blocker && !gpuSetup && poolState && (poolState.refused || !collapsed) && <PoolNote state={poolState} />}
{!blocker && gpuSetup && (
<p className="px-2 text-[12px] text-muted-foreground">
<button
diff --git a/src/components/studio/pool-note.tsx b/src/components/studio/pool-note.tsx
new file mode 100644
index 00000000..26e23060
--- /dev/null
+++ b/src/components/studio/pool-note.tsx
@@ -0,0 +1,47 @@
+"use client";
+
+import { safeLink, useInterest, type poolRunState } from "@/lib/hosted";
+import { cn } from "@/lib/utils";
+
+type PoolState = NonNullable<ReturnType<typeof poolRunState>>;
+
+/**
+ * The line under a composer's toolbar for a run on this studio's GPUs: where it would stand in line and the wait, about,
+ * before Run is pressed; or, when the price check refused it, the words (the toolbar's price slot has no room for them
+ * on a phone), with the link or offer the answer carries.
+ */
+export function PoolNote({ state, className }: { state: PoolState; className?: string }) {
+ const interest = useInterest();
+ const href = safeLink(state.action?.url);
+ if (!state.refused) {
+ if (!state.wait) return null;
+ return (
+ <p data-pool-note="wait" className={cn("px-2 text-[12px] text-muted-foreground tabular-nums", className)}>
+ {state.wait}
+ </p>
+ );
+ }
+ const more = !!(href || state.offer || state.sub);
+ return (
+ <p data-pool-note="refused" className={cn("flex flex-wrap items-center gap-x-2 px-2 text-[12px] text-muted-foreground", !more && "sm:hidden", className)}>
+ <span className="sm:hidden">{state.text}</span>
+ {state.sub && <span>{state.sub}</span>}
+ {href && state.action && (
+ <a href={href} target={href.startsWith("/") ? undefined : "_blank"} rel="noreferrer" className="font-medium text-brand-text underline-offset-2 hover:underline">
+ {state.action.label}
+ </a>
+ )}
+ {state.offer && (
+ <button
+ type="button"
+ onMouseDown={(e) => e.preventDefault()}
+ onClick={() => interest.mutate(state.offer!.key)}
+ disabled={interest.isPending}
+ className="font-medium text-brand-text underline-offset-2 hover:underline"
+ >
+ {state.offer.label}
+ </button>
+ )}
+ </p>
+ );
+}
diff --git a/src/lib/hosted.ts b/src/lib/hosted.ts
index 193a85d8..f76b9142 100644
--- a/src/lib/hosted.ts
+++ b/src/lib/hosted.ts
@@ -4,6 +4,7 @@ import { useEffect, useState } from "react";
import { useMutation, useQuery } from "@tanstack/react-query";
import { toast } from "sonner";
import type { GenerationRequest } from "./catalog/types";
+import { lineWords } from "./pool-line";
/**
* The browser's side of hosted runs and the optional billing service (src/server/hosted.ts, src/server/billing.ts).
@@ -85,6 +86,19 @@ export function useSettled<T>(value: T, ms = 300): T {
return v;
}
+/** Where a new run would stand in line on this studio's GPUs right now (1: next), and the wait, about (null: unknown). */
+export interface HostedLine {
+ place: number;
+ etaSeconds: number | null;
+}
+
+/** The price check's answer for a run on this studio's GPUs: the quote, and where the run would stand in line. */
+export interface HostedCheck {
+ place?: "pool";
+ quote?: HostedQuote;
+ line?: HostedLine;
+}
+
/**
* The price of a run on this studio's GPUs: `?preview=1` with `place: "pool"`. `body` is the request as JSON (null:
* nothing to price). The answer's `quote` is absent when the run would go to the person's own GPU or key.
@@ -95,15 +109,30 @@ export function useHostedQuote(body: string | null) {
enabled: !!body,
staleTime: 10_000,
retry: false,
- queryFn: async (): Promise<{ place?: "pool"; quote?: HostedQuote } | null> => {
+ queryFn: async (): Promise<HostedCheck | null> => {
const res = await fetch("/api/generations?preview=1", { method: "POST", headers: { "Content-Type": "application/json" }, body: body! });
if (!res.ok) return null;
- const b = (await res.json()) as { place?: "pool"; quote?: HostedQuote };
- return { place: b.place, quote: b.quote };
+ const b = (await res.json()) as HostedCheck;
+ return { place: b.place, quote: b.quote, ...(b.line && { line: b.line }) };
},
});
}
+/**
+ * What Run says and does for a run on this studio's GPUs, from its price check:
+ * - `refused`: the run wouldn't be taken now (busy, a limit, not offered here, closed, paused, a top-up): Run is off,
+ * and the price slot says the service's words (`text`), with its line under them (`sub`) and its link or offer;
+ * - otherwise the price (`text`: the service's words, empty when there is none) and, under it, where the run would stand
+ * in line and the wait (`wait`).
+ * Null while there is no answer yet.
+ */
+export function poolRunState(check: HostedCheck | null | undefined): { refused: boolean; text: string; sub?: string; wait?: string; action?: BillingAction; offer?: BillingOffer } | null {
+ const q = check?.quote;
+ if (!q) return null;
+ if (!q.allowed) return { refused: true, text: q.text, ...(q.sub && { sub: q.sub }), ...(q.action && { action: q.action }), ...(q.offer && { offer: q.offer }) };
+ return { refused: false, text: q.text, ...(q.sub && { sub: q.sub }), ...(check?.line && { wait: lineWords(check.line) }) };
+}
+
/** The request as the price check sends it: the run, plus where it should go. */
export function quoteBody(req: GenerationRequest | null, runOn: RunOn): string | null {
return req ? JSON.stringify({ ...req, place: runOn }) : null;
@@ -123,10 +152,4 @@ export function useInterest() {
});
}
-/** "In line · 3rd · about 40 s": a waiting run's place on this studio's GPUs. */
-export function lineWords(q: { place: number; etaSeconds: number | null }): string {
- const n = q.place;
- const ord = n % 100 >= 11 && n % 100 <= 13 ? "th" : ({ 1: "st", 2: "nd", 3: "rd" } as Record<number, string>)[n % 10] ?? "th";
- const eta = q.etaSeconds === null ? "" : q.etaSeconds < 60 ? ` · about ${Math.max(5, Math.round(q.etaSeconds / 5) * 5)} s` : ` · about ${Math.round(q.etaSeconds / 60)} min`;
- return n === 1 ? `Next in line${eta}` : `In line · ${n}${ord}${eta}`;
-}
+export { lineWords };
diff --git a/src/lib/pool-line.ts b/src/lib/pool-line.ts
new file mode 100644
index 00000000..d1c9d696
--- /dev/null
+++ b/src/lib/pool-line.ts
@@ -0,0 +1,14 @@
+/**
+ * The words for a run's place in line on this studio's GPUs (hosted runs), shared by the price check before Run and the
+ * run's tile: "Next in line · about 40 s", "In line · 3rd · about 2 min". A run shows only "In line" (with its place and
+ * wait), "Working" (with its progress), then its result.
+ */
+
+/** "In line · 3rd · about 40 s": a run's place on this studio's GPUs (1: next), and the wait, about. */
+export function lineWords(q: { place: number; etaSeconds: number | null }): string {
+ const n = Math.max(1, Math.floor(q.place));
+ const ord = n % 100 >= 11 && n % 100 <= 13 ? "th" : ({ 1: "st", 2: "nd", 3: "rd" } as Record<number, string>)[n % 10] ?? "th";
+ const s = q.etaSeconds;
+ const eta = s === null || !Number.isFinite(s) || s < 0 ? "" : s < 60 ? ` · about ${Math.max(5, Math.round(s / 5) * 5)} s` : ` · about ${Math.round(s / 60)} min`;
+ return n === 1 ? `Next in line${eta}` : `In line · ${n}${ord}${eta}`;
+}
diff --git a/src/lib/run-place.ts b/src/lib/run-place.ts
index 0445eac5..801b8ca8 100644
--- a/src/lib/run-place.ts
+++ b/src/lib/run-place.ts
@@ -1,3 +1,4 @@
+import { lineWords } from "./pool-line";
import { billedTo, CLOUD_KEY, type CloudProvider } from "./your-keys";
/**
@@ -32,8 +33,12 @@ export interface RunPlaceInput {
hosted?: boolean;
/** Runs go to this studio's GPUs first, even when the viewer has a GPU of its own (the studio's policy). */
preferPool?: boolean;
- /** The price of a run on this studio's GPUs (the billing service's words; empty text: free), undefined while pricing. */
- pool?: { text: string; sub?: string } | null;
+ /**
+ * The price of a run on this studio's GPUs (the billing service's words; empty text: free), undefined while pricing.
+ * `refused`: the price check refused the run (its words are `text`), so it can't start now. `wait`: where it would
+ * stand in line, and the wait.
+ */
+ pool?: { text: string; sub?: string; refused?: boolean; wait?: string } | null;
/** The provider an account's paid run is billed to (its own key), or null when it has no key for this model. */
payer?: CloudProvider | null;
/** How a price reads: "$0.04". */
@@ -55,6 +60,8 @@ export interface RunPlace {
send: string;
/** What this viewer does before the run can start: create an account, connect a GPU, or add a key. */
needs?: "signup" | "gpu" | "key";
+ /** The run can't start now (this studio's GPUs refused it before Run): the send button is off, and these words say why. */
+ refused?: string;
/** The cloud model the chip names, when known (the label is "Cloud" without one). */
model?: string;
}
@@ -104,18 +111,22 @@ export function runPlace(input: RunPlaceInput): RunPlace {
// at the billing service's price (the studio composer's "This studio's GPUs" chip).
if (open && input.hosted && audience !== "owner" && (!input.gpu || input.preferPool)) {
const signup = audience === "guest";
+ const refused = !input.demo && input.pool?.refused ? input.pool.text : undefined;
const poolPrice = input.demo ? price : input.pool ? input.pool.text || "Free" : "";
const tip = input.demo
? "Placeholder results are on (Settings), so outputs are free stand-ins."
- : `${input.pool?.sub ?? `Runs on this studio's GPUs${withModels}.`}${signup ? " Create a free account to run it." : ""}`;
+ : refused
+ ? (input.pool?.sub ?? refused)
+ : `${input.pool?.sub ?? `Runs on this studio's GPUs${withModels}.`}${input.pool?.wait ? ` ${input.pool.wait}.` : ""}${signup ? " Create a free account to run it." : ""}`;
return {
where: "pool",
label: "This studio's GPUs",
price: poolPrice,
title: "Runs on this studio's GPUs",
tip,
- send: input.demo ? price : [poolPrice, signup ? "this studio's GPUs, after sign-up" : "this studio's GPUs"].filter(Boolean).join(" · "),
- ...(signup && { needs: "signup" as const }),
+ send: input.demo ? price : refused ?? [poolPrice, signup ? "this studio's GPUs, after sign-up" : "this studio's GPUs"].filter(Boolean).join(" · "),
+ ...(signup && !refused && { needs: "signup" as const }),
+ ...(refused && { refused }),
};
}
if (open) {
@@ -180,8 +191,13 @@ export const IN_BROWSER: RunPlace = runPlace({ audience: "guest", engine: "brows
* model the studio doesn't offer there, its own GPU or key): the chip then says your GPU, never this studio's.
* `count`: runs one press starts (the quote is for one, said "each").
*/
-export function checkedPool(check: { place?: "pool"; quote?: { text: string; sub?: string } } | null | undefined, count = 1): { text: string; sub?: string } | undefined {
+export function checkedPool(
+ check: { place?: "pool"; quote?: { text: string; sub?: string; allowed?: boolean }; line?: { place: number; etaSeconds: number | null } } | null | undefined,
+ count = 1,
+): { text: string; sub?: string; refused?: boolean; wait?: string } | undefined {
if (check?.place !== "pool" || !check.quote) return undefined;
const { text, sub } = check.quote;
- return { text: count > 1 && text ? `${text} each` : text, ...(sub && { sub }) };
+ // Refused before Run (busy, a limit, not offered here): its words, never priced "each".
+ if (check.quote.allowed === false) return { text, ...(sub && { sub }), refused: true };
+ return { text: count > 1 && text ? `${text} each` : text, ...(sub && { sub }), ...(check.line && { wait: lineWords(check.line) }) };
}
diff --git a/tests/hosted-run-button.test.ts b/tests/hosted-run-button.test.ts
new file mode 100644
index 00000000..c5c92fb6
--- /dev/null
+++ b/tests/hosted-run-button.test.ts
@@ -0,0 +1,85 @@
+import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
+import { createElement, type ReactNode } from "react";
+import { renderToStaticMarkup } from "react-dom/server";
+import { describe, expect, it, vi } from "vitest";
+
+/*
+ * Run on this studio's GPUs (hosted runs) before it is pressed: the price in the service's words, where the run would
+ * stand in line and the wait, or a refusal (busy, a limit, not offered here, paused) that turns Run off and says why.
+ */
+
+vi.mock("next/navigation", () => ({
+ useRouter: () => ({ prefetch: () => {}, push: () => {}, replace: () => {}, back: () => {}, refresh: () => {} }),
+ usePathname: () => "/image",
+ useSearchParams: () => new URLSearchParams(),
+}));
+
+const { lineWords } = await import("@/lib/pool-line");
+const { poolRunState } = await import("@/lib/hosted");
+const { checkedPool, runPlace } = await import("@/lib/run-place");
+const { PoolNote } = await import("@/components/studio/pool-note");
+const { TooltipProvider } = await import("@/components/ui/tooltip");
+
+const render = (node: ReactNode) => renderToStaticMarkup(createElement(QueryClientProvider, { client: new QueryClient() }, createElement(TooltipProvider, null, node)));
+
+describe("the words for a place in line", () => {
+ it("says next, or the place, with the wait about", () => {
+ expect(lineWords({ place: 1, etaSeconds: null })).toBe("Next in line");
+ expect(lineWords({ place: 1, etaSeconds: 38 })).toBe("Next in line · about 40 s");
+ expect(lineWords({ place: 3, etaSeconds: 130 })).toBe("In line · 3rd · about 2 min");
+ expect(lineWords({ place: 12, etaSeconds: null })).toBe("In line · 12th");
+ expect(lineWords({ place: 22, etaSeconds: 3 })).toBe("In line · 22nd · about 5 s");
+ // Never a place before the first, nor a wait that can't be.
+ expect(lineWords({ place: 0, etaSeconds: -5 })).toBe("Next in line");
+ });
+});
+
+describe("Run before it is pressed (the price check's answer)", () => {
+ it("allowed: the service's words as they are, and where the run would stand in line", () => {
+ expect(poolRunState({ place: "pool", quote: { allowed: true, amount: 0, priceVersion: "v1", text: "Free" }, line: { place: 2, etaSeconds: 90 } })).toEqual({
+ refused: false,
+ text: "Free",
+ wait: "In line · 2nd · about 2 min",
+ });
+ // No service: no words of its own (Run keeps its own), still the place.
+ expect(poolRunState({ place: "pool", quote: { allowed: true, amount: 0, priceVersion: "", text: "" }, line: { place: 1, etaSeconds: null } })).toEqual({ refused: false, text: "", wait: "Next in line" });
+ });
+ it("refused (busy, a limit, not offered, paused, a top-up): Run is off, with the words, the line under them and the link", () => {
+ for (const code of ["busy", "limit", "not-offered", "closed", "paused", "top-up"]) {
+ const s = poolRunState({ place: "pool", quote: { allowed: false, amount: 0, priceVersion: "", text: "Busy right now. Try again in about 10 min.", code, action: { label: "Get more", url: "https://billing.example.com/top-up" } } });
+ expect(s, code).toMatchObject({ refused: true, text: "Busy right now. Try again in about 10 min.", action: { label: "Get more" } });
+ expect(s?.wait, code).toBeUndefined();
+ }
+ });
+ it("nothing to say before the answer comes", () => {
+ expect(poolRunState(null)).toBeNull();
+ expect(poolRunState({ place: "pool" })).toBeNull();
+ });
+ it("a tool's place chip: a refusal turns its button off with the words; otherwise the price and the wait", () => {
+ const refused = checkedPool({ place: "pool", quote: { allowed: false, text: "You have 2 runs going. Start this one when one finishes." } }, 3);
+ expect(refused).toEqual({ text: "You have 2 runs going. Start this one when one finishes.", refused: true });
+ const off = runPlace({ audience: "account", engine: "open", hosted: true, pool: refused, format: String });
+ expect(off).toMatchObject({ where: "pool", refused: "You have 2 runs going. Start this one when one finishes.", send: "You have 2 runs going. Start this one when one finishes." });
+ expect(off.needs).toBeUndefined();
+ const ok = checkedPool({ place: "pool", quote: { allowed: true, text: "Free" }, line: { place: 1, etaSeconds: 40 } });
+ expect(ok).toEqual({ text: "Free", wait: "Next in line · about 40 s" });
+ const on = runPlace({ audience: "account", engine: "open", hosted: true, models: ["Qwen Image"], pool: ok, format: String });
+ expect(on.refused).toBeUndefined();
+ expect(on.tip).toBe("Runs on this studio's GPUs with Qwen Image. Next in line · about 40 s.");
+ });
+ it("the line under the toolbar: the wait before Run, or the refusal's words with its link and offer", () => {
+ const wait = render(createElement(PoolNote, { state: { refused: false, text: "Free", wait: "Next in line · about 40 s" } }));
+ expect(wait).toContain('data-pool-note="wait"');
+ expect(wait).toContain("Next in line · about 40 s");
+ expect(render(createElement(PoolNote, { state: { refused: false, text: "Free" } }))).toBe("");
+ const refused = render(
+ createElement(PoolNote, { state: { refused: true, text: "Busy right now. Try again in about 10 min.", action: { label: "Get more", url: "javascript:alert(1)" }, offer: { key: "priority", text: "Skip the line", label: "Tell me when" } } }),
+ );
+ expect(refused).toContain('data-pool-note="refused"');
+ expect(refused).toContain("Busy right now. Try again in about 10 min.");
+ expect(refused).toContain("Tell me when");
+ // A link the service sent is opened only when it is a plain https (or same-site) link.
+ expect(refused).not.toContain("javascript:");
+ });
+});
+