Files
coder/coderd/httpmw/requestid_test.go
Kyle Carberry edee917d88 feat: add experimental agents support (#22290)
feat: add AI chat system with agent tools and chat UI

Introduce the chatd subsystem and Agents UI for AI-powered chat
within Coder workspaces.

- Add chatd package with chat loop, message compaction, prompt
  management, and LLM provider integration (OpenAI, Anthropic)
- Add agent tools: create workspace, list/read templates, read/write/
  edit files, execute commands
- Add chat API endpoints with streaming, message editing, and
  durable reconnection
- Add database schema and migrations for chats, chat messages, chat
  providers, and chat model configs
- Add RBAC policies and dbauthz enforcement for chat resources
- Add Agents UI pages with conversation timeline, queued messages
  list, diff viewer, and model configuration panel
- Add comprehensive test coverage including coderd integration tests,
  chatd unit tests, and Storybook stories
- Gate feature behind experiments flag

---------

Co-authored-by: Cian Johnston <cian@coder.com>
Co-authored-by: Danielle Maywood <danielle@themaywoods.com>
Co-authored-by: Jeremy Ruppel <jeremy@coder.com>
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-27 16:50:56 +00:00

49 lines
1.1 KiB
Go

package httpmw_test
import (
"context"
"net/http"
"net/http/httptest"
"testing"
"github.com/go-chi/chi/v5"
"github.com/google/uuid"
"github.com/stretchr/testify/require"
"github.com/coder/coder/v2/coderd/httpmw"
)
func TestRequestID(t *testing.T) {
t.Parallel()
rtr := chi.NewRouter()
rtr.Use(httpmw.AttachRequestID)
rtr.Get("/", func(w http.ResponseWriter, r *http.Request) {
rid := httpmw.RequestID(r)
w.WriteHeader(http.StatusOK)
w.Write([]byte(rid.String()))
})
r := httptest.NewRequest("GET", "/", nil)
rw := httptest.NewRecorder()
rtr.ServeHTTP(rw, r)
res := rw.Result()
defer res.Body.Close()
require.Equal(t, http.StatusOK, res.StatusCode)
require.NotEmpty(t, res.Header.Get("X-Coder-Request-ID"))
require.NotEmpty(t, rw.Body.Bytes())
}
func TestRequestIDHelpers(t *testing.T) {
t.Parallel()
requestID := uuid.New()
ctx := httpmw.WithRequestID(context.Background(), requestID)
req := httptest.NewRequest(http.MethodGet, "/", nil).WithContext(ctx)
gotRequestID, ok := httpmw.RequestIDOptional(req)
require.True(t, ok)
require.Equal(t, requestID, gotRequestID)
require.Equal(t, requestID, httpmw.RequestID(req))
}