@@ -28,6 +28,8 @@ const state = vi.hoisted(() => ({
2828 cloneCalls : [ ] as string [ ] ,
2929 alerts : [ ] as string [ ] ,
3030 navigations : [ ] as unknown [ ] ,
31+ draftLoadError : false ,
32+ stateUpdates : [ ] as unknown [ ] ,
3133 draftTexts : [ ] as Array < { draftId : string ; text : string } > ,
3234} ) ) ;
3335
@@ -42,7 +44,10 @@ vi.mock("react", async (importOriginal) => ({
4244 ...( await importOriginal < typeof import ( "react" ) > ( ) ) ,
4345 useCallback : ( callback : unknown ) => callback ,
4446 useMemo : ( factory : ( ) => unknown ) => factory ( ) ,
45- useState : ( initial : unknown ) => [ typeof initial === "function" ? initial ( ) : initial , ( ) => { } ] ,
47+ useState : ( initial : unknown ) => [
48+ typeof initial === "function" ? initial ( ) : initial ,
49+ ( value : unknown ) => state . stateUpdates . push ( value ) ,
50+ ] ,
4651 useRef : ( current : unknown ) => ( { current } ) ,
4752 useEffect : ( ) => { } ,
4853} ) ) ;
@@ -80,7 +85,9 @@ vi.mock("../../state/session", () => ({
8085 readEnvironmentScope : ( _environmentId : string , scope : string ) => state . scopes . has ( scope ) ,
8186} ) ) ;
8287vi . mock ( "../../state/use-composer-drafts" , ( ) => ( {
83- waitForComposerDraftsLoaded : async ( ) => { } ,
88+ waitForComposerDraftsLoaded : async ( ) => {
89+ if ( state . draftLoadError ) throw new Error ( "Draft storage unavailable" ) ;
90+ } ,
8491 createNewTaskDraft : ( ) => "draft" ,
8592 setComposerDraftText : ( draftId : string , text : string ) => state . draftTexts . push ( { draftId, text } ) ,
8693} ) ) ;
@@ -276,6 +283,8 @@ describe("adding an already registered project", () => {
276283 state . alerts = [ ] ;
277284 state . navigations = [ ] ;
278285 state . draftTexts = [ ] ;
286+ state . draftLoadError = false ;
287+ state . stateUpdates = [ ] ;
279288 state . supportsCloneTracking = false ;
280289 state . home = "/home/tester" ;
281290 state . os = "linux" ;
@@ -332,6 +341,33 @@ describe("adding an already registered project", () => {
332341 ] ) ;
333342 } ) ;
334343
344+ it ( "keeps the prompt available and reports draft failure before retrying" , async ( ) => {
345+ state . baseDirectory = "~/repro" ;
346+ state . draftLoadError = true ;
347+ const action = findAction (
348+ AddProjectDestinationScreen ( {
349+ environmentId : "environment" ,
350+ remoteUrl : "https://example.com/bike-documents.git" ,
351+ repositoryName : "bike-documents" ,
352+ prompt : "Fix the bike" ,
353+ } ) ,
354+ "Clone project" ,
355+ ) ;
356+ if ( ! action ) throw new Error ( "Clone action missing" ) ;
357+ await action ( ) ;
358+
359+ expect ( state . navigations ) . toEqual ( [ ] ) ;
360+ expect ( state . cloneCalls ) . toEqual ( [ ] ) ;
361+ expect ( state . stateUpdates ) . toContain ( "Draft storage unavailable" ) ;
362+ expect ( state . stateUpdates . at ( - 1 ) ) . toBe ( false ) ;
363+
364+ state . draftLoadError = false ;
365+ await action ( ) ;
366+ expect ( state . draftTexts ) . toEqual ( [ { draftId : "draft" , text : "Fix the bike" } ] ) ;
367+ expect ( state . navigations ) . toHaveLength ( 1 ) ;
368+ expect ( state . cloneCalls ) . toEqual ( [ ] ) ;
369+ } ) ;
370+
335371 it . each ( [ false , true ] ) (
336372 "opens the existing project's draft with the prompt before cloning (clone tracking: %s)" ,
337373 async ( supportsCloneTracking ) => {
0 commit comments