@@ -314,54 +314,66 @@ describe("Composer submission", () => {
314314 gate . resolve ( )
315315 await submitted
316316 await sent . promise
317- expect ( calls . filter ( ( call ) => call === "gate" || call === "admit" || call === "send" ) ) . toEqual ( [ "gate" , "admit" , "send" ] )
317+ expect ( calls . filter ( ( call ) => call === "gate" || call === "admit" || call === "send" ) ) . toEqual ( [
318+ "gate" ,
319+ "admit" ,
320+ "send" ,
321+ ] )
318322 expect ( composer . submission . state ( ) ) . toEqual ( { type : "idle" , attempt : 1 } )
319323 } )
320324
321325 test . each ( [
322326 { name : "a prompt" , prompt : "Hello" , left : "Hello" } ,
323327 { name : "a prompt, with a draft typed since" , prompt : "Hello" , edit : "next" , left : "Hello\n\nnext" } ,
324328 { name : "a server command" , prompt : "/review now" , left : "/review now" } ,
325- ] ) ( "Stop while $name waits on the gate cancels that send: nothing reaches the server and its text comes back" , async ( row ) => {
326- const calls : string [ ] = [ ]
327- const timeline : string [ ] = [ ]
328- const statuses : ( "idle" | "running" ) [ ] = [ ]
329- const gate = Promise . withResolvers < void > ( )
330-
331- const target = session ( {
332- calls,
333- statuses,
334- handoff : { set : ( ) => timeline . push ( "set" ) , hold ( ) { } , settle : ( ) => timeline . push ( "settle" ) , clear : ( ) => timeline . push ( "clear" ) } ,
335- command : async ( ) => void calls . push ( "command" ) ,
336- } )
337-
338- const composer = gated ( target , ( ) => gate . promise , { prompt : row . prompt , calls } )
339- const submitted = composer . submission . submit ( new Event ( "submit" ) )
340- await flush ( )
341- expect ( composer . submission . state ( ) . type ) . toBe ( "sending" )
342- expect ( text ( composer . state ) ) . toBe ( "" )
343-
344- if ( row . edit ) composer . state . set ( typed ( row . edit ) , row . edit . length )
345- await composer . submission . stop ( )
346- await submitted
347- await flush ( )
329+ ] ) (
330+ "Stop while $name waits on the gate cancels that send: nothing reaches the server and its text comes back" ,
331+ async ( row ) => {
332+ const calls : string [ ] = [ ]
333+ const timeline : string [ ] = [ ]
334+ const statuses : ( "idle" | "running" ) [ ] = [ ]
335+ const gate = Promise . withResolvers < void > ( )
348336
349- // Neither the request nor an interrupt: the Session was never told of this send.
350- expect ( calls . filter ( ( call ) => call === "send" || call === "command" || call === "interrupt" ) ) . toEqual ( [ ] )
351- expect ( text ( composer . state ) ) . toBe ( row . left )
352- expect ( composer . failures ) . toEqual ( [ ] )
353- expect ( composer . submission . state ( ) ) . toEqual ( { type : "idle" , attempt : 1 } )
354- // A prompt that showed in the Session is taken out of it again, and the Session is not left looking busy.
355- expect ( timeline ) . toEqual ( row . prompt . startsWith ( "/" ) ? [ ] : [ "set" , "clear" ] )
356- expect ( statuses . at ( - 1 ) ?? "idle" ) . toBe ( "idle" )
357- expect ( composer . history ) . toEqual ( [ `add:${ row . prompt } ` , `remove:${ row . prompt } ` ] )
337+ const target = session ( {
338+ calls,
339+ statuses,
340+ handoff : {
341+ set : ( ) => timeline . push ( "set" ) ,
342+ hold ( ) { } ,
343+ settle : ( ) => timeline . push ( "settle" ) ,
344+ clear : ( ) => timeline . push ( "clear" ) ,
345+ } ,
346+ command : async ( ) => void calls . push ( "command" ) ,
347+ } )
358348
359- // What the send waited for is ready later: the result belongs to a send that no longer exists.
360- gate . resolve ( )
361- await flush ( )
362- expect ( calls . filter ( ( call ) => call === "send" || call === "command" ) ) . toEqual ( [ ] )
363- expect ( composer . submission . state ( ) ) . toEqual ( { type : "idle" , attempt : 1 } )
364- } )
349+ const composer = gated ( target , ( ) => gate . promise , { prompt : row . prompt , calls } )
350+ const submitted = composer . submission . submit ( new Event ( "submit" ) )
351+ await flush ( )
352+ expect ( composer . submission . state ( ) . type ) . toBe ( "sending" )
353+ expect ( text ( composer . state ) ) . toBe ( "" )
354+
355+ if ( row . edit ) composer . state . set ( typed ( row . edit ) , row . edit . length )
356+ await composer . submission . stop ( )
357+ await submitted
358+ await flush ( )
359+
360+ // Neither the request nor an interrupt: the Session was never told of this send.
361+ expect ( calls . filter ( ( call ) => call === "send" || call === "command" || call === "interrupt" ) ) . toEqual ( [ ] )
362+ expect ( text ( composer . state ) ) . toBe ( row . left )
363+ expect ( composer . failures ) . toEqual ( [ ] )
364+ expect ( composer . submission . state ( ) ) . toEqual ( { type : "idle" , attempt : 1 } )
365+ // A prompt that showed in the Session is taken out of it again, and the Session is not left looking busy.
366+ expect ( timeline ) . toEqual ( row . prompt . startsWith ( "/" ) ? [ ] : [ "set" , "clear" ] )
367+ expect ( statuses . at ( - 1 ) ?? "idle" ) . toBe ( "idle" )
368+ expect ( composer . history ) . toEqual ( [ `add:${ row . prompt } ` , `remove:${ row . prompt } ` ] )
369+
370+ // What the send waited for is ready later: the result belongs to a send that no longer exists.
371+ gate . resolve ( )
372+ await flush ( )
373+ expect ( calls . filter ( ( call ) => call === "send" || call === "command" ) ) . toEqual ( [ ] )
374+ expect ( composer . submission . state ( ) ) . toEqual ( { type : "idle" , attempt : 1 } )
375+ } ,
376+ )
365377
366378 test . each ( [
367379 {
@@ -405,7 +417,12 @@ describe("Composer submission", () => {
405417
406418 await flush ( )
407419 expect ( composer . state . context . items ( ) ) . toEqual ( [ ] )
408- composer . state . context . add ( { type : "file" , path : "src/later.ts" , comment : "Added while it waited" , commentID : "later" } )
420+ composer . state . context . add ( {
421+ type : "file" ,
422+ path : "src/later.ts" ,
423+ comment : "Added while it waited" ,
424+ commentID : "later" ,
425+ } )
409426 await composer . submission . stop ( )
410427 await submitted
411428 await flush ( )
@@ -526,8 +543,7 @@ describe("Composer submission", () => {
526543 const ref = { key : `server\n${ target . id } ` , id : target . id } as SessionRef
527544 const never = { plugin : "browser" , value : { ready : ( ) => new Promise < void > ( ( ) => undefined ) } }
528545
529- const ready = ( ) =>
530- how === "times out" ? settlePromptGates ( [ never ] , ( ) => true , ref ) : gate . promise
546+ const ready = ( ) => ( how === "times out" ? settlePromptGates ( [ never ] , ( ) => true , ref ) : gate . promise )
531547
532548 const sends = [
533549 gated ( target , ready , { prompt : "Hello" } ) ,
@@ -557,9 +573,7 @@ describe("Composer submission", () => {
557573 const accepted = Promise . withResolvers < void > ( )
558574 const state = createMemoryComposerState ( { prompt : "Hello" } ) . capture ( )
559575
560- await submitInput ( active ( state , session ( { calls, accept : ( ) => accepted . resolve ( ) } ) ) ) . submit (
561- new Event ( "submit" ) ,
562- )
576+ await submitInput ( active ( state , session ( { calls, accept : ( ) => accepted . resolve ( ) } ) ) ) . submit ( new Event ( "submit" ) )
563577 await accepted . promise
564578
565579 expect ( calls . filter ( ( call ) => call === "accept-send" ) ) . toHaveLength ( 1 )
@@ -657,9 +671,7 @@ describe("Composer submission", () => {
657671 expect ( await submission . submitComment ( "quote:c=selected" , "Compare @src/api.ts with @here" ) ) . toBe ( true )
658672 expect ( calls [ 0 ] ) . toBe ( "keep-preview" )
659673 expect ( requests ) . toHaveLength ( 1 )
660- expect ( requests [ 0 ] ?. text ) . toBe (
661- "> Selected passage\n\nCompare @src/api.ts with @here" ,
662- )
674+ expect ( requests [ 0 ] ?. text ) . toBe ( "> Selected passage\n\nCompare @src/api.ts with @here" )
663675 expect ( requests [ 0 ] ) . toMatchObject ( {
664676 delivery,
665677 files : [ { uri : "file:///C:/repo/src/api.ts" , name : "api.ts" } ] ,
@@ -759,7 +771,7 @@ describe("Composer submission", () => {
759771 expect ( await pending ) . toBe ( false )
760772 expect ( errors ) . toHaveLength ( 1 )
761773 expect ( state . current ( ) ) . toEqual ( [ { type : "text" , content : "Keep this draft" , start : 0 , end : 15 } ] )
762- expect ( state . context . items ( ) ) . toMatchObject ( [
774+ expect ( JSON . parse ( JSON . stringify ( state . context . items ( ) ) ) ) . toMatchObject ( [
763775 { key : "quote:c=selected" , text : "Selected passage" , comment : "Latest comment" } ,
764776 ] )
765777 expect ( calls . filter ( ( call ) => call === "send" ) ) . toHaveLength ( 2 )
@@ -1310,7 +1322,7 @@ describe("Composer submission", () => {
13101322 expect ( statuses ) . toEqual ( [ "running" , "idle" , "running" , "idle" ] )
13111323 expect ( state . current ( ) ) . toEqual ( prompt )
13121324 // In the order it was sent, so the resend's request matches the first.
1313- expect ( state . context . items ( ) ) . toMatchObject ( [
1325+ expect ( JSON . parse ( JSON . stringify ( state . context . items ( ) ) ) ) . toMatchObject ( [
13141326 { type : "file" , path : "notes.md" , description : "the failing version" } ,
13151327 note ,
13161328 ] )
@@ -1350,8 +1362,10 @@ describe("Composer submission", () => {
13501362 ) . submit ( new Event ( "submit" ) )
13511363 await failed . promise
13521364
1353- expect ( promoted . current ( ) ) . toMatchObject ( [ { type : "text" , content : "first prompt" } ] )
1354- expect ( promoted . context . items ( ) ) . toMatchObject ( [ { type : "file" , path : "src/app.ts" , comment : "Keep this comment" } ] )
1365+ expect ( JSON . parse ( JSON . stringify ( promoted . current ( ) ) ) ) . toMatchObject ( [ { type : "text" , content : "first prompt" } ] )
1366+ expect ( JSON . parse ( JSON . stringify ( promoted . context . items ( ) ) ) ) . toMatchObject ( [
1367+ { type : "file" , path : "src/app.ts" , comment : "Keep this comment" } ,
1368+ ] )
13551369 expect ( promoted . mode . current ( ) ) . toBe ( "shell" )
13561370 } )
13571371
@@ -1392,7 +1406,9 @@ describe("Composer submission", () => {
13921406 await failed . promise
13931407
13941408 expect ( text ( promoted ) ) . toBe ( "first prompt\n\nfollow-up" )
1395- expect ( promoted . context . items ( ) ) . toMatchObject ( [ { key, type : "quote" , text : "quoted passage" } ] )
1409+ expect ( JSON . parse ( JSON . stringify ( promoted . context . items ( ) ) ) ) . toMatchObject ( [
1410+ { key, type : "quote" , text : "quoted passage" } ,
1411+ ] )
13961412 expect ( promoted . quoteSource . state . sources [ key ] ) . toEqual ( source )
13971413 // A recovered follow-up changes the payload, so it is not a retry of the failed admission.
13981414 expect ( promoted . retry . current ( ) ) . toBeUndefined ( )
0 commit comments