Files
coder/coderd/coderd_internal_test.go
T
Cian Johnston 4936ff9808 refactor: deprecate AIGatewayRoutingEnabled, remove direct chat routing (#26862)
This PR removes the now-dead direct-routing code:

- Deletes the direct routing implementation.
- Collapses the resolvedModelRoute discriminated union into aiGatewayModelRoute.
- Removes the dead providerKeys cascade.
- Deletes the preferredShortTextCandidates quickgen function.
- Simplifies the advisor override error handling.
- Deprecates the AIGatewayRoutingEnabled deployment option. It is now a no-op so as to not break existing deployments on upgrade.

Once direct routing was gone, the AI Gateway became mandatory for chat, which surfaced gaps in how the product behaves with the gateway disabled:

- Exposes ai-gateway-enabled to the frontend via embedded page metadata.
- Disables the chat composer via the existing AgentSetupNotice when the gateway is disabled, for both new and existing chats.
- Fixes nil/typed-nil chatDaemon panics on startup and shutdown when gateway is disabled.
- Fixes chat WebSocket from retrying the still-gated stream endpoint forever when the gateway is disabled.
2026-07-01 20:15:03 +01:00

81 lines
2.2 KiB
Go

package coderd
import (
"context"
"net/http"
"net/http/httptest"
"testing"
"github.com/go-chi/chi/v5"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestStripSlashesMW(t *testing.T) {
t.Parallel()
tests := []struct {
name string
inputPath string
wantPath string
}{
{"No changes", "/api/v1/buildinfo", "/api/v1/buildinfo"},
{"Double slashes", "/api//v2//buildinfo", "/api/v2/buildinfo"},
{"Triple slashes", "/api///v2///buildinfo", "/api/v2/buildinfo"},
{"Leading slashes", "///api/v2/buildinfo", "/api/v2/buildinfo"},
{"Root path", "/", "/"},
{"Double slashes root", "//", "/"},
{"Only slashes", "/////", "/"},
}
handler := http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
w.WriteHeader(http.StatusOK)
})
for _, tt := range tests {
t.Run("chi/"+tt.name, func(t *testing.T) {
t.Parallel()
req := httptest.NewRequest("GET", tt.inputPath, nil)
rec := httptest.NewRecorder()
// given
rctx := chi.NewRouteContext()
rctx.RoutePath = tt.inputPath
req = req.WithContext(context.WithValue(req.Context(), chi.RouteCtxKey, rctx))
// when
singleSlashMW(handler).ServeHTTP(rec, req)
updatedCtx := chi.RouteContext(req.Context())
// then
assert.Equal(t, tt.inputPath, req.URL.Path)
assert.Equal(t, tt.wantPath, updatedCtx.RoutePath)
})
t.Run("stdlib/"+tt.name, func(t *testing.T) {
t.Parallel()
req := httptest.NewRequest("GET", tt.inputPath, nil)
rec := httptest.NewRecorder()
// when
singleSlashMW(handler).ServeHTTP(rec, req)
// then
assert.Equal(t, tt.wantPath, req.URL.Path)
assert.Nil(t, chi.RouteContext(req.Context()))
})
}
}
// TestChatDaemonPublishDiffStatusChangeFunc verifies that
// chatDaemonPublishDiffStatusChangeFunc returns a true nil, not a method
// value bound to a nil receiver, when chatDaemon is nil. See that function
// for why the distinction matters. The non-nil path is covered by
// coderd/exp_chats_test.go.
func TestChatDaemonPublishDiffStatusChangeFunc(t *testing.T) {
t.Parallel()
fn := chatDaemonPublishDiffStatusChangeFunc(nil)
require.Nil(t, fn, "func value must be a true nil, not a bound method on a nil receiver")
}