@@ -2521,6 +2521,186 @@ describe("ChatView timeline estimator parity (full app)", () => {
25212521 }
25222522 } ) ;
25232523
2524+ it ( "keeps new-worktree mode on empty server threads and bootstraps the first send" , async ( ) => {
2525+ const snapshot = addThreadToSnapshot ( createDraftOnlySnapshot ( ) , THREAD_ID ) ;
2526+ const mounted = await mountChatView ( {
2527+ viewport : DEFAULT_VIEWPORT ,
2528+ snapshot : {
2529+ ...snapshot ,
2530+ threads : snapshot . threads . map ( ( thread ) =>
2531+ thread . id === THREAD_ID ? Object . assign ( { } , thread , { session : null } ) : thread ,
2532+ ) ,
2533+ } ,
2534+ resolveRpc : ( body ) => {
2535+ if ( body . _tag === WS_METHODS . gitListBranches ) {
2536+ return {
2537+ isRepo : true ,
2538+ hasOriginRemote : true ,
2539+ nextCursor : null ,
2540+ totalCount : 1 ,
2541+ branches : [
2542+ {
2543+ name : "main" ,
2544+ current : true ,
2545+ isDefault : true ,
2546+ worktreePath : null ,
2547+ } ,
2548+ ] ,
2549+ } ;
2550+ }
2551+ if ( body . _tag === ORCHESTRATION_WS_METHODS . dispatchCommand ) {
2552+ return {
2553+ sequence : fixture . snapshot . snapshotSequence + 1 ,
2554+ } ;
2555+ }
2556+ return undefined ;
2557+ } ,
2558+ } ) ;
2559+
2560+ try {
2561+ await page . getByText ( "Current checkout" , { exact : true } ) . click ( ) ;
2562+ await page . getByText ( "New worktree" , { exact : true } ) . click ( ) ;
2563+
2564+ await vi . waitFor (
2565+ ( ) => {
2566+ expect ( findButtonByText ( "New worktree" ) ) . toBeTruthy ( ) ;
2567+ } ,
2568+ { timeout : 8_000 , interval : 16 } ,
2569+ ) ;
2570+
2571+ useComposerDraftStore . getState ( ) . setPrompt ( THREAD_REF , "Ship it" ) ;
2572+ await waitForLayout ( ) ;
2573+
2574+ const sendButton = await waitForSendButton ( ) ;
2575+ expect ( sendButton . disabled ) . toBe ( false ) ;
2576+ sendButton . click ( ) ;
2577+
2578+ await vi . waitFor (
2579+ ( ) => {
2580+ const turnStartRequest = wsRequests . find (
2581+ ( request ) =>
2582+ request . _tag === ORCHESTRATION_WS_METHODS . dispatchCommand &&
2583+ request . type === "thread.turn.start" ,
2584+ ) as
2585+ | {
2586+ _tag : string ;
2587+ type ?: string ;
2588+ bootstrap ?: {
2589+ createThread ?: { projectId ?: string } ;
2590+ prepareWorktree ?: { projectCwd ?: string ; baseBranch ?: string ; branch ?: string } ;
2591+ runSetupScript ?: boolean ;
2592+ } ;
2593+ }
2594+ | undefined ;
2595+
2596+ expect ( turnStartRequest ) . toMatchObject ( {
2597+ _tag : ORCHESTRATION_WS_METHODS . dispatchCommand ,
2598+ type : "thread.turn.start" ,
2599+ bootstrap : {
2600+ prepareWorktree : {
2601+ projectCwd : "/repo/project" ,
2602+ baseBranch : "main" ,
2603+ branch : expect . stringMatching ( / ^ t 3 c o d e \/ [ 0 - 9 a - f ] { 8 } $ / ) ,
2604+ } ,
2605+ runSetupScript : true ,
2606+ } ,
2607+ } ) ;
2608+ expect ( turnStartRequest ?. bootstrap ?. createThread ) . toBeUndefined ( ) ;
2609+ } ,
2610+ { timeout : 8_000 , interval : 16 } ,
2611+ ) ;
2612+ } finally {
2613+ await mounted . cleanup ( ) ;
2614+ }
2615+ } ) ;
2616+
2617+ it ( "updates the selected worktree base branch on empty server threads" , async ( ) => {
2618+ const snapshot = addThreadToSnapshot ( createDraftOnlySnapshot ( ) , THREAD_ID ) ;
2619+ const mounted = await mountChatView ( {
2620+ viewport : DEFAULT_VIEWPORT ,
2621+ snapshot : {
2622+ ...snapshot ,
2623+ threads : snapshot . threads . map ( ( thread ) =>
2624+ thread . id === THREAD_ID ? Object . assign ( { } , thread , { session : null } ) : thread ,
2625+ ) ,
2626+ } ,
2627+ resolveRpc : ( body ) => {
2628+ if ( body . _tag === WS_METHODS . gitListBranches ) {
2629+ return {
2630+ isRepo : true ,
2631+ hasOriginRemote : true ,
2632+ nextCursor : null ,
2633+ totalCount : 2 ,
2634+ branches : [
2635+ {
2636+ name : "main" ,
2637+ current : true ,
2638+ isDefault : true ,
2639+ worktreePath : null ,
2640+ } ,
2641+ {
2642+ name : "release/next" ,
2643+ current : false ,
2644+ isDefault : false ,
2645+ worktreePath : null ,
2646+ } ,
2647+ ] ,
2648+ } ;
2649+ }
2650+ if ( body . _tag === ORCHESTRATION_WS_METHODS . dispatchCommand ) {
2651+ return {
2652+ sequence : fixture . snapshot . snapshotSequence + 1 ,
2653+ } ;
2654+ }
2655+ return undefined ;
2656+ } ,
2657+ } ) ;
2658+
2659+ try {
2660+ await page . getByText ( "Current checkout" , { exact : true } ) . click ( ) ;
2661+ await page . getByText ( "New worktree" , { exact : true } ) . click ( ) ;
2662+ await page . getByText ( "From main" , { exact : true } ) . click ( ) ;
2663+ await page . getByText ( "release/next" , { exact : true } ) . click ( ) ;
2664+
2665+ await vi . waitFor (
2666+ ( ) => {
2667+ expect ( findButtonByText ( "From release/next" ) ) . toBeTruthy ( ) ;
2668+ } ,
2669+ { timeout : 8_000 , interval : 16 } ,
2670+ ) ;
2671+
2672+ useComposerDraftStore . getState ( ) . setPrompt ( THREAD_REF , "Ship it" ) ;
2673+ await waitForLayout ( ) ;
2674+
2675+ const sendButton = await waitForSendButton ( ) ;
2676+ expect ( sendButton . disabled ) . toBe ( false ) ;
2677+ sendButton . click ( ) ;
2678+
2679+ await vi . waitFor (
2680+ ( ) => {
2681+ const turnStartRequest = wsRequests . find (
2682+ ( request ) =>
2683+ request . _tag === ORCHESTRATION_WS_METHODS . dispatchCommand &&
2684+ request . type === "thread.turn.start" ,
2685+ ) as
2686+ | {
2687+ _tag : string ;
2688+ type ?: string ;
2689+ bootstrap ?: {
2690+ prepareWorktree ?: { baseBranch ?: string } ;
2691+ } ;
2692+ }
2693+ | undefined ;
2694+
2695+ expect ( turnStartRequest ?. bootstrap ?. prepareWorktree ?. baseBranch ) . toBe ( "release/next" ) ;
2696+ } ,
2697+ { timeout : 8_000 , interval : 16 } ,
2698+ ) ;
2699+ } finally {
2700+ await mounted . cleanup ( ) ;
2701+ }
2702+ } ) ;
2703+
25242704 it ( "shows the send state once bootstrap dispatch is in flight" , async ( ) => {
25252705 useTerminalStateStore . setState ( {
25262706 terminalStateByThreadKey : { } ,
0 commit comments