File tree Expand file tree Collapse file tree 2 files changed +35
-0
lines changed
Expand file tree Collapse file tree 2 files changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -316,6 +316,11 @@ async function replayState(
316316 return res ;
317317 }
318318 async function cancel ( key ?: unknown ) {
319+ if ( complete ) {
320+ throw new Error (
321+ "Cannot perform a cancel operation after the conversation has completed, are you missing an `await`?" ,
322+ ) ;
323+ }
319324 canceled = true ;
320325 interrupted = true ;
321326 message = key ;
Original file line number Diff line number Diff line change 44 assert ,
55 assertEquals ,
66 assertGreater ,
7+ assertRejects ,
78 assertSpyCall ,
89 assertSpyCalls ,
910 describe ,
@@ -387,4 +388,33 @@ describe("ReplayEngine", () => {
387388 assertSpyCalls ( builder , 2 ) ;
388389 assertEquals ( i , 0 ) ;
389390 } ) ;
391+ it ( "should throw error if the controls are used after the replay has finished" , async ( ) => {
392+ let controls : ReplayControls | undefined ;
393+ const engine = new ReplayEngine ( ( c ) => {
394+ controls = c ;
395+ } ) ;
396+ const res = await engine . play ( ) ;
397+ assertEquals ( res . type , "returned" ) ;
398+ assertRejects (
399+ async ( ) => {
400+ await controls ?. action ( ( ) => 0 , "" ) ;
401+ } ,
402+ Error ,
403+ "missing an `await`" ,
404+ ) ;
405+ assertRejects (
406+ async ( ) => {
407+ await controls ?. cancel ( ) ;
408+ } ,
409+ Error ,
410+ "missing an `await`" ,
411+ ) ;
412+ assertRejects (
413+ async ( ) => {
414+ await controls ?. interrupt ( "" ) ;
415+ } ,
416+ Error ,
417+ "missing an `await`" ,
418+ ) ;
419+ } ) ;
390420} ) ;
You can’t perform that action at this time.
0 commit comments