(t *testing.T)
| 959 | } |
| 960 | |
| 961 | func 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 { |
nothing calls this directly
no test coverage detected
searching dependent graphs…