@@ -21,8 +21,10 @@ import (
2121type mockRuntime struct {
2222 events []runtime.Event
2323
24- mu sync.Mutex
25- resumes []runtime.ResumeRequest
24+ mu sync.Mutex
25+ resumes []runtime.ResumeRequest
26+ elicitationDeclines int
27+ elicitationLastAction tools.ElicitationAction
2628}
2729
2830func (m * mockRuntime ) CurrentAgentName () string { return "test" }
@@ -37,7 +39,11 @@ func (m *mockRuntime) Run(context.Context, *session.Session) ([]session.Message,
3739 return nil , nil
3840}
3941
40- func (m * mockRuntime ) ResumeElicitation (context.Context , tools.ElicitationAction , map [string ]any ) error {
42+ func (m * mockRuntime ) ResumeElicitation (_ context.Context , action tools.ElicitationAction , _ map [string ]any ) error {
43+ m .mu .Lock ()
44+ defer m .mu .Unlock ()
45+ m .elicitationDeclines ++
46+ m .elicitationLastAction = action
4147 return nil
4248}
4349func (m * mockRuntime ) SessionStore () session.Store { return nil }
@@ -178,6 +184,33 @@ func TestMaxIterationsRejectInJSONModeWithoutYolo(t *testing.T) {
178184 assert .Equal (t , resumes [0 ].Type , runtime .ResumeTypeReject )
179185}
180186
187+ func TestElicitationAutoDeclineInJSONMode (t * testing.T ) {
188+ t .Parallel ()
189+
190+ rt := & mockRuntime {
191+ events : []runtime.Event {
192+ & runtime.ElicitationRequestEvent {
193+ Type : "elicitation_request" ,
194+ Message : "Please authorize" ,
195+ Meta : map [string ]any {"cagent/server_url" : "https://example.com" },
196+ },
197+ },
198+ }
199+
200+ var buf bytes.Buffer
201+ out := NewPrinter (& buf )
202+ sess := session .New ()
203+ cfg := Config {OutputJSON : true }
204+
205+ err := Run (t .Context (), out , cfg , rt , sess , []string {"hello" })
206+ assert .NilError (t , err )
207+
208+ rt .mu .Lock ()
209+ defer rt .mu .Unlock ()
210+ assert .Equal (t , rt .elicitationDeclines , 1 )
211+ assert .Equal (t , rt .elicitationLastAction , tools .ElicitationAction ("decline" ))
212+ }
213+
181214func TestMaxIterationsSafetyCapJSONMode (t * testing.T ) {
182215 t .Parallel ()
183216
0 commit comments