TestSessionPrompterTransportError verifies that a prompt which fails to be delivered (the client errors instead of returning an action) is reported as ErrPromptUnavailable, not ErrPromptDeclined. The manager relies on this distinction to fall back to manual instructions instead of aborting.
(t *testing.T)
| 199 | // ErrPromptUnavailable, not ErrPromptDeclined. The manager relies on this |
| 200 | // distinction to fall back to manual instructions instead of aborting. |
| 201 | func TestSessionPrompterTransportError(t *testing.T) { |
| 202 | t.Parallel() |
| 203 | |
| 204 | caps := &mcp.ClientCapabilities{Elicitation: &mcp.ElicitationCapabilities{ |
| 205 | URL: &mcp.URLElicitationCapabilities{}, |
| 206 | Form: &mcp.FormElicitationCapabilities{}, |
| 207 | }} |
| 208 | |
| 209 | for _, mode := range []string{"url", "form"} { |
| 210 | t.Run(mode, func(t *testing.T) { |
| 211 | t.Parallel() |
| 212 | |
| 213 | handler := func(_ context.Context, _ *mcp.ElicitRequest) (*mcp.ElicitResult, error) { |
| 214 | return nil, errors.New("client cannot deliver elicitation") |
| 215 | } |
| 216 | |
| 217 | got := runProbe(t, caps, handler, func(ctx context.Context, p *sessionPrompter) string { |
| 218 | var err error |
| 219 | if mode == "url" { |
| 220 | err = p.PromptURL(ctx, oauth.Prompt{Message: "msg", URL: "https://example.com/auth"}) |
| 221 | } else { |
| 222 | err = p.PromptForm(ctx, oauth.Prompt{Message: "msg"}) |
| 223 | } |
| 224 | switch { |
| 225 | case err == nil: |
| 226 | return "ok" |
| 227 | case errors.Is(err, oauth.ErrPromptDeclined): |
| 228 | return "declined" |
| 229 | case errors.Is(err, oauth.ErrPromptUnavailable): |
| 230 | return "unavailable" |
| 231 | default: |
| 232 | return "error: " + err.Error() |
| 233 | } |
| 234 | }) |
| 235 | |
| 236 | assert.Equal(t, "unavailable", got, |
| 237 | "a delivery failure must be classified as undeliverable, not a decline") |
| 238 | }) |
| 239 | } |
| 240 | } |
| 241 | |
| 242 | // fakeAuthenticator is a deterministic stand-in for *oauth.Manager that lets the |
| 243 | // middleware be tested at each branch without standing up live GitHub flows. |
nothing calls this directly
no test coverage detected