Skip to content

High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.

fix: the API-discovery endpoints /openapi.json and /help 404 in server… (PIN-291)

Luigi Agostie8df6a889ba2
diff --git a/internal/server/front_door_openapi.go b/internal/server/front_door_openapi.go
index 4d2a1188..5f6ae3bc 100644
--- a/internal/server/front_door_openapi.go
+++ b/internal/server/front_door_openapi.go
@@ -15,6 +15,13 @@ import (
// exists to avoid — and they are named as a scope instead.
const frontDoorOpenAPIScope = "Browser-automation API reachable through the pinchtab server front door; requests are forwarded to the active instance. The front door also serves orchestrator management routes under /instances/ and /profiles/, which are not enumerated in this document."
+// frontDoorOpenAPIRoutes is the single source of truth for API-discovery routes
+// registered specially on the front door rather than through the route catalogue.
+var frontDoorOpenAPIRoutes = []string{
+ "GET /openapi.json",
+ "GET /help",
+}
+
// registerFrontDoorOpenAPI answers GET /openapi.json and its /help alias on the
// front door, which otherwise fall through to the mux's plain-text 404. It reads
// the live config per request so capability states track a dashboard save, and
@@ -24,6 +31,7 @@ func registerFrontDoorOpenAPI(mux *http.ServeMux, live *config.Live) {
serve := func(w http.ResponseWriter, _ *http.Request) {
(&handlers.Handlers{Config: live.Get()}).ServeOpenAPI(w, frontDoorOpenAPIScope)
}
- mux.HandleFunc("GET /openapi.json", serve)
- mux.HandleFunc("GET /help", serve)
+ for _, route := range frontDoorOpenAPIRoutes {
+ mux.HandleFunc(route, serve)
+ }
}
diff --git a/internal/server/front_door_openapi_test.go b/internal/server/front_door_openapi_test.go
index 21074dd7..49c9a0de 100644
--- a/internal/server/front_door_openapi_test.go
+++ b/internal/server/front_door_openapi_test.go
@@ -18,7 +18,14 @@ func TestFrontDoorServesOpenAPIAndHelp(t *testing.T) {
registerFrontDoorOpenAPI(mux, config.NewLive(&config.RuntimeConfig{}))
handler := notFoundEnvelope(mux)
- for _, path := range []string{"/openapi.json", "/help"} {
+ if len(frontDoorOpenAPIRoutes) != 2 {
+ t.Fatalf("front-door API-discovery route count = %d, want canonical endpoint and alias", len(frontDoorOpenAPIRoutes))
+ }
+ for _, pattern := range frontDoorOpenAPIRoutes {
+ _, path, ok := strings.Cut(pattern, " ")
+ if !ok {
+ t.Fatalf("invalid front-door API-discovery route pattern %q", pattern)
+ }
w := httptest.NewRecorder()
handler.ServeHTTP(w, httptest.NewRequest(http.MethodGet, path, nil))
diff --git a/internal/server/notfound_test.go b/internal/server/notfound_test.go
index 33245bd1..ec603d54 100644
--- a/internal/server/notfound_test.go
+++ b/internal/server/notfound_test.go
@@ -6,6 +6,8 @@ import (
"net/http/httptest"
"strings"
"testing"
+
+ "github.com/pinchtab/pinchtab/internal/srccensus"
)
func decodeEnvelope(t *testing.T, w *httptest.ResponseRecorder) (code, message string) {
@@ -67,6 +69,34 @@ func TestCodedRefusalsWinOverTheGenericFallback(t *testing.T) {
}
}
+// notFoundEnvelope is unit-tested against a bare mux, but that cannot show either
+// MODE wraps its mux in it — and a mode that stops wrapping is silently back to the
+// plain-text "404 page not found" this card exists to remove. Neither entry point is
+// drivable from a unit test: RunDashboard and RunBridgeServer bind a listener, launch
+// a browser and block on signals. So the wiring is pinned at the source, inside the
+// enclosing function, following the same guard the session family already carries.
+func TestBothModesWrapTheMuxInTheNotFoundEnvelope(t *testing.T) {
+ pkg := srccensus.Load(t, ".", 4)
+
+ for _, mode := range []string{"RunDashboard", "RunBridgeServer"} {
+ t.Run(mode, func(t *testing.T) {
+ fn, ok := pkg.Func(mode)
+ if !ok {
+ t.Fatalf("%s not found in %s; if it was renamed, re-point this guard at the new entry point rather than deleting it", mode, pkg.Dir())
+ }
+ inside := 0
+ for _, site := range pkg.Calls(t, "notFoundEnvelope") {
+ if pkg.Contains(fn, site) {
+ inside++
+ }
+ }
+ if inside == 0 {
+ t.Errorf("%s never wraps its mux in notFoundEnvelope, so an unrouted path on that front answers net/http's bare plain-text 404 instead of the JSON envelope", mode)
+ }
+ })
+ }
+}
+
// A matched route serves normally; the wrapper only fires when nothing is routed.
func TestMatchedRouteIsUntouched(t *testing.T) {
mux := http.NewServeMux()