mirror of
https://github.com/coder/coder.git
synced 2026-09-01 14:53:15 +08:00
351bb14032
## Stack context This is the base of a 3-PR stack promoting the chat API from `/api/experimental` to `/api/v2`: server compatibility mounts (this PR), codersdk promotion (#28497), and frontend path updates (#28498). ## Summary Double-mount the stable chat and MCP handlers under `/api/v2` while retaining the existing experimental routes for the one-release compatibility window decided in CODAGT-921. CODAGT-922 tracks removing the compatibility mounts. The shared route builders preserve existing authentication and middleware behavior. Experiment-gated, debug, tombstone, and legacy default-organization model routes remain experimental-only. Signed file URLs, external OAuth callback URLs, and mixed-version replica relays also remain on the experimental prefix during the transition. Update Swagger and the generated API reference for the promoted routes, including the workspace lookup and a runnable raw-body chat file upload example. Retain internal endpoints outside the published reference, share chat-file rate limits across both prefixes, enable CORS for the v2 MCP routes, and cover dual mounts plus exclusions with compatibility tests. Remote dogfood UAT passed for the promoted chat, model, MCP, and file flows. > [!NOTE] > Xum acted on Mike's behalf in this pull request. <!-- xum-attribution: model=claude-fable-5 thinking=high -->
37 lines
941 B
Go
37 lines
941 B
Go
package coderd
|
|
|
|
import (
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestChatFilesRateLimitMWCompatibilityAliases(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
api := &API{Options: &Options{FilesRateLimit: 1}}
|
|
handler := api.chatFilesRateLimitMW()(http.HandlerFunc(func(rw http.ResponseWriter, _ *http.Request) {
|
|
rw.WriteHeader(http.StatusOK)
|
|
}))
|
|
|
|
for i, requestPath := range []string{
|
|
"/api/v2/chats/files/00000000-0000-0000-0000-000000000000",
|
|
"/api/experimental/chats/files/00000000-0000-0000-0000-000000000000",
|
|
} {
|
|
req := httptest.NewRequest(http.MethodGet, requestPath, nil)
|
|
req.RemoteAddr = "192.0.2.1:1234"
|
|
rec := httptest.NewRecorder()
|
|
handler.ServeHTTP(rec, req)
|
|
resp := rec.Result()
|
|
_ = resp.Body.Close()
|
|
|
|
expectedStatus := http.StatusOK
|
|
if i > 0 {
|
|
expectedStatus = http.StatusTooManyRequests
|
|
}
|
|
require.Equal(t, expectedStatus, resp.StatusCode, requestPath)
|
|
}
|
|
}
|