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 { EnvironmentId, ProviderInstanceId, RunId, ThreadId } from "@t3tools/contracts"; |
| 2 | import type { AtomCommandResult } from "@t3tools/client-runtime/state/runtime"; |
| 3 | import { AsyncResult } from "effect/reactivity"; |
| 4 | import { expect, it, vi } from "vite-plus/test"; |
| 5 | |
| 6 | const state = vi.hoisted(() => ({ |
| 7 | startedTurn: null as ReturnType<typeof deferred<unknown>> | null, |
| 8 | })); |
| 9 | |
| 10 | vi.mock(import("../../state/use-orchestration-command"), async (importOriginal) => ({ |
| 11 | ...(await importOriginal()), |
| 12 | useOrchestrationCommand: (() => async (value: { readonly input: unknown }) => { |
| 13 | state.startedTurn?.resolve(value.input); |
| 14 | return AsyncResult.success(undefined); |
| 15 | }) as never, |
| 16 | })); |
| 17 | |
| 18 | import { render } from "../../../test/render"; |
| 19 | import type { ComposerHandleRef } from "../../composerHandleContext"; |
| 20 | import { useComposerResume } from "./useComposerResume"; |
| 21 | |
| 22 | function deferred<T>() { |
| 23 | let resolve!: (value: T) => void; |
| 24 | const promise = new Promise<T>((complete) => { |
| 25 | resolve = complete; |
| 26 | }); |
| 27 | return { promise, resolve }; |
| 28 | } |
| 29 | |
| 30 | function setup() { |
| 31 | const startedTurn = deferred<unknown>(); |
| 32 | state.startedTurn = startedTurn; |
| 33 | return { startedTurn }; |
| 34 | } |
| 35 | |
| 36 | const threadA = ThreadId.make("thread:a"); |
| 37 | const threadAModel = { instanceId: ProviderInstanceId.make("codex"), model: "gpt-5.5" }; |
| 38 | const threadBModel = { instanceId: ProviderInstanceId.make("claudeAgent"), model: "claude-opus" }; |
| 39 | |
| 40 | function composerShowing(selectedModelSelection: typeof threadAModel) { |
| 41 | return { getSendContext: () => ({ selectedModelSelection }) } as never; |
| 42 | } |
| 43 | |
| 44 | function ResumeButton(props: { |
| 45 | readonly composerRef: ComposerHandleRef; |
| 46 | readonly persistSettings: () => Promise<AtomCommandResult<void, unknown>>; |
| 47 | }) { |
| 48 | const { onResume } = useComposerResume({ |
| 49 | environmentId: EnvironmentId.make("environment:test"), |
| 50 | routeThreadKey: "environment:test:thread:a", |
| 51 | currentRouteThreadKeyRef: { current: "environment:test:thread:a" }, |
| 52 | activeThread: { id: threadA } as never, |
| 53 | resumableRunId: RunId.make("run:interrupted"), |
| 54 | hasHeldQueuedRuns: false, |
| 55 | canResume: true, |
| 56 | isSendBusy: false, |
| 57 | isRevertingCheckpoint: false, |
| 58 | threadDetailLoading: false, |
| 59 | activeEnvironmentUnavailable: false, |
| 60 | runtimeMode: "full-access", |
| 61 | localCheckoutBranchMismatch: null, |
| 62 | composerRef: props.composerRef, |
| 63 | persistThreadSettingsForNextTurn: props.persistSettings, |
| 64 | clearUsageLimitsFor: () => undefined, |
| 65 | scrollToEnd: () => undefined, |
| 66 | setThreadError: () => undefined, |
| 67 | }); |
| 68 | return ( |
| 69 | <button type="button" onClick={() => void onResume()}> |
| 70 | Resume |
| 71 | </button> |
| 72 | ); |
| 73 | } |
| 74 | |
| 75 | it("continues on the resumed thread's model after the composer moves to another thread", async () => { |
| 76 | const { startedTurn } = setup(); |
| 77 | const settingsPersisted = deferred<AtomCommandResult<void, unknown>>(); |
| 78 | // ChatView keeps one composer across thread routes, so its ref follows navigation. |
| 79 | const composerRef: ComposerHandleRef = { current: composerShowing(threadAModel) }; |
| 80 | await using screen = await render( |
| 81 | <ResumeButton composerRef={composerRef} persistSettings={() => settingsPersisted.promise} />, |
| 82 | ); |
| 83 | |
| 84 | await screen.getByRole("button", { name: "Resume" }).click(); |
| 85 | composerRef.current = composerShowing(threadBModel); |
| 86 | settingsPersisted.resolve(AsyncResult.success(undefined)); |
| 87 | |
| 88 | expect(await startedTurn.promise).toMatchObject({ |
| 89 | threadId: threadA, |
| 90 | manualContinuationOfRunId: "run:interrupted", |
| 91 | modelSelection: threadAModel, |
| 92 | }); |
| 93 | }); |