Extract Grammaratur, Dregarnuhr, Geduldh, Mestionora, Ordoschnellic, Schutzaria, Kunstzeal and Seheweit behind compatible application contracts. Include accumulated editor resilience, navigation and theme UX, remote CLI, storage/schema and DR groundwork, tests and design/operations documentation. Verified: uncached full Go suite; go vet ./...; race tests for all eight components; 11 targeted Chromium tests; Node suites; 19 Python CLI tests; reproducible editor build. No push, release tag or deployment in this checkpoint.
72 lines
2.3 KiB
Go
72 lines
2.3 KiB
Go
package server
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"os"
|
|
"os/exec"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestThemePreferenceDoesNotChangeDomain(t *testing.T) {
|
|
s, token, domain, _ := editorFixture(t)
|
|
for _, tc := range []struct{ value, css string }{
|
|
{"light", "/static/css/theme/light.css"},
|
|
{"index-white", "/static/css/theme/index-white.css"},
|
|
{"https://evil.test/theme.css", "/static/css/theme/dark.css"},
|
|
{"unknown", "/static/css/theme/dark.css"},
|
|
} {
|
|
r := httptest.NewRequest("GET", "http://localhost/e/-/editor-fixture", nil)
|
|
r.Header.Set("Authorization", "Bearer "+token)
|
|
r.AddCookie(&http.Cookie{Name: "pageswiki_theme", Value: tc.value})
|
|
w := httptest.NewRecorder()
|
|
s.withAuthorization(s.mux).ServeHTTP(w, r)
|
|
if w.Code != 200 || !strings.Contains(w.Body.String(), `href="`+tc.css+`"`) {
|
|
t.Fatalf("%s: %d %s", tc.value, w.Code, w.Body.String())
|
|
}
|
|
if s.getTheme(domain) != "dark" {
|
|
t.Fatal("browser preference overwrote Domain theme")
|
|
}
|
|
if !strings.Contains(strings.Join(w.Header().Values("Vary"), ","), "Cookie") {
|
|
t.Fatal("missing cache variation")
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestEditorThemeChromium(t *testing.T) {
|
|
if os.Getenv("PAGESWIKI_BROWSER_TEST") != "1" {
|
|
t.Skip("opt-in Chromium")
|
|
}
|
|
s, token, domain, _ := editorFixture(t)
|
|
if err := s.store.SetConfigInDomain(domain, "editor_keymap", "vim"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
script, err := os.ReadFile("internal/server/testdata/editor-theme.js")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
r.Host = "localhost"
|
|
r.Header.Set("Authorization", "Bearer "+token)
|
|
if r.URL.Path == "/fixture" {
|
|
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
|
_, _ = w.Write([]byte("<!doctype html><body style='margin:0'><script>" + string(script) + "</script></body>"))
|
|
return
|
|
}
|
|
s.withAuthorization(s.mux).ServeHTTP(w, r)
|
|
}))
|
|
defer server.Close()
|
|
ctx, cancel := context.WithTimeout(context.Background(), 55*time.Second)
|
|
defer cancel()
|
|
args := []string{"internal/server/testdata/vim-browser-smoke.mjs", server.URL + "/fixture", t.TempDir()}
|
|
if shot := os.Getenv("EDITOR_THEME_SCREENSHOT"); shot != "" {
|
|
args = append(args, shot)
|
|
}
|
|
if out, err := exec.CommandContext(ctx, "node", args...).CombinedOutput(); err != nil {
|
|
t.Fatalf("theme: %v\n%s", err, out)
|
|
}
|
|
}
|