Skip to content

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

test: pin that BuildSnapshot routes checkedness through the parser, so an unrecognised AX reading cannot reach the wire as an undefined state (PIN-102)

Luigi Agosti9757e715ce1d
diff --git a/internal/bridge/observe/snapshot.go b/internal/bridge/observe/snapshot.go
index b51a7571..3f706668 100644
--- a/internal/bridge/observe/snapshot.go
+++ b/internal/bridge/observe/snapshot.go
@@ -28,12 +28,10 @@ func IsSensitiveAutocomplete(value string) bool {
return false
}
-// CheckedState is the tri-state checkedness of a checkable control, taken
-// verbatim from the accessibility tree's own "checked" property. It is a
-// three-value string rather than a bool because "mixed" is a real state — a
-// native indeterminate checkbox and aria-checked="mixed" both report it — and
-// because ABSENT must never read as unchecked: the empty value means this node
-// has no checkedness, not that it is off. A bool could not say all three things.
+// CheckedState is the accessibility tree's own "checked" property, verbatim. A bool
+// could not carry it: "mixed" is a real state that both a native indeterminate
+// checkbox and aria-checked="mixed" report, and absent has to mean "this node has no
+// checkedness" rather than "off".
type CheckedState string
const (
@@ -42,9 +40,6 @@ const (
CheckedMixed CheckedState = "mixed"
)
-// checkedStateFromAX accepts only the three states the accessibility tree
-// defines. Anything else — including an empty value — leaves the field absent,
-// so an unrecognised reading is reported as "no answer" rather than as "off".
func checkedStateFromAX(value string) (CheckedState, bool) {
switch CheckedState(value) {
case CheckedTrue, CheckedFalse, CheckedMixed:
@@ -57,10 +52,6 @@ func checkedStateFromAX(value string) (CheckedState, bool) {
// the wire) means the bounds pass never measured this node, which is a
// different statement from a measured false: it is set exactly when
// BoundingBox is.
-//
-// Checked is empty for every node that has no checkedness. Only a checkable
-// control gets it, because only such a control carries the accessibility
-// property it is read from.
type A11yNode struct {
Ref string `json:"ref"`
Role string `json:"role"`
diff --git a/internal/bridge/observe/snapshot_checked_test.go b/internal/bridge/observe/snapshot_checked_test.go
index a7777632..b0beb124 100644
--- a/internal/bridge/observe/snapshot_checked_test.go
+++ b/internal/bridge/observe/snapshot_checked_test.go
@@ -283,3 +283,76 @@ func TestUnrecognisedCheckedReadingIsNotReportedAsUnchecked(t *testing.T) {
t.Errorf("a measured false must reach the wire: %s", encoded)
}
}
+
+// checkboxNodeWithAXChecked builds the one shape a real browser cannot produce: a
+// checkable control whose accessibility "checked" property carries something outside
+// the three defined states. BuildSnapshot is a pure function over []RawAXNode, which
+// is the only way to feed it such a reading.
+func checkboxNodeWithAXChecked(axChecked string) []RawAXNode {
+ raw, _ := json.Marshal(axChecked)
+ return []RawAXNode{
+ {
+ NodeID: "root",
+ Role: &RawAXValue{Value: json.RawMessage(`"WebArea"`)},
+ Name: &RawAXValue{Value: json.RawMessage(`"Form"`)},
+ ChildIDs: []string{"box"},
+ },
+ {
+ NodeID: "box",
+ Role: &RawAXValue{Value: json.RawMessage(`"checkbox"`)},
+ Name: &RawAXValue{Value: json.RawMessage(`"Terms"`)},
+ BackendDOMNodeID: 11,
+ Properties: []RawAXProp{
+ {Name: "checked", Value: &RawAXValue{Value: raw}},
+ },
+ },
+ }
+}
+
+// checkedStateFromAX being correct is not the same as BuildSnapshot USING it, and only
+// this shape can tell the two apart: the browser-backed tests can only produce what
+// Chrome emits — true, false and mixed — so an unrecognised reading is unreachable from
+// them by construction, and a helper-level test cannot show the helper is wired.
+//
+// Assigning the raw property value at the call site passes every other test in this
+// package while putting checked:"undefined" on the wire, which the three-value contract
+// in docs/reference/snapshot.md forbids and which every renderer then annotates as
+// nothing at all — indistinguishable from a node the field does not apply to.
+func TestBuildSnapshotRoutesCheckednessThroughTheParserSoAnUnrecognisedReadingIsDropped(t *testing.T) {
+ for _, axChecked := range []string{"undefined", "", "unknown", "TRUE", "1"} {
+ t.Run("ax checked="+axChecked, func(t *testing.T) {
+ flat, _ := BuildSnapshot(checkboxNodeWithAXChecked(axChecked), "", -1)
+ if len(flat) != 2 {
+ t.Fatalf("expected 2 nodes, got %d", len(flat))
+ }
+
+ if got := flat[1].Checked; got != "" {
+ t.Errorf("Checked = %q for an accessibility reading of %q; only true/false/mixed are answers, and anything else must leave the field ABSENT rather than put an undefined state on the wire", got, axChecked)
+ }
+ encoded, err := json.Marshal(flat[1])
+ if err != nil {
+ t.Fatal(err)
+ }
+ if strings.Contains(string(encoded), `"checked"`) {
+ t.Errorf("node serialises a checked key for an unrecognised reading: %s", encoded)
+ }
+ })
+ }
+}
+
+// The positive half, on the same synthetic path: the three defined states must survive
+// it. Without this, dropping every reading — the crudest possible bypass — would satisfy
+// the test above.
+func TestBuildSnapshotKeepsTheThreeDefinedCheckedStatesFromTheAXProperty(t *testing.T) {
+ for _, want := range []CheckedState{CheckedTrue, CheckedFalse, CheckedMixed} {
+ t.Run(string(want), func(t *testing.T) {
+ flat, _ := BuildSnapshot(checkboxNodeWithAXChecked(string(want)), "", -1)
+ if len(flat) != 2 {
+ t.Fatalf("expected 2 nodes, got %d", len(flat))
+ }
+ if got := flat[1].Checked; got != want {
+ t.Errorf("Checked = %q, want %q", got, want)
+ }
+ })
+ }
+}
diff --git a/internal/bridge/observe/snapshot_format.go b/internal/bridge/observe/snapshot_format.go
index 8151674e..e1a21812 100644
--- a/internal/bridge/observe/snapshot_format.go
+++ b/internal/bridge/observe/snapshot_format.go
@@ -2,11 +2,9 @@ package observe
import "strings"
-// checkedAnnotations render all THREE states, not just the checked one. A bare
-// node and an unchecked one must not look alike: absent means the control has no
-// checkedness, false means it is off, and an agent reading a radio group needs to
-// tell those apart at a glance. The compact forms stay three characters so a
-// five-option group costs fifteen.
+// All THREE states are annotated, not just the checked one: absent means the control
+// has no checkedness and false means it is off, so rendering only [checked] would make
+// an unchecked option look like a node the field does not apply to.
var checkedAnnotations = map[CheckedState]string{
CheckedTrue: " [checked]",
CheckedFalse: " [unchecked]",