High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.
feat: add NewTestServer(t, cfg) with t.Cleanup auto-shutdown
Boscha59c4369f275
diff --git a/TESTING.md b/TESTING.mdindex cf9b844c..a343ff82 100644--- a/TESTING.md+++ b/TESTING.md@@ -54,6 +54,8 @@ The `testutil` package provides reusable helpers:### Writing New Tests+New tests should use `testutil.Client` and `testutil.NewTestServer` (or `StartServer`) instead of the legacy `httpGet`/`httpPost` wrappers. The legacy helpers are kept only for backward compatibility.+```go//go:build integration@@ -72,6 +74,18 @@ func TestMyFeature(t *testing.T) {}```+For tests that need their own isolated server (outside the shared `TestMain` setup):++```go+func TestIsolatedFeature(t *testing.T) {+ srv := testutil.NewTestServer(t, testutil.DefaultConfig())+ c := testutil.NewClient(srv.URL)++ code, _ := c.Get(t, "/health")+ // ... srv.Stop() is called automatically via t.Cleanup+}+```+### Process CleanupThe test server runs in its own process group (`Setpgid`). On shutdown, `SIGTERM` is sent to the entire group, killing Chrome and all child processes. If graceful shutdown fails after 10 seconds, `SIGKILL` is sent to the group.diff --git a/tests/testutil/server.go b/tests/testutil/server.goindex a544f9ee..7906e898 100644--- a/tests/testutil/server.go+++ b/tests/testutil/server.go@@ -12,6 +12,7 @@ import ("path/filepath""strings""syscall"+ "testing""time")@@ -53,6 +54,19 @@ type Server struct {cmd *exec.Cmd}+// NewTestServer builds, launches, and registers cleanup with t.Cleanup.+// This is the preferred way to create a test server — cleanup runs automatically+// even if the test panics. For use in TestMain (no *testing.T), use StartServer instead.+func NewTestServer(t *testing.T, cfg ServerConfig) *Server {+ t.Helper()+ srv, err := StartServer(cfg)+ if err != nil {+ t.Fatalf("start test server: %v", err)+ }+ t.Cleanup(srv.Stop)+ return srv+}+// StartServer builds, launches, and waits for a pinchtab server.// The caller must call server.Stop() to shut down and clean up.func StartServer(cfg ServerConfig) (*Server, error) {