CI / test (push) Failing after 6m12s
/v1/openapi.json is the API clients use — OpenAI's endpoints, Anthropic's, and what llmgw adds — in OpenAPI 3.1, generated from internal/clientapi's route table by the generator the admin API's document comes from, now told each document's title, server, token and error. A test reads the router's mux.HandleFunc calls and refuses a route described and not mounted, or mounted and not described. Asked for before there is a key, so it needs none. /docs/api shows it in Swagger UI 5.33.1 (Apache 2.0, served from the gateway as the page's policy requires): Authorize takes a key, Try it out sends to this gateway. Staff are offered the admin API's document too, from /docs/api/admin.json, which nobody else is given. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
84 lines
2.8 KiB
Go
84 lines
2.8 KiB
Go
package web
|
|
|
|
import (
|
|
"context"
|
|
"net/http/httptest"
|
|
"strings"
|
|
"testing"
|
|
|
|
"gitea.mynodes.xyz/ilker/llmgw/internal/store"
|
|
)
|
|
|
|
func TestThePicturesPageDrawsInEveryLanguage(t *testing.T) {
|
|
for _, lang := range []string{"en", "tr"} {
|
|
req := httptest.NewRequest("GET", "/images", nil)
|
|
req.Header.Set("Accept-Language", lang)
|
|
rec := httptest.NewRecorder()
|
|
Images(store.User{Email: "a@b.c"}, []ChatModel{{Name: "flux-schnell", Hardware: []string{"6000-24g"}}},
|
|
[]ChatContext{{Value: "personal", Label: "Personal"}}, "personal", "v0")(rec, req)
|
|
if rec.Code != 200 {
|
|
t.Fatalf("%s: %d %s", lang, rec.Code, rec.Body.String())
|
|
}
|
|
page := rec.Body.String()
|
|
for _, want := range []string{`<option value="flux-schnell">`, `id="prompt"`, `/images/generate`} {
|
|
if !strings.Contains(page, want) {
|
|
t.Errorf("%s: %s missing", lang, want)
|
|
}
|
|
}
|
|
if strings.Contains(page, "images.") {
|
|
t.Errorf("%s: an untranslated key is on the page", lang)
|
|
}
|
|
}
|
|
rec := httptest.NewRecorder()
|
|
Images(store.User{}, nil, nil, "", "v0")(rec, httptest.NewRequest("GET", "/images", nil))
|
|
if !strings.Contains(rec.Body.String(), `class="empty"`) {
|
|
t.Error("no models, and the page does not say so")
|
|
}
|
|
}
|
|
|
|
func TestThe3DPageDrawsInEveryLanguageWithItsViewer(t *testing.T) {
|
|
for _, lang := range []string{"en", "tr"} {
|
|
req := httptest.NewRequest("GET", "/3d", nil)
|
|
req.Header.Set("Accept-Language", lang)
|
|
rec := httptest.NewRecorder()
|
|
Meshes(store.User{Email: "a@b.c"}, []ChatModel{{Name: "triposr"}},
|
|
[]ChatContext{{Value: "personal", Label: "Personal"}}, "personal", "v0")(rec, req)
|
|
page := rec.Body.String()
|
|
if rec.Code != 200 {
|
|
t.Fatalf("%s: %d %s", lang, rec.Code, page)
|
|
}
|
|
for _, want := range []string{`<option value="triposr">`, `id="picture"`, `/3d/generate`, `model-viewer.min.js?v=`} {
|
|
if !strings.Contains(page, want) {
|
|
t.Errorf("%s: %s missing", lang, want)
|
|
}
|
|
}
|
|
if strings.Contains(page, "meshes.") {
|
|
t.Errorf("%s: an untranslated key is on the page", lang)
|
|
}
|
|
if csp := rec.Header().Get("Content-Security-Policy"); !strings.Contains(csp, "script-src 'self'") || !strings.Contains(csp, "blob:") {
|
|
t.Errorf("policy %q", csp)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestTheAPIReferenceOffersTheAdminAPIToStaff(t *testing.T) {
|
|
page := func(n *Nav) string {
|
|
req := httptest.NewRequest("GET", "/docs/api", nil)
|
|
if n != nil {
|
|
req = req.WithContext(context.WithValue(req.Context(), navKey{}, *n))
|
|
}
|
|
rec := httptest.NewRecorder()
|
|
APIDocs("v0", true)(rec, req)
|
|
if rec.Code != 200 {
|
|
t.Fatalf("%d", rec.Code)
|
|
}
|
|
return rec.Body.String()
|
|
}
|
|
if p := page(&Nav{}); strings.Contains(p, "admin.json") || !strings.Contains(p, "/v1/openapi.json") {
|
|
t.Error("a person not staff is offered the admin API, or not the client API")
|
|
}
|
|
if p := page(&Nav{Admin: true}); !strings.Contains(p, "/docs/api/admin.json") {
|
|
t.Error("staff are not offered the admin API")
|
|
}
|
|
}
|