@@ -147,4 +147,22 @@ describe("dispatchChatAction (#6519)", () => {
147147 const result = await dispatchChatAction ( { action : "demo" , params : { } } , { env : enabledEnv , registry } ) ;
148148 expect ( result ) . toEqual ( { ok : false , status : "invalid_params" , action : "demo" , error : "boom" } ) ;
149149 } ) ;
150+
151+ it ( "fails closed with handler_error when the handler throws, not an unhandled rejection (#6989)" , async ( ) => {
152+ const registry = registryWith ( "demo" , ( ) => true , ( ) => {
153+ throw new Error ( "network down" ) ;
154+ } ) ;
155+ const result = await dispatchChatAction ( { action : "demo" , params : { } } , { env : enabledEnv , registry } ) ;
156+ // Typed result, distinct from invalid_params so a caller can tell an execution failure from a validation
157+ // failure. The thrown value is deliberately not surfaced (it may carry external detail).
158+ expect ( result ) . toEqual ( { ok : false , status : "handler_error" , action : "demo" } ) ;
159+ } ) ;
160+
161+ it ( "fails closed the same way regardless of what the handler throws (#6989)" , async ( ) => {
162+ const registry = registryWith ( "demo" , ( ) => true , ( ) => {
163+ throw "kaboom" ;
164+ } ) ;
165+ const result = await dispatchChatAction ( { action : "demo" , params : { } } , { env : enabledEnv , registry } ) ;
166+ expect ( result ) . toEqual ( { ok : false , status : "handler_error" , action : "demo" } ) ;
167+ } ) ;
150168} ) ;
0 commit comments