MCPcopy Create free account
hub / github.com/github/copilot-sdk / TestSession_ElicitationHandler

Function TestSession_ElicitationHandler

go/session_test.go:961–1028  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

959}
960
961func TestSession_ElicitationHandler(t *testing.T) {
962 t.Run("registerElicitationHandler stores handler", func(t *testing.T) {
963 session, cleanup := newTestSession()
964 defer cleanup()
965
966 if session.getElicitationHandler() != nil {
967 t.Error("Expected nil handler before registration")
968 }
969
970 session.registerElicitationHandler(func(ctx ElicitationContext) (ElicitationResult, error) {
971 return ElicitationResult{Action: ElicitationActionAccept}, nil
972 })
973
974 if session.getElicitationHandler() == nil {
975 t.Error("Expected non-nil handler after registration")
976 }
977 })
978
979 t.Run("handler error is returned correctly", func(t *testing.T) {
980 session, cleanup := newTestSession()
981 defer cleanup()
982
983 session.registerElicitationHandler(func(ctx ElicitationContext) (ElicitationResult, error) {
984 return ElicitationResult{}, fmt.Errorf("handler exploded")
985 })
986
987 handler := session.getElicitationHandler()
988 if handler == nil {
989 t.Fatal("Expected non-nil handler")
990 }
991
992 _, err := handler(
993 ElicitationContext{SessionID: "test-session", Message: "Pick a color"},
994 )
995 if err == nil {
996 t.Fatal("Expected error from handler")
997 }
998 if !strings.Contains(err.Error(), "handler exploded") {
999 t.Errorf("Expected error to contain 'handler exploded', got %q", err.Error())
1000 }
1001 })
1002
1003 t.Run("handler success returns result", func(t *testing.T) {
1004 session, cleanup := newTestSession()
1005 defer cleanup()
1006
1007 session.registerElicitationHandler(func(ctx ElicitationContext) (ElicitationResult, error) {
1008 return ElicitationResult{
1009 Action: ElicitationActionAccept,
1010 Content: map[string]any{"color": "blue"},
1011 }, nil
1012 })
1013
1014 handler := session.getElicitationHandler()
1015 result, err := handler(
1016 ElicitationContext{SessionID: "test-session", Message: "Pick a color"},
1017 )
1018 if err != nil {

Callers

nothing calls this directly

Calls 5

newTestSessionFunction · 0.85
handlerFunction · 0.85
getElicitationHandlerMethod · 0.80
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…