@@ -613,6 +613,66 @@ test('pending waiting Goals float in a quiet orb chip above the steward composer
613613 }
614614} ) ;
615615
616+ test ( 'retry a lost POST receipt with the same identity only for the restored draft and session' , async t => {
617+ const location = Object . getOwnPropertyDescriptor ( globalThis , 'location' ) ;
618+ Object . defineProperty ( globalThis , 'location' , { configurable : true , value : { origin : 'http://localhost' } } ) ;
619+ Object . assign ( globalThis , { IS_REACT_ACT_ENVIRONMENT : true } ) ;
620+ const submissions : { client_turn_id : string ; message : string } [ ] = [ ] ;
621+ let renderer : ReactTestRenderer | undefined ;
622+ let loseReceipt = true ;
623+ t . mock . method ( globalThis , 'fetch' , async ( input : RequestInfo | URL , init : RequestInit ) => {
624+ const url = String ( input ) ;
625+ if ( url . endsWith ( '/sessions' ) ) return json ( { session_id : 'original' } ) ;
626+ if ( url . endsWith ( '/sessions/original' ) ) return json ( { messages : [ ] } ) ;
627+ if ( url . endsWith ( '/turns' ) ) {
628+ submissions . push ( JSON . parse ( String ( init . body ) ) ) ;
629+ if ( submissions . length === 2 ) return new Response ( null , { status : 429 } ) ;
630+ if ( loseReceipt ) throw new TypeError ( 'response lost after acceptance' ) ;
631+ return json ( { turn_id : 'accepted' , events_url : '/api/chat/sessions/original/turns/accepted/events' } ) ;
632+ }
633+ if ( url . endsWith ( '/events' ) ) return new Response ( 'event: turn.completed\ndata: {}\n\n' ) ;
634+ throw new Error ( 'Unexpected endpoint ' + url ) ;
635+ } ) ;
636+ const submit = async ( text ?: string ) => {
637+ if ( text !== undefined ) await act ( async ( ) => {
638+ renderer ! . root . findByType ( 'textarea' ) . props . onChange ( { target : { value : text } } ) ;
639+ } ) ;
640+ await act ( async ( ) => { renderer ! . root . findByType ( 'form' ) . props . onSubmit ( { preventDefault ( ) { } } ) ; await tick ( ) ; } ) ;
641+ } ;
642+ const open = async ( token : string ) => {
643+ const element = createElement ( StewardConversation , { token, failure : null } ) ;
644+ await act ( async ( ) => {
645+ if ( renderer ) renderer . update ( element ) ;
646+ else renderer = create ( element , { createNodeMock : ( ) => ( { scrollIntoView ( ) { } } ) } ) ;
647+ await tick ( ) ;
648+ } ) ;
649+ } ;
650+ try {
651+ await open ( 'scope-one' ) ;
652+ await submit ( 'Check the draft' ) ;
653+ assert . equal ( renderer ! . root . findByType ( 'textarea' ) . props . value , 'Check the draft' ) ;
654+ loseReceipt = false ;
655+ await submit ( ) ;
656+ assert . deepEqual ( submissions [ 1 ] , submissions [ 0 ] ) ;
657+ // A rejection of the retry leaves the outcome of the first submission unknown.
658+ assert . equal ( renderer ! . root . findByType ( 'textarea' ) . props . value , 'Check the draft' ) ;
659+ await submit ( ) ;
660+ assert . deepEqual ( submissions [ 2 ] , submissions [ 0 ] ) ;
661+ loseReceipt = true ;
662+ await submit ( 'Check the draft' ) ;
663+ assert . notEqual ( submissions [ 3 ] ! . client_turn_id , submissions [ 2 ] ! . client_turn_id ) ;
664+ await submit ( 'Check the revision' ) ;
665+ assert . notEqual ( submissions [ 4 ] ! . client_turn_id , submissions [ 3 ] ! . client_turn_id ) ;
666+ await open ( 'scope-two' ) ;
667+ await submit ( 'Check the revision' ) ;
668+ assert . notEqual ( submissions [ 5 ] ! . client_turn_id , submissions [ 4 ] ! . client_turn_id ) ;
669+ } finally {
670+ await act ( async ( ) => renderer ?. unmount ( ) ) ;
671+ if ( location ) Object . defineProperty ( globalThis , 'location' , location ) ;
672+ else Reflect . deleteProperty ( globalThis , 'location' ) ;
673+ }
674+ } ) ;
675+
616676test ( 'deferring session open while a session open is pending clears the loading hint and shows the greeting' , async ( ) => {
617677 const saved = globalThis . fetch ;
618678 const oldLocation = Object . getOwnPropertyDescriptor ( globalThis , 'location' ) ;
0 commit comments