High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.
fix(handlers): route /text and /snapshot selector failures through the one exit so they carry element_not_found, and pin the exit in the census (PIN-275)
Luigi Agosti031e2a590cc7
diff --git a/internal/handlers/semantic_status_test.go b/internal/handlers/semantic_status_test.goindex 7a39e3a3..6847f20c 100644--- a/internal/handlers/semantic_status_test.go+++ b/internal/handlers/semantic_status_test.go@@ -229,7 +229,19 @@ func TestOneMapperServesEverySelectorResolvingPath(t *testing.T) {callers[site.Func] = true}}- for _, required := range []string{"inspectElement", "resolveActionRequestSelectorInScope", "handleInspect", "resolveScreenshotClip"} {+ exits := map[string]bool{}+ for _, site := range pkg.Calls(t, "respondSelectorFailure") {+ exits[site.Func] = true+ }+ for _, required := range []string{"HandleText", "HandleSnapshot", "handleInspect"} {+ if !exits[required] {+ t.Errorf("%s does not answer a selector failure through respondSelectorFailure; asking the owner for a status and writing it with httpx.Error answers the right status with the generic code", required)+ }+ }+ for _, required := range []string{+ "inspectElement", "resolveActionRequestSelectorInScope", "handleInspect",+ "resolveScreenshotClip", "HandleText", "HandleSnapshot",+ } {if !callers[required] {t.Errorf("%s no longer maps its selector failures through the one owner; a second copy of the status switch is how the read paths came to give five different answers", required)}diff --git a/internal/handlers/snapshot.go b/internal/handlers/snapshot.goindex eb305aac..ee8f1f1f 100644--- a/internal/handlers/snapshot.go+++ b/internal/handlers/snapshot.go@@ -140,7 +140,7 @@ func (h *Handlers) HandleSnapshot(w http.ResponseWriter, r *http.Request) {if !ghostRoute {modalNodeID, modalOpen, modalErr = bridge.TopmostModalNodeID(tCtx, frameScope)if modalErr != nil {- httpx.Error(w, selectorFailureStatus(modalErr), modalErr)+ respondSelectorFailure(w, modalErr)return}}@@ -151,7 +151,7 @@ func (h *Handlers) HandleSnapshot(w http.ResponseWriter, r *http.Request) {if !ghostRoute {afterNodeID, afterOpen, recheckErr := bridge.TopmostModalNodeID(tCtx, frameScope)if recheckErr != nil {- httpx.Error(w, selectorFailureStatus(recheckErr), fmt.Errorf("recheck topmost dialog: %w", recheckErr))+ respondSelectorFailure(w, fmt.Errorf("recheck topmost dialog: %w", recheckErr))return}if modalNodeID != afterNodeID || modalOpen != afterOpen {@@ -159,7 +159,7 @@ func (h *Handlers) HandleSnapshot(w http.ResponseWriter, r *http.Request) {}}if scopeErr != nil {- httpx.Error(w, selectorFailureStatus(scopeErr), scopeErr)+ respondSelectorFailure(w, scopeErr)return}rawNodes, scopeNodeID, stable = candidateNodes, candidateScope, truediff --git a/internal/handlers/text.go b/internal/handlers/text.goindex a9eea684..ce665df9 100644--- a/internal/handlers/text.go+++ b/internal/handlers/text.go@@ -68,7 +68,7 @@ func (h *Handlers) HandleText(w http.ResponseWriter, r *http.Request) {if !ghostRoute {modalNodeID, modalOpen, err = bridge.TopmostModalNodeID(tCtx, targetFrameID)if err != nil {- httpx.Error(w, selectorFailureStatus(err), err)+ respondSelectorFailure(w, err)return}}@@ -89,7 +89,7 @@ func (h *Handlers) HandleText(w http.ResponseWriter, r *http.Request) {if !ghostRoute {afterNodeID, afterOpen, scopeErr := bridge.TopmostModalNodeID(tCtx, targetFrameID)if scopeErr != nil {- httpx.Error(w, selectorFailureStatus(scopeErr), fmt.Errorf("recheck topmost dialog: %w", scopeErr))+ respondSelectorFailure(w, fmt.Errorf("recheck topmost dialog: %w", scopeErr))return}stable = modalNodeID == afterNodeID && modalOpen == afterOpen@@ -98,12 +98,11 @@ func (h *Handlers) HandleText(w http.ResponseWriter, r *http.Request) {continue}if err != nil {- status := http.StatusInternalServerErrorif selectorParam != "" || refParam != "" {- status = selectorFailureStatus(err)- err = fmt.Errorf("element text extract: %w", err)+ respondSelectorFailure(w, fmt.Errorf("element text extract: %w", err))+ return}- httpx.Error(w, status, err)+ httpx.Error(w, http.StatusInternalServerError, err)return}scopeInfo := h.frameDisclosureFor(tCtx, resolvedTabID, targetFrameID)