From 742fb9057118417d600dde96adeb2e64d1c487f8 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Thu, 19 Feb 2026 07:00:49 +0000 Subject: [PATCH] test(queue): cover collect drain helper states --- src/utils/queue-helpers.test.ts | 56 +++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/src/utils/queue-helpers.test.ts b/src/utils/queue-helpers.test.ts index 7df1a0d4958..a0d31952315 100644 --- a/src/utils/queue-helpers.test.ts +++ b/src/utils/queue-helpers.test.ts @@ -3,6 +3,7 @@ import { applyQueueRuntimeSettings, buildQueueSummaryPrompt, clearQueueSummaryState, + drainCollectItemIfNeeded, previewQueueSummaryPrompt, } from "./queue-helpers.js"; @@ -111,3 +112,58 @@ describe("queue summary helpers", () => { expect(state.summaryLines).toEqual([]); }); }); + +describe("drainCollectItemIfNeeded", () => { + it("skips when neither force mode nor cross-channel routing is active", async () => { + const seen: number[] = []; + const items = [1]; + + const result = await drainCollectItemIfNeeded({ + forceIndividualCollect: false, + isCrossChannel: false, + items, + run: async (item) => { + seen.push(item); + }, + }); + + expect(result).toBe("skipped"); + expect(seen).toEqual([]); + expect(items).toEqual([1]); + }); + + it("drains one item in force mode", async () => { + const seen: number[] = []; + const items = [1, 2]; + + const result = await drainCollectItemIfNeeded({ + forceIndividualCollect: true, + isCrossChannel: false, + items, + run: async (item) => { + seen.push(item); + }, + }); + + expect(result).toBe("drained"); + expect(seen).toEqual([1]); + expect(items).toEqual([2]); + }); + + it("switches to force mode and returns empty when cross-channel with no queued item", async () => { + let forced = false; + + const result = await drainCollectItemIfNeeded({ + forceIndividualCollect: false, + isCrossChannel: true, + setForceIndividualCollect: (next) => { + forced = next; + }, + items: [], + run: async () => {}, + }); + + expect(result).toBe("empty"); + expect(forced).toBe(true); + }); +});