@@ -18,6 +18,7 @@ const testState = vi.hoisted(() => {
1818 readonly promotedTo : null ;
1919 readonly threadId : string ;
2020 } | null = null ;
21+ let openDraftRoute : { readonly kind : "draft" ; readonly draftId : string } | null = null ;
2122 const router = {
2223 state : {
2324 location : { href : "/" } ,
@@ -30,7 +31,18 @@ const testState = vi.hoisted(() => {
3031 const draftStore = {
3132 getComposerDraft : vi . fn ( ( ) => ( { } ) ) ,
3233 getDraftSessionByLogicalProjectKey : vi . fn ( ( ) => storedDraft ) ,
33- getDraftSession : vi . fn ( ( ) => null ) ,
34+ getDraftSession : vi . fn ( ( ) =>
35+ openDraftRoute === null
36+ ? null
37+ : {
38+ logicalProjectKey : "remote-project" ,
39+ promotedTo : null ,
40+ threadId : "thread-open" ,
41+ createdAt : "2026-01-01T00:00:00.000Z" ,
42+ runtimeMode : "full-access" ,
43+ interactionMode : "default" ,
44+ } ,
45+ ) ,
3446 getDraftThread : vi . fn ( ( ) => null ) ,
3547 applyStickyState : vi . fn ( ) ,
3648 setDraftThreadContext : vi . fn ( ) ,
@@ -57,6 +69,12 @@ const testState = vi.hoisted(() => {
5769 removeProject ( ) {
5870 projectRemoved = true ;
5971 } ,
72+ get openDraftRoute ( ) {
73+ return openDraftRoute ;
74+ } ,
75+ openEmptyDraft ( draftId : string ) {
76+ openDraftRoute = { kind : "draft" , draftId } ;
77+ } ,
6078 get targetSettings ( ) {
6179 return targetSettings ;
6280 } ,
@@ -68,6 +86,7 @@ const testState = vi.hoisted(() => {
6886 } ,
6987 ) {
7088 storedDraft = nextStoredDraft ;
89+ openDraftRoute = null ;
7190 projectRemoved = false ;
7291 connectedEnvironmentIds = [ "environment-primary" , "environment-ssh" ] ;
7392 targetSettings = {
@@ -210,7 +229,9 @@ vi.mock("../state/server", () => ({
210229 environmentServerConfigsAtom : { } ,
211230 primaryServerSettingsAtom : "primary-settings" ,
212231} ) ) ;
213- vi . mock ( "../threadRoutes" , ( ) => ( { resolveThreadRouteTarget : ( ) => null } ) ) ;
232+ vi . mock ( "../threadRoutes" , ( ) => ( {
233+ resolveThreadRouteTarget : ( ) => testState . openDraftRoute ,
234+ } ) ) ;
214235vi . mock ( "../uiStateStore" , ( ) => ( {
215236 legacyProjectCwdPreferenceKey : ( ) => "remote-project" ,
216237 useUiStateStore : ( ) => [ ] ,
@@ -284,6 +305,22 @@ describe.each([
284305} ) ;
285306
286307describe ( "useNewThreadHandler" , ( ) => {
308+ it ( "seeds the prompt into the empty draft that is already open" , async ( ) => {
309+ testState . reset ( null ) ;
310+ testState . openEmptyDraft ( "draft-open" ) ;
311+
312+ const opened = await useNewThreadHandler ( ) (
313+ { environmentId : "environment-ssh" , projectId : "project-remote" } as never ,
314+ { prompt : "Read the playbook. " } ,
315+ ) ;
316+
317+ expect ( opened ?. draftId ) . toBe ( "draft-open" ) ;
318+ expect ( testState . draftStore . setPrompt ) . toHaveBeenCalledWith (
319+ "draft-open" ,
320+ "Read the playbook. " ,
321+ ) ;
322+ } ) ;
323+
287324 it ( "opens the draft without waiting on a project file from an offline machine" , async ( ) => {
288325 testState . reset ( null , { envMode : null , startFromOrigin : false } ) ;
289326 testState . disconnect ( "environment-ssh" ) ;
0 commit comments