@@ -435,8 +435,14 @@ describe("dispatchEvent sender agent identity", () => {
435435} ) ;
436436
437437describe ( "dispatchEvent external providers" , ( ) => {
438- it ( "hands a non-inkbox event to onExternal and acks" , async ( ) => {
439- const onExternal = vi . fn ( async ( ) => { } ) ;
438+ it ( "hands a non-inkbox event to onExternal and acks without waiting for the turn" , async ( ) => {
439+ let finish : ( ) => void = ( ) => { } ;
440+ const onExternal = vi . fn (
441+ ( ) =>
442+ new Promise < void > ( ( resolve ) => {
443+ finish = resolve ;
444+ } ) ,
445+ ) ;
440446 const deps = makeDeps ( { onExternal } ) ;
441447 const external : VerifiedEvent = {
442448 provider : "github" ,
@@ -451,6 +457,28 @@ describe("dispatchEvent external providers", () => {
451457 expect ( ok ) . toBe ( true ) ;
452458 expect ( onExternal ) . toHaveBeenCalledWith ( external ) ;
453459 expect ( deps . sessions . handleInbound ) . not . toHaveBeenCalled ( ) ;
460+ finish ( ) ;
461+ } ) ;
462+
463+ it ( "logs an external turn rejected after acknowledgement" , async ( ) => {
464+ const onExternal = vi . fn ( async ( ) => {
465+ throw new Error ( "capture failed" ) ;
466+ } ) ;
467+ const deps = makeDeps ( { onExternal } ) ;
468+ const external : VerifiedEvent = {
469+ provider : "github" ,
470+ verified : true ,
471+ eventType : "push" ,
472+ body : { ref : "refs/heads/main" } ,
473+ headers : { } ,
474+ } ;
475+
476+ await expect ( dispatchEvent ( deps , external ) ) . resolves . toBe ( true ) ;
477+ await vi . waitFor ( ( ) =>
478+ expect ( deps . logger . error ) . toHaveBeenCalledWith ( "external.dispatch_failed" , {
479+ error : "Error: capture failed" ,
480+ } ) ,
481+ ) ;
454482 } ) ;
455483} ) ;
456484
0 commit comments