import { test } from "node:test"; import assert from "node:assert/strict"; import { buildSpeakersReadout } from "./speakersReadout"; import { emptySpeakersLedger } from "../lib/speakersLedger-server"; import { speakersReadoutLine } from "../lib/speakersReadout"; import { emptyHeldAudio, emptySpeakersWork } from "./channelSnapshot"; const GB = 1024 ** 3; function brief(slug: string, o: { external?: boolean; awaitingBytes: number; awaitingVideos: number; neverBytes?: number; neverVideos?: number; workSeconds?: number; unmeasured?: number; engineMs?: number; engineAudioSeconds?: number; measured?: number; speakers?: boolean; }) { const heldAudioBytes = { ...emptyHeldAudio(), awaitingDiarization: o.awaitingBytes, diarizationNeverClears: o.neverBytes ?? 0 }; const heldAudioCounts = { ...emptyHeldAudio(), awaitingDiarization: o.awaitingVideos, diarizationNeverClears: o.neverVideos ?? 0 }; return { slug, config: (o.external ? { mediaDir: "/mnt/x" } : {}) as never, snapshot: { heldAudioBytes, heldAudioCounts, ...(o.speakers === false ? {} : { speakers: { ...emptySpeakersWork(), workSeconds: o.workSeconds ?? 0, workUnmeasured: o.unmeasured ?? 0, engineMs: o.engineMs ?? 0, engineAudioSeconds: o.engineAudioSeconds ?? 0, measured: o.measured ?? 0, }, }), } as never, }; } test("the readout: waiting is the hold the lane WILL clear; rate from the sidecars; days at concurrency 1", () => { const r = buildSpeakersReadout( [ // 10 GB held, 2 GB of it never clears; 9 h of work measured, 1 video unmeasured. brief("ext", { external: true, awaitingBytes: 10 * GB, awaitingVideos: 10, neverBytes: 2 * GB, neverVideos: 2, workSeconds: 7 * 3600, unmeasured: 1 }), brief("int", { awaitingBytes: 1 * GB, awaitingVideos: 2, workSeconds: 2 * 3600, engineMs: 600_000, engineAudioSeconds: 3600, measured: 4 }), brief("old", { awaitingBytes: GB, awaitingVideos: 1, speakers: false }), ], { ...emptySpeakersLedger(), freedBytes: 3 * GB, freedVideos: 5, startedAt: "2026-11-11T00:00:00.000Z" }, ); assert.equal(r.waitingBytes, 10 * GB); assert.equal(r.waitingVideos, 11); assert.equal(r.neverClearsVideos, 2); assert.equal(r.secondsPerAudioHour, 600); assert.equal(r.unmeasuredVideos, 1); // 9 measured hours; the unmeasured video is estimated at the measured mean. assert.ok(r.remainingAudioHours > 9 && r.remainingAudioHours < 11); assert.equal(r.etaDays, Math.round(((r.remainingAudioHours * 600) / 86400) * 10) / 10); assert.equal(r.staleSnapshots, 1); // Corpus disk first. assert.deepEqual(r.channels.map((c) => c.slug), ["int", "old", "ext"]); assert.equal(r.freedBytes, 3 * GB); assert.equal( speakersReadoutLine(r), `waiting: 10.00 GB in 11 videos · freed this run: 3.00 GB · about ${r.etaDays! < 1 ? "under a day" : `${r.etaDays} day${r.etaDays === 1 ? "" : "s"}`} left`, ); }); test("the readout line with nothing measured and nothing waiting", () => { const unmeasured = buildSpeakersReadout([brief("a", { awaitingBytes: GB, awaitingVideos: 1, workSeconds: 3600 })], emptySpeakersLedger()); assert.equal(unmeasured.etaDays, null); assert.match(speakersReadoutLine(unmeasured), /time left not yet measured$/); const none = buildSpeakersReadout([], emptySpeakersLedger()); assert.equal(speakersReadoutLine(none), "waiting: 0 B in 0 videos · freed this run: 0 B · nothing left"); });