| 1 | import { ProviderInstanceId, RunId } from "@t3tools/contracts"; |
| 2 | import { describe, expect, it } from "vite-plus/test"; |
| 3 | |
| 4 | import type { ThreadRuntimeSummary } from "@t3tools/client-runtime/state/models"; |
| 5 | import { threadCanArchive } from "./threadArchive"; |
| 6 | |
| 7 | function runtime( |
| 8 | status: ThreadRuntimeSummary["status"], |
| 9 | activeRunId: ThreadRuntimeSummary["activeRunId"], |
| 10 | ): ThreadRuntimeSummary { |
| 11 | return { |
| 12 | status, |
| 13 | activeRunId, |
| 14 | providerInstanceId: ProviderInstanceId.make("codex"), |
| 15 | providerName: "codex", |
| 16 | lastError: null, |
| 17 | updatedAt: "2026-07-28T10:00:00.000Z", |
| 18 | }; |
| 19 | } |
| 20 | |
| 21 | describe("threadCanArchive", () => { |
| 22 | it("blocks provider-active work", () => { |
| 23 | const activeRunId = RunId.make("run-live"); |
| 24 | expect(threadCanArchive(runtime("preparing", activeRunId))).toBe(false); |
| 25 | expect(threadCanArchive(runtime("starting", activeRunId))).toBe(false); |
| 26 | expect(threadCanArchive(runtime("running", activeRunId))).toBe(false); |
| 27 | }); |
| 28 | |
| 29 | it("only allows queued work when no provider run remains active", () => { |
| 30 | const activeRunId = RunId.make("run-live"); |
| 31 | expect(threadCanArchive(runtime("queued", null))).toBe(true); |
| 32 | expect(threadCanArchive(runtime("queued", activeRunId))).toBe(false); |
| 33 | }); |
| 34 | |
| 35 | it("allows post-provider waiting work despite a retained active run id", () => { |
| 36 | const staleActiveRunId = RunId.make("run-finished"); |
| 37 | expect(threadCanArchive(runtime("waiting", null))).toBe(true); |
| 38 | expect(threadCanArchive(runtime("waiting", staleActiveRunId))).toBe(true); |
| 39 | }); |
| 40 | }); |