MCPcopy Index your code
hub / github.com/github/github-mcp-server / TestSessionPrompterPromptActions

Function TestSessionPrompterPromptActions

internal/ghmcp/oauth_test.go:143–195  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

141}
142
143func TestSessionPrompterPromptActions(t *testing.T) {
144 t.Parallel()
145
146 tests := []struct {
147 name string
148 action string
149 wantDecline bool
150 }{
151 {name: "accept", action: "accept", wantDecline: false},
152 {name: "decline", action: "decline", wantDecline: true},
153 {name: "cancel", action: "cancel", wantDecline: true},
154 }
155
156 caps := &mcp.ClientCapabilities{Elicitation: &mcp.ElicitationCapabilities{
157 URL: &mcp.URLElicitationCapabilities{},
158 Form: &mcp.FormElicitationCapabilities{},
159 }}
160
161 for _, tc := range tests {
162 // URL and form modes share the accept/decline mapping; cover both.
163 for _, mode := range []string{"url", "form"} {
164 t.Run(tc.name+"/"+mode, func(t *testing.T) {
165 t.Parallel()
166
167 handler := func(_ context.Context, _ *mcp.ElicitRequest) (*mcp.ElicitResult, error) {
168 return &mcp.ElicitResult{Action: tc.action}, nil
169 }
170
171 got := runProbe(t, caps, handler, func(ctx context.Context, p *sessionPrompter) string {
172 var err error
173 if mode == "url" {
174 err = p.PromptURL(ctx, oauth.Prompt{Message: "msg", URL: "https://example.com/auth"})
175 } else {
176 err = p.PromptForm(ctx, oauth.Prompt{Message: "msg"})
177 }
178 if err == nil {
179 return "ok"
180 }
181 if err == oauth.ErrPromptDeclined {
182 return "declined"
183 }
184 return "error: " + err.Error()
185 })
186
187 if tc.wantDecline {
188 assert.Equal(t, "declined", got)
189 } else {
190 assert.Equal(t, "ok", got)
191 }
192 })
193 }
194 }
195}
196
197// TestSessionPrompterTransportError verifies that a prompt which fails to be
198// delivered (the client errors instead of returning an action) is reported as

Callers

nothing calls this directly

Calls 4

runProbeFunction · 0.85
PromptURLMethod · 0.65
PromptFormMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected