Skip to content

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

test: pin the 409's recovery disclosure at the wire and spell the stale-ref remedy out as a literal (PIN-234)

Luigi Agostie1f6f3de2bfe
diff --git a/internal/handlers/action_stale_submit_test.go b/internal/handlers/action_stale_submit_test.go
index 5f404d7e..23dfa106 100644
--- a/internal/handlers/action_stale_submit_test.go
+++ b/internal/handlers/action_stale_submit_test.go
@@ -278,8 +278,11 @@ func TestTheEndpointRefusesAStaleSubmitRefWithASnapshotRemedyAndNoOrder(t *testi
if dispatched, ok := resp.Details["dispatched"].(bool); !ok || dispatched {
t.Errorf("details.dispatched = %v, want false: this refusal exists to say nothing was clicked", resp.Details["dispatched"])
}
- if got, _ := resp.Details["remedy"].(string); got != reSnapshot.Remedy().String() {
- t.Errorf("remedy = %q, want %q", got, reSnapshot.Remedy())
+ // Spelled out rather than compared against reSnapshot, which production formats from the
+ // same constant: that comparison holds whatever the constant is changed to, so it pins
+ // the two sides agreeing rather than the advice being the one that resolves a stale ref.
+ if got, _ := resp.Details["remedy"].(string); got != "pinchtab snap" {
+ t.Errorf("remedy = %q, want %q — the only advice that re-resolves a stale ref", got, "pinchtab snap")
}
if placed := f.settleForOrder(); placed != 0 {
t.Fatalf("%d order(s) placed by a refused request", placed)
@@ -297,6 +300,44 @@ func TestTheEndpointRefusesAStaleSubmitRefWithASnapshotRemedyAndNoOrder(t *testi
}
}
+// The helper returns the record; this pins that it survives the endpoint and reaches the
+// caller. Without it the 409 discloses the navigation and hides the substitution — and the
+// helper-level pair cannot see that, because the field is attached one layer out.
+func TestTheNavigation409DisclosesWhichElementWasActuallyClicked(t *testing.T) {
+ f := newOrderFixture(t)
+ h, _, tabID := staleSubmitHandlers(t, f)
+
+ body := `{"kind":"click","ref":"e3","tabId":"` + tabID + `"}`
+ rec := httptest.NewRecorder()
+ h.HandleAction(rec, httptest.NewRequest(http.MethodPost, "/action", strings.NewReader(body)))
+
+ if rec.Code != http.StatusConflict {
+ t.Fatalf("status = %d, want 409: %s", rec.Code, rec.Body.String())
+ }
+ var resp struct {
+ Code string `json:"code"`
+ Error string `json:"error"`
+ Details map[string]any `json:"details"`
+ }
+ if err := json.Unmarshal(rec.Body.Bytes(), &resp); err != nil {
+ t.Fatalf("decode navigation response: %v (%s)", err, rec.Body.String())
+ }
+ if resp.Code != "navigation_changed" {
+ t.Errorf("code = %q, want navigation_changed", resp.Code)
+ }
+ if strings.Contains(resp.Error, "not found and recovery failed") {
+ t.Errorf("the wire still reports the dispatch as a lookup failure: %q", resp.Error)
+ }
+
+ published, ok := resp.Details["recovery"].(map[string]any)
+ if !ok {
+ t.Fatalf("details.recovery absent, so the 409 says the page moved without saying the click went to a different element than the caller named: %v", resp.Details)
+ }
+ if newRef, _ := published["new_ref"].(string); newRef == "" {
+ t.Errorf("details.recovery names no matched ref, so the substitution is still undisclosed: %v", published)
+ }
+}
+
// The macro/batch step path takes the same helper and the same refMissing argument, so the
// refusal has to arrive there as a failed step carrying the same advice — a step that
// reported success, or one whose text sent the caller back to --submit, would be the same