The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import * as DateTime from "effect/DateTime"; |
| 2 | import { describe, expect, it } from "vite-plus/test"; |
| 3 | |
| 4 | import { queuedRunsInDeliveryOrder } from "./QueuedRunOrder.ts"; |
| 5 | |
| 6 | const at = (time: string) => DateTime.makeUnsafe(`2026-01-01T${time}Z`); |
| 7 | const delegatedCompletion = { |
| 8 | generation: 1, |
| 9 | parentRunId: "run:parent", |
| 10 | taskIds: ["task:child"], |
| 11 | }; |
| 12 | |
| 13 | describe("queued run delivery order", () => { |
| 14 | it("delivers completions and queued messages in request order, keeping manual queue order", () => { |
| 15 | const projection = { |
| 16 | messages: [ |
| 17 | { id: "message:old" }, |
| 18 | { id: "message:moved" }, |
| 19 | { id: "message:earlier-completion", delegatedCompletion }, |
| 20 | { id: "message:later-completion", delegatedCompletion }, |
| 21 | ], |
| 22 | runs: [ |
| 23 | { |
| 24 | id: "run:old", |
| 25 | ordinal: 3, |
| 26 | queuePosition: 2, |
| 27 | requestedAt: at("10:00:00"), |
| 28 | status: "queued", |
| 29 | userMessageId: "message:old", |
| 30 | }, |
| 31 | { |
| 32 | id: "run:moved", |
| 33 | ordinal: 4, |
| 34 | queuePosition: 1, |
| 35 | requestedAt: at("10:02:00"), |
| 36 | status: "queued", |
| 37 | userMessageId: "message:moved", |
| 38 | }, |
| 39 | { |
| 40 | id: "run:earlier-completion", |
| 41 | ordinal: 2, |
| 42 | queuePosition: 3, |
| 43 | requestedAt: at("09:59:00"), |
| 44 | status: "queued", |
| 45 | userMessageId: "message:earlier-completion", |
| 46 | }, |
| 47 | { |
| 48 | id: "run:later-completion", |
| 49 | ordinal: 5, |
| 50 | queuePosition: 4, |
| 51 | requestedAt: at("10:03:00"), |
| 52 | status: "queued", |
| 53 | userMessageId: "message:later-completion", |
| 54 | }, |
| 55 | ], |
| 56 | } as never; |
| 57 | |
| 58 | expect(queuedRunsInDeliveryOrder(projection).map((run) => run.id)).toEqual([ |
| 59 | "run:earlier-completion", |
| 60 | "run:moved", |
| 61 | "run:old", |
| 62 | "run:later-completion", |
| 63 | ]); |
| 64 | }); |
| 65 | }); |