Files
llmgw/internal/web/i18n_chat_test.go
T
Ilker ManapandClaude Opus 5.5 5ee8e74de1 The portal's chat answers from the documents a person picks
A Documents picker on /chat offers the collections the person may read in
the chosen project, the default when there is one, or none; the sources an
answer was given are listed under it. The page's choice becomes the
X-Llmgw-Knowledge header; one the page sent itself is dropped. In English
and Turkish.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-08 15:59:23 +02:00

98 lines
3.0 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package web
import (
"bytes"
"net/http"
"net/http/httptest"
"strings"
"testing"
"gitea.mynodes.xyz/ilker/llmgw/internal/store"
)
func TestTheChatPageSpeaksTurkishWhenAsked(t *testing.T) {
h := Chat(store.User{Email: "a@example.com"},
[]ChatModel{{Name: "qwen"}, {Name: "big-model", Simulated: true}}, nil, "", "v1",
ChatKnowledge{Collections: []ChatCollection{{ID: "kb_x", Label: "politikalar"}}, Default: "politikalar"})
r := httptest.NewRequest(http.MethodGet, "http://x/chat", nil)
r.Header.Set("Accept-Language", "tr-TR,tr;q=0.9")
w := httptest.NewRecorder()
h(w, r)
if w.Code != http.StatusOK {
t.Fatalf("status %d", w.Code)
}
page := w.Body.String()
for _, want := range []string{
`<html lang="tr">`,
"<h1>Sohbet</h1>",
">big-model (benzetim)<",
"Yeni sohbet",
`placeholder="Bir şey sorun…"`,
`<output id="temp-out">0,7</output>`,
// The script's own words come from the catalogue too.
`"Uzunluk sınırında kesildi — devam etmesini isteyin."`,
`decimal: ","`,
// The documents picker, with the default named.
"Belgeler",
`<option value="">varsayılan (politikalar)</option>`,
`<option value="none">yok</option>`,
`<option value="kb_x">politikalar</option>`,
`"Kaynaklar:"`,
} {
if !strings.Contains(page, want) {
t.Errorf("the Turkish chat page does not have %q", want)
}
}
for _, not := range []string{"New conversation", "Cut off at the length limit", "Ask something", "Documents", "Sources:"} {
if strings.Contains(page, not) {
t.Errorf("the Turkish chat page still says %q", not)
}
}
}
func TestTheChatDownloadRefusesInTheReadersLanguage(t *testing.T) {
r := httptest.NewRequest(http.MethodPost, "/chat/download", strings.NewReader(`{"content":"no code here"}`))
r.AddCookie(&http.Cookie{Name: langCookie, Value: "tr"})
w := httptest.NewRecorder()
CodeArchive(1<<20)(w, r)
if w.Code != http.StatusBadRequest || !strings.Contains(w.Body.String(), "indirilecek kod yok") {
t.Errorf("%d %q", w.Code, w.Body.String())
}
}
func TestTheAboutPageSpeaksTurkishWhenAsked(t *testing.T) {
code, body := get(t, About("v1.2.3"), "http://llmgw.example/about",
map[string]string{"Accept-Language": "tr"})
if code != http.StatusOK {
t.Fatalf("status %d", code)
}
for _, want := range []string{
`<html lang="tr">`,
`<a href="/">Bu ağ geçidi</a>`,
"<em>Kendi GPU'larınızın</em> önünde tek bir uç nokta.",
"Sıfırdan ilk isteğe",
"Sağlama toplamları",
// The configurations are shown as they are.
"reverse_proxy",
"proxy_read_timeout",
} {
if !strings.Contains(body, want) {
t.Errorf("the Turkish about page does not have %q", want)
}
}
if strings.Contains(body, "What it does") {
t.Error("the Turkish about page still has English headings")
}
// The published website is English whatever anyone's browser says.
d := NewAboutData("v1.2.3")
d.Site = true
var b bytes.Buffer
if err := RenderAbout(&b, d); err != nil {
t.Fatal(err)
}
if !strings.Contains(b.String(), "What it does") || strings.Contains(b.String(), "Ne yapar") {
t.Error("the website is not in English")
}
}