Files
Agent-System/internal/server/web_assets_test.go
T
weichenandCursor 7fdbee6c0c test(server): adapt fixtures to IAM dual-gate fail-closed
Boot memory IAM only via explicit test env opt-in; strict auth cases
disable AllowInMemory after startup.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-16 09:42:07 +00:00

42 lines
1.2 KiB
Go

package server
import (
"net/http"
"net/http/httptest"
"testing"
"chat-agent-system/internal/config"
)
func TestServer_WebAssetsHostingAndFallback(t *testing.T) {
cfg := &config.Config{
Env: "test",
AgentBackend: "stub",
DataDir: t.TempDir(),
}
srv := newServerWithMemoryIAM(t, cfg)
srv.cfg.AllowInMemory = false
handler := srv.Routes()
reqRoot := httptest.NewRequest(http.MethodGet, "/", nil)
wRoot := httptest.NewRecorder()
handler.ServeHTTP(wRoot, reqRoot)
if wRoot.Code != http.StatusOK && wRoot.Code != http.StatusNotFound {
t.Errorf("expected status 200 or 404 for root SPA, got %d", wRoot.Code)
}
reqClientRoute := httptest.NewRequest(http.MethodGet, "/sessions/sess-001", nil)
wClient := httptest.NewRecorder()
handler.ServeHTTP(wClient, reqClientRoute)
if wClient.Code != http.StatusOK && wClient.Code != http.StatusNotFound {
t.Errorf("expected status 200 or 404 for client route fallback, got %d", wClient.Code)
}
reqAPI := httptest.NewRequest(http.MethodGet, "/api/v1/chat/sessions", nil)
wAPI := httptest.NewRecorder()
handler.ServeHTTP(wAPI, reqAPI)
if wAPI.Code != http.StatusUnauthorized {
t.Errorf("expected status 401 for unauthenticated /api/v1/chat/sessions, got %d", wAPI.Code)
}
}