import test from "node:test"; import assert from "node:assert/strict"; import { BACKFILL_QUEUE, DIGEST_LOCAL_QUEUE, DIGEST_REMOTE_QUEUE, channelQueueKey, relocationQueueKey, resolveQueueKey, } from "./queueKeys"; // THE ONE PROPERTY THAT IS NOT OBVIOUS FROM READING THE CALLER. // // registry.ts submits every non-empty queueKey at concurrency 1 and caps // nothing across keys, so "do these two jobs serialize?" is answered entirely by // whether their keys are EQUAL. For a media relocation the answer has to be yes // even across channels — N moves selected on /channels write to one destination // volume, and each job's space check runs when it starts, so concurrent starts // each measure a root the others have not written to yet and jointly overrun it. test("two channels' relocations land on one queue, and their bookkeeping does not", () => { // THE CLAIM: two channels, one key. It is stated as a function of the slug on // both sides so the test still reads as the claim if someone gives // relocationQueueKey a slug parameter — at which point it fails, which is the // point. channelQueueKey is the control: that one SHOULD differ per channel. const relocationKeyFor = (_slug: string) => relocationQueueKey(); assert.equal(relocationKeyFor("omnimirror"), relocationKeyFor("rekietalaw")); assert.notEqual(channelQueueKey("omnimirror"), channelQueueKey("rekietalaw")); // A relocation does not sit on the channel's bookkeeping queue either — that // key is per-channel, so using it is the bug above by another route. assert.notEqual(relocationQueueKey(), channelQueueKey("omnimirror")); // Non-empty, or the registry would run it immediately and untracked. assert.notEqual(relocationQueueKey(), ""); }); // The lane keys are distinct from each other and from the relocation queue, so // a move never blocks (or is blocked by) a sweep. test("the named lane queues stay distinct", () => { const keys = [ BACKFILL_QUEUE, DIGEST_LOCAL_QUEUE, DIGEST_REMOTE_QUEUE, relocationQueueKey(), ]; assert.equal(new Set(keys).size, keys.length); }); test("resolveQueueKey: undefined keeps the default, a string overrides, blank is immediate", () => { assert.equal(resolveQueueKey("channel:a", undefined), "channel:a"); assert.equal(resolveQueueKey("channel:a", " relocate "), "relocate"); assert.equal(resolveQueueKey("channel:a", ""), ""); });