From 7eb2f5f313431b0fd885c6311850f95230e850af Mon Sep 17 00:00:00 2001 From: Mikhail Date: Fri, 21 Aug 2026 08:56:20 +0300 Subject: [PATCH] feat: make chat the public starting surface --- cmd/creator-web/chat_test.go | 23 +++++++++ cmd/creator-web/server.go | 18 ++++++- cmd/creator-web/server_test.go | 2 +- cmd/creator-web/static/chat.html | 4 +- dev/ACTIVE_TASK.json | 6 +-- ...V-000075-creator-chat-primary-surface.json | 47 +++++++++++++++++++ 6 files changed, 93 insertions(+), 7 deletions(-) create mode 100644 dev/tasks/DEV-000075-creator-chat-primary-surface.json diff --git a/cmd/creator-web/chat_test.go b/cmd/creator-web/chat_test.go index b01b301..da67997 100644 --- a/cmd/creator-web/chat_test.go +++ b/cmd/creator-web/chat_test.go @@ -32,6 +32,29 @@ func TestChatPageServedWithoutInternalIDs(t *testing.T) { } } +func TestPublicSurfacesSeparateChatAndConsole(t *testing.T) { + handler, err := newHandler("http://core", "http://continuity", "http://commit", http.DefaultClient, "http://cognitive") + if err != nil { + t.Fatal(err) + } + for _, test := range []struct { + path string + must string + mustNot string + }{ + {path: "/", must: "Напишите Домовому обычное сообщение", mustNot: "context-preset"}, + {path: "/admin", must: "context-preset", mustNot: "Напишите Домовому обычное сообщение"}, + {path: "/chat", must: "Напишите Домовому обычное сообщение", mustNot: "context-preset"}, + } { + recorder := httptest.NewRecorder() + handler.ServeHTTP(recorder, httptest.NewRequest(http.MethodGet, test.path, nil)) + body := recorder.Body.String() + if recorder.Code != http.StatusOK || !strings.Contains(body, test.must) || strings.Contains(body, test.mustNot) { + t.Fatalf("%s response=%d contains expected=%t forbidden=%t", test.path, recorder.Code, strings.Contains(body, test.must), strings.Contains(body, test.mustNot)) + } + } +} + func TestChatMessageUsesCoreAndLocalOnlyCognitiveGateway(t *testing.T) { var cognitiveRequest cognitive.GatewayAdvisoryRequest core := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { diff --git a/cmd/creator-web/server.go b/cmd/creator-web/server.go index 0915183..1a6ca2c 100644 --- a/cmd/creator-web/server.go +++ b/cmd/creator-web/server.go @@ -112,7 +112,12 @@ func (g *gateway) ServeHTTP(w http.ResponseWriter, r *http.Request) { return } if r.URL.Path == "/" { - w.Header().Set("Cache-Control", "no-store") + serveEmbeddedHTML(w, "chat.html") + return + } + if r.URL.Path == "/admin" { + serveEmbeddedHTML(w, "index.html") + return } if r.URL.Path == "/chat" { r = r.Clone(r.Context()) @@ -122,6 +127,17 @@ func (g *gateway) ServeHTTP(w http.ResponseWriter, r *http.Request) { g.static.ServeHTTP(w, r) } +func serveEmbeddedHTML(w http.ResponseWriter, name string) { + body, err := staticFiles.ReadFile("static/" + name) + if err != nil { + http.Error(w, "page unavailable", http.StatusNotFound) + return + } + w.Header().Set("Cache-Control", "no-store") + w.Header().Set("Content-Type", "text/html; charset=utf-8") + _, _ = w.Write(body) +} + type browserAdvisoryRequest struct { Message string `json:"message"` SessionID string `json:"session_id"` diff --git a/cmd/creator-web/server_test.go b/cmd/creator-web/server_test.go index b8482cf..a5641d1 100644 --- a/cmd/creator-web/server_test.go +++ b/cmd/creator-web/server_test.go @@ -229,7 +229,7 @@ func TestConsoleAndSecurityHeaders(t *testing.T) { if err != nil { t.Fatal(err) } - request := httptest.NewRequest(http.MethodGet, "/", nil) + request := httptest.NewRequest(http.MethodGet, "/admin", nil) response := httptest.NewRecorder() handler.ServeHTTP(response, request) if response.Code != http.StatusOK || !strings.Contains(response.Body.String(), "Домовой") || diff --git a/cmd/creator-web/static/chat.html b/cmd/creator-web/static/chat.html index 605fe98..08211d3 100644 --- a/cmd/creator-web/static/chat.html +++ b/cmd/creator-web/static/chat.html @@ -25,12 +25,12 @@