High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.
fix: report the navigation outcome for every form, including waitNav and submit clicks (PIN-266)
Luigi Agosti8613b0434c44
diff --git a/docs/reference/click.md b/docs/reference/click.mdindex 483e8c78..4790ffe8 100644--- a/docs/reference/click.md+++ b/docs/reference/click.md@@ -54,6 +54,11 @@ minted per snapshot, so take a new one before the next ref-targeted action:pinchtab click e1 --snap # click, then print the new snapshot in one call```+These fields are present whichever form you use: a plain click, a click with+`--wait-nav`, and a `--submit` click that redirects all report where they landed and+that your refs are dead. A `--submit` click keeps its own `postState` as the headline+and carries the landing alongside it.+`--wait-nav` is not permission to navigate — it makes the click *wait* for thenavigation to settle before returning, which is what you want when the next actiondepends on the new page having loaded.diff --git a/internal/bridge/action_request.go b/internal/bridge/action_request.goindex 9138b7ef..7837874a 100644--- a/internal/bridge/action_request.go+++ b/internal/bridge/action_request.go@@ -323,15 +323,21 @@ func (b *Bridge) ExecuteAction(ctx context.Context, kind string, req ActionRequeif !ok {return nil, fmt.Errorf("unknown action: %s", kind)}- guardEnabled := b.Config == nil || b.Config.EnableActionGuards- checkNav := guardEnabled && shouldCheckUnexpectedNavigation(req)+ // Measured for every action, not for a selected few. This used to skip a+ // waitNav click and a submit click, from when the check RAISED an error and+ // refusing to error on a declared navigation was right. It only annotates the+ // result now, so both exclusions had stopped meaning anything except that the+ // two forms most likely to navigate were the two that never said where they+ // landed — a waiting caller got strictly less than a plain one, and refsStale+ // was missing from exactly the form whose next action depends on the new page.+ reportNavigation := b.Config == nil || b.Config.EnableActionGuardsurlReader := b.URLReaderif urlReader == nil {urlReader = defaultActionURLReaderslog.Debug("URLReader is nil, using default fallback (guard checks may be no-ops without chromedp context)")}var beforeURL string- if checkNav {+ if reportNavigation {if u, err := urlReader(ctx); err == nil {beforeURL = u}@@ -342,7 +348,7 @@ func (b *Bridge) ExecuteAction(ctx context.Context, kind string, req ActionRequereturn nil, classifyActionError(err)}- if checkNav && beforeURL != "" {+ if reportNavigation && beforeURL != "" {if afterURL, uErr := urlReader(ctx); uErr == nil && navigationChanged(beforeURL, afterURL) {res = withNavigationOutcome(res, beforeURL, afterURL)}diff --git a/internal/bridge/guards.go b/internal/bridge/guards.goindex bf38cf4d..907adea3 100644--- a/internal/bridge/guards.go+++ b/internal/bridge/guards.go@@ -51,14 +51,6 @@ func classifyActionError(err error) error {return err}-// shouldCheckUnexpectedNavigation selects the actions whose landing URL is worth-// measuring. waitNav is not an assertion the caller made about navigation — it-// asks the action to WAIT for one — so a caller that waits already learns the-// landed URL from the wait itself and needs no second report here.-func shouldCheckUnexpectedNavigation(req ActionRequest) bool {- return !req.WaitNav && !IsSubmitClick(req.Kind, req)-}-// navigationChanged reports whether an action moved the page. It used to return// an error, and ExecuteAction returned that error INSTEAD of the successful// result the action had already produced — so clicking an ordinary link faileddiff --git a/internal/bridge/guards_test.go b/internal/bridge/guards_test.goindex 02bf0f2b..dce08c84 100644--- a/internal/bridge/guards_test.go+++ b/internal/bridge/guards_test.go@@ -53,18 +53,47 @@ func TestNormalizeGuardURL(t *testing.T) {}}-func TestShouldCheckUnexpectedNavigation(t *testing.T) {- if !shouldCheckUnexpectedNavigation(ActionRequest{}) {- t.Fatal("click should be guarded when WaitNav is false")- }- if !shouldCheckUnexpectedNavigation(ActionRequest{}) {- t.Fatal("press should be guarded when WaitNav is false")- }- if shouldCheckUnexpectedNavigation(ActionRequest{WaitNav: true}) {- t.Fatal("WaitNav=true should disable navigation guard")- }- if shouldCheckUnexpectedNavigation(ActionRequest{Kind: ActionClick, Submit: true}) {- t.Fatal("click submit should treat navigation as an expected post-state")+// The forms that used to be excluded, and the reason the exclusion was wrong: a+// caller that DECLARES a navigation is the one most certain to need where it landed+// and that its refs are dead, and it was the one form that never got told. The+// exclusion made sense only while the check raised an error.+func TestEveryFormOfANavigatingActionReportsWhereItLanded(t *testing.T) {+ for _, tc := range []struct {+ name string+ req ActionRequest+ }{+ {"plain click", ActionRequest{Kind: ActionClick}},+ {"click that declares the navigation", ActionRequest{Kind: ActionClick, WaitNav: true}},+ {"submit click", ActionRequest{Kind: ActionClick, Submit: true, Ref: "e1"}},+ {"non-click action", ActionRequest{Kind: ActionType}},+ } {+ t.Run(tc.name, func(t *testing.T) {+ call := 0+ b := &Bridge{+ Config: &config.RuntimeConfig{EnableActionGuards: true},+ URLReader: func(context.Context) (string, error) {+ call+++ if call == 1 {+ return "https://a.example", nil+ }+ return "https://b.example", nil+ },+ Actions: map[string]ActionFunc{+ ActionClick: func(context.Context, ActionRequest) (map[string]any, error) {+ return map[string]any{"ok": true}, nil+ },+ ActionType: func(context.Context, ActionRequest) (map[string]any, error) {+ return map[string]any{"ok": true}, nil+ },+ },+ }++ res, err := b.ExecuteAction(context.Background(), tc.req.Kind, tc.req)+ if err != nil {+ t.Fatalf("an action that ran and moved the page reported failure: %v", err)+ }+ assertNavigationOutcome(t, res, "https://a.example", "https://b.example")+ })}}diff --git a/internal/cli/actions/actions_element.go b/internal/cli/actions/actions_element.goindex 4afd7f55..48322d51 100644--- a/internal/cli/actions/actions_element.go+++ b/internal/cli/actions/actions_element.go@@ -193,15 +193,9 @@ func printActionResult(kind string, result map[string]any) {return}if actionResult, ok := result["result"].(map[string]any); ok {- // A click that moved the page succeeded. It used to exit 1 with a 409, which- // is the signal every agent loop and CI harness branches on, so the natural- // reaction — retry — re-clicked on the page the first click had reached.- if actionResult["navigated"] == true {- landed, _ := actionResult["url"].(string)- output.Value("OK navigated " + landed)- output.Hint("every ref from your last snapshot is dead — run `pinchtab snap -i` before the next action")- return- }+ // A submit reports its own bounded post-state, which says more than "it+ // moved" — so it is the headline, and the navigation rides underneath it+ // rather than replacing it.if postState, ok := actionResult["postState"].(map[string]any); ok {status, _ := postState["status"].(string)signal, _ := postState["signal"].(string)@@ -209,17 +203,46 @@ func printActionResult(kind string, result map[string]any) {case "pending":output.Value("PENDING")output.Hint("submit post-state is still pending; do not retry automatically")+ printNavigationOutcome(actionResult)returncase "succeeded":output.Value("SUCCEEDED " + signal)+ printNavigationOutcome(actionResult)return}}+ // A click that moved the page succeeded. It used to exit 1 with a 409, which+ // is the signal every agent loop and CI harness branches on, so the natural+ // reaction — retry — re-clicked on the page the first click had reached.+ if actionResult["navigated"] == true {+ landed, _ := actionResult["url"].(string)+ output.Value("OK navigated " + landed)+ printStaleRefsHint()+ return+ }}output.Success()}+// printNavigationOutcome reports the landing for an action whose headline is+// something else. Every form that navigates says where it landed, including the+// forms that declare the navigation — those are the ones whose next action depends+// on the new page, so they are the ones that most need to hear their refs are dead.+func printNavigationOutcome(actionResult map[string]any) {+ if actionResult["navigated"] != true {+ return+ }+ if landed, _ := actionResult["url"].(string); landed != "" {+ output.Value("navigated " + landed)+ }+ printStaleRefsHint()+}++func printStaleRefsHint() {+ output.Hint("every ref from your last snapshot is dead — run `pinchtab snap -i` before the next action")+}+func setPointBody(body map[string]any, x, y float64) {body["x"] = xbody["y"] = ydiff --git a/internal/cli/actions/actions_element_test.go b/internal/cli/actions/actions_element_test.goindex f2a265a8..c7fc7162 100644--- a/internal/cli/actions/actions_element_test.go+++ b/internal/cli/actions/actions_element_test.go@@ -1014,3 +1014,33 @@ func TestPrintActionResultAClickThatDidNotNavigateStaysPlain(t *testing.T) {t.Errorf("output = %q; a click that moved nothing reported a navigation", got)}}++// A submit that redirects keeps its own post-state headline — that says more than+// "it moved" — and reports the landing underneath it. The landing used to be absent+// from this form entirely.+func TestPrintActionResultASubmitThatNavigatedKeepsItsPostStateAndSaysWhereItLanded(t *testing.T) {+ navigatedSubmit := map[string]any{+ "success": true,+ "result": map[string]any{+ "clicked": true,+ "postState": map[string]any{"status": "succeeded", "signal": "url_changed"},+ "navigated": true,+ "url": "https://shop.example.com/order/confirmed",+ "previousUrl": "https://shop.example.com/checkout",+ "refsStale": true,+ },+ }++ out := captureStdout(t, func() { printActionResult("click", navigatedSubmit) })+ if !strings.Contains(out, "SUCCEEDED url_changed") {+ t.Errorf("stdout = %q; the submit lost its observed post-state signal", out)+ }+ if !strings.Contains(out, "https://shop.example.com/order/confirmed") {+ t.Errorf("stdout = %q; the submit does not say where it landed", out)+ }++ hint := captureStderr(t, func() { printActionResult("click", navigatedSubmit) })+ if !strings.Contains(hint, "snap") {+ t.Errorf("stderr = %q; nothing tells the caller its refs are dead", hint)+ }+}diff --git a/internal/handlers/action_navigation_success_test.go b/internal/handlers/action_navigation_success_test.goindex e7baad6f..aebaf3f9 100644--- a/internal/handlers/action_navigation_success_test.go+++ b/internal/handlers/action_navigation_success_test.go@@ -2,6 +2,7 @@ package handlersimport ("bytes"+ "encoding/json""fmt""net/http""net/http/httptest"@@ -135,3 +136,45 @@ func emptyMetric(value any) bool {}return false}++// What this proves and what it does NOT. The bridge is mocked here, so it returns the+// navigated result whatever the request said — this pins that the outcome survives the+// endpoint and reaches the wire for both request shapes, and it would stay GREEN if the+// waitNav exclusion came back. The property that every form is MEASURED is owned by+// bridge.TestEveryFormOfANavigatingActionReportsWhereItLanded, which is the test that+// reds when either clause is restored.+func TestEveryFormOfANavigatingClickCarriesTheOutcomeOverTheWire(t *testing.T) {+ for _, tc := range []struct {+ name string+ body string+ }{+ {"plain click", `{"kind":"click","ref":"e1","nodeId":42,"tabId":"tab1"}`},+ {"click that declares the navigation", `{"kind":"click","ref":"e1","nodeId":42,"tabId":"tab1","waitNav":true}`},+ } {+ t.Run(tc.name, func(t *testing.T) {+ mb := &mockBridge{availableActions: []string{bridge.ActionClick}, actionResult: navigatedActionResult()}+ h := New(mb, &config.RuntimeConfig{ActionTimeout: time.Second}, nil, nil, nil)+ w := httptest.NewRecorder()+ req := httptest.NewRequest("POST", "/action", bytes.NewReader([]byte(tc.body)))+ req.Header.Set("Content-Type", "application/json")++ h.HandleAction(w, req)++ if w.Code != http.StatusOK {+ t.Fatalf("status = %d: %s", w.Code, w.Body.String())+ }+ var resp struct {+ Result map[string]any `json:"result"`+ }+ if err := json.Unmarshal(w.Body.Bytes(), &resp); err != nil {+ t.Fatalf("decode: %v", err)+ }+ if got, _ := resp.Result[bridge.ResultLandedURL].(string); got == "" {+ t.Errorf("result carries no landed URL: %v", resp.Result)+ }+ if resp.Result[bridge.ResultRefsStale] != true {+ t.Errorf("result does not say the caller's refs are dead: %v — this is the form whose next action depends on the new page", resp.Result)+ }+ })+ }+}diff --git a/internal/handlers/action_stale_submit_test.go b/internal/handlers/action_stale_submit_test.goindex 878d5eba..a6dc93ea 100644--- a/internal/handlers/action_stale_submit_test.go+++ b/internal/handlers/action_stale_submit_test.go@@ -444,9 +444,10 @@ func TestAnActionThatNavigatedIsNotDispatchedTwice(t *testing.T) {}}-// The converse, and the reason the guard keys on the sentinel rather than on recovery's-// "navigation" failure class: that class also carries a detached frame and a crashed page,-// where the dispatch never landed and re-dispatching is the whole point of recovery.+// The converse of the test above, and what stops that one from being read as "never+// heal anything a navigation touched": recovery's "navigation" failure class also+// carries a detached frame and a crashed page, where the dispatch never landed and+// re-dispatching is the whole point. Those still heal.func TestANavigationClassifiedFailureThatNeverDispatchedStillHeals(t *testing.T) {for name, actionErr := range map[string]error{"a detached frame": errors.New("frame was detached"),