-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathcommands_and_elicitation_e2e_test.go
More file actions
672 lines (595 loc) · 21.4 KB
/
commands_and_elicitation_e2e_test.go
File metadata and controls
672 lines (595 loc) · 21.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
package e2e
import (
"fmt"
"strings"
"testing"
"time"
copilot "github.com/github/copilot-sdk/go"
"github.com/github/copilot-sdk/go/internal/e2e/testharness"
"github.com/github/copilot-sdk/go/rpc"
)
func TestCommandsE2E(t *testing.T) {
ctx := testharness.NewTestContext(t)
client1 := ctx.NewClient(func(opts *copilot.ClientOptions) {
opts.UseStdio = copilot.Bool(false)
opts.TCPConnectionToken = sharedTcpToken
})
t.Cleanup(func() { client1.ForceStop() })
// Start client1 with an init session to get the port
initSession, err := client1.CreateSession(t.Context(), &copilot.SessionConfig{
OnPermissionRequest: copilot.PermissionHandler.ApproveAll,
})
if err != nil {
t.Fatalf("Failed to create init session: %v", err)
}
initSession.Disconnect()
actualPort := client1.ActualPort()
if actualPort == 0 {
t.Fatalf("Expected non-zero port from TCP mode client")
}
client2 := copilot.NewClient(&copilot.ClientOptions{
CLIUrl: fmt.Sprintf("localhost:%d", actualPort),
TCPConnectionToken: sharedTcpToken,
})
t.Cleanup(func() { client2.ForceStop() })
t.Run("commands.changed event when another client joins with commands", func(t *testing.T) {
ctx.ConfigureForTest(t)
// Client1 creates a session without commands
session1, err := client1.CreateSession(t.Context(), &copilot.SessionConfig{
OnPermissionRequest: copilot.PermissionHandler.ApproveAll,
})
if err != nil {
t.Fatalf("Failed to create session: %v", err)
}
// Listen for commands.changed event on client1
commandsChangedCh := make(chan copilot.SessionEvent, 1)
unsubscribe := session1.On(func(event copilot.SessionEvent) {
if _, ok := event.Data.(*copilot.CommandsChangedData); ok {
select {
case commandsChangedCh <- event:
default:
}
}
})
defer unsubscribe()
// Client2 joins with commands
session2, err := client2.ResumeSession(t.Context(), session1.SessionID, &copilot.ResumeSessionConfig{
OnPermissionRequest: copilot.PermissionHandler.ApproveAll,
DisableResume: true,
Commands: []copilot.CommandDefinition{
{
Name: "deploy",
Description: "Deploy the app",
Handler: func(ctx copilot.CommandContext) error { return nil },
},
},
})
if err != nil {
t.Fatalf("Failed to resume session: %v", err)
}
select {
case event := <-commandsChangedCh:
d, ok := event.Data.(*copilot.CommandsChangedData)
if !ok || len(d.Commands) == 0 {
t.Errorf("Expected commands in commands.changed event")
} else {
found := false
for _, cmd := range d.Commands {
if cmd.Name == "deploy" {
found = true
if cmd.Description == nil || *cmd.Description != "Deploy the app" {
t.Errorf("Expected deploy command description 'Deploy the app', got %v", cmd.Description)
}
break
}
}
if !found {
t.Errorf("Expected 'deploy' command in commands.changed event, got %+v", d.Commands)
}
}
case <-time.After(30 * time.Second):
t.Fatal("Timed out waiting for commands.changed event")
}
session2.Disconnect()
})
t.Run("session with commands creates successfully", func(t *testing.T) {
ctx.ConfigureForTest(t)
session, err := client1.CreateSession(t.Context(), &copilot.SessionConfig{
OnPermissionRequest: copilot.PermissionHandler.ApproveAll,
Commands: []copilot.CommandDefinition{
{Name: "deploy", Description: "Deploy the app", Handler: func(_ copilot.CommandContext) error { return nil }},
{Name: "rollback", Handler: func(_ copilot.CommandContext) error { return nil }},
},
})
if err != nil {
t.Fatalf("CreateSession failed: %v", err)
}
if session.SessionID == "" {
t.Error("Expected non-empty SessionID")
}
_ = session.Disconnect()
})
t.Run("session with commands resumes successfully", func(t *testing.T) {
ctx.ConfigureForTest(t)
session1, err := client1.CreateSession(t.Context(), &copilot.SessionConfig{
OnPermissionRequest: copilot.PermissionHandler.ApproveAll,
})
if err != nil {
t.Fatalf("CreateSession failed: %v", err)
}
sessionID := session1.SessionID
t.Cleanup(func() { _ = session1.Disconnect() })
resumeClient := newResumeClient(t, client1)
session2, err := resumeClient.ResumeSession(t.Context(), sessionID, &copilot.ResumeSessionConfig{
OnPermissionRequest: copilot.PermissionHandler.ApproveAll,
DisableResume: true,
Commands: []copilot.CommandDefinition{
{Name: "deploy", Description: "Deploy", Handler: func(_ copilot.CommandContext) error { return nil }},
},
})
if err != nil {
t.Fatalf("ResumeSession failed: %v", err)
}
if session2.SessionID != sessionID {
t.Errorf("Expected SessionID %q, got %q", sessionID, session2.SessionID)
}
_ = session2.Disconnect()
})
t.Run("session with no commands creates successfully", func(t *testing.T) {
ctx.ConfigureForTest(t)
session, err := client1.CreateSession(t.Context(), &copilot.SessionConfig{
OnPermissionRequest: copilot.PermissionHandler.ApproveAll,
})
if err != nil {
t.Fatalf("CreateSession failed: %v", err)
}
if session == nil {
t.Fatal("Expected non-nil session")
}
_ = session.Disconnect()
})
}
func TestUIElicitationE2E(t *testing.T) {
ctx := testharness.NewTestContext(t)
client := ctx.NewClient()
t.Cleanup(func() { client.ForceStop() })
t.Run("elicitation methods error in headless mode", func(t *testing.T) {
ctx.ConfigureForTest(t)
session, err := client.CreateSession(t.Context(), &copilot.SessionConfig{
OnPermissionRequest: copilot.PermissionHandler.ApproveAll,
})
if err != nil {
t.Fatalf("Failed to create session: %v", err)
}
// Verify capabilities report no elicitation
caps := session.Capabilities()
if caps.UI != nil && caps.UI.Elicitation {
t.Error("Expected no elicitation capability in headless mode")
}
// All UI methods should return a "not supported" error
ui := session.UI()
_, err = ui.Confirm(t.Context(), "Are you sure?")
if err == nil {
t.Error("Expected error calling Confirm without elicitation capability")
} else if !strings.Contains(err.Error(), "not supported") {
t.Errorf("Expected 'not supported' in error message, got: %s", err.Error())
}
_, _, err = ui.Select(t.Context(), "Pick one", []string{"a", "b"})
if err == nil {
t.Error("Expected error calling Select without elicitation capability")
} else if !strings.Contains(err.Error(), "not supported") {
t.Errorf("Expected 'not supported' in error message, got: %s", err.Error())
}
_, _, err = ui.Input(t.Context(), "Enter name", nil)
if err == nil {
t.Error("Expected error calling Input without elicitation capability")
} else if !strings.Contains(err.Error(), "not supported") {
t.Errorf("Expected 'not supported' in error message, got: %s", err.Error())
}
})
}
func TestUIElicitationCallbackE2E(t *testing.T) {
ctx := testharness.NewTestContext(t)
client := ctx.NewClient()
t.Cleanup(func() { client.ForceStop() })
t.Run("session with OnElicitationRequest reports elicitation capability", func(t *testing.T) {
ctx.ConfigureForTest(t)
session, err := client.CreateSession(t.Context(), &copilot.SessionConfig{
OnPermissionRequest: copilot.PermissionHandler.ApproveAll,
OnElicitationRequest: func(ctx copilot.ElicitationContext) (copilot.ElicitationResult, error) {
return copilot.ElicitationResult{Action: "accept", Content: map[string]any{}}, nil
},
})
if err != nil {
t.Fatalf("Failed to create session: %v", err)
}
caps := session.Capabilities()
if caps.UI == nil || !caps.UI.Elicitation {
// The test harness may or may not include capabilities in the response.
// When running against a real CLI, this will be true.
t.Logf("Note: capabilities.ui.elicitation=%v (may be false with test harness)", caps.UI)
}
})
t.Run("session without OnElicitationRequest reports no elicitation capability", func(t *testing.T) {
ctx.ConfigureForTest(t)
session, err := client.CreateSession(t.Context(), &copilot.SessionConfig{
OnPermissionRequest: copilot.PermissionHandler.ApproveAll,
})
if err != nil {
t.Fatalf("Failed to create session: %v", err)
}
caps := session.Capabilities()
if caps.UI != nil && caps.UI.Elicitation {
t.Error("Expected no elicitation capability when OnElicitationRequest is not provided")
}
})
t.Run("confirm returns true when handler accepts", func(t *testing.T) {
ctx.ConfigureForTest(t)
session, err := client.CreateSession(t.Context(), &copilot.SessionConfig{
OnPermissionRequest: copilot.PermissionHandler.ApproveAll,
OnElicitationRequest: func(ec copilot.ElicitationContext) (copilot.ElicitationResult, error) {
if ec.Message != "Confirm?" {
t.Errorf("Expected Message='Confirm?', got %q", ec.Message)
}
if !schemaHasProperty(ec.RequestedSchema, "confirmed") {
t.Errorf("Expected RequestedSchema to contain 'confirmed' property")
}
return copilot.ElicitationResult{
Action: "accept",
Content: map[string]any{"confirmed": true},
}, nil
},
})
if err != nil {
t.Fatalf("CreateSession failed: %v", err)
}
ok, err := session.UI().Confirm(t.Context(), "Confirm?")
if err != nil {
t.Fatalf("Confirm failed: %v", err)
}
if !ok {
t.Error("Expected Confirm to return true when handler accepts")
}
})
t.Run("confirm returns false when handler declines", func(t *testing.T) {
ctx.ConfigureForTest(t)
session, err := client.CreateSession(t.Context(), &copilot.SessionConfig{
OnPermissionRequest: copilot.PermissionHandler.ApproveAll,
OnElicitationRequest: func(ec copilot.ElicitationContext) (copilot.ElicitationResult, error) {
return copilot.ElicitationResult{Action: "decline"}, nil
},
})
if err != nil {
t.Fatalf("CreateSession failed: %v", err)
}
ok, err := session.UI().Confirm(t.Context(), "Confirm?")
if err != nil {
t.Fatalf("Confirm failed: %v", err)
}
if ok {
t.Error("Expected Confirm to return false when handler declines")
}
})
t.Run("select returns selected option", func(t *testing.T) {
ctx.ConfigureForTest(t)
session, err := client.CreateSession(t.Context(), &copilot.SessionConfig{
OnPermissionRequest: copilot.PermissionHandler.ApproveAll,
OnElicitationRequest: func(ec copilot.ElicitationContext) (copilot.ElicitationResult, error) {
if ec.Message != "Choose" {
t.Errorf("Expected Message='Choose', got %q", ec.Message)
}
if !schemaHasProperty(ec.RequestedSchema, "selection") {
t.Errorf("Expected RequestedSchema to contain 'selection' property")
}
return copilot.ElicitationResult{
Action: "accept",
Content: map[string]any{"selection": "beta"},
}, nil
},
})
if err != nil {
t.Fatalf("CreateSession failed: %v", err)
}
value, ok, err := session.UI().Select(t.Context(), "Choose", []string{"alpha", "beta"})
if err != nil {
t.Fatalf("Select failed: %v", err)
}
if !ok {
t.Error("Expected Select to return ok=true on accept")
}
if value != "beta" {
t.Errorf("Expected selected value 'beta', got %q", value)
}
})
t.Run("input returns freeform value", func(t *testing.T) {
ctx.ConfigureForTest(t)
session, err := client.CreateSession(t.Context(), &copilot.SessionConfig{
OnPermissionRequest: copilot.PermissionHandler.ApproveAll,
OnElicitationRequest: func(ec copilot.ElicitationContext) (copilot.ElicitationResult, error) {
if ec.Message != "Enter value" {
t.Errorf("Expected Message='Enter value', got %q", ec.Message)
}
if !schemaHasProperty(ec.RequestedSchema, "value") {
t.Errorf("Expected RequestedSchema to contain 'value' property")
}
return copilot.ElicitationResult{
Action: "accept",
Content: map[string]any{"value": "typed value"},
}, nil
},
})
if err != nil {
t.Fatalf("CreateSession failed: %v", err)
}
minLen := 1
maxLen := 20
value, ok, err := session.UI().Input(t.Context(), "Enter value", &copilot.InputOptions{
Title: "Value",
Description: "A value to test",
MinLength: &minLen,
MaxLength: &maxLen,
Default: "default",
})
if err != nil {
t.Fatalf("Input failed: %v", err)
}
if !ok {
t.Error("Expected Input to return ok=true on accept")
}
if value != "typed value" {
t.Errorf("Expected typed value 'typed value', got %q", value)
}
})
t.Run("elicitation returns all action shapes", func(t *testing.T) {
ctx.ConfigureForTest(t)
responses := []copilot.ElicitationResult{
{Action: "accept", Content: map[string]any{"name": "Mona"}},
{Action: "decline"},
{Action: "cancel"},
}
var idx int
session, err := client.CreateSession(t.Context(), &copilot.SessionConfig{
OnPermissionRequest: copilot.PermissionHandler.ApproveAll,
OnElicitationRequest: func(ec copilot.ElicitationContext) (copilot.ElicitationResult, error) {
if ec.Message != "Name?" {
t.Errorf("Expected Message='Name?', got %q", ec.Message)
}
if idx >= len(responses) {
t.Fatalf("Handler called more times than expected (%d)", idx+1)
}
resp := responses[idx]
idx++
return resp, nil
},
})
if err != nil {
t.Fatalf("CreateSession failed: %v", err)
}
schema := rpc.UIElicitationSchema{
Type: rpc.UIElicitationSchemaTypeObject,
Properties: map[string]rpc.UIElicitationSchemaProperty{
"name": &rpc.UIElicitationSchemaPropertyString{},
},
Required: []string{"name"},
}
accept, err := session.UI().Elicitation(t.Context(), "Name?", schema)
if err != nil {
t.Fatalf("Elicitation accept call failed: %v", err)
}
if accept.Action != "accept" {
t.Errorf("Expected accept.Action='accept', got %q", accept.Action)
}
if accept.Content == nil || fmt.Sprintf("%v", accept.Content["name"]) != "Mona" {
t.Errorf("Expected accept.Content[name]='Mona', got %v", accept.Content)
}
decline, err := session.UI().Elicitation(t.Context(), "Name?", schema)
if err != nil {
t.Fatalf("Elicitation decline call failed: %v", err)
}
if decline.Action != "decline" {
t.Errorf("Expected decline.Action='decline', got %q", decline.Action)
}
cancel, err := session.UI().Elicitation(t.Context(), "Name?", schema)
if err != nil {
t.Fatalf("Elicitation cancel call failed: %v", err)
}
if cancel.Action != "cancel" {
t.Errorf("Expected cancel.Action='cancel', got %q", cancel.Action)
}
})
t.Run("defaults capabilities when not provided", func(t *testing.T) {
ctx.ConfigureForTest(t)
session, err := client.CreateSession(t.Context(), &copilot.SessionConfig{
OnPermissionRequest: copilot.PermissionHandler.ApproveAll,
})
if err != nil {
t.Fatalf("CreateSession failed: %v", err)
}
// A session always exposes some capability struct (even when empty).
_ = session.Capabilities()
_ = session.Disconnect()
})
t.Run("sends requestElicitation when handler provided", func(t *testing.T) {
ctx.ConfigureForTest(t)
session, err := client.CreateSession(t.Context(), &copilot.SessionConfig{
OnPermissionRequest: copilot.PermissionHandler.ApproveAll,
OnElicitationRequest: func(ec copilot.ElicitationContext) (copilot.ElicitationResult, error) {
return copilot.ElicitationResult{Action: "accept", Content: map[string]any{}}, nil
},
})
if err != nil {
t.Fatalf("CreateSession failed: %v", err)
}
if session.SessionID == "" {
t.Error("Expected non-empty SessionID when handler provided")
}
_ = session.Disconnect()
})
}
// schemaHasProperty reports whether the elicitation schema map has a top-level
// property with the given name. RequestedSchema["properties"] is typically a
// map[string]rpc.UIElicitationSchemaProperty, but we accept any map[string]X.
func schemaHasProperty(schema map[string]any, name string) bool {
if schema == nil {
return false
}
props, ok := schema["properties"]
if !ok || props == nil {
return false
}
switch p := props.(type) {
case map[string]any:
_, found := p[name]
return found
case map[string]rpc.UIElicitationSchemaProperty:
_, found := p[name]
return found
default:
// Fallback: marshal/unmarshal via reflection-friendly route.
// For test diagnostic purposes we treat unknown shapes as not found.
return false
}
}
func TestUIElicitationMultiClientE2E(t *testing.T) {
ctx := testharness.NewTestContext(t)
client1 := ctx.NewClient(func(opts *copilot.ClientOptions) {
opts.UseStdio = copilot.Bool(false)
opts.TCPConnectionToken = sharedTcpToken
})
t.Cleanup(func() { client1.ForceStop() })
// Start client1 with an init session to get the port
initSession, err := client1.CreateSession(t.Context(), &copilot.SessionConfig{
OnPermissionRequest: copilot.PermissionHandler.ApproveAll,
})
if err != nil {
t.Fatalf("Failed to create init session: %v", err)
}
initSession.Disconnect()
actualPort := client1.ActualPort()
if actualPort == 0 {
t.Fatalf("Expected non-zero port from TCP mode client")
}
t.Run("capabilities.changed fires when second client joins with elicitation handler", func(t *testing.T) {
ctx.ConfigureForTest(t)
// Client1 creates a session without elicitation handler
session1, err := client1.CreateSession(t.Context(), &copilot.SessionConfig{
OnPermissionRequest: copilot.PermissionHandler.ApproveAll,
})
if err != nil {
t.Fatalf("Failed to create session: %v", err)
}
// Verify initial state: no elicitation capability
caps := session1.Capabilities()
if caps.UI != nil && caps.UI.Elicitation {
t.Error("Expected no elicitation capability before second client joins")
}
// Listen for capabilities.changed with elicitation enabled
capEnabledCh := make(chan copilot.SessionEvent, 1)
unsubscribe := session1.On(func(event copilot.SessionEvent) {
if d, ok := event.Data.(*copilot.CapabilitiesChangedData); ok && d.UI != nil && d.UI.Elicitation != nil && *d.UI.Elicitation {
select {
case capEnabledCh <- event:
default:
}
}
})
// Client2 joins with elicitation handler — should trigger capabilities.changed
client2 := copilot.NewClient(&copilot.ClientOptions{
CLIUrl: fmt.Sprintf("localhost:%d", actualPort),
TCPConnectionToken: sharedTcpToken,
})
session2, err := client2.ResumeSession(t.Context(), session1.SessionID, &copilot.ResumeSessionConfig{
OnPermissionRequest: copilot.PermissionHandler.ApproveAll,
DisableResume: true,
OnElicitationRequest: func(ctx copilot.ElicitationContext) (copilot.ElicitationResult, error) {
return copilot.ElicitationResult{Action: "accept", Content: map[string]any{}}, nil
},
})
if err != nil {
client2.ForceStop()
t.Fatalf("Failed to resume session: %v", err)
}
// Wait for the elicitation-enabled capabilities.changed event
select {
case capEvent := <-capEnabledCh:
capData, capOk := capEvent.Data.(*copilot.CapabilitiesChangedData)
if !capOk || capData.UI == nil || capData.UI.Elicitation == nil || !*capData.UI.Elicitation {
t.Errorf("Expected capabilities.changed with ui.elicitation=true, got %+v", capEvent.Data)
}
case <-time.After(30 * time.Second):
t.Fatal("Timed out waiting for capabilities.changed event (elicitation enabled)")
}
unsubscribe()
session2.Disconnect()
client2.ForceStop()
})
t.Run("capabilities.changed fires when elicitation provider disconnects", func(t *testing.T) {
ctx.ConfigureForTest(t)
// Client1 creates a session without elicitation handler
session1, err := client1.CreateSession(t.Context(), &copilot.SessionConfig{
OnPermissionRequest: copilot.PermissionHandler.ApproveAll,
})
if err != nil {
t.Fatalf("Failed to create session: %v", err)
}
// Verify initial state: no elicitation capability
caps := session1.Capabilities()
if caps.UI != nil && caps.UI.Elicitation {
t.Error("Expected no elicitation capability before provider joins")
}
// Listen for capability enabled
capEnabledCh := make(chan struct{}, 1)
unsubEnabled := session1.On(func(event copilot.SessionEvent) {
if d, ok := event.Data.(*copilot.CapabilitiesChangedData); ok && d.UI != nil && d.UI.Elicitation != nil && *d.UI.Elicitation {
select {
case capEnabledCh <- struct{}{}:
default:
}
}
})
// Client3 (dedicated for this test) joins with elicitation handler
client3 := copilot.NewClient(&copilot.ClientOptions{
CLIUrl: fmt.Sprintf("localhost:%d", actualPort),
TCPConnectionToken: sharedTcpToken,
})
_, err = client3.ResumeSession(t.Context(), session1.SessionID, &copilot.ResumeSessionConfig{
OnPermissionRequest: copilot.PermissionHandler.ApproveAll,
DisableResume: true,
OnElicitationRequest: func(ctx copilot.ElicitationContext) (copilot.ElicitationResult, error) {
return copilot.ElicitationResult{Action: "accept", Content: map[string]any{}}, nil
},
})
if err != nil {
client3.ForceStop()
t.Fatalf("Failed to resume session for client3: %v", err)
}
// Wait for elicitation to become enabled
select {
case <-capEnabledCh:
// Good — elicitation is now enabled
case <-time.After(30 * time.Second):
client3.ForceStop()
t.Fatal("Timed out waiting for capabilities.changed event (elicitation enabled)")
}
unsubEnabled()
// Now listen for elicitation to become disabled
capDisabledCh := make(chan struct{}, 1)
unsubDisabled := session1.On(func(event copilot.SessionEvent) {
if d, ok := event.Data.(*copilot.CapabilitiesChangedData); ok && d.UI != nil && d.UI.Elicitation != nil && !*d.UI.Elicitation {
select {
case capDisabledCh <- struct{}{}:
default:
}
}
})
// Disconnect client3 — should trigger capabilities.changed with elicitation=false
client3.ForceStop()
select {
case <-capDisabledCh:
// Good — got the disabled event
case <-time.After(30 * time.Second):
t.Fatal("Timed out waiting for capabilities.changed event (elicitation disabled)")
}
unsubDisabled()
})
}