High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.
fix: clicking a link returns 409 with no remedy, though the CLI already renders details.hint/remedy PIN-021
Luigi Agostib642fe384476
diff --git a/internal/cli/apiclient/apierror_test.go b/internal/cli/apiclient/apierror_test.goindex 69836789..5990ef62 100644--- a/internal/cli/apiclient/apierror_test.go+++ b/internal/cli/apiclient/apierror_test.go@@ -76,3 +76,26 @@ func TestRenderAPIErrorKeepsApplicationErrors(t *testing.T) {t.Errorf("hint rendering changed:\n%s", msg)}}++// The /action navigation guard reports a 409 whose details carry the way+// forward; the renderer is what puts it in front of the user.+func TestRenderAPIErrorBodyShowsNavigationChangedHintAndRemedy(t *testing.T) {+ body := `{"code":"navigation_changed",` ++ `"error":"unexpected page navigation: https://pinchtab.com/ -> https://pinchtab.com/docs/",` ++ `"details":{"hint":"The action navigated the page; set waitNav true or submit true.",` ++ `"remedy":"pinchtab click <ref> --wait-nav (use --submit instead when the click submits a form)",` ++ `"url":"https://pinchtab.com/docs/"}}`++ out := renderAPIErrorBody(409, []byte(body))++ for _, want := range []string{+ "Error 409: unexpected page navigation",+ "💡 The action navigated the page",+ "Remedy: pinchtab click <ref> --wait-nav",+ "--submit",+ } {+ if !strings.Contains(out, want) {+ t.Errorf("rendered error missing %q:\n%s", want, out)+ }+ }+}diff --git a/internal/handlers/actions.go b/internal/handlers/actions.goindex f868cd12..d789af60 100644--- a/internal/handlers/actions.go+++ b/internal/handlers/actions.go@@ -102,6 +102,33 @@ func rejectMultiStepSubmitClicks(w http.ResponseWriter, actions []bridge.ActionRconst dialogActionHint = "use --dialog-action accept or --dialog-action dismiss"+const navigationChangedHint = "The action navigated the page, which the guard reports unless the request declares it: set waitNav true to wait for the navigation, or submit true when the click submits a form."++const navigationChangedRemedy = "pinchtab click <ref> --wait-nav (use --submit instead when the click submits a form)"++func navigationChangedDetails(err error) map[string]any {+ details := map[string]any{+ "hint": navigationChangedHint,+ "remedy": navigationChangedRemedy,+ }+ if url := navigatedToURL(err); url != "" {+ details["url"] = url+ }+ return details+}++func navigatedToURL(err error) string {+ if err == nil {+ return ""+ }+ message := err.Error()+ idx := strings.LastIndex(message, " -> ")+ if idx < 0 {+ return ""+ }+ return strings.TrimSpace(message[idx+len(" -> "):])+}+type dialogBlockingError struct {message stringdialogType string@@ -406,7 +433,7 @@ func (h *Handlers) HandleAction(w http.ResponseWriter, r *http.Request) {return}if errors.Is(actionErr, bridge.ErrUnexpectedNavigation) {- httpx.ErrorCode(w, 409, "navigation_changed", actionErr.Error(), false, nil)+ httpx.ErrorCode(w, 409, "navigation_changed", actionErr.Error(), false, navigationChangedDetails(actionErr))return}if browserops.IsIDPIBlocked(actionErr) {diff --git a/internal/handlers/actions_test.go b/internal/handlers/actions_test.goindex 8871dd97..029fda01 100644--- a/internal/handlers/actions_test.go+++ b/internal/handlers/actions_test.go@@ -638,3 +638,49 @@ func TestEnsureChromeAliasServes(t *testing.T) {t.Errorf("/ensure-chrome should return legacy chrome_ready status, got %s", w.Body.String())}}++func TestHandleAction_NavigationChangedCarriesHintAndRemedy(t *testing.T) {+ navErr := fmt.Errorf("%w: %s -> %s", bridge.ErrUnexpectedNavigation, "https://pinchtab.com/", "https://pinchtab.com/docs/")+ mb := &mockBridge{executeActionErr: navErr}+ h := New(mb, &config.RuntimeConfig{ActionTimeout: time.Second}, nil, nil, nil)+ req := httptest.NewRequest("POST", "/action", bytes.NewReader([]byte(`{"kind":"click"}`)))+ req.Header.Set("Content-Type", "application/json")+ w := httptest.NewRecorder()++ h.HandleAction(w, req)++ if w.Code != 409 {+ t.Fatalf("expected 409, got %d: %s", w.Code, w.Body.String())+ }+ var resp struct {+ Code string `json:"code"`+ Details map[string]any `json:"details"`+ }+ if err := json.Unmarshal(w.Body.Bytes(), &resp); err != nil {+ t.Fatalf("decode response: %v", err)+ }+ if resp.Code != "navigation_changed" {+ t.Fatalf("code = %q, want navigation_changed", resp.Code)+ }+ for _, key := range []string{"hint", "remedy", "url"} {+ value, _ := resp.Details[key].(string)+ if value == "" {+ t.Fatalf("details[%q] missing or empty: %#v", key, resp.Details)+ }+ }+ hint, _ := resp.Details["hint"].(string)+ for _, want := range []string{"waitNav", "submit"} {+ if !strings.Contains(hint, want) {+ t.Fatalf("hint %q does not name request field %q", hint, want)+ }+ }+ remedy, _ := resp.Details["remedy"].(string)+ for _, want := range []string{"--wait-nav", "--submit"} {+ if !strings.Contains(remedy, want) {+ t.Fatalf("remedy %q does not name CLI flag %q", remedy, want)+ }+ }+ if got, _ := resp.Details["url"].(string); got != "https://pinchtab.com/docs/" {+ t.Fatalf("details[url] = %q, want the resulting URL", got)+ }+}