1- import { AuthOrchestrationOperateScope , RuntimeRequestId } from "@t3tools/contracts" ;
1+ import {
2+ AuthOrchestrationOperateScope ,
3+ DEFAULT_SERVER_SETTINGS ,
4+ MessageId ,
5+ ProjectId ,
6+ ProviderDriverKind ,
7+ ProviderInstanceId ,
8+ RunId ,
9+ RuntimeRequestId ,
10+ TurnItemId ,
11+ type ModelSelection ,
12+ type OrchestrationV2ThreadProjection ,
13+ type ServerConfig ,
14+ } from "@t3tools/contracts" ;
15+ import {
16+ v2Now ,
17+ v2Projection ,
18+ } from "../../../../packages/client-runtime/src/state/orchestrationV2TestFixtures" ;
219import type { DraftComposerImageAttachment } from "../lib/composerImages" ;
320import type { PendingThreadRequests } from "@t3tools/client-runtime/state/thread-requests" ;
421import { AsyncResult , type Atom } from "effect/reactivity" ;
@@ -7,7 +24,13 @@ import { beforeEach, describe, expect, it, vi } from "vite-plus/test";
724const state = vi . hoisted ( ( ) => ( {
825 grantedEnvironments : new Set < string > ( ) ,
926 connectionState : "connected" ,
10- draft : { text : "Keep my draft" , attachments : [ ] as DraftComposerImageAttachment [ ] } ,
27+ draft : {
28+ text : "Keep my draft" ,
29+ attachments : [ ] as DraftComposerImageAttachment [ ] ,
30+ modelSelection : undefined as ModelSelection | undefined ,
31+ } ,
32+ serverConfig : null as ServerConfig | null ,
33+ projection : null as OrchestrationV2ThreadProjection | null ,
1134 pendingRequests : { approvals : [ ] , userInputs : [ ] } as PendingThreadRequests ,
1235 enqueue : vi . fn ( async ( ) => undefined ) ,
1336 clearDraft : vi . fn ( ) ,
@@ -25,6 +48,7 @@ const state = vi.hoisted(() => ({
2548 thread : {
2649 id : "thread" ,
2750 environmentId : "secondary" ,
51+ projectId : "project" ,
2852 modelSelection : { instanceId : "codex" , model : "gpt-5.4" } ,
2953 runtimeMode : "full-access" ,
3054 interactionMode : "default" ,
@@ -70,15 +94,13 @@ vi.mock("./use-thread-selection", () => ({
7094 selectedThreadCreation : null ,
7195 selectedEnvironmentRuntime : {
7296 connectionState : state . connectionState ,
73- serverConfig : {
74- providers : [ { instanceId : "codex" , driver : "codex" } ] ,
75- environment : { capabilities : { } } ,
76- } ,
97+ serverConfig : state . serverConfig ,
7798 } ,
7899 } ) ,
79100} ) ) ;
80101vi . mock ( "./use-thread-detail" , ( ) => ( {
81- useSelectedThreadProjection : ( ) => null ,
102+ useSelectedThreadProjection : ( ) =>
103+ state . projection === null ? null : { projection : state . projection } ,
82104 useSelectedThreadVisibleTurnItems : ( ) => [ ] ,
83105 useSelectedThreadPendingRequests : ( ) => state . pendingRequests ,
84106} ) ) ;
@@ -126,7 +148,7 @@ vi.mock("./use-composer-drafts", async () => {
126148 mergeComposerDraftContent : vi . fn ( ) ,
127149 removeComposerDraftAttachment : vi . fn ( ) ,
128150 useComposerDraft : ( ) => state . draft ,
129- useComposerDraftSettings : ( ) => ( { } ) ,
151+ useComposerDraftSettings : ( ) => state . draft ,
130152 questionAttachmentDraftsAtom : ( ) => Atom . make ( { } ) ,
131153 } ;
132154} ) ;
@@ -144,7 +166,6 @@ vi.mock("../lib/commandMetadata", () => ({
144166 } ) ,
145167} ) ) ;
146168vi . mock ( "../lib/copyTextWithHaptic" , ( ) => ( { copyTextWithHaptic : vi . fn ( ) } ) ) ;
147- vi . mock ( "../lib/modelOptions" , ( ) => ( { isModelSelectionUnavailable : ( ) => false } ) ) ;
148169vi . mock ( "./use-remote-environment-registry" , ( ) => ( { setPendingConnectionError : vi . fn ( ) } ) ) ;
149170
150171import { useThreadComposerState } from "./use-thread-composer-state" ;
@@ -153,7 +174,12 @@ import { useSelectedThreadRequests } from "./use-selected-thread-requests";
153174beforeEach ( ( ) => {
154175 state . grantedEnvironments = new Set ( [ "primary" ] ) ;
155176 state . connectionState = "connected" ;
156- state . draft = { text : "Keep my draft" , attachments : [ ] } ;
177+ state . draft = { text : "Keep my draft" , attachments : [ ] , modelSelection : undefined } ;
178+ state . projection = null ;
179+ state . serverConfig = {
180+ providers : [ { instanceId : "codex" , driver : "codex" , enabled : true } ] ,
181+ environment : { capabilities : { } } ,
182+ } as unknown as ServerConfig ;
157183 state . pendingRequests = {
158184 approvals : [
159185 {
@@ -260,3 +286,113 @@ describe("mobile task permissions", () => {
260286 } ) ;
261287 } ) ;
262288} ) ;
289+
290+ describe ( "mobile handoff preview and submission" , ( ) => {
291+ it ( "follows project enablement and provider availability for the selected destination" , async ( ) => {
292+ state . grantedEnvironments . add ( "secondary" ) ;
293+ const instanceId = ProviderInstanceId . make ( "antigravity" ) ;
294+ const projectId = ProjectId . make ( state . thread . projectId ) ;
295+ const selection = { instanceId, model : "gemini" } ;
296+ const provider = {
297+ instanceId,
298+ driver : ProviderDriverKind . make ( "antigravity" ) ,
299+ enabled : false ,
300+ installed : true ,
301+ auth : { status : "authenticated" as const } ,
302+ availability : "available" as "available" | "unavailable" ,
303+ models : [ { slug : selection . model } ] ,
304+ } ;
305+ const projectOverride = { enabled : false } ;
306+ state . serverConfig = {
307+ ...state . serverConfig ,
308+ providers : [ provider ] ,
309+ settings : {
310+ ...DEFAULT_SERVER_SETTINGS ,
311+ providerInstances : { [ instanceId ] : { driver : provider . driver , enabled : false } } ,
312+ projectSettingsOverrides : {
313+ [ projectId ] : { providerInstances : { [ instanceId ] : projectOverride } } ,
314+ } ,
315+ } ,
316+ } as unknown as ServerConfig ;
317+ state . draft . modelSelection = selection ;
318+ const source = v2Projection . thread . modelSelection ;
319+ state . projection = {
320+ ...v2Projection ,
321+ runs : [
322+ {
323+ id : RunId . make ( "source-run" ) ,
324+ threadId : v2Projection . thread . id ,
325+ ordinal : 1 ,
326+ providerInstanceId : source . instanceId ,
327+ modelSelection : source ,
328+ providerThreadId : null ,
329+ userMessageId : MessageId . make ( "source-message" ) ,
330+ rootNodeId : null ,
331+ activeAttemptId : null ,
332+ status : "completed" ,
333+ requestedAt : v2Now ,
334+ startedAt : v2Now ,
335+ completedAt : v2Now ,
336+ checkpointId : null ,
337+ contextHandoffId : null ,
338+ } ,
339+ ] ,
340+ visibleTurnItems : [
341+ {
342+ position : 0 ,
343+ visibility : "local" ,
344+ sourceThreadId : v2Projection . thread . id ,
345+ sourceItemId : TurnItemId . make ( "reply" ) ,
346+ item : {
347+ id : TurnItemId . make ( "reply" ) ,
348+ threadId : v2Projection . thread . id ,
349+ runId : RunId . make ( "source-run" ) ,
350+ nodeId : null ,
351+ providerThreadId : null ,
352+ providerTurnId : null ,
353+ nativeItemRef : null ,
354+ parentItemId : null ,
355+ ordinal : 1 ,
356+ type : "assistant_message" ,
357+ messageId : MessageId . make ( "reply" ) ,
358+ status : "completed" ,
359+ title : null ,
360+ text : "Task started" ,
361+ streaming : false ,
362+ startedAt : v2Now ,
363+ completedAt : v2Now ,
364+ updatedAt : v2Now ,
365+ } ,
366+ } ,
367+ ] ,
368+ } ;
369+
370+ const disabled = useThreadComposerState ( ) ;
371+ expect ( disabled . pendingHandoff ) . toBeNull ( ) ;
372+ expect ( await disabled . onSendMessage ( ) ) . toBeNull ( ) ;
373+ expect ( state . enqueue ) . not . toHaveBeenCalled ( ) ;
374+ expect ( state . clearDraft ) . not . toHaveBeenCalled ( ) ;
375+
376+ projectOverride . enabled = true ;
377+ expect ( useThreadComposerState ( ) . pendingHandoff ) . toEqual ( { from : [ source ] , to : selection } ) ;
378+
379+ provider . availability = "unavailable" ;
380+ const unavailable = useThreadComposerState ( ) ;
381+ expect ( unavailable . pendingHandoff ) . toBeNull ( ) ;
382+ expect ( await unavailable . onSendMessage ( ) ) . toBeNull ( ) ;
383+ expect ( state . enqueue ) . not . toHaveBeenCalled ( ) ;
384+ expect ( state . clearDraft ) . not . toHaveBeenCalled ( ) ;
385+
386+ provider . availability = "available" ;
387+ const available = useThreadComposerState ( ) ;
388+ expect ( available . pendingHandoff ) . toEqual ( { from : [ source ] , to : selection } ) ;
389+ expect ( await available . onSendMessage ( ) ) . toBe ( "message" ) ;
390+ expect ( state . enqueue ) . toHaveBeenCalledExactlyOnceWith (
391+ expect . objectContaining ( {
392+ modelSelection : selection ,
393+ text : "Keep my draft" ,
394+ } ) ,
395+ ) ;
396+ expect ( state . clearDraft ) . toHaveBeenCalledTimes ( 1 ) ;
397+ } ) ;
398+ } ) ;
0 commit comments