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.

Hosted runs: pickers leave out what this studio's GPUs won't run, and preset cards say Try free

Adarsh60f8188fab8e
diff --git a/src/components/preset-gallery.tsx b/src/components/preset-gallery.tsx
index 776ebcc2..08e312a1 100644
--- a/src/components/preset-gallery.tsx
+++ b/src/components/preset-gallery.tsx
@@ -11,6 +11,8 @@ import { onAttr, TAB_PILL, TabRow, useFadeOn } from "@/components/ui/tab-row";
import { useProgressive } from "@/components/use-progressive";
import { CardChip, badgeKey, parseBadgeKey } from "@/components/gpu/readiness-chip";
import { useGpuBadges } from "@/hooks/use-gpu";
+import { usePoolRules, useTryFree } from "@/hooks/use-pool-rules";
+import { poolRunsPreset } from "@/lib/pool-rules";
import { useEngineMode, useViewer } from "@/lib/api";
import { categoryFrom, skippedInAll } from "@/lib/gallery-category";
import { matchesSearch, previewFlip, readMoreTap, searchText, TAP_TO_READ, type PresetCardData } from "@/lib/preset-cards";
@@ -63,6 +65,8 @@ export const PresetCard = memo(function PresetCard({
gpuName?: string;
}) {
const badge = engine !== "cloud" ? parseBadgeKey(gpu) : null;
+ // Hosted runs on, and this preset runs on this studio's GPUs for the viewer: the card says it can be tried there.
+ const tryFree = useTryFree()?.(preset) && !badge;
const Icon = PRESET_ICONS[preset.icon] ?? Sparkles;
const { ref, playing, asked, handlers } = usePreviewPlayback<HTMLAnchorElement>(preset.id, preset.preview);
const [more, setMore] = useState(false);
@@ -97,6 +101,11 @@ export const PresetCard = memo(function PresetCard({
<CardChip badge={badge} gpu={gpuName} />
</span>
)}
+ {tryFree && (
+ <span data-try-free className="pointer-events-none absolute top-1.5 right-1.5 rounded-full bg-primary px-1.5 py-0.5 text-[10.5px] font-semibold text-primary-foreground">
+ Try free
+ </span>
+ )}
<CardPending />
</div>
<div className="min-w-0 px-0.5">
@@ -252,13 +261,17 @@ export function PresetGallery({
}, [categories]);
const [q, setQ] = useState("");
const [runsOnChoice, setRunsOn] = useState<RunsOn>("all");
+ // For a viewer with no GPU of its own (hosted runs), a preset only this studio's GPUs could run, and which they keep
+ // off, is left out (src/lib/pool-rules.ts): nothing here fails at Run for it.
+ const rules = usePoolRules();
+ const offered = useMemo(() => (rules ? presets.filter((p) => !p.open || p.cloud || poolRunsPreset(rules, p.id)) : presets), [presets, rules]);
// "both" until hydrated, so the server HTML and the first client render agree.
const mode = useEngineMode();
const locked = mode === "both" ? undefined : mode;
const runsOn: RunsOn = locked ?? runsOnChoice;
const query = useDeferredValue(q.trim().toLowerCase());
- const index = useMemo(() => presets.map((p) => [p, searchText(p)] as const), [presets]);
+ const index = useMemo(() => offered.map((p) => [p, searchText(p)] as const), [offered]);
const cats = useMemo(() => ["All", ...categories], [categories]);
const list = useMemo(
() =>
@@ -294,7 +307,7 @@ export function PresetGallery({
type="search"
value={q}
onChange={(e) => setQ(e.target.value)}
- placeholder={`Search ${presets.length} ${noun}`}
+ placeholder={`Search ${offered.length} ${noun}`}
aria-label={`Search ${noun}`}
className="h-9 w-full rounded-full border bg-background pr-9 pl-9 text-[14px] outline-none placeholder:text-subtle-foreground focus:border-primary focus:ring-4 focus:ring-brand-faint [&::-webkit-search-cancel-button]:hidden"
/>
@@ -311,7 +324,7 @@ export function PresetGallery({
</div>
<div className="flex items-center justify-between gap-2 sm:ml-auto sm:justify-end">
<span className="order-last text-[12px] whitespace-nowrap text-muted-foreground tabular-nums sm:order-first sm:mr-2" aria-live="polite">
- {list.length === presets.length || (cat === "All" && !query && runsOn === "all") ? `${presets.length} ${noun}` : `${list.length} of ${presets.length}`}
+ {list.length === offered.length || (cat === "All" && !query && runsOn === "all") ? `${offered.length} ${noun}` : `${list.length} of ${offered.length}`}
</span>
<RunsOnControl value={runsOn} onChange={setRunsOn} locked={locked} owner={!!viewer?.owner} />
</div>
diff --git a/src/components/studio/composer.tsx b/src/components/studio/composer.tsx
index fc179f41..79cd2737 100644
--- a/src/components/studio/composer.tsx
+++ b/src/components/studio/composer.tsx
@@ -21,6 +21,7 @@ import { DEFAULT_LOOK, lookCard } from "@/lib/catalog/soul-cards";
import { formatsOf } from "@/lib/av/formats";
import { poolRunState, quoteBody, useHostedQuote, useSettled, type RunOn } from "@/lib/hosted";
import { PoolNote } from "./pool-note";
+import { poolRunsModel } from "@/lib/pool-rules";
import { ExactOrbitControls } from "@/components/exact-orbit-controls";
import { useFlyAround } from "@/components/fly-around-run";
import { exactDefaults, takesExact, type ExactOrbit } from "@/lib/exact-orbit";
@@ -313,7 +314,12 @@ export function Composer({ docked }: { docked: boolean }) {
}, []);
const pickerOps = config.pickerOps ?? config.ops;
- const models = useMemo(() => filterModels(catalog.models, { kind: config.kind, ops: pickerOps }), [catalog.models, config.kind, pickerOps]);
+ // For a viewer with no GPU of its own (hosted runs), the open models this studio's GPUs keep off are left out.
+ const poolRules = status?.viewer?.hosted && !status.viewer.gpu.connected ? status.viewer.pool : undefined;
+ const models = useMemo(
+ () => filterModels(catalog.models, { kind: config.kind, ops: pickerOps }).filter((m) => poolRunsModel(poolRules, m)),
+ [catalog.models, config.kind, pickerOps, poolRules],
+ );
const model: ModelDef | undefined = catalog.getModel(draft.modelId);
// Fuobe Soul's presetId is a look (its own chip), not an app, motion or effect.
const takesLook = !!model?.options.looks;
@@ -447,6 +453,16 @@ export function Composer({ docked }: { docked: boolean }) {
toast(`${offModel.name} is turned off in Settings → Models & licences, so this uses ${m.name}`, { id: "model-access" });
}, [offModel, fallback, lockedModel, presetFallback, catalog, setDraft]);
+ // A model this studio's GPUs keep off, for a viewer with no GPU of its own (the studio's default, a link, a Reuse): the
+ // composer moves to the studio's default, else the first model of its list they run, before Run could fail on it.
+ const poolOff = model && !lockedModel && !presetFallback && !offModel && !poolRunsModel(poolRules, model) ? model : undefined;
+ const poolTo = poolOff ? [defaults[engine], ...models.filter((m) => m.engine === engine).map((m) => m.id)].find((id) => !!id && id !== poolOff.id && models.some((m) => m.id === id)) : undefined;
+ useEffect(() => {
+ const m = poolOff && poolTo ? catalog.getModel(poolTo) : undefined;
+ if (!m || !poolOff) return;
+ setDraft((d) => (d.modelId !== poolOff.id ? {} : { modelId: m.id, params: { ...m.defaults, numOutputs: d.params.numOutputs, enhancePrompt: d.params.enhancePrompt }, ...lookCleared(poolOff, m) }));
+ }, [poolOff, poolTo, catalog, setDraft]);
+
// An account (Your keys) starts on a paid model it can run: the studio's untouched default when it has that key, else
// the first of the list it can run. Quietly: nothing it picked changed (a model it picked is never swapped). A preset's
// recipe moves to the preset's own route instead (presetFallback).
diff --git a/src/components/studio/preset-chips.tsx b/src/components/studio/preset-chips.tsx
index 5a7fc32e..413d0f2a 100644
--- a/src/components/studio/preset-chips.tsx
+++ b/src/components/studio/preset-chips.tsx
@@ -11,6 +11,8 @@ import { cn } from "@/lib/utils";
import { onAttr, TAB_PILL, TabRow } from "@/components/ui/tab-row";
import { CoverScrollBox, CoverTile, usePickerPlayback } from "@/components/cover-tile";
import { PRESET_ICONS } from "@/components/preset-icons";
+import { usePoolRules } from "@/hooks/use-pool-rules";
+import { poolRunsPreset } from "@/lib/pool-rules";
import { loadFullCatalog, useCatalog } from "./catalog";
import { Chip, ClearableChip } from "./chip";
@@ -120,7 +122,10 @@ export function PresetChip({ type, value, onChange }: { type: "motion" | "effect
const [open, setOpen] = useState(false);
const { chip, side, measure } = usePickerSide();
const catalog = useCatalog();
- const list = catalog.presets?.[type] ?? null;
+ // For a viewer with no GPU of its own, what this studio's GPUs keep off is left out (src/lib/pool-rules.ts).
+ const rules = usePoolRules();
+ const all = catalog.presets?.[type] ?? null;
+ const list = useMemo(() => (all && rules ? all.filter((p) => poolRunsPreset(rules, p.id)) : all), [all, rules]);
const selected = value ? catalog.getPreset(value) : undefined;
// The picked preset's poster in place of its icon, as the Look chip shows its look.
const cover = selected && presetCover(selected.id);
@@ -187,9 +192,10 @@ export function MixChip({
const cover = second && presetCover(second.id);
// Kept while the sliders move, so the picker isn't sorted again on every step.
const presets = catalog.presets;
+ const rules = usePoolRules();
const mixable = useMemo(
- () => (presets ? [...presets.motion, ...presets.effect].filter((p) => p.id !== primary.id && !p.inputs.some((i) => i.key === "endImage")) : null),
- [presets, primary.id],
+ () => (presets ? [...presets.motion, ...presets.effect].filter((p) => p.id !== primary.id && !p.inputs.some((i) => i.key === "endImage") && poolRunsPreset(rules, p.id)) : null),
+ [presets, primary.id, rules],
);
return (
<ClearableChip active={!!mix} onClear={() => onChange({ mix: undefined })} clearLabel="Remove the mix">
diff --git a/src/hooks/use-pool-rules.ts b/src/hooks/use-pool-rules.ts
new file mode 100644
index 00000000..8a8bf4ab
--- /dev/null
+++ b/src/hooks/use-pool-rules.ts
@@ -0,0 +1,21 @@
+"use client";
+
+import { useEngineMode, useHydrated, useStatus } from "@/lib/api";
+import { tryFreeFor, type PoolRules } from "@/lib/pool-rules";
+
+/**
+ * What this studio's GPUs keep off for this viewer (hosted runs on, no GPU of its own): pickers leave it out
+ * (src/lib/pool-rules.ts). Undefined when nothing is kept off, with hosted runs off, or for a viewer with its own GPU.
+ */
+export function usePoolRules(): PoolRules | undefined {
+ const v = useStatus().data?.viewer;
+ return v?.hosted && !v.gpu.connected ? v.pool : undefined;
+}
+
+/** "Try free" on preset cards (tryFreeFor), once the page has hydrated: null until then, and with hosted runs off. */
+export function useTryFree(): ((p: { id: string; open: boolean }) => boolean) | null {
+ const hydrated = useHydrated();
+ const v = useStatus().data?.viewer;
+ const mode = useEngineMode();
+ return hydrated ? tryFreeFor(v, mode) : null;
+}
diff --git a/src/lib/api.ts b/src/lib/api.ts
index 515fc6b3..b7b0e458 100644
--- a/src/lib/api.ts
+++ b/src/lib/api.ts
@@ -29,6 +29,7 @@ import { fetchWithin, READ_LIMIT_MS } from "./fetch-within";
import { cursorAfter, filterToSearch, type AssetUse, type FeedFilter, type Folder } from "./library";
import { markRefusalShown, refusalShown, responseError } from "./refusals";
import { PLACE_ASK_HEADER, RUNS_CHANGED_EVENT } from "./guest-access";
+import type { PoolRules } from "./pool-rules";
import { postFile } from "./upload";
import type { ShareCreated, ShareInfo, ShareListItem, SharePatch, ShareRequest } from "./share";
import type { AccessSummary } from "./model-access";
@@ -889,6 +890,8 @@ export interface StatusInfo {
hosted?: boolean;
/** "pool": runs go to this studio's GPUs first, even with its own GPU online (either can still be picked). */
prefer?: "pool";
+ /** What this studio's GPUs keep off, for a viewer with no GPU of its own: its pickers leave it out (src/lib/pool-rules.ts). */
+ pool?: PoolRules;
/** The billing service's words for the account's balance (src/server/billing.ts). */
balance?: HostedBalance;
links?: BillingAction[];
diff --git a/src/lib/pool-rules.ts b/src/lib/pool-rules.ts
new file mode 100644
index 00000000..0d21c4ba
--- /dev/null
+++ b/src/lib/pool-rules.ts
@@ -0,0 +1,65 @@
+import type { MediaKind } from "./catalog/types";
+
+/**
+ * What this studio's GPUs run for a visitor with no GPU of its own (hosted runs): the policy's model and app lists and
+ * its kinds, as GET /api/status sends them (`viewer.pool`). Pickers leave out what these rules keep off, so a run never
+ * fails at Run for it. The server checks the same rules on every run (src/server/hosted.ts poolAllows).
+ *
+ * - `allow`: only these models (absent: every model); `deny`: never these.
+ * - `apps`: the same for apps, camera motions and effects (by preset id).
+ * - `kinds`: a kind set to false runs on the visitor's own GPU only (absent: every kind).
+ */
+export interface PoolRules {
+ allow?: string[];
+ deny?: string[];
+ apps?: { allow?: string[]; deny?: string[] };
+ kinds?: Partial<Record<MediaKind, boolean>>;
+}
+
+/** The rules a policy's pool lists and kinds make, or undefined when they keep nothing off. */
+export function poolRulesOf(p: { pool?: { allow?: string[]; deny?: string[]; apps?: { allow?: string[]; deny?: string[] } }; kinds?: Partial<Record<MediaKind, boolean>> }): PoolRules | undefined {
+ const list = (xs: unknown) => (Array.isArray(xs) ? xs.filter((x): x is string => typeof x === "string") : undefined);
+ const lists = p.pool ?? {};
+ const out: PoolRules = {};
+ const allow = list(lists.allow);
+ const deny = list(lists.deny);
+ if (allow) out.allow = allow;
+ if (deny?.length) out.deny = deny;
+ const appsAllow = list(lists.apps?.allow);
+ const appsDeny = list(lists.apps?.deny);
+ if (appsAllow || appsDeny?.length) out.apps = { ...(appsAllow && { allow: appsAllow }), ...(appsDeny?.length && { deny: appsDeny }) };
+ const off = Object.entries(p.kinds ?? {}).filter(([, v]) => v === false);
+ if (off.length) out.kinds = Object.fromEntries(off) as PoolRules["kinds"];
+ return Object.keys(out).length ? out : undefined;
+}
+
+/** Does this studio's GPUs run this open model under the rules (no rules: yes)? Cloud models are never left out here. */
+export function poolRunsModel(rules: PoolRules | undefined, m: { id: string; kind: MediaKind; engine: string }): boolean {
+ if (!rules || m.engine !== "open") return true;
+ if (rules.deny?.includes(m.id)) return false;
+ if (rules.allow && !rules.allow.includes(m.id)) return false;
+ return rules.kinds?.[m.kind] !== false;
+}
+
+/** Does this studio's GPUs run this app, camera motion or effect under the rules (no rules: yes)? */
+export function poolRunsPreset(rules: PoolRules | undefined, presetId: string): boolean {
+ const apps = rules?.apps;
+ if (!apps) return true;
+ if (apps.deny?.includes(presetId)) return false;
+ return !apps.allow || apps.allow.includes(presetId);
+}
+
+/**
+ * "Try free" on preset cards: with hosted runs on, a card whose preset runs on this studio's GPUs for this viewer (a
+ * guest, an account with no GPU of its own, or one whose runs go to this studio's GPUs first) says it can be tried there.
+ * Null (no card says it) with hosted runs off, for a viewer whose runs go to its own GPU, and with cloud models only.
+ */
+export function tryFreeFor(
+ viewer: { hosted?: boolean; prefer?: "pool"; gpu: { connected: boolean }; pool?: PoolRules } | undefined,
+ engineMode: "cloud" | "open" | "both",
+): ((p: { id: string; open: boolean }) => boolean) | null {
+ if (!viewer?.hosted || engineMode === "cloud") return null;
+ if (viewer.gpu.connected && viewer.prefer !== "pool") return null;
+ const rules = viewer.gpu.connected ? undefined : viewer.pool;
+ return (p) => p.open && poolRunsPreset(rules, p.id);
+}
diff --git a/src/server/account-gpu.ts b/src/server/account-gpu.ts
index e423f44a..369ae622 100644
--- a/src/server/account-gpu.ts
+++ b/src/server/account-gpu.ts
@@ -14,6 +14,7 @@ import { blockedForAccounts, fetchPublic, isLoopbackGpu } from "./remote-fetch";
import { isInstallHost, REFUSED_ADDRESS } from "./gpu/hosts";
import { balance as billingBalance, policy as billingPolicy, type Action, type Balance } from "./billing";
import { poolReady } from "./hosted";
+import { poolRulesOf, type PoolRules } from "@/lib/pool-rules";
/**
* "Your GPU" (public sign-up): the ComfyUI an account connects, where its runs go. The server calls
@@ -186,6 +187,11 @@ export interface VisitorView {
* policy says so). Absent: its own GPU first, as before. Either can always be picked.
*/
prefer?: "pool";
+ /**
+ * What this install's GPUs keep off (the policy's model and app lists, and its kinds), for a visitor with no GPU of its
+ * own: its pickers leave those out instead of failing at Run. Absent: nothing is kept off, or it has a GPU of its own.
+ */
+ pool?: PoolRules;
/** The billing service's words for the account's balance (billing.ts): the top bar's chip and the account menu. */
balance?: Balance;
/** Extra links the billing service sends for the menu. */
@@ -218,6 +224,8 @@ export async function visitorStatus(account: Account | null) {
const p = await billingPolicy(account?.id ?? null);
if (p?.hosted) viewer.hosted = true;
if (p?.hosted && p.prefer === "pool") viewer.prefer = "pool";
+ const rules = p?.hosted && !gpu ? poolRulesOf(p) : undefined;
+ if (rules) viewer.pool = rules;
if (account && p?.links?.length) viewer.links = p.links;
if (account && p?.notice) viewer.notice = p.notice;
const b = account ? await billingBalance(account.id) : null;
diff --git a/tests/hosted-pickers.test.ts b/tests/hosted-pickers.test.ts
new file mode 100644
index 00000000..4be1441e
--- /dev/null
+++ b/tests/hosted-pickers.test.ts
@@ -0,0 +1,62 @@
+import { describe, expect, it } from "vitest";
+import { poolRulesOf, poolRunsModel, poolRunsPreset, tryFreeFor } from "@/lib/pool-rules";
+
+/*
+ * For a visitor with no GPU of its own (hosted runs), pickers leave out what this studio's GPUs keep off (the policy's
+ * model and app lists and its kinds), the same rules the server checks on every run; and "Try free" on preset cards.
+ */
+
+describe("what pickers leave out for a visitor with no GPU of its own", () => {
+ const open = (id: string, kind: "image" | "video" | "model3d" = "image") => ({ id, kind, engine: "open" });
+ it("the policy's lists and kinds, made into rules only when they keep something off", () => {
+ expect(poolRulesOf({ pool: {} })).toBeUndefined();
+ expect(poolRulesOf({ pool: { deny: [] }, kinds: { image: true } })).toBeUndefined();
+ expect(poolRulesOf({ pool: { allow: ["a"], deny: ["b"], apps: { deny: ["app-x"] } }, kinds: { model3d: false, video: true } })).toEqual({
+ allow: ["a"],
+ deny: ["b"],
+ apps: { deny: ["app-x"] },
+ kinds: { model3d: false },
+ });
+ });
+ it("models: the deny list, the allow list and the kinds; cloud models are never theirs to judge", () => {
+ const rules = poolRulesOf({ pool: { deny: ["oss-x"] }, kinds: { model3d: false } });
+ expect(poolRunsModel(rules, open("oss-x"))).toBe(false);
+ expect(poolRunsModel(rules, open("oss-y"))).toBe(true);
+ expect(poolRunsModel(rules, open("oss-3d", "model3d"))).toBe(false);
+ expect(poolRunsModel(rules, { id: "oss-x", kind: "image", engine: "cloud" })).toBe(true);
+ expect(poolRunsModel({ allow: ["oss-y"] }, open("oss-z"))).toBe(false);
+ expect(poolRunsModel(undefined, open("oss-x"))).toBe(true);
+ });
+ it("apps, camera motions and effects: by their own lists", () => {
+ expect(poolRunsPreset({ apps: { deny: ["app-x"] } }, "app-x")).toBe(false);
+ expect(poolRunsPreset({ apps: { allow: ["app-y"] } }, "app-x")).toBe(false);
+ expect(poolRunsPreset({ apps: { allow: ["app-y"] } }, "app-y")).toBe(true);
+ expect(poolRunsPreset({ deny: ["m"] }, "app-x")).toBe(true);
+ });
+ it("agree with the server's own check of every run", async () => {
+ const { poolAllows } = await import("@/server/hosted");
+ const policies = [{}, { allow: ["m"] }, { deny: ["m"] }, { allow: ["n"] }, { apps: { deny: ["app-x"] } }, { apps: { allow: ["app-y"] } }];
+ for (const pool of policies) {
+ const rules = poolRulesOf({ pool });
+ for (const [model, app] of [["m", undefined], ["n", undefined], ["m", "app-x"], ["m", "app-y"]] as const) {
+ const client = poolRunsModel(rules, open(model)) && (!app || poolRunsPreset(rules, app));
+ expect(client, JSON.stringify({ pool, model, app })).toBe(poolAllows({ pool }, model, app));
+ }
+ }
+ });
+});
+
+describe("Try free on preset cards", () => {
+ const card = { id: "app-x", open: true };
+ it("only with hosted runs on, for a viewer whose runs go to this studio's GPUs, on presets they run", () => {
+ expect(tryFreeFor(undefined, "both")).toBeNull();
+ expect(tryFreeFor({ gpu: { connected: false } }, "both")).toBeNull();
+ expect(tryFreeFor({ hosted: true, gpu: { connected: false } }, "cloud")).toBeNull();
+ expect(tryFreeFor({ hosted: true, gpu: { connected: true } }, "both")).toBeNull();
+ expect(tryFreeFor({ hosted: true, gpu: { connected: true }, prefer: "pool" }, "both")?.(card)).toBe(true);
+ const guest = tryFreeFor({ hosted: true, gpu: { connected: false }, pool: { apps: { deny: ["app-x"] } } }, "both")!;
+ expect(guest(card)).toBe(false);
+ expect(guest({ id: "app-y", open: true })).toBe(true);
+ expect(guest({ id: "app-y", open: false })).toBe(false);
+ });
+});
diff --git a/tests/hosted-price-check.test.ts b/tests/hosted-price-check.test.ts
index a98a4524..690ea1f6 100644
--- a/tests/hosted-price-check.test.ts
+++ b/tests/hosted-price-check.test.ts
@@ -7,7 +7,8 @@ import { tempDir } from "./helpers/temp-dir";
// The price check before Run (`?preview=1`) on hosted runs: where a new run would stand in line and the wait, and a
// refusal (busy, a limit, a model or files this install's GPUs don't take) said before Run is pressed, in the words the
// run itself would get. A run's state reads the same from the list and from its own route (a refresh, a second
-// device). With hosted runs off every answer is as before.
+// device), and the status tells a visitor with no GPU of its own what this install's GPUs keep off, for its pickers.
+// With hosted runs off every answer is as before.
vi.mock("next/server", async (importOriginal) => ({ ...(await importOriginal<typeof import("next/server")>()), connection: async () => {} }));
const dir = tempDir("fuobe-hosted-price-check-");
process.env.FUOBE_DATA_DIR = dir;
@@ -28,6 +29,7 @@ process.env.COMFYUI_URL = comfy.url;
const auth = await import("@/server/auth");
const generationsRoute = await import("@/app/api/generations/route");
const oneRoute = await import("@/app/api/generations/[id]/route");
+const { visitorStatus } = await import("@/server/account-gpu");
const { POOL_WORDS } = await import("@/lib/relay");
const { db } = await import("@/server/db");
const { resetRates } = await import("@/server/rate");
@@ -216,3 +218,22 @@ describe("a run's state after a refresh or on a second device", () => {
});
});
+describe("what this install's GPUs keep off, in the status", () => {
+ it("is told to a visitor with no GPU of its own, only when the policy keeps something off, and never with hosted runs off", async () => {
+ process.env.FUOBE_BILLING_URL = fake.url;
+ process.env.FUOBE_BILLING_TOKEN = "test-billing-token";
+ fake.policy = { ...FAKE_POLICY, pool: { deny: ["oss-z-image-turbo"], apps: { deny: ["app-x"] } }, kinds: { model3d: false } };
+ expect((await visitorStatus(auth.accountById(a)!)).viewer.pool).toBeUndefined();
+ process.env.FUOBE_HOSTED_RUNS = "1";
+ const s = await visitorStatus(auth.accountById(a)!);
+ expect(s.viewer.pool).toEqual({ deny: ["oss-z-image-turbo"], apps: { deny: ["app-x"] }, kinds: { model3d: false } });
+ expect((await visitorStatus(null)).viewer.pool).toEqual(s.viewer.pool);
+ // Its own GPU runs what this install's GPUs don't: nothing is left out of its pickers.
+ auth.setAccountGpu(a, { mode: "computer" });
+ expect((await visitorStatus(auth.accountById(a)!)).viewer.pool).toBeUndefined();
+ auth.setAccountGpu(a, null);
+ billing.resetBillingCache();
+ fake.policy = { ...FAKE_POLICY };
+ expect((await visitorStatus(auth.accountById(a)!)).viewer.pool).toBeUndefined();
+ });
+});