The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 04:45 UTC
| 1 | import type { OrchestrationV2ThreadProjection } from "@t3tools/contracts"; |
| 2 | import { describe, expect, it } from "vite-plus/test"; |
| 3 | |
| 4 | import { threadAllowsProviderSwitch } from "./thread-provider-switching"; |
| 5 | |
| 6 | const startedThread = { |
| 7 | latestRun: { id: "run-1" }, |
| 8 | latestUserMessageAt: "2026-06-01T00:00:00.000Z", |
| 9 | runtime: { status: "idle" }, |
| 10 | } as never; |
| 11 | |
| 12 | function projectionWithSession(supportsProviderSwitchingViaHandoff: boolean) { |
| 13 | return { |
| 14 | thread: { id: "thread", activeProviderThreadId: "provider-thread" }, |
| 15 | runs: [], |
| 16 | providerThreads: [ |
| 17 | { id: "provider-thread", appThreadId: "thread", providerSessionId: "provider-session" }, |
| 18 | ], |
| 19 | providerSessions: [ |
| 20 | { |
| 21 | id: "provider-session", |
| 22 | status: "running", |
| 23 | capabilities: { sessions: { supportsProviderSwitchingViaHandoff } }, |
| 24 | }, |
| 25 | ], |
| 26 | } as unknown as OrchestrationV2ThreadProjection; |
| 27 | } |
| 28 | |
| 29 | describe("threadAllowsProviderSwitch", () => { |
| 30 | it("keeps a started thread on its provider when the session cannot hand off", () => { |
| 31 | expect( |
| 32 | threadAllowsProviderSwitch({ |
| 33 | thread: startedThread, |
| 34 | projection: projectionWithSession(false), |
| 35 | }), |
| 36 | ).toBe(false); |
| 37 | }); |
| 38 | |
| 39 | it("allows an imported thread to hand off before opening a provider session", () => { |
| 40 | expect( |
| 41 | threadAllowsProviderSwitch({ |
| 42 | thread: startedThread, |
| 43 | projection: { |
| 44 | thread: { id: "thread", activeProviderThreadId: null, historyOrigin: "v1_import" }, |
| 45 | runs: [], |
| 46 | providerThreads: [], |
| 47 | providerSessions: [], |
| 48 | } as unknown as OrchestrationV2ThreadProjection, |
| 49 | }), |
| 50 | ).toBe(true); |
| 51 | }); |
| 52 | |
| 53 | it("keeps a preparing turn bound before its provider session appears", () => { |
| 54 | expect( |
| 55 | threadAllowsProviderSwitch({ |
| 56 | thread: startedThread, |
| 57 | projection: { |
| 58 | thread: { id: "thread", activeProviderThreadId: null, historyOrigin: "v1_import" }, |
| 59 | runs: [{ status: "preparing", providerThreadId: "provider-thread" }], |
| 60 | providerThreads: [], |
| 61 | providerSessions: [], |
| 62 | } as unknown as OrchestrationV2ThreadProjection, |
| 63 | }), |
| 64 | ).toBe(false); |
| 65 | }); |
| 66 | |
| 67 | it("keeps a started thread bound until its projection resolves a session", () => { |
| 68 | expect(threadAllowsProviderSwitch({ thread: startedThread, projection: null })).toBe(false); |
| 69 | }); |
| 70 | }); |