High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.
fix(bridge): report a click's navigation outcome whatever security.enableActionGuards says, so the shipped refsStale contract holds under every config (PIN-288)
Luigi Agostie2d5cab32e87
diff --git a/internal/bridge/action_request.go b/internal/bridge/action_request.goindex 7837874a..c5e0abb1 100644--- a/internal/bridge/action_request.go+++ b/internal/bridge/action_request.go@@ -323,24 +323,14 @@ func (b *Bridge) ExecuteAction(ctx context.Context, kind string, req ActionRequeif !ok {return nil, fmt.Errorf("unknown action: %s", kind)}- // 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 reportNavigation {- if u, err := urlReader(ctx); err == nil {- beforeURL = u- }+ if u, err := urlReader(ctx); err == nil {+ beforeURL = u}res, err := fn(ctx, req)@@ -348,7 +338,7 @@ func (b *Bridge) ExecuteAction(ctx context.Context, kind string, req ActionRequereturn nil, classifyActionError(err)}- if reportNavigation && beforeURL != "" {+ if beforeURL != "" {if afterURL, uErr := urlReader(ctx); uErr == nil && navigationChanged(beforeURL, afterURL) {res = withNavigationOutcome(res, beforeURL, afterURL)}diff --git a/internal/bridge/guards_test.go b/internal/bridge/guards_test.goindex dce08c84..fc1cde86 100644--- a/internal/bridge/guards_test.go+++ b/internal/bridge/guards_test.go@@ -107,34 +107,64 @@ func TestReadActionURL_NoChromeDPContext(t *testing.T) {}}-func TestExecuteAction_UnexpectedNavigation_WhenEnabled(t *testing.T) {- call := 0- readActionURL := func(context.Context) (string, error) {- call++- if call == 1 {- return "https://a.example", nil- }- return "https://b.example", nil+func TestExecuteAction_ReportsTheNavigationOutcomeWhateverEnableActionGuardsSays(t *testing.T) {+ settings := map[string]*config.RuntimeConfig{+ "guards on": {EnableActionGuards: true},+ "guards off": {EnableActionGuards: false},+ "nil config": nil,+ }+ for name, cfg := range settings {+ t.Run(name, func(t *testing.T) {+ t.Run("a navigating click reports where it landed", func(t *testing.T) {+ res := executeClickAcross(t, cfg, "https://a.example", "https://b.example")+ assertNavigationOutcome(t, res, "https://a.example", "https://b.example")+ })+ t.Run("a click that stays put reports none of it", func(t *testing.T) {+ res := executeClickAcross(t, cfg, "https://a.example", "https://a.example")+ assertNoNavigationOutcome(t, res)+ })+ })}+}+func executeClickAcross(t *testing.T, cfg *config.RuntimeConfig, before, after string) map[string]any {+ t.Helper()+ call := 0b := &Bridge{- Config: &config.RuntimeConfig{EnableActionGuards: true},- URLReader: readActionURL,+ Config: cfg,+ URLReader: func(context.Context) (string, error) {+ call+++ if call == 1 {+ return before, nil+ }+ return after, 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(), ActionClick, ActionRequest{})if err != nil {- t.Fatalf("a click that ran and moved the page reported failure: %v", err)+ t.Fatalf("a click that ran reported failure: %v", err)+ }+ if call != 2 {+ t.Fatalf("the page url was read %d times, want before and after the click", call)+ }+ return res+}++func assertNoNavigationOutcome(t *testing.T, res map[string]any) {+ t.Helper()+ if res["ok"] != true {+ t.Errorf("the action's own result was discarded: %v", res)+ }+ for _, key := range []string{ResultNavigated, ResultLandedURL, ResultPreviousURL, ResultRefsStale} {+ if _, present := res[key]; present {+ t.Errorf("a click that did not move the page reports %s: %v", key, res)+ }}- assertNavigationOutcome(t, res, "https://a.example", "https://b.example")}// The whole defect in one assertion: the action's own result is what the API used@@ -161,57 +191,6 @@ func assertNavigationOutcome(t *testing.T, res map[string]any, before, after str}}-func TestExecuteAction_UnexpectedNavigationGuardDisabled(t *testing.T) {- called := 0- readActionURL := func(context.Context) (string, error) {- called++- return "https://a.example", nil- }-- b := &Bridge{- Config: &config.RuntimeConfig{EnableActionGuards: false},- URLReader: readActionURL,- Actions: map[string]ActionFunc{- ActionType: func(context.Context, ActionRequest) (map[string]any, error) {- return map[string]any{"ok": true}, nil- },- },- }-- if _, err := b.ExecuteAction(context.Background(), ActionType, ActionRequest{}); err != nil {- t.Fatalf("expected nil error, got %v", err)- }- if called != 0 {- t.Fatalf("expected readActionURL to not be called when guards are disabled, got %d calls", called)- }-}--func TestExecuteAction_UnexpectedNavigation_WithNilConfigDefaultsEnabled(t *testing.T) {- call := 0- readActionURL := func(context.Context) (string, error) {- call++- if call == 1 {- return "https://a.example", nil- }- return "https://b.example", nil- }-- b := &Bridge{- URLReader: readActionURL,- Actions: map[string]ActionFunc{- ActionType: func(context.Context, ActionRequest) (map[string]any, error) {- return map[string]any{"ok": true}, nil- },- },- }-- res, err := b.ExecuteAction(context.Background(), ActionType, ActionRequest{})- 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")-}-func TestExecuteAction_ClassifiesStaleError_WhenGuardsDisabled(t *testing.T) {b := &Bridge{Config: &config.RuntimeConfig{EnableActionGuards: false},