Files
olivv-cs-ComfyUI-FunPack/app/shell/tests/client.test.js
T
digital-garbage ea30989752 app: half the queue was never read
/queue answers with queue_running AND queue_pending, and only the first was
looked at. A job sits in the second from the moment /prompt returns until the
worker picks it up -- always briefly, and for as long as it takes whenever
something is running ahead of it, which on a shared box is the ordinary case. A
reload in that window found nothing, handed Generate back, and let the same job
be queued twice: the first copy then ran unnamed, its messages failing the id
check, burning GPU time while the UI narrated the second.

Every fixture in client.test.js was cleaner than the real payload -- none of
them carried a queue_pending key at all, though ComfyUI always sends both. That
is the third time a stand-in tidier than the real thing hid what it stood in
for, so the fixtures now carry both halves, including the malformed entries a
real answer can contain.

Also renamed, because the function no longer answers the question its name
asked: queuedFor returns which half it found the job in, and a job waiting its
turn is adopted as QUEUED. Saying "working" over a run that has not started is
the same small lie as saying "cancelled" over one that has not stopped.
2026-08-30 04:39:00 +03:00

136 lines
4.8 KiB
JavaScript

// Reattaching to a run that outlived the page.
import test from "node:test";
import assert from "node:assert/strict";
import { queuedFor, finishedFor } from "../client.js";
const answering = (body, ok = true) => async () => ({
ok, status: ok ? 200 : 500, json: async () => body,
});
test("the run this browser queued is found by its client id", async () => {
const found = await queuedFor("me", {
fetch: answering({
queue_running: [
[1, "someone-elses", {}, { client_id: "them" }, []],
[2, "mine", {}, { client_id: "me" }, []],
],
queue_pending: [],
}),
});
assert.deepEqual(found, { promptId: "mine", running: true });
});
test("another browser's run is not adopted", async () => {
const promptId = await queuedFor("me", {
fetch: answering({
queue_running: [[1, "theirs", {}, { client_id: "them" }, []]],
queue_pending: [[2, "also-theirs", {}, { client_id: "them" }, []]],
}),
});
assert.equal(promptId, null);
});
test("nothing running means nothing to reattach to", async () => {
assert.equal(await queuedFor("me", {
fetch: answering({ queue_running: [], queue_pending: [] }),
}), null);
});
test("a queue that cannot be reached is not an error the app has to show", async () => {
// The dev server has no queue behind it, which is the ordinary case while
// working on the UI.
const promptId = await queuedFor("me", {
fetch: async () => { throw new TypeError("Failed to fetch"); },
});
assert.equal(promptId, null);
});
test("a malformed queue entry is skipped rather than crashing the load", async () => {
const found = await queuedFor("me", {
fetch: answering({
queue_running: [null, "nonsense", [1], [2, "mine", {}, { client_id: "me" }, []]],
queue_pending: [undefined, {}, [3, null, {}, { client_id: "me" }, []]],
}),
});
assert.deepEqual(found, { promptId: "mine", running: true });
});
test("a finished run is recognised as this browser's from its history entry", async () => {
const asked = [];
const promptId = await finishedFor("me", ["theirs", "mine"], {
fetch: async (url) => {
asked.push(url);
const id = url.split("/").pop();
const owner = id === "mine" ? "me" : "them";
return { ok: true, status: 200, json: async () => ({
[id]: { prompt: [1, id, {}, { client_id: owner }, []], outputs: {}, status: {} },
}) };
},
});
assert.equal(promptId, "mine");
// Newest first: the run that just ended is the one being looked for.
assert.equal(asked[0], "/history/mine");
});
test("a finished run belonging to someone else is not adopted", async () => {
const promptId = await finishedFor("me", ["theirs"], {
fetch: async (url) => ({ ok: true, status: 200, json: async () => ({
theirs: { prompt: [1, "theirs", {}, { client_id: "them" }, []] },
}) }),
});
assert.equal(promptId, null);
});
test("a history entry with nothing in it is skipped, not trusted", async () => {
for (const body of [{}, { mine: {} }, { mine: { prompt: [] } }, { mine: { prompt: [1, "mine", {}] } }]) {
const promptId = await finishedFor("me", ["mine"], {
fetch: async () => ({ ok: true, status: 200, json: async () => body }),
});
assert.equal(promptId, null, JSON.stringify(body));
}
});
test("no history to ask is not an error", async () => {
const promptId = await finishedFor("me", ["mine"], {
fetch: async () => { throw new TypeError("Failed to fetch"); },
});
assert.equal(promptId, null);
});
test("a run still waiting its turn is found too", async () => {
// /queue answers with both halves, and a job sits in the pending one from the
// moment /prompt returns until the worker picks it up -- always briefly, and
// for as long as it takes whenever something is running ahead of it. A reload
// in that window found nothing and let the same job be queued twice.
const promptId = await queuedFor("me", {
fetch: answering({
queue_running: [[1, "theirs", {}, { client_id: "them" }, []]],
queue_pending: [[2, "mine", {}, { client_id: "me" }, []]],
}),
});
assert.deepEqual(promptId, { promptId: "mine", running: false },
"a job waiting its turn was reported as one already under way");
});
test("a run under way is preferred over one still waiting", async () => {
const promptId = await queuedFor("me", {
fetch: answering({
queue_running: [[1, "under-way", {}, { client_id: "me" }, []]],
queue_pending: [[2, "waiting", {}, { client_id: "me" }, []]],
}),
});
assert.deepEqual(promptId, { promptId: "under-way", running: true });
});
test("somebody else's pending run is not adopted either", async () => {
const promptId = await queuedFor("me", {
fetch: answering({
queue_running: [],
queue_pending: [[1, "theirs", {}, { client_id: "them" }, []]],
}),
});
assert.equal(promptId, null);
});