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.

Admin runs: look runs up by id, name the job a worker holds back, mark API runs

Adarshfaa3684525a2
diff --git a/docs/admin-api.md b/docs/admin-api.md
index 57d34fa2..960c7b2b 100644
--- a/docs/admin-api.md
+++ b/docs/admin-api.md
@@ -107,7 +107,7 @@ Times are epoch milliseconds and sizes are bytes. Every answer is `Cache-Control
| `GET /api/admin/accounts/{id}` | | one account with its numbers; 404 `No such account` |
| `PATCH /api/admin/accounts/{id}` | exactly one of `{ disabled: boolean }` or `{ signOut: true }` | the account (no numbers) |
| `DELETE /api/admin/accounts/{id}` | | 204 |
-| `GET /api/admin/generations` | `account` (one account), else `whose` (`people`: accounts' and guests' runs, the default; `ours`: the owner's own; `everyone`); `source` (the owner's runs only: `hands-on`, or `batch` for any run a script said it made: `batch`, `drill`, `example`, `test`); `where` (`pool`: this install's GPUs, the owner's runs on its ComfyUI too; `provider`: a cloud provider; `own`: an account's own GPU); `status` (`finished` or `done`, `failed`, `canceled`, `waiting`, `started`, and `running` for waiting and started); `kind` (`image`, `video`, `audio`, `model3d`, `text`); `model` (letters of the model id); `from` and `to` (`yyyy-mm-dd` in UTC, both days included); `q` (words of the prompt, or a run id); `before` (the last page's `next`); `limit` (1 to 100, default 30) | `{ items, next }`; `next` is null on the last page. Each run has `whose`: `account`, `guest` or `owner`. Each output has a `state`: `shown`, `held` (hidden, or waiting for its check) or `removed` (its file is gone). A failed run on this install's GPUs (and the owner's own failed run) also has `detail`: the technical reason, which the account never sees. `account` is `{ id, email }` (`email` null: a deleted account), `{ id, emailHidden: true }` without `accounts:read`, or `null` for the owner's own run, which has `source` too |
+| `GET /api/admin/generations` | `account` (one account), else `whose` (`people`: accounts' and guests' runs, the default; `ours`: the owner's own; `everyone`); `source` (the owner's runs only: `hands-on`, or `batch` for any automated run: `batch`, `drill`, `example`, `test`, `api`); `where` (`pool`: this install's GPUs, the owner's runs on its ComfyUI too; `provider`: a cloud provider; `own`: an account's own GPU); `status` (`finished` or `done`, `failed`, `canceled`, `waiting`, `started`, and `running` for waiting and started); `kind` (`image`, `video`, `audio`, `model3d`, `text`); `model` (letters of the model id); `from` and `to` (`yyyy-mm-dd` in UTC, both days included); `q` (words of the prompt, or a run id); `ids` (a comma list of up to 100 run ids: those runs, whoever's they are); `before` (the last page's `next`); `limit` (1 to 100, default 30) | `{ items, next }`; `next` is null on the last page. Each run has `whose`: `account`, `guest` or `owner`. Each output has a `state`: `shown`, `held` (hidden, or waiting for its check) or `removed` (its file is gone). A failed run on this install's GPUs (and the owner's own failed run) also has `detail`: the technical reason, which the account never sees. `account` is `{ id, email }` (`email` null: a deleted account), `{ id, emailHidden: true }` without `accounts:read`, or `null` for the owner's own run, which has `source` too (`hands-on` from the site; `batch`, `drill`, `example`, `test` as its script said; `api` for a run sent with an API token that said none) and `sourceName` when its script gave one |
| `GET /api/admin/generations/{id}` | needs `runs:read` and `outputs:view` | One run in full, an account's, a guest's or the owner's own: `{ run, stored, fix, trouble, where, model, preset, studio, prompt, negativePrompt, asked, settings, inputs, batch, near, chain, sent, timing, jobs, workerLog, money, madeBy, surface, providerId, progress, checks }`. `stored.detail` is the technical reason for the owner. `inputs` lists each input file by slot, with its `state` (`kept` with its `url`, `removed`, `example`, `inline`, `link`). `chain` is `{ before, after }`: the steps it waits for and the steps that wait for it. Keys, tokens and GPU addresses are never part of it. 404 for an unknown run |
| `DELETE /api/admin/generations/{id}` | | 204; 404 for an unknown run or the owner's own |
| `POST /api/admin/outputs/hide` | `{ assetIds?, generationIds? }` (up to 500 each) | `{ hidden }` |
@@ -115,7 +115,7 @@ Times are epoch milliseconds and sizes are bytes. Every answer is `Cache-Control
| `POST /api/admin/outputs/remove` | the same, and `evidence?: true` to keep the files in a locked folder | `{ removed }` |
| `GET /api/admin/files/{path}` | `Range` works | the file, an account's or the owner's own (held ones too); 404 for unknown paths |
| `GET /api/admin/reports` | `limit` (1 to 500, default 100) | `{ items }`, newest first |
-| `GET /api/admin/queue` | | `{ held, lanes, running, holding, queued, next, nextTotal, text, controls, now }`. `queued` is in the order the workers serve it, each with `rank` (null while no worker takes it), `why`, `code` (`class`, `next`, `boost`, `held`, `pinned`, `paused`), `override` and `person` (a key, never an account id). `controls`: `{ pools, workers, overrides, ended, modes }` ([gpu-workers.md](gpu-workers.md#the-queue)) |
+| `GET /api/admin/queue` | | `{ held, lanes, running, holding, queued, next, nextTotal, text, controls, now }`. `queued` is in the order the workers serve it, each with `rank` (null while no worker takes it), `why`, `code` (`class`, `next`, `boost`, `held`, `pinned`, `paused`), `override` and `person` (a key, never an account id). A `holding` row for a worker that holds back the line (`task` null) names the job it would take first (`generationId`, `model`, `op`, `principal`). `controls`: `{ pools, workers, overrides, ended, modes }` ([gpu-workers.md](gpu-workers.md#the-queue)) |
| `POST /api/admin/queue/mode` | `{ pool?, worker?, mode, forMin? }`: `mode` is `people-first`, `people-only`, `ours-first`, `balanced`, or `null` (back to normal); `forMin` is 1 to 10080, or `null` (until switched back) | `{ mode, before }`; 400 for a value out of bounds, 404 for no such worker |
| `GET /api/admin/queue/overrides` | | `{ live, ended }` (the last 20 that ended) |
| `POST /api/admin/queue/overrides` | `{ kind: "run", generationId, action: "next" | "hold", worker?, forMin? }` or `{ kind: "person", person | account, action: "boost" | "hold", forMin }` (`forMin` is needed for a boost) | 201 `{ override, replaced }`; 404 for no such run, worker or person with a run on the GPUs; 409 for a run that ended |
diff --git a/docs/cli.md b/docs/cli.md
index 9b17e73b..f67bd119 100644
--- a/docs/cli.md
+++ b/docs/cli.md
@@ -352,8 +352,9 @@ For script writers who'd rather call the API directly: `GET /api/models` (`kind`
`q`, `hidden=1`; it answers with the studios' `defaults` per engine, `demoMode`, and per model
`connected` and `runs`), `POST /api/generations` (with `?preview=1` to price; a model id Fuobe has
retired runs on the model that replaced it, and the answer gives that `modelId` with `notes` saying so;
-a script can say what made the run with `source`: `batch`, `drill`, `example` or `test`, which the admin runs
-list tells apart from `hands-on` runs),
+a script can say what made the run with `source` (`batch`, `drill`, `example` or `test`) and `sourceName` (its own
+name, up to 80 characters); a run sent with an API token and no `source` reads as `api`, and the admin runs list tells
+all of them apart from `hands-on` runs made on the site),
`GET /api/generations[/<id>]`,
`POST /api/generations/<id>/cancel`, `POST /api/uploads` (multipart `file`), `GET /api/files/…`,
`GET /api/status`, `GET|PATCH /api/assist/skills[/<name>]`, `POST /api/assist/skills/upload`
diff --git a/src/app/api/generations/route.ts b/src/app/api/generations/route.ts
index 66374708..740249f5 100644
--- a/src/app/api/generations/route.ts
+++ b/src/app/api/generations/route.ts
@@ -180,7 +180,8 @@ export async function POST(request: Request) {
// or key only (src/lib/own-setup.ts), as on the Genjutsu page: an account's run goes there (accountRun answers Connect
// your GPU or Add your key when it has neither), a run on this install's GPUs is refused with the setup's label
// (hosted-run.ts poolGate), and a guest signs up first. Never this studio's own GPU for a visitor.
- let req = account ? { ...asked, account: account.id, source: undefined, engine: accountEngineMode(account.id) === "open" ? ("open" as const) : asked.engine } : { ...asked, account: undefined };
+ // The owner's run sent with an API token (a script, the CLI, an agent) and no source of its own reads as automated.
+ let req = account ? { ...asked, account: account.id, source: undefined, sourceName: undefined, engine: accountEngineMode(account.id) === "open" ? ("open" as const) : asked.engine } : { ...asked, account: undefined, ...(token && !asked.source && { source: "api" as const }) };
const onOwn = <T,>(fn: () => T): T => (account ? asAccount(account.id, fn) : fn());
// A visitor's price check: priced as it would run, as that visitor (an account: its own GPU and keys; a guest: the open
// engine, no demo).
diff --git a/src/lib/catalog/types.ts b/src/lib/catalog/types.ts
index b708618c..d8a922cd 100644
--- a/src/lib/catalog/types.ts
+++ b/src/lib/catalog/types.ts
@@ -1362,9 +1362,12 @@ export interface GenerationRequest {
batchTitle?: string;
/**
* Where an owner's run came from, as the script or runner that made it said (POST /api/generations): "hands-on" (none
- * said), or a batch, drill, example or test run. The admin runs list tells them apart. An account's run never has one.
+ * said, from the site), a batch, drill, example or test run, or "api" (sent with an API token and no source of its
+ * own: a script, the CLI or an agent). The admin runs list tells them apart. An account's run never has one.
*/
source?: RunSource;
+ /** The script, runner or app that made an owner's run, in its own words ("Object Remover examples"): shown beside its source. */
+ sourceName?: string;
/**
* Server-set: made by a run of a skill's recipe (src/lib/recipe.ts): the skill's name and the run's id (its batch), so
* a run's history can be read back. Stripped from API input, like chainFilled.
@@ -1800,5 +1803,5 @@ export interface PrestepRoute {
export const LAST_FRAME_CHAIN = "chain:last-frame";
/** Where an owner's run came from (GenerationRequest.source). */
-export const RUN_SOURCES = ["hands-on", "batch", "drill", "example", "test"] as const;
+export const RUN_SOURCES = ["hands-on", "batch", "drill", "example", "test", "api"] as const;
export type RunSource = (typeof RUN_SOURCES)[number];
diff --git a/src/server/account-admin.ts b/src/server/account-admin.ts
index 2c745b3b..e8a6c18d 100644
--- a/src/server/account-admin.ts
+++ b/src/server/account-admin.ts
@@ -136,8 +136,10 @@ export function accountRunOptions(sp: URLSearchParams): (ListOptions & { whose:
const asked = Math.trunc(Number(sp.get("limit")));
const source = sp.get("source");
const askedWhose = sp.get("whose");
+ // Up to 100 runs by id (the panel's Queue and Activity: whose each run is), whoever's they are.
+ const ids = sp.get("ids") === null ? undefined : [...new Set(sp.get("ids")!.split(",").map((x) => x.trim()).filter((x) => /^[\w-]{1,64}$/.test(x)))].slice(0, MAX_RUNS_PAGE);
// A source names the owner's runs, so it means Ours.
- const whose: RunsWhose = account ? "people" : source === "hands-on" || source === "batch" ? "ours" : askedWhose === "ours" || askedWhose === "everyone" ? askedWhose : "people";
+ const whose: RunsWhose = account ? "people" : ids ? "everyone" : source === "hands-on" || source === "batch" ? "ours" : askedWhose === "ours" || askedWhose === "everyone" ? askedWhose : "people";
const where = sp.get("where");
const model = sp.get("model")?.trim().slice(0, 80);
const q = sp.get("q")?.trim().slice(0, 200);
@@ -152,10 +154,11 @@ export function accountRunOptions(sp: URLSearchParams): (ListOptions & { whose:
kind: KINDS.has(kind) ? kind : undefined,
...(model && { modelLike: model }),
...(q && { q }),
+ ...(ids && { ids }),
...(from !== undefined && { since: from }),
...(to !== undefined && { until: to + DAY }),
...cursorFrom(sp.get("before")),
- limit: sp.get("limit") && Number.isFinite(asked) ? Math.max(1, Math.min(asked, MAX_RUNS_PAGE)) : RUNS_PAGE,
+ limit: ids ? Math.max(1, ids.length) : sp.get("limit") && Number.isFinite(asked) ? Math.max(1, Math.min(asked, MAX_RUNS_PAGE)) : RUNS_PAGE,
};
}
@@ -180,7 +183,7 @@ export type RunWhose = "account" | "guest" | "owner";
* A run in the owner's admin list: an account's or a guest's (as AccountRun), or the owner's own (`account` null, `whose`
* "owner", and `source`: what made it, "hands-on" when its runner said nothing).
*/
-export type AdminRun = Omit<AccountRun, "account"> & { account: AccountOfRun | null; source?: RunSource };
+export type AdminRun = Omit<AccountRun, "account"> & { account: AccountOfRun | null; source?: RunSource; sourceName?: string };
/** Whose a run is: its email (null: the account was deleted), or no email and `emailHidden` for a reader that may not see emails. */
export type AccountOfRun = { id: string; email?: string | null; emailHidden?: true };
@@ -203,7 +206,7 @@ function withStates(outputs: OutputFile[]): (OutputFile & { state: OutputState }
*/
export type AccountRunFacts = Pick<
AdminRun,
- "id" | "batchId" | "feature" | "presetId" | "presetName" | "modelId" | "modelName" | "engine" | "provider" | "op" | "kind" | "status" | "progress" | "costUsd" | "createdAt" | "updatedAt" | "completedAt" | "place" | "account" | "whose" | "source"
+ "id" | "batchId" | "feature" | "presetId" | "presetName" | "modelId" | "modelName" | "engine" | "provider" | "op" | "kind" | "status" | "progress" | "costUsd" | "createdAt" | "updatedAt" | "completedAt" | "place" | "account" | "whose" | "source" | "sourceName"
> & { outputs: { kind: OutputFile["kind"]; state: OutputState }[] };
function factsOnly(r: AdminRun): AccountRunFacts {
@@ -229,6 +232,7 @@ function factsOnly(r: AdminRun): AccountRunFacts {
account: r.account,
whose: r.whose,
...(r.source && { source: r.source }),
+ ...(r.sourceName && { sourceName: r.sourceName }),
outputs: r.outputs.map((x) => ({ kind: x.kind, state: x.state })),
};
}
@@ -288,7 +292,7 @@ function asAccountRun(g: Generation, emails: Map<string, string>, showEmails: bo
/** Any run as the owner's admin list has it: an account's (asAccountRun), or the owner's own with its source. */
function asAdminRun(g: Generation, emails: Map<string, string>, showEmails: boolean): AdminRun {
if (g.request.account) return asAccountRun(g, emails, showEmails);
- return { ...g, outputs: withStates(g.outputs), account: null, whose: "owner", source: g.request.source ?? "hands-on", ...ownDetail(g), ...declinedCardsIn(g.id) };
+ return { ...g, outputs: withStates(g.outputs), account: null, whose: "owner", source: g.request.source ?? "hands-on", ...(g.request.sourceName && { sourceName: g.request.sourceName }), ...ownDetail(g), ...declinedCardsIn(g.id) };
}
/**
diff --git a/src/server/computer/pool.ts b/src/server/computer/pool.ts
index a61fae25..2f726802 100644
--- a/src/server/computer/pool.ts
+++ b/src/server/computer/pool.ts
@@ -523,6 +523,11 @@ export function ownerWaitingNow(w: WorkerRow, now = Date.now()): number {
return gpuClaimable(w, now, "owner");
}
+/** The first job in line this worker may claim right now (people's before the owner's), or null: what a worker that holds back the line would take first. */
+export function firstClaimableNow(w: WorkerRow, now = Date.now()): TaskRow | null {
+ return gpuClaimableRows(w, now, "people")[0] ?? gpuClaimableRows(w, now, "owner")[0] ?? null;
+}
+
function gpuClaimable(w: WorkerRow, now: number, whose: "people" | "owner"): number {
return gpuClaimableRows(w, now, whose).length;
}
diff --git a/src/server/computer/queue-live.ts b/src/server/computer/queue-live.ts
index 2a5dd194..e3017ef1 100644
--- a/src/server/computer/queue-live.ts
+++ b/src/server/computer/queue-live.ts
@@ -6,7 +6,7 @@ import { laneLabel } from "@/lib/lanes";
import { HOLDING_OTHER, HOLDING_WHY, SENT_STATES, type WorkerHolding } from "@/lib/relay";
import { db } from "../db";
import { loadIndex } from "../gpu/index-file";
-import { claimableNow, controlledLine, localWorkOf, ownerWaitingNow, workerState } from "./pool";
+import { claimableNow, controlledLine, firstClaimableNow, localWorkOf, ownerWaitingNow, workerState } from "./pool";
import { controlWords, effectiveMode, liveOverrides, MODE_WORDS, overrideView, personKey, poolMode, poolModes, recentOverrides, sweepControls, workerModeOf, type EffectiveMode, type OverrideView, type QueueMode } from "./queue-controls";
import type { LocalWork } from "@/lib/relay";
import { json, taskCold, taskProgress, type TaskRow } from "./tasks";
@@ -90,8 +90,8 @@ export interface QueueControls {
/**
* Held on a worker: a job a worker took that doesn't run yet (`task` set), or a worker that may take the line's work
- * and holds it back (`task` null; `waiting`: how many jobs in line it could take now). `why` in plain words, `code`
- * short, `since` when known.
+ * and holds it back (`task` null; `waiting`: how many jobs in line it could take now; `generationId`, `model`, `op`
+ * and `principal`: the job it would take first). `why` in plain words, `code` short, `since` when known.
*/
export interface HeldJob {
worker: string;
@@ -237,8 +237,12 @@ export function liveQueue(now = Date.now()): { running: RunningJob[]; holding: H
const waiting = claimableNow(w, now) + ownerWaitingNow(w, now);
if (!waiting) continue;
const s = workerState(w, now);
- if (h && now - w.seen_at <= HOLDING_FRESH_MS) holding.push({ worker: w.name, task: null, generationId: null, model: null, op: null, principal: null, why: holdingWords(h.why), code: h.why, since: h.since, waiting });
- else if (!busy.has(w.id) && s.state !== "idle" && s.state !== "busy") holding.push({ worker: w.name, task: null, generationId: null, model: null, op: null, principal: null, why: s.words, code: s.state, since: null, waiting });
+ // The job it would take first: whose run the worker holds back.
+ const first = firstClaimableNow(w, now);
+ const g = first ? genOf(first.generation_id) : undefined;
+ const next = first ? { generationId: first.generation_id, model: modelLabel(g?.model_id), op: g?.op ?? null, principal: principalKind(first) } : { generationId: null, model: null, op: null, principal: null };
+ if (h && now - w.seen_at <= HOLDING_FRESH_MS) holding.push({ worker: w.name, task: null, ...next, why: holdingWords(h.why), code: h.why, since: h.since, waiting });
+ else if (!busy.has(w.id) && s.state !== "idle" && s.state !== "busy") holding.push({ worker: w.name, task: null, ...next, why: s.words, code: s.state, since: null, waiting });
}
// Later steps of chains: queued, not handed to a provider, waiting for their earlier steps.
diff --git a/src/server/generations.ts b/src/server/generations.ts
index 920f1d43..ff8b8709 100644
--- a/src/server/generations.ts
+++ b/src/server/generations.ts
@@ -736,6 +736,8 @@ export interface ListOptions {
where?: "pool" | "provider" | "own";
/** A model id that holds these letters. */
modelLike?: string;
+ /** Only these runs (by id), helper steps too. */
+ ids?: string[];
/** The owner's runs only, by `request.source`: "hands-on" (none set, or "hands-on") or "batch" (any other source). */
source?: "hands-on" | "batch";
/** Date range on createdAt: since ≤ t < until. */
@@ -767,6 +769,10 @@ export function listGenerations(o: ListOptions = {}): Generation[] {
else if (o.where === "provider") add(`${place} <> 'pool' AND g.provider NOT IN ('comfyui', 'mock')`);
else if (o.where === "own") add(`${place} <> 'pool' AND g.provider = 'comfyui' AND json_extract(g.request_json, '$.account') > ''`);
if (o.modelLike) add("g.model_id LIKE ? ESCAPE '!'", `%${o.modelLike.replace(/[!%_]/g, (c) => `!${c}`)}%`);
+ if (o.ids) {
+ if (!o.ids.length) add("0");
+ else oneOf("g.id", o.ids);
+ }
if (o.batchId) add("g.batch_id = ?", o.batchId);
if (o.feature) add("g.feature = ?", o.feature);
if (o.features?.length) add(`(${o.features.map(() => "g.feature LIKE ?").join(" OR ")})`, ...o.features.map(featureLike));
@@ -785,7 +791,7 @@ export function listGenerations(o: ListOptions = {}): Generation[] {
const any = [set.length ? `g.review IN (${set.map(() => "?").join(", ")})` : "", o.reviews.includes("none") ? "g.review IS NULL" : ""].filter(Boolean);
add(`(${any.join(" OR ")})`, ...set);
}
- if (!o.steps && !o.feature && !o.features?.length && !o.batchId) {
+ if (!o.steps && !o.feature && !o.features?.length && !o.batchId && !o.ids) {
add(`g.feature NOT LIKE ? AND g.feature NOT IN (${HELPER_FEATURES.map(() => "?").join(", ")})`, `%${HELPER_SUFFIX}`, ...HELPER_FEATURES);
}
// The cursor's order: the Trash by deletion, a pinned list by pin, the rest by creation (then id, all descending).
diff --git a/src/server/request-schema.ts b/src/server/request-schema.ts
index 5ebdb2fd..52c882c7 100644
--- a/src/server/request-schema.ts
+++ b/src/server/request-schema.ts
@@ -164,4 +164,5 @@ export const GenerationRequestSchema = z.object({
batchTitle: z.string().max(200).optional(),
// An owner's script or runner says what made the run (a batch, a drill…); an account's run drops it.
source: z.enum(RUN_SOURCES).optional(),
+ sourceName: z.string().trim().min(1).max(80).optional(),
});
diff --git a/tests/account-runs-admin.test.ts b/tests/account-runs-admin.test.ts
index ab65a3cb..a62d68de 100644
--- a/tests/account-runs-admin.test.ts
+++ b/tests/account-runs-admin.test.ts
@@ -306,6 +306,11 @@ describe("Settings → Accounts: what accounts make", () => {
const day = new Date().toISOString().slice(0, 10);
expect(ids(await listed(`from=${day}&to=${day}&limit=100`))).toContain(ofB);
expect(ids(await listed("from=2001-01-01&to=2001-01-02&limit=100"))).toEqual([]);
+ // By id, whoever's: the panel's Queue and Activity ask whose each run is.
+ const byId = await listed(`ids=${ofB},${mineDrill},${guest},nope,../x`);
+ expect(ids(byId).sort()).toEqual([guest, mineDrill, ofB].sort());
+ expect(byId.items.find((g) => g.id === mineDrill)).toMatchObject({ whose: "owner", account: null, source: "drill" });
+ expect(ids(await listed("ids="))).toEqual([]);
});
it("never lists the owner's runs unless asked, and never deletes them", async () => {
diff --git a/tests/admin-queue-live.test.ts b/tests/admin-queue-live.test.ts
index 36302a5f..53e27396 100644
--- a/tests/admin-queue-live.test.ts
+++ b/tests/admin-queue-live.test.ts
@@ -159,9 +159,12 @@ describe("what the workers do now", () => {
it("a worker that holds back the line's work: its reason, since when and how many jobs it could take", () => {
const w = worker("holds");
task();
- task({ account: "acct-2" });
+ const person = task({ account: "acct-2" });
beat(w, { holding: { why: "local-work", since: clock - 12 * MIN } });
- expect(liveQueue(clock).holding).toEqual([{ worker: "holds", task: null, generationId: null, model: null, op: null, principal: null, why: "Waiting for local ComfyUI work to finish", code: "local-work", since: clock - 12 * MIN, waiting: 2 }]);
+ // It names the job it would take first, a person's before the owner's, so the panel can say whose it holds back.
+ expect(liveQueue(clock).holding).toEqual([
+ { worker: "holds", task: null, generationId: person.gid, model: expect.anything(), op: expect.anything(), principal: "user", why: "Waiting for local ComfyUI work to finish", code: "local-work", since: clock - 12 * MIN, waiting: 2 },
+ ]);
// An unknown reason from a newer worker reads plainly.
beat(w, { holding: { why: "something-new", since: clock } });
expect(liveQueue(clock).holding[0]).toMatchObject({ why: "Not starting yet", code: "something-new" });
diff --git a/tests/cli-api.test.ts b/tests/cli-api.test.ts
index e81bb158..0daba4ba 100644
--- a/tests/cli-api.test.ts
+++ b/tests/cli-api.test.ts
@@ -156,3 +156,25 @@ describe("POST /api/generations?preview=1", () => {
expect((await res.json()).error).toBe("Add a start frame");
});
});
+
+describe("POST /api/generations: where an owner's run came from", () => {
+ const send = (body: unknown, headers: Record<string, string> = {}) => postGeneration(new Request("http://localhost/api/generations", { method: "POST", headers, body: JSON.stringify(body) }));
+ const stored = (id: string) => listGenerations({ limit: 200, steps: true }).find((g) => g.id === id)!.request;
+ const idOf = async (res: Response) => {
+ expect(res.status).toBeLessThan(300);
+ const j = (await res.json()) as { id?: string; ids?: string[]; items?: { id: string }[] };
+ return j.id ?? j.ids?.[0] ?? j.items![0]!.id;
+ };
+
+ it("keeps a script's source and name, reads an API token's run as automated, and the site's own as hands-on", async () => {
+ const { createToken } = await import("@/server/auth");
+ const { token } = createToken("runner");
+ const tagged = await idOf(await send({ feature: "cli", modelId: "nano-banana-pro", prompt: "a fox", source: "example", sourceName: "Object Remover" }, { authorization: `Bearer ${token}` }));
+ expect(stored(tagged)).toMatchObject({ source: "example", sourceName: "Object Remover" });
+ const api = await idOf(await send({ feature: "cli", modelId: "nano-banana-pro", prompt: "a fox" }, { authorization: `Bearer ${token}` }));
+ expect(stored(api).source).toBe("api");
+ const site = await idOf(await send({ feature: "cli", modelId: "nano-banana-pro", prompt: "a fox" }));
+ expect(stored(site).source).toBeUndefined();
+ expect((await send({ feature: "cli", modelId: "nano-banana-pro", prompt: "a fox", source: "robot" })).status).toBe(400);
+ });
+});