package server import ( "context" "net/http" "net/http/httptest" "os" "os/exec" "strings" "testing" "time" ) func TestUUIDCompatibilityJS(t *testing.T) { node, err := exec.LookPath("node") if err != nil { t.Skip("node is required for UUID compatibility tests") } t.Chdir("../..") if out, err := exec.Command(node, "internal/server/testdata/uuid.test.cjs").CombinedOutput(); err != nil { t.Fatalf("UUID compatibility: %v\n%s", err, out) } } func TestTaskProjectUUIDFallbackChromium(t *testing.T) { if os.Getenv("PAGESWIKI_BROWSER_TEST") != "1" { t.Skip("opt-in Chromium") } s, token, _, _ := taskFixture(t) script, err := os.ReadFile("internal/server/testdata/uuid-project-browser.js") if err != nil { t.Fatal(err) } server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { r.Header.Set("Authorization", "Bearer "+token) if r.Method == "GET" && strings.HasPrefix(r.URL.Path, "/v/plan/") { rec := httptest.NewRecorder() s.withAuthorization(s.mux).ServeHTTP(rec, r) for key, values := range rec.Header() { w.Header()[key] = values } body := strings.Replace(rec.Body.String(), "", ``, 1) if r.URL.Path == "/v/plan/projects" { body = strings.Replace(body, "", "", 1) } w.Header().Del("Content-Length") w.WriteHeader(rec.Code) _, _ = w.Write([]byte(body)) return } s.withAuthorization(s.mux).ServeHTTP(w, r) })) defer server.Close() ctx, cancel := context.WithTimeout(context.Background(), 45*time.Second) defer cancel() target := strings.Replace(server.URL, "127.0.0.1", "localhost", 1) + "/v/plan/projects" cmd := exec.CommandContext(ctx, "node", "internal/server/testdata/vim-browser-smoke.mjs", target, t.TempDir()) if out, err := cmd.CombinedOutput(); err != nil { t.Fatalf("project creation without randomUUID: %v\n%s", err, out) } }