MCPcopy Index your code
hub / github.com/coder/coder / TestInMemoryRoundTripper_HandlerPanic

Function TestInMemoryRoundTripper_HandlerPanic

coderd/aibridged/transport_test.go:284–306  ·  view source on GitHub ↗

A panicking handler must not crash the process; it should produce a 500 response with an error on the body read, mirroring net/http.Server behavior.

(t *testing.T)

Source from the content-addressed store, hash-verified

282// A panicking handler must not crash the process; it should produce a 500
283// response with an error on the body read, mirroring net/http.Server behavior.
284func TestInMemoryRoundTripper_HandlerPanic(t *testing.T) {
285 t.Parallel()
286
287 handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
288 panic("unexpected nil pointer")
289 })
290
291 rt, err := aibridged.NewTransportFactory(handler).TransportFor("openai", aibridge.SourceAgents)
292 require.NoError(t, err)
293
294 ctx := aibridge.WithDelegatedAPIKeyID(testutil.Context(t, testutil.WaitShort), "test-key-id")
295 req, err := http.NewRequestWithContext(ctx, http.MethodPost, "http://aibridge/panic", nil)
296 require.NoError(t, err)
297
298 resp, err := rt.RoundTrip(req)
299 require.NoError(t, err)
300 defer resp.Body.Close()
301
302 require.Equal(t, http.StatusInternalServerError, resp.StatusCode)
303 _, err = io.ReadAll(resp.Body)
304 require.Error(t, err)
305 require.Contains(t, err.Error(), "handler panicked")
306}
307
308// The in-memory transport must reject any RoundTrip whose context does not
309// carry a delegated API key ID. The handler relies on this invariant to know

Callers

nothing calls this directly

Calls 10

NewTransportFactoryFunction · 0.92
WithDelegatedAPIKeyIDFunction · 0.92
ContextFunction · 0.92
TransportForMethod · 0.65
CloseMethod · 0.65
RoundTripMethod · 0.45
EqualMethod · 0.45
ReadAllMethod · 0.45
ErrorMethod · 0.45
ContainsMethod · 0.45

Tested by

no test coverage detected