Files
coder/coderd/aibridged/testhooks.go
T
Paweł Banaszewski 7cfc38d0e7 feat: wire AI Gateway proxy routing and recorder dependencies (#29725)
Adds `forwardingHandler` for "bridged" routes in proxy mode. Wires
provider snapshots to a shared mux and recorder, tracing, circuit
breakers, and the server-owned inflight gate.

Generated by Coder Agents on behalf of @pawbana.
2026-10-05 17:33:07 +00:00

30 lines
831 B
Go

package aibridged
import (
"context"
"testing"
"golang.org/x/xerrors"
)
// SetPoolForTest closes the unused interception pool and installs a replacement.
// Call it after interception is selected, before requests, reloads, or shutdown.
// The server owns the replacement pool and shuts it down with the server.
func (s *Server) SetPoolForTest(ctx context.Context, t testing.TB, pool Pooler) error {
t.Helper()
s.backendMu.Lock()
defer s.backendMu.Unlock()
if pool == nil {
return xerrors.New("nil request pool")
}
current := s.backend.Load()
if current == nil || current.pool == nil {
return xerrors.New("interception mode not selected")
}
if err := current.pool.Shutdown(ctx); err != nil {
return xerrors.Errorf("shutdown unused request pool: %w", err)
}
s.backend.Store(&backend{pool: pool})
return nil
}