@@ -12,6 +12,7 @@ import {
1212 resolveNewDraftStartFromOrigin ,
1313 resolveNewThreadModelSelectionOverride ,
1414 startNewThreadFromContext ,
15+ startNewThreadOnBranch ,
1516 type ChatThreadActionContext ,
1617} from "./chatThreadActions" ;
1718
@@ -169,3 +170,46 @@ describe("chatThreadActions", () => {
169170 expect ( handleNewThread ) . not . toHaveBeenCalled ( ) ;
170171 } ) ;
171172} ) ;
173+
174+ describe ( "startNewThreadOnBranch" , ( ) => {
175+ it . each ( [ null , "/remote/project-feature" ] ) (
176+ "reuses the branch with checkout %s" ,
177+ async ( worktreePath ) => {
178+ const handleNewThread = vi . fn ( async ( ) => ( { draftId : "draft" } ) ) ;
179+ const thread = {
180+ environmentId : ENVIRONMENT_ID ,
181+ projectId : PROJECT_ID ,
182+ branch : "feature" ,
183+ worktreePath,
184+ } ;
185+ expect ( await startNewThreadOnBranch ( thread , handleNewThread ) ) . toBe ( true ) ;
186+ expect ( handleNewThread ) . toHaveBeenCalledWith ( scopeProjectRef ( ENVIRONMENT_ID , PROJECT_ID ) , {
187+ branch : "feature" ,
188+ worktreePath,
189+ envMode : worktreePath ? "worktree" : "local" ,
190+ startFromOrigin : false ,
191+ } ) ;
192+ } ,
193+ ) ;
194+ it . each ( [
195+ null ,
196+ { environmentId : ENVIRONMENT_ID , projectId : PROJECT_ID , branch : null , worktreePath : null } ,
197+ ] ) ( "does not create a draft without a saved branch" , async ( thread ) => {
198+ const handleNewThread = vi . fn ( async ( ) => ( { } ) ) ;
199+ expect ( await startNewThreadOnBranch ( thread , handleNewThread ) ) . toBe ( false ) ;
200+ expect ( handleNewThread ) . not . toHaveBeenCalled ( ) ;
201+ } ) ;
202+ it ( "reports when creation does not open a draft" , async ( ) => {
203+ expect (
204+ await startNewThreadOnBranch (
205+ {
206+ environmentId : ENVIRONMENT_ID ,
207+ projectId : PROJECT_ID ,
208+ branch : "feature" ,
209+ worktreePath : null ,
210+ } ,
211+ async ( ) => null ,
212+ ) ,
213+ ) . toBe ( false ) ;
214+ } ) ;
215+ } ) ;
0 commit comments