@@ -1428,44 +1428,9 @@ describe("composerDraftStore draft promotion", () => {
14281428 const state = useComposerDraftStore . getState ( ) ;
14291429 expect ( state . getDraftSession ( draftId ) ) . toBeNull ( ) ;
14301430 expect ( state . getPromotedDraftRedirect ( draftId ) ) . toEqual ( threadRef ) ;
1431- expect ( state . getPromotedDraftIdByRef ( threadRef ) ) . toBe ( draftId ) ;
14321431 expect ( draftFor ( threadId , TEST_ENVIRONMENT_ID ) ?. prompt ) . toBe ( "typed during setup" ) ;
14331432 } ) ;
14341433
1435- it ( "keeps a promotion redirect only while the route shows the draft or its thread" , ( ) => {
1436- const otherRef = scopeThreadRef ( TEST_ENVIRONMENT_ID , ThreadId . make ( "thread-other" ) ) ;
1437- useComposerDraftStore . setState ( { promotedDraftRedirects : { [ draftId ] : threadRef } } ) ;
1438- const store = useComposerDraftStore . getState ( ) ;
1439-
1440- store . retainPromotedDraftRedirectsForRoute ( {
1441- modalPage : false ,
1442- target : { kind : "draft" , draftId } ,
1443- } ) ;
1444- store . retainPromotedDraftRedirectsForRoute ( {
1445- modalPage : false ,
1446- target : { kind : "server" , threadRef } ,
1447- } ) ;
1448- expect ( useComposerDraftStore . getState ( ) . getPromotedDraftIdByRef ( threadRef ) ) . toBe ( draftId ) ;
1449-
1450- store . retainPromotedDraftRedirectsForRoute ( {
1451- modalPage : false ,
1452- target : { kind : "server" , threadRef : otherRef } ,
1453- } ) ;
1454- expect ( useComposerDraftStore . getState ( ) . promotedDraftRedirects ) . toEqual ( { } ) ;
1455- // A later visit renders the shared unkeyed ChatView.
1456- expect ( useComposerDraftStore . getState ( ) . getPromotedDraftIdByRef ( threadRef ) ) . toBeNull ( ) ;
1457- } ) ;
1458-
1459- it ( "keeps a promotion redirect while Settings or Usage is open over its draft" , ( ) => {
1460- useComposerDraftStore . setState ( { promotedDraftRedirects : { [ draftId ] : threadRef } } ) ;
1461- const store = useComposerDraftStore . getState ( ) ;
1462-
1463- // Each settings section is its own route with no thread target; closing returns to the draft.
1464- store . retainPromotedDraftRedirectsForRoute ( { modalPage : true , target : null } ) ;
1465- store . retainPromotedDraftRedirectsForRoute ( { modalPage : true , target : null } ) ;
1466- expect ( useComposerDraftStore . getState ( ) . getPromotedDraftRedirect ( draftId ) ) . toEqual ( threadRef ) ;
1467- } ) ;
1468-
14691434 it ( "holds a background submission on its draft until the send settles" , async ( ) => {
14701435 const h = draftPromotionHarness ( ) ;
14711436 const store = useComposerDraftStore . getState ( ) ;
@@ -1486,6 +1451,30 @@ describe("composerDraftStore draft promotion", () => {
14861451 expect ( useComposerDraftStore . getState ( ) . getDraftSession ( draftId ) ) . toBeNull ( ) ;
14871452 } ) ;
14881453
1454+ it ( "keeps the redirect of a draft finalized while another route was open" , async ( ) => {
1455+ // A failed send restored onto its existing thread, or a background send, finalizes while the
1456+ // user is elsewhere; "Open draft" or Back to /draft/<id> later must still reach the thread.
1457+ const h = draftPromotionHarness ( ) ;
1458+ const store = useComposerDraftStore . getState ( ) ;
1459+ store . setProjectDraftThreadId ( projectRef , draftId , { threadId } ) ;
1460+ h . arrive ( threadRef , {
1461+ latestRun : preparingRun ,
1462+ latestUserMessageAt : "2026-03-29T00:00:00.000Z" ,
1463+ } ) ;
1464+ await waitForDraftHeroTransition ( ) ;
1465+ expect ( useComposerDraftStore . getState ( ) . getDraftSession ( draftId ) ) . toBeNull ( ) ;
1466+
1467+ const laterDraftId = DraftId . make ( "draft-later" ) ;
1468+ const laterThreadId = ThreadId . make ( "thread-later" ) ;
1469+ store . setProjectDraftThreadId ( projectRef , laterDraftId , { threadId : laterThreadId } ) ;
1470+ h . arrive ( scopeThreadRef ( TEST_ENVIRONMENT_ID , laterThreadId ) , {
1471+ latestRun : preparingRun ,
1472+ latestUserMessageAt : "2026-03-29T00:00:00.000Z" ,
1473+ } ) ;
1474+ await waitForDraftHeroTransition ( ) ;
1475+ expect ( useComposerDraftStore . getState ( ) . getPromotedDraftRedirect ( draftId ) ) . toEqual ( threadRef ) ;
1476+ } ) ;
1477+
14891478 it ( "does not finalize a draft whose send failed and was restored" , async ( ) => {
14901479 const h = draftPromotionHarness ( ) ;
14911480 const store = useComposerDraftStore . getState ( ) ;
0 commit comments