import test from "node:test"; import assert from "node:assert/strict"; import { defaultSiteSettings } from "../lib/settings"; import type { WorkerSummary } from "../jobs/workerPool"; import { buildAutoQueueLanes } from "./autoQueueLanes"; // WHERE A LANE'S WORK CAN RUN, and the three rules that decide it. The rows are // read straight off `workerMatches`, the same predicate the dispatchers grant // by, so what this test really pins is the FOLD around it: one row per // configured worker, not one per slot and not one per (operation, slot) pair. const worker = (over: Partial & { id: string }): WorkerSummary => ({ name: over.id, kind: "remote", priority: 0, busy: false, state: "enabled", degraded: false, enabled: true, ...over, }); // The default corpus has exactly one lane operation — `digest`, on the digest // lane — which is all these rules need. const lanes = (workerSummary: WorkerSummary[]) => buildAutoQueueLanes({ settings: defaultSiteSettings(), briefs: [], workerSummary, }); test("the digest lane names its operation, and the empty lanes stay empty", () => { const payload = lanes([]); assert.deepEqual( payload.operations.digest.map((o) => o.id), ["digest"], ); assert.deepEqual(payload.operations.transcription, []); assert.deepEqual(payload.runsOn.digest, []); // The rail is the CATALOG view: one band per catalogued operation whatever // queue it runs on, on the two media bands the pipeline always has. assert.deepEqual( payload.bands.map((b) => b.id), ["download", "transcription", "digest"], ); }); test("a worker's slots fold back to one row", () => { // Slot expansion writes `gpu#1` / `gpu#2` with names to match. They are ONE // machine with two slots: two rows would advertise two workers, and counting // the slots per operation would advertise capacity that does not exist. const payload = lanes([ worker({ id: "gpu#1", name: "GPU box #1", tags: ["digest"] }), worker({ id: "gpu#2", name: "GPU box #2", tags: ["digest"] }), ]); assert.deepEqual(payload.runsOn.digest, [ { id: "gpu", name: "GPU box", kind: "remote", slots: 2, available: 2 }, ]); }); test("only slots that could take work right now are available", () => { const payload = lanes([ worker({ id: "gpu#1", name: "GPU box #1", tags: ["digest"] }), worker({ id: "gpu#2", name: "GPU box #2", tags: ["digest"], degraded: true }), worker({ id: "gpu#3", name: "GPU box #3", tags: ["digest"], state: "disabled" }), ]); assert.deepEqual(payload.runsOn.digest, [ { id: "gpu", name: "GPU box", kind: "remote", slots: 3, available: 1 }, ]); }); test("an untagged remote worker is not listed", () => { // Tagging IS the unit-dispatch opt-in for a remote worker: untagged means // "transcriptions only", and `workerMatches` says true for an untagged remote // because that predicate is also asked about transcription leases. The lane // rows have to apply the opt-in themselves. assert.deepEqual(lanes([worker({ id: "plain", name: "plain" })]).runsOn.digest, []); assert.deepEqual( lanes([worker({ id: "other", name: "other", tags: ["diarization"] })]).runsOn .digest, [], ); }); test("an llm worker is listed by tag", () => { const payload = lanes([ worker({ id: "ollama", name: "ollama", kind: "llm", tags: ["digest"] }), worker({ id: "elsewhere", name: "elsewhere", kind: "llm", tags: ["attribution-text"] }), ]); assert.deepEqual(payload.runsOn.digest, [ { id: "ollama", name: "ollama", kind: "llm", slots: 1, available: 1 }, ]); }); test("a local worker is never listed", () => { // The lane always runs here; saying so would be noise on every row. assert.deepEqual( lanes([worker({ id: "local", name: "local", kind: "local", tags: ["digest"] })]) .runsOn.digest, [], ); });