High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.
feat(extract): resolve array-of-object schemas by detecting repeated groups in the snapshot (PIN-392)
Luigi Agosti11409717b205
diff --git a/docs/architecture/extract.md b/docs/architecture/extract.mdindex 882410b4..e992df9a 100644--- a/docs/architecture/extract.md+++ b/docs/architecture/extract.md@@ -1,7 +1,7 @@# Extract Architecture-`internal/extract` fills a flat JSON schema against a captured accessibility-snapshot. It sits between `find` (one element) and `scrape` (a whole site): an+`internal/extract` fills a JSON schema — flat fields plus arrays of objects —+against a captured accessibility snapshot. It sits between `find` (one element) and `scrape` (a whole site): anagent hands over a schema and gets typed data back, with per-field confidence soit can fall back to `find` where a field is uncertain.@@ -15,11 +15,17 @@ network, no model download) over a node list it is handed. It never touches CDP.JSON schema ──ParseSchema──► Schema (ordered properties, resolved hints)node list ──canonical order (by ref)──► descriptors (semdesc.Build)│- per property: build query ──► matcher.Find (TopK 1) ──► best ref + score- │+ per property: build query ──► matcher.Find ──► best ref + score+ │ (score desc, then document order)read value (Value|Text|Name, Checked for bool) ──► coerce to type│data + per-field {ref, score, confidence, source, reason}++array property: choose container (scope | group detection) ──► items+ │+ per item: the same field resolution over the item's subtree only+ │+ data[prop] = [ {…}, … ] fields[prop] = {ref: container, items: [{ref, fields}], truncated}```## Schema subset@@ -34,6 +40,10 @@ honours:- `x-pinchtab-hint` — an explicit query or selector that overrides thename-based query (see below).+An `array` property must carry `items` of type `object` with its own flat+`properties`; per array the extractor honours `minItems`, `maxItems`, and+`x-pinchtab-scope` (a selector naming the container, same grammar as a hint).+`ParseSchema` returns a typed `*UnsupportedError` naming the offending path forconstructs outside the subset:@@ -41,11 +51,11 @@ constructs outside the subset:- a property typed `object` (`properties.price.type: object is not supported`),- an unknown type (`properties.price.type: decimal is not supported`),- nested `properties` on a property (`properties.price.properties: ...`),-- a `css:` or `xpath:` hint, which needs a browser- (`properties.price.x-pinchtab-hint: ...`).--`array` parses successfully but resolves to a missing field with reason-`unsupported`; array-of-object resolution is a follow-up task.+- a `css:` or `xpath:` hint or scope, which needs a browser+ (`properties.price.x-pinchtab-hint: ...`),+- an array without object `items` (`properties.tags.items: ...`), an array+ nested inside `items` (`properties.rows.items.properties.tags.type: ...`), or+ a negative `minItems`/`maxItems`.Property order is alphabetical, so `missing` and iteration are deterministic.@@ -56,8 +66,11 @@ above the threshold (default `0.3`, same as `find`):1. **Query.** A resolved `x-pinchtab-hint` wins. Otherwise the query is theproperty name joined with its description.-2. **Match.** The query runs through the shared combined matcher against the- descriptors. `best_ref` and `score` come straight from the matcher.+2. **Match.** The query runs through the shared combined matcher against every+ descriptor. The winner is picked here, not taken from the matcher's own+ `best_ref`: scores are rounded to six decimals and the highest wins, ties+ broken by document order, because the combined matcher merges its halves+ concurrently and its tie ordering is not stable.3. **Read.** The matched node's value is read in priority order `Value`, `Text`,`Name`; booleans consult the accessibility `Checked` state first.4. **Coerce.** The raw string is coerced to the schema type. A coercion failure@@ -81,6 +94,79 @@ kinds a node list can answer without a browser:A hint that resolves beats the name-based query, so an agent can pin an ambiguousfield (e.g. a sale price among several prices) without renaming the schema.+## Arrays of objects++An `array` property resolves to one object per repeated group in the snapshot.++### Tree derivation++`A11yNode` carries no child links; the tree is derived from the pre-order node+list and `Depth`:++- the **subtree** of a node is the contiguous run of following nodes whose+ `Depth` is greater than the node's,+- its **direct children** are the nodes in that run at exactly `Depth + 1`,+- its **ancestors** are found by walking backwards, taking each earlier node+ whose `Depth` is smaller than the last one taken.++Every step below (candidates, items, per-item scoping, header lookup) is built+on those three derivations and nothing else.++### Container++1. **Scope.** If the property carries `x-pinchtab-scope`, that selector is+ resolved over the whole node list exactly like a hint (`ref:` verbatim, the+ semantic kinds through the matcher) and the matched node is the container.+ A scope that matches nothing leaves the property missing with reason+ `scope_not_found`; no detection runs in its place.+2. **Detection.** Otherwise every node is a candidate whose direct children+ share a dominant role (the most frequent role among them) at least **three**+ times, or at least **two** times when the node's own role is `list`,+ `table`, `rowgroup`, `grid`, or `feed`.+3. **Scoring.** Each candidate is scored by resolving the item schema inside+ its first three items (fewer if it has fewer) and taking the fraction of+ fields filled: `score = filled / (sampled items × fields)`. Candidates are+ ranked by score, then by item count, then by document order. A best score of+ `0` — no item field resolves anywhere — reports `no_repeated_group`, as+ does a page with no candidate at all. A scoped container skips the `0`+ check: the agent chose it.++The ranking is what disambiguates a page with several repeated groups: a nav+menu of links scores `0` against a product item schema whose fields want a+heading and a price, while the product region scores `1`.++### Items++The items are the container's direct children carrying the dominant role+(`listitem`, `article`, `row`, …). A `row` whose children include a+`columnheader` is a header, never an item.++Two per-item modes exist:++- **Subtree.** The flat resolver runs over the item's descendants only (the+ item node itself excluded), so `price` in item 3 can never match item 1 and a+ field absent from one item stays missing there even when every other item+ has it.+- **Columnar.** When the items are `row`s and the nearest enclosing `table` or+ `grid` (or the container itself) holds a header row, each field is resolved+ once against the header cells to a column index, and every row reads the cell+ at that index. Table cells are named by their value, not their column, so+ matching them per row would find nothing. A row shorter than the index leaves+ the field missing with `no_match`.++Items where every field is missing are dropped. The output is capped at the+smaller of the schema's `maxItems` and `Options.MaxItems` (default `100`); when+unresolved items remain past the cap the field reports `truncated: true`.+Fewer items than `minItems` leaves the property missing with reason+`too_few_items`.++### Result shape++`data[prop]` is the array of objects. `fields[prop]` carries the container+`ref`, the group `score` and its confidence band, `items` — one `{ref, fields}`+per returned item with the same per-field diagnostics as a flat field — and+`truncated`.+## Coercion rules- **string** — the trimmed raw value.@@ -109,7 +195,8 @@ can fall back to `find` on a `low` field.sorted into document order by ref (snapshot refs `e1`, `e2`, … are assigned inpre-order, so numeric ref order is document order). The same schema over the samenodes — in any input order — yields identical output; ties break on document-order.+order. Array resolution inherits this: candidates and items are enumerated in+document order and ties rank by document order.## Descriptorsdiff --git a/internal/extract/coerce.go b/internal/extract/coerce.goindex 2811b1fb..879dc620 100644--- a/internal/extract/coerce.go+++ b/internal/extract/coerce.go@@ -7,15 +7,6 @@ import ("github.com/pinchtab/pinchtab/internal/bridge/observe")-// coerceNumber parses the FIRST numeric token of a display string into a-// float64, stripping a leading currency symbol/sign and the token's thousands-// separators while keeping sign and decimal. "$1,299.00" -> 1299, "−3.5 kg" ->-// -3.5 (Unicode minus honoured), "4.7 out of 5" -> 4.7, "2 of 3" -> 2, "call-// for price" -> not numeric. ok is false when no digit is present.-//-// It stops at the first rune after the token that is not a digit, '.', or ','-// so digits from a trailing word ("out of 5", "of 3") are never glued on — a-// coercion must leave a field missing, never hand back a wrong-typed value.func coerceNumber(s string) (float64, bool) {var b strings.Buildersign := ""@@ -34,14 +25,11 @@ func coerceNumber(s string) (float64, bool) {b.WriteRune('.')seenDot = truecase r == ',' && seenDigit:- // thousands separator inside the token: droppedcase isMinus(r) && !seenDigit && sign == "":sign = "-"case r == '+' && !seenDigit && sign == "":sign = "+"default:- // A non-numeric rune: before the first digit it is leading noise- // (currency, spaces) and is skipped; after it, the token has ended.if seenDigit {done = true}@@ -56,16 +44,9 @@ func coerceNumber(s string) (float64, bool) {}return f, true}--// isMinus reports whether r is an ASCII hyphen-minus or the Unicode minus sign-// (U+2212), which price and weight strings use interchangeably.func isMinus(r rune) bool {return r == '-' || r == '−'}--// coerceBool reads a boolean from a node: its accessibility checked state first,-// then yes/no/true/false words in the read value. ok is false when neither-// yields a decision (a mixed checkbox or an unrelated string).func coerceBool(node observe.A11yNode, value string) (bool, bool) {switch node.Checked {case observe.CheckedTrue:diff --git a/internal/extract/extract_test.go b/internal/extract/extract_test.goindex 86e3e531..e1a21931 100644--- a/internal/extract/extract_test.go+++ b/internal/extract/extract_test.go@@ -38,7 +38,7 @@ func TestResolve_FromSnapshotFixtures(t *testing.T) {want := map[string]any{"name": "Sony WH-1000XM5 Wireless Headphones","price": 1299.0,- "rating": 4.7, // "4.7 out of 5" -> first token 4.7, never 4.75+ "rating": 4.7,"in_stock": true,}for k, v := range want {@@ -227,13 +227,13 @@ func TestCoerceNumber(t *testing.T) {ok bool}{{"$1,299.00", 1299, true},- {"−3.5 kg", -3.5, true}, // Unicode minus U+2212- {"-3.5 kg", -3.5, true}, // ASCII hyphen+ {"−3.5 kg", -3.5, true},+ {"-3.5 kg", -3.5, true},{"call for price", 0, false},{"42", 42, true},{"1,000,000", 1000000, true},- {"4.7 out of 5", 4.7, true}, // trailing "5" must not glue onto the token- {"2 of 3", 2, true}, // trailing "3" must not glue onto the token+ {"4.7 out of 5", 4.7, true},+ {"2 of 3", 2, true},{"", 0, false},}for _, tc := range tests {@@ -264,8 +264,6 @@ func TestResolve_NotNumericLeavesFieldMissing(t *testing.T) {}func TestResolve_HintSelectorBeatsName(t *testing.T) {- // Two plausible price-ish nodes; the name-based query would prefer the one- // literally named "Price", but the hint points at the sale price by role/name.nodes := []observe.A11yNode{{Ref: "e1", Role: "region", Name: "Product", Depth: 0},{Ref: "e2", Role: "text", Name: "Price", Text: "$1,299.00", Depth: 1},@@ -280,8 +278,6 @@ func TestResolve_HintSelectorBeatsName(t *testing.T) {if got.Data["price"] != 999.0 {t.Errorf("price = %#v, want 999", got.Data["price"])}-- // A bare query hint is used verbatim.bare := mustSchema(t, `{"type":"object","properties":{"price":{"type":"number","x-pinchtab-hint":"Sale price"}}}`)if got := Resolve(bare, nodes, Options{}); got.Fields["price"].Ref != "e3" {@@ -312,21 +308,6 @@ func TestResolve_Deterministic(t *testing.T) {}}-func TestResolve_ArrayReportsUnsupported(t *testing.T) {- schema := mustSchema(t, `{"type":"object","required":["tags"],"properties":{- "tags":{"type":"array","description":"tag list"}}}`)- got := Resolve(schema, productNodes(), Options{})- if got.Fields["tags"].Reason != reasonUnsupported {- t.Errorf("array reason = %q, want %q", got.Fields["tags"].Reason, reasonUnsupported)- }- if _, present := got.Data["tags"]; present {- t.Errorf("unsupported array must not appear in data")- }- if len(got.Missing) != 1 || got.Missing[0] != "tags" {- t.Errorf("missing = %v, want [tags]", got.Missing)- }-}-func TestParseSchema_UnsupportedConstructs(t *testing.T) {tests := []struct {name string@@ -339,6 +320,11 @@ func TestParseSchema_UnsupportedConstructs(t *testing.T) {{"non-object root", `{"type":"array","properties":{"price":{"type":"string"}}}`, "type"},{"css hint", `{"type":"object","properties":{"price":{"type":"number","x-pinchtab-hint":"css:.price"}}}`, "properties.price.x-pinchtab-hint"},{"xpath hint", `{"type":"object","properties":{"price":{"type":"number","x-pinchtab-hint":"xpath://span"}}}`, "properties.price.x-pinchtab-hint"},+ {"css scope", `{"type":"object","properties":{"rows":{"type":"array","x-pinchtab-scope":"css:table","items":{"type":"object","properties":{"id":{"type":"string"}}}}}}`, "properties.rows.x-pinchtab-scope"},+ {"array without items", `{"type":"object","properties":{"tags":{"type":"array"}}}`, "properties.tags.items"},+ {"array of strings", `{"type":"object","properties":{"tags":{"type":"array","items":{"type":"string"}}}}`, "properties.tags.items.type"},+ {"nested array", `{"type":"object","properties":{"rows":{"type":"array","items":{"type":"object","properties":{"tags":{"type":"array","items":{"type":"object","properties":{"x":{"type":"string"}}}}}}}}}`, "properties.rows.items.properties.tags.type"},+ {"negative maxItems", `{"type":"object","properties":{"rows":{"type":"array","maxItems":-1,"items":{"type":"object","properties":{"x":{"type":"string"}}}}}}`, "properties.rows.maxItems"},}for _, tc := range tests {t.Run(tc.name, func(t *testing.T) {@@ -362,7 +348,6 @@ func TestParseSchema_ValidFlatSchema(t *testing.T) {if len(s.Properties) != 3 {t.Fatalf("expected 3 properties, got %d", len(s.Properties))}- // Deterministic (alphabetical) property order.wantOrder := []string{"in_stock", "name", "price"}for i, p := range s.Properties {if p.Name != wantOrder[i] {diff --git a/internal/extract/group.go b/internal/extract/group.gonew file mode 100644index 00000000..512b86c8--- /dev/null+++ b/internal/extract/group.go@@ -0,0 +1,293 @@+package extract++import (+ "sort"+ "strings"++ "github.com/pinchtab/pinchtab/internal/bridge/observe"+ "github.com/pinchtab/semantic"+)++const (+ minRepeats = 3+ minContainerRepeats = 2+ sampleItems = 3+)++var containerRoles = map[string]bool{"list": true, "table": true, "rowgroup": true, "grid": true, "feed": true}++type group struct {+ container int+ items []int+ columns []int+ score float64+}++func resolveArray(prop Property, v view, opts Options) (FieldResult, any, bool) {+ g, fr, ok := chooseGroup(prop, v, opts)+ if !ok {+ return fr, nil, false+ }+ items := newItemResolver(g, *prop.Items, v, opts)+ limit := opts.MaxItems+ if prop.MaxItems > 0 && prop.MaxItems < limit {+ limit = prop.MaxItems+ }+ data := []map[string]any{}+ for _, item := range g.items {+ if len(data) == limit {+ fr.Truncated = true+ break+ }+ res := items.resolve(item)+ if len(res.Data) == 0 {+ continue+ }+ data = append(data, res.Data)+ fr.Items = append(fr.Items, ItemResult{Ref: v.nodes[item].Ref, Fields: res.Fields})+ }+ if len(data) < prop.MinItems {+ return FieldResult{Ref: fr.Ref, Score: fr.Score, Confidence: fr.Confidence, Reason: reasonTooFewItems}, nil, false+ }+ return fr, data, true+}++func chooseGroup(prop Property, v view, opts Options) (group, FieldResult, bool) {+ var candidates []group+ if prop.scope.kind != targetNone {+ node, fr, ok := matchTarget(prop.scope, "", v, opts)+ if !ok {+ fr.Reason = reasonScopeNotFound+ return group{}, fr, false+ }+ g, ok := groupAt(v, v.index[node.Ref], 1)+ if !ok {+ return group{}, FieldResult{Ref: node.Ref, Confidence: semantic.CalibrateConfidence(0), Reason: reasonNoRepeatedGroup}, false+ }+ candidates = []group{g}+ } else {+ candidates = detectGroups(v)+ }++ for i := range candidates {+ candidates[i].score = scoreGroup(candidates[i], *prop.Items, v, opts)+ }+ sort.SliceStable(candidates, func(i, j int) bool {+ a, b := candidates[i], candidates[j]+ if a.score != b.score {+ return a.score > b.score+ }+ if len(a.items) != len(b.items) {+ return len(a.items) > len(b.items)+ }+ return a.container < b.container+ })+ if len(candidates) == 0 || (prop.scope.kind == targetNone && candidates[0].score == 0) {+ return group{}, FieldResult{Confidence: semantic.CalibrateConfidence(0), Reason: reasonNoRepeatedGroup}, false+ }+ best := candidates[0]+ return best, FieldResult{Ref: v.nodes[best.container].Ref, Score: best.score, Confidence: semantic.CalibrateConfidence(best.score)}, true+}++func detectGroups(v view) []group {+ var groups []group+ for i := range v.nodes {+ min := minRepeats+ if containerRoles[role(v.nodes[i])] {+ min = minContainerRepeats+ }+ if g, ok := groupAt(v, i, min); ok {+ groups = append(groups, g)+ }+ }+ return groups+}++func groupAt(v view, container, min int) (group, bool) {+ children := v.children(container)+ dominant, count := dominantRole(v, children)+ if count < min || count == 0 {+ return group{}, false+ }+ g := group{container: container}+ for _, c := range children {+ if role(v.nodes[c]) == dominant && !v.isHeaderRow(c) {+ g.items = append(g.items, c)+ }+ }+ if len(g.items) == 0 {+ return group{}, false+ }+ if dominant == "row" {+ g.columns = headerColumns(v, container)+ }+ return g, true+}++func (v view) isHeaderRow(i int) bool {+ if role(v.nodes[i]) != "row" {+ return false+ }+ for _, c := range v.children(i) {+ if role(v.nodes[c]) == "columnheader" {+ return true+ }+ }+ return false+}++func dominantRole(v view, children []int) (string, int) {+ counts := map[string]int{}+ best, bestCount := "", 0+ for _, c := range children {+ r := role(v.nodes[c])+ counts[r]+++ if counts[r] > bestCount {+ best, bestCount = r, counts[r]+ }+ }+ return best, bestCount+}++func headerColumns(v view, container int) []int {+ table := container+ for _, a := range v.ancestors(container) {+ if r := role(v.nodes[a]); r == "table" || r == "grid" {+ table = a+ break+ }+ }+ end := v.subtreeEnd(table)+ for i := table; i < end; i++ {+ if v.isHeaderRow(i) {+ return v.children(i)+ }+ }+ return nil+}++func scoreGroup(g group, schema Schema, v view, opts Options) float64 {+ items := newItemResolver(g, schema, v, opts)+ sample := g.items+ if len(sample) > sampleItems {+ sample = sample[:sampleItems]+ }+ resolved := 0+ for _, item := range sample {+ resolved += len(items.resolve(item).Data)+ }+ return roundScore(float64(resolved) / float64(len(sample)*len(schema.Properties)))+}++type itemResolver struct {+ schema Schema+ v view+ opts Options+ columns map[string]columnField+}++type columnField struct {+ index int+ field FieldResult+}++func newItemResolver(g group, schema Schema, v view, opts Options) itemResolver {+ r := itemResolver{schema: schema, v: v, opts: opts}+ if g.columns == nil {+ return r+ }+ header := make([]observe.A11yNode, len(g.columns))+ position := make(map[string]int, len(g.columns))+ for i, c := range g.columns {+ header[i] = v.nodes[c]+ position[v.nodes[c].Ref] = i+ }+ headerView := newView(header)+ r.columns = map[string]columnField{}+ for _, prop := range schema.Properties {+ node, fr, ok := matchTarget(prop.hint, fieldQuery(prop), headerView, opts)+ if !ok {+ continue+ }+ r.columns[prop.Name] = columnField{index: position[node.Ref], field: fr}+ }+ return r+}++func (r itemResolver) resolve(item int) Result {+ if r.columns == nil {+ return resolveObject(r.schema, r.v.descendants(item), r.opts)+ }+ cells := r.v.children(item)+ result := Result{Data: map[string]any{}, Fields: map[string]FieldResult{}}+ for _, prop := range r.schema.Properties {+ fr, value, ok := r.resolveCell(prop, cells)+ result.Fields[prop.Name] = fr+ if ok {+ result.Data[prop.Name] = value+ } else if prop.Required {+ result.Missing = append(result.Missing, prop.Name)+ }+ }+ sort.Strings(result.Missing)+ return result+}++func (r itemResolver) resolveCell(prop Property, cells []int) (FieldResult, any, bool) {+ col, ok := r.columns[prop.Name]+ if !ok {+ return FieldResult{Confidence: semantic.CalibrateConfidence(0), Reason: reasonNoMatch}, nil, false+ }+ if col.index >= len(cells) {+ return FieldResult{Score: col.field.Score, Confidence: col.field.Confidence, Reason: reasonNoMatch}, nil, false+ }+ cell := r.v.nodes[cells[col.index]]+ fr := FieldResult{Ref: cell.Ref, Score: col.field.Score, Confidence: col.field.Confidence}+ value, source, ok := readValue(prop.Type, cell)+ fr.Source = source+ if !ok {+ fr.Reason = coercionReason(prop.Type)+ return fr, nil, false+ }+ return fr, value, true+}++func role(n observe.A11yNode) string {+ return strings.ToLower(strings.TrimSpace(n.Role))+}++func (v view) subtreeEnd(i int) int {+ depth := v.nodes[i].Depth+ end := i + 1+ for end < len(v.nodes) && v.nodes[end].Depth > depth {+ end+++ }+ return end+}++func (v view) children(i int) []int {+ var children []int+ depth := v.nodes[i].Depth + 1+ for j, end := i+1, v.subtreeEnd(i); j < end; j++ {+ if v.nodes[j].Depth == depth {+ children = append(children, j)+ }+ }+ return children+}++func (v view) descendants(i int) view {+ return newView(v.nodes[i+1 : v.subtreeEnd(i)])+}++func (v view) ancestors(i int) []int {+ var ancestors []int+ depth := v.nodes[i].Depth+ for j := i - 1; j >= 0; j-- {+ if v.nodes[j].Depth < depth {+ ancestors = append(ancestors, j)+ depth = v.nodes[j].Depth+ }+ }+ return ancestors+}diff --git a/internal/extract/group_test.go b/internal/extract/group_test.gonew file mode 100644index 00000000..cf17c040--- /dev/null+++ b/internal/extract/group_test.go@@ -0,0 +1,278 @@+package extract++import (+ "reflect"+ "testing"++ "github.com/pinchtab/pinchtab/internal/bridge/observe"+)++const productListSchema = `{"type":"object","required":["products"],"properties":{+ "products":{"type":"array","items":{"type":"object","required":["name","price"],"properties":{+ "name":{"type":"string","description":"product name","x-pinchtab-hint":"role:heading"},+ "price":{"type":"number","description":"product price"},+ "rating":{"type":"number","description":"rating out of 5"}}}}}}`++const ordersSchema = `{"type":"object","properties":{+ "orders":{"type":"array","items":{"type":"object","properties":{+ "order":{"type":"integer","description":"order number"},+ "customer":{"type":"string","description":"customer name"},+ "total":{"type":"number","description":"order total"}}}}}}`++func items(t *testing.T, got Result, prop string) []map[string]any {+ t.Helper()+ list, ok := got.Data[prop].([]map[string]any)+ if !ok {+ t.Fatalf("data[%q] = %#v (field %+v), want an array", prop, got.Data[prop], got.Fields[prop])+ }+ return list+}++func TestResolveArray_ProductGridFixture(t *testing.T) {+ got := Resolve(mustSchema(t, productListSchema), loadSnapshot(t, "extract-list.json"), Options{})+ list := items(t, got, "products")+ want := []map[string]any{+ {"name": "Sony WH-1000XM5", "price": 399.0, "rating": 4.7},+ {"name": "Bose QuietComfort Ultra", "price": 429.0, "rating": 4.5},+ {"name": "Apple AirPods Max", "price": 549.0, "rating": 4.6},+ {"name": "Sennheiser Momentum 4", "price": 349.95, "rating": 4.4},+ {"name": "Bowers & Wilkins Px8", "price": 699.0, "rating": 4.3},+ {"name": "Beats Studio Pro", "price": 349.99, "rating": 4.2},+ }+ if !reflect.DeepEqual(list, want) {+ t.Fatalf("products =\n%v\nwant\n%v", list, want)+ }+ fr := got.Fields["products"]+ if fr.Ref != "e20" {+ t.Errorf("container ref = %q, want e20 (products region)", fr.Ref)+ }+ wantRefs := []string{"e21", "e28", "e35", "e42", "e49", "e56"}+ for i, ir := range fr.Items {+ if ir.Ref != wantRefs[i] {+ t.Errorf("item %d ref = %q, want %q", i, ir.Ref, wantRefs[i])+ }+ }+ if fr.Items[0].Fields["price"].Ref != "e24" || fr.Items[1].Fields["name"].Ref != "e29" {+ t.Errorf("per-item refs = %+v / %+v", fr.Items[0].Fields, fr.Items[1].Fields)+ }+ if fr.Truncated || len(got.Missing) != 0 {+ t.Errorf("truncated=%v missing=%v", fr.Truncated, got.Missing)+ }+}++func TestResolveArray_TableFixture(t *testing.T) {+ got := Resolve(mustSchema(t, ordersSchema), loadSnapshot(t, "extract-list.json"), Options{})+ list := items(t, got, "orders")+ want := []map[string]any{+ {"order": int64(1001), "customer": "Alice Johnson", "total": 399.0},+ {"order": int64(1002), "customer": "Bob Smith", "total": 429.0},+ {"order": int64(1003), "customer": "Carol White", "total": 549.0},+ {"order": int64(1004), "customer": "Dan Brown", "total": 349.95},+ {"order": int64(1005), "customer": "Eve Black", "total": 699.0},+ }+ if !reflect.DeepEqual(list, want) {+ t.Fatalf("orders =\n%v\nwant\n%v", list, want)+ }+ fr := got.Fields["orders"]+ if fr.Ref != "e63" && fr.Ref != "e64" {+ t.Errorf("container ref = %q, want the table or its body rowgroup", fr.Ref)+ }+ if fr.Items[0].Ref != "e72" || fr.Items[0].Fields["customer"].Ref != "e75" || fr.Items[4].Fields["total"].Ref != "e105" {+ t.Errorf("row refs = %+v", fr.Items)+ }+}++func searchNodes() []observe.A11yNode {+ return []observe.A11yNode{+ {Ref: "e1", Role: "main", Name: "Results", Depth: 0},+ {Ref: "e2", Role: "list", Depth: 1},+ {Ref: "e3", Role: "listitem", Depth: 2},+ {Ref: "e4", Role: "link", Name: "Result title", Text: "Go by Example", Depth: 3},+ {Ref: "e5", Role: "text", Name: "Snippet", Text: "Hands-on introduction to Go.", Depth: 3},+ {Ref: "e6", Role: "listitem", Depth: 2},+ {Ref: "e7", Role: "link", Name: "Result title", Text: "A Tour of Go", Depth: 3},+ {Ref: "e8", Role: "text", Name: "Snippet", Text: "Interactive tour.", Depth: 3},+ {Ref: "e9", Role: "listitem", Depth: 2},+ {Ref: "e10", Role: "link", Name: "Result title", Text: "Effective Go", Depth: 3},+ {Ref: "e11", Role: "listitem", Depth: 2},+ {Ref: "e12", Role: "link", Name: "Result title", Text: "Go FAQ", Depth: 3},+ {Ref: "e13", Role: "text", Name: "Snippet", Text: "Frequently asked questions.", Depth: 3},+ }+}++const searchSchema = `{"type":"object","properties":{+ "results":{"type":"array","items":{"type":"object","properties":{+ "title":{"type":"string","description":"result title"},+ "snippet":{"type":"string","x-pinchtab-hint":"role:text Snippet"}}}}}}`++func TestResolveArray_SearchResultsList(t *testing.T) {+ got := Resolve(mustSchema(t, searchSchema), searchNodes(), Options{})+ list := items(t, got, "results")+ want := []map[string]any{+ {"title": "Go by Example", "snippet": "Hands-on introduction to Go."},+ {"title": "A Tour of Go", "snippet": "Interactive tour."},+ {"title": "Effective Go"},+ {"title": "Go FAQ", "snippet": "Frequently asked questions."},+ }+ if !reflect.DeepEqual(list, want) {+ t.Fatalf("results =\n%v\nwant\n%v", list, want)+ }+ fr := got.Fields["results"]+ if fr.Ref != "e2" || fr.Items[2].Ref != "e9" || fr.Items[2].Fields["title"].Ref != "e10" {+ t.Errorf("refs = %q %+v", fr.Ref, fr.Items)+ }+}++func TestResolveArray_FieldAbsentFromOneItemStaysMissing(t *testing.T) {+ got := Resolve(mustSchema(t, searchSchema), searchNodes(), Options{})+ third := got.Fields["results"].Items[2]+ if _, present := items(t, got, "results")[2]["snippet"]; present {+ t.Fatalf("item 3 has no snippet node but resolved one: %+v", third.Fields["snippet"])+ }+ if third.Fields["snippet"].Reason != reasonNoMatch || third.Fields["snippet"].Ref != "" {+ t.Errorf("item 3 snippet = %+v, want no_match without a ref", third.Fields["snippet"])+ }+}++func TestResolveArray_AmbiguousGroupsPickBestResolving(t *testing.T) {+ nodes := loadSnapshot(t, "extract-list.json")+ products := Resolve(mustSchema(t, productListSchema), nodes, Options{})+ if products.Fields["products"].Ref != "e20" {+ t.Errorf("products chose %q over the products region e20", products.Fields["products"].Ref)+ }++ menu := mustSchema(t, `{"type":"object","properties":{+ "menu":{"type":"array","items":{"type":"object","properties":{+ "link":{"type":"string","x-pinchtab-hint":"role:link"}}}}}}`)+ got := Resolve(menu, nodes, Options{})+ if got.Fields["menu"].Ref != "e2" {+ t.Fatalf("menu chose %q over the nav list e2 (%+v)", got.Fields["menu"].Ref, got.Fields["menu"])+ }+ want := []map[string]any{{"link": "Home"}, {"link": "Shop"}, {"link": "About"}, {"link": "Contact"}}+ if list := items(t, got, "menu"); !reflect.DeepEqual(list, want) {+ t.Errorf("menu = %v, want %v", list, want)+ }+}++func TestResolveArray_ScopeForcesContainer(t *testing.T) {+ nodes := loadSnapshot(t, "extract-list.json")+ scoped := mustSchema(t, `{"type":"object","properties":{+ "links":{"type":"array","x-pinchtab-scope":"role:list","items":{"type":"object","properties":{+ "name":{"type":"string","x-pinchtab-hint":"role:link"}}}}}}`)+ got := Resolve(scoped, nodes, Options{})+ if got.Fields["links"].Ref != "e2" {+ t.Fatalf("scope should force the nav list e2, got %q (%+v)", got.Fields["links"].Ref, got.Fields["links"])+ }+ if list := items(t, got, "links"); len(list) != 4 {+ t.Errorf("links = %v, want 4 nav items", list)+ }++ byRef := mustSchema(t, `{"type":"object","properties":{+ "rows":{"type":"array","x-pinchtab-scope":"ref:e64","items":{"type":"object","properties":{+ "order":{"type":"integer","description":"order number"}}}}}}`)+ got = Resolve(byRef, nodes, Options{})+ if got.Fields["rows"].Ref != "e64" || len(items(t, got, "rows")) != 5 {+ t.Errorf("ref scope = %+v data=%v", got.Fields["rows"], got.Data["rows"])+ }++ absent := mustSchema(t, `{"type":"object","required":["rows"],"properties":{+ "rows":{"type":"array","x-pinchtab-scope":"ref:e999","items":{"type":"object","properties":{+ "order":{"type":"integer"}}}}}}`)+ got = Resolve(absent, nodes, Options{})+ if _, present := got.Data["rows"]; present {+ t.Fatalf("rows must be missing when the scope resolves nothing")+ }+ if got.Fields["rows"].Reason != reasonScopeNotFound || !reflect.DeepEqual(got.Missing, []string{"rows"}) {+ t.Errorf("field = %+v missing = %v", got.Fields["rows"], got.Missing)+ }+}++func TestResolveArray_MaxItemsCapsAndReportsTruncated(t *testing.T) {+ nodes := loadSnapshot(t, "extract-list.json")+ capped := mustSchema(t, `{"type":"object","properties":{+ "products":{"type":"array","maxItems":2,"items":{"type":"object","properties":{+ "name":{"type":"string","x-pinchtab-hint":"role:heading"}}}}}}`)+ got := Resolve(capped, nodes, Options{})+ if n := len(items(t, got, "products")); n != 2 || !got.Fields["products"].Truncated {+ t.Errorf("schema maxItems: len=%d truncated=%v", n, got.Fields["products"].Truncated)+ }++ got = Resolve(mustSchema(t, productListSchema), nodes, Options{MaxItems: 4})+ if n := len(items(t, got, "products")); n != 4 || !got.Fields["products"].Truncated {+ t.Errorf("Options.MaxItems: len=%d truncated=%v", n, got.Fields["products"].Truncated)+ }++ got = Resolve(mustSchema(t, productListSchema), nodes, Options{MaxItems: 6})+ if n := len(items(t, got, "products")); n != 6 || got.Fields["products"].Truncated {+ t.Errorf("exact cap: len=%d truncated=%v", n, got.Fields["products"].Truncated)+ }+}++func TestResolveArray_MinItemsLeavesPropertyMissing(t *testing.T) {+ schema := mustSchema(t, `{"type":"object","required":["products"],"properties":{+ "products":{"type":"array","minItems":10,"items":{"type":"object","properties":{+ "name":{"type":"string","x-pinchtab-hint":"role:heading"}}}}}}`)+ got := Resolve(schema, loadSnapshot(t, "extract-list.json"), Options{})+ if _, present := got.Data["products"]; present {+ t.Fatalf("products must be missing below minItems")+ }+ if got.Fields["products"].Reason != reasonTooFewItems || len(got.Fields["products"].Items) != 0 {+ t.Errorf("field = %+v", got.Fields["products"])+ }+}++func TestResolveArray_NoRepeatedGroup(t *testing.T) {+ got := Resolve(mustSchema(t, productListSchema), productNodes(), Options{})+ if _, present := got.Data["products"]; present {+ t.Fatalf("flat product page has no repeated group")+ }+ if got.Fields["products"].Reason != reasonNoRepeatedGroup || !reflect.DeepEqual(got.Missing, []string{"products"}) {+ t.Errorf("field = %+v missing = %v", got.Fields["products"], got.Missing)+ }+}++func TestResolveArray_Deterministic(t *testing.T) {+ nodes := loadSnapshot(t, "extract-list.json")+ first := Resolve(mustSchema(t, productListSchema), nodes, Options{})+ second := Resolve(mustSchema(t, productListSchema), nodes, Options{})+ if !reflect.DeepEqual(first, second) {+ t.Fatalf("array resolution is not stable:\n%+v\n%+v", first, second)+ }+}++func TestView_ChildrenAndSubtreeFromDepth(t *testing.T) {+ v := newView(searchNodes())+ if end := v.subtreeEnd(v.index["e3"]); end != v.index["e6"] {+ t.Errorf("subtree of e3 ends at %d, want index of e6 %d", end, v.index["e6"])+ }+ var refs []string+ for _, c := range v.children(v.index["e2"]) {+ refs = append(refs, v.nodes[c].Ref)+ }+ if !reflect.DeepEqual(refs, []string{"e3", "e6", "e9", "e11"}) {+ t.Errorf("children of e2 = %v", refs)+ }+ if got := v.descendants(v.index["e6"]).nodes; len(got) != 2 || got[0].Ref != "e7" || got[1].Ref != "e8" {+ t.Errorf("descendants of e6 = %v", got)+ }+ var anc []string+ for _, a := range v.ancestors(v.index["e12"]) {+ anc = append(anc, v.nodes[a].Ref)+ }+ if !reflect.DeepEqual(anc, []string{"e11", "e2", "e1"}) {+ t.Errorf("ancestors of e12 = %v", anc)+ }+}++func TestResolveArray_GroupResolvingNoFieldIsNoRepeatedGroup(t *testing.T) {+ schema := mustSchema(t, `{"type":"object","properties":{+ "results":{"type":"array","items":{"type":"object","properties":{+ "price":{"type":"number","x-pinchtab-hint":"role:link"}}}}}}`)+ got := Resolve(schema, searchNodes(), Options{})+ if _, present := got.Data["results"]; present {+ t.Fatalf("a group whose items resolve no field must not be returned: %v", got.Data["results"])+ }+ if got.Fields["results"].Reason != reasonNoRepeatedGroup || got.Fields["results"].Ref != "" {+ t.Errorf("field = %+v", got.Fields["results"])+ }+}diff --git a/internal/extract/resolve.go b/internal/extract/resolve.goindex 6fe7f837..de1bd869 100644--- a/internal/extract/resolve.go+++ b/internal/extract/resolve.go@@ -13,51 +13,80 @@ import ("github.com/pinchtab/semantic")-// Reasons a field is left missing rather than filled with a wrong-typed value.const (- reasonNoMatch = "no_match"- reasonNotNumeric = "not_numeric"- reasonNotBoolean = "not_boolean"- reasonUnsupported = "unsupported"- reasonRefNotFound = "ref_not_found"+ reasonNoMatch = "no_match"+ reasonNotNumeric = "not_numeric"+ reasonNotBoolean = "not_boolean"+ reasonRefNotFound = "ref_not_found"+ reasonScopeNotFound = "scope_not_found"+ reasonNoRepeatedGroup = "no_repeated_group"+ reasonTooFewItems = "too_few_items")-// Field value sources, in the order they are tried.const (sourceValue = "value"sourceText = "text"sourceName = "name"sourceChecked = "checked"+ sourceHint = "hint"+)++const (+ defaultThreshold = 0.3+ defaultMaxItems = 100)-// Options tunes resolution. Zero values fall back to the same defaults /find-// uses (threshold 0.3, the shared combined matcher).type Options struct {Threshold float64LexicalWeight float64EmbeddingWeight float64- // Matcher overrides the default combined matcher; nil uses the shared one.- Matcher semantic.ElementMatcher+ MaxItems int+ Matcher semantic.ElementMatcher}-// FieldResult is the per-field outcome. Ref/Score/Confidence let an agent fall-// back to /find on a low-confidence field; Reason explains a missing field.type FieldResult struct {- Ref string `json:"ref,omitempty"`- Score float64 `json:"score"`- Confidence string `json:"confidence"`- Source string `json:"source,omitempty"`- Reason string `json:"reason,omitempty"`+ Ref string `json:"ref,omitempty"`+ Score float64 `json:"score"`+ Confidence string `json:"confidence"`+ Source string `json:"source,omitempty"`+ Reason string `json:"reason,omitempty"`+ Items []ItemResult `json:"items,omitempty"`+ Truncated bool `json:"truncated,omitempty"`+}++type ItemResult struct {+ Ref string `json:"ref"`+ Fields map[string]FieldResult `json:"fields"`}-// Result is the extraction outcome: typed data, per-field diagnostics, and the-// required fields that could not be filled (never invented).type Result struct {Data map[string]any `json:"data"`Fields map[string]FieldResult `json:"fields"`Missing []string `json:"missing"`}+type view struct {+ nodes []observe.A11yNode+ descs []semantic.ElementDescriptor+ index map[string]int+}++func newView(ordered []observe.A11yNode) view {+ index := make(map[string]int, len(ordered))+ for i, n := range ordered {+ index[n.Ref] = i+ }+ return view{nodes: ordered, descs: semdesc.Build(ordered), index: index}+}++func (v view) node(ref string) (observe.A11yNode, bool) {+ i, ok := v.index[ref]+ if !ok {+ return observe.A11yNode{}, false+ }+ return v.nodes[i], true+}+var (defaultMatcherOnce sync.OncedefaultMatcher semantic.ElementMatcher@@ -70,31 +99,35 @@ func sharedMatcher() semantic.ElementMatcher {return defaultMatcher}-// Resolve fills each schema property against the node list. It is deterministic:-// nodes are canonicalised to document order (by ref) before matching, so the-// same schema over the same nodes — in any input order — yields identical output.func Resolve(schema Schema, nodes []observe.A11yNode, opts Options) Result {if opts.Threshold <= 0 {- opts.Threshold = 0.3+ opts.Threshold = defaultThreshold}- matcher := opts.Matcher- if matcher == nil {- matcher = sharedMatcher()+ if opts.MaxItems <= 0 {+ opts.MaxItems = defaultMaxItems}-- ordered := canonicalOrder(nodes)- byRef := make(map[string]observe.A11yNode, len(ordered))- for _, n := range ordered {- byRef[n.Ref] = n+ if opts.Matcher == nil {+ opts.Matcher = sharedMatcher()}- descs := semdesc.Build(ordered)+ return resolveObject(schema, newView(canonicalOrder(nodes)), opts)+}+func resolveObject(schema Schema, v view, opts Options) Result {result := Result{Data: map[string]any{},Fields: map[string]FieldResult{},}for _, prop := range schema.Properties {- fr, value, ok := resolveField(prop, descs, byRef, matcher, opts)+ var (+ fr FieldResult+ value any+ ok bool+ )+ if prop.Type == TypeArray {+ fr, value, ok = resolveArray(prop, v, opts)+ } else {+ fr, value, ok = resolveField(prop, v, opts)+ }result.Fields[prop.Name] = frif ok {result.Data[prop.Name] = value@@ -106,12 +139,8 @@ func Resolve(schema Schema, nodes []observe.A11yNode, opts Options) Result {return result}-func resolveField(prop Property, descs []semantic.ElementDescriptor, byRef map[string]observe.A11yNode, matcher semantic.ElementMatcher, opts Options) (FieldResult, any, bool) {- if prop.Type == TypeArray {- return FieldResult{Confidence: semantic.CalibrateConfidence(0), Reason: reasonUnsupported}, nil, false- }-- node, fr, ok := matchNode(prop, descs, byRef, matcher, opts)+func resolveField(prop Property, v view, opts Options) (FieldResult, any, bool) {+ node, fr, ok := matchTarget(prop.hint, fieldQuery(prop), v, opts)if !ok {return fr, nil, false}@@ -125,12 +154,10 @@ func resolveField(prop Property, descs []semantic.ElementDescriptor, byRef map[sreturn fr, value, true}-// matchNode finds the best node for a property: a ref hint selects verbatim,-// otherwise the matcher scores the name+description(+hint) query.-func matchNode(prop Property, descs []semantic.ElementDescriptor, byRef map[string]observe.A11yNode, matcher semantic.ElementMatcher, opts Options) (observe.A11yNode, FieldResult, bool) {- if prop.hintKindResolved == hintRef {- node, found := byRef[prop.hintValue]- fr := FieldResult{Ref: prop.hintValue, Score: 1, Confidence: semantic.CalibrateConfidence(1), Source: "hint"}+func matchTarget(tg target, fallbackQuery string, v view, opts Options) (observe.A11yNode, FieldResult, bool) {+ if tg.kind == targetRef {+ node, found := v.node(tg.value)+ fr := FieldResult{Ref: tg.value, Score: 1, Confidence: semantic.CalibrateConfidence(1), Source: sourceHint}if !found {fr.Score = 0fr.Confidence = semantic.CalibrateConfidence(0)@@ -140,13 +167,13 @@ func matchNode(prop Property, descs []semantic.ElementDescriptor, byRef map[strireturn node, fr, true}- // TopK spans every descriptor and the winner is chosen here, not taken from- // res.BestRef: the combined matcher merges its lexical and embedding halves- // concurrently, so its tie ordering is not stable. Per-ref scores are, so a- // deterministic pick (score desc, then document order) makes Resolve stable.- res, err := matcher.Find(context.Background(), fieldQuery(prop), descs, semantic.FindOptions{+ query := fallbackQuery+ if tg.kind == targetQuery {+ query = tg.value+ }+ res, err := opts.Matcher.Find(context.Background(), query, v.descs, semantic.FindOptions{Threshold: opts.Threshold,- TopK: len(descs),+ TopK: len(v.descs),LexicalWeight: opts.LexicalWeight,EmbeddingWeight: opts.EmbeddingWeight,})@@ -158,7 +185,7 @@ func matchNode(prop Property, descs []semantic.ElementDescriptor, byRef map[strireturn observe.A11yNode{}, fr, false}fr.Ref = best.Ref- node, found := byRef[best.Ref]+ node, found := v.node(best.Ref)if !found {fr.Reason = reasonNoMatchreturn observe.A11yNode{}, fr, false@@ -166,11 +193,6 @@ func matchNode(prop Property, descs []semantic.ElementDescriptor, byRef map[strireturn node, fr, true}-// pickBest chooses the winning match deterministically: highest score, ties-// broken by document order (numeric ref ascending). Scores are compared rounded-// because the combined matcher's concurrent merge is only stable to ~1 ULP, so-// two matches within rounding are a tie the ref order settles. ok is false when-// empty.func pickBest(matches []semantic.ElementMatch) (semantic.ElementMatch, bool) {best, ok := semantic.ElementMatch{}, falsevar bestScore float64@@ -184,24 +206,14 @@ func pickBest(matches []semantic.ElementMatch) (semantic.ElementMatch, bool) {return best, ok}-// roundScore quantises a heuristic score to 6 decimals so equal-in-practice-// scores compare equal across runs despite the matcher's 1-ULP jitter.func roundScore(s float64) float64 {return math.Round(s*1e6) / 1e6}-// fieldQuery builds the matcher query. A resolved hint query wins over the-// name-based query; otherwise name and description are combined.func fieldQuery(prop Property) string {- if prop.hintKindResolved == hintQuery {- return prop.hintValue- }return strings.TrimSpace(prop.Name + " " + prop.Description)}-// readValue reads the node's value for a type and coerces it. Priority is-// Value, Text, Name; booleans consult Checked first. A coercion failure returns-// ok=false so the field is left missing rather than wrong-typed.func readValue(t Type, node observe.A11yNode) (any, string, bool) {if t == TypeBoolean {if node.Checked == observe.CheckedTrue || node.Checked == observe.CheckedFalse || node.Checked == observe.CheckedMixed {@@ -262,9 +274,6 @@ func coercionReason(t Type) string {}}-// canonicalOrder returns a copy of nodes sorted into document order by ref, so-// resolution is invariant to input node order. Snapshot refs ("e5", "e12") are-// assigned in pre-order, so their numeric order is document order.func canonicalOrder(nodes []observe.A11yNode) []observe.A11yNode {ordered := make([]observe.A11yNode, len(nodes))copy(ordered, nodes)@@ -281,7 +290,7 @@ func refLess(a, b string) bool {return na < nb}if oka != okb {- return oka // numeric refs sort before non-numeric ones+ return oka}return a < b}diff --git a/internal/extract/schema.go b/internal/extract/schema.goindex 98f64d04..23adee03 100644--- a/internal/extract/schema.go+++ b/internal/extract/schema.go@@ -1,8 +1,3 @@-// Package extract fills a flat JSON-schema against a captured accessibility-// snapshot using the same semantic matcher that backs /find. It is model-free:-// no network, no model download, no browser. Given a schema and a node list it-// returns typed data plus per-field ref/score/confidence so an agent can fall-// back to /find on a low-confidence field.package extractimport (@@ -14,7 +9,6 @@ import ("github.com/pinchtab/pinchtab/internal/selector")-// Type is a supported JSON-schema property type.type Type stringconst (@@ -25,35 +19,38 @@ const (TypeArray Type = "array")-// hintKind classifies how a resolved x-pinchtab-hint drives matching.-type hintKind int+type target struct {+ kind targetKind+ value string+}++type targetKind intconst (- hintNone hintKind = iota- hintQuery // a natural-language query string for the matcher- hintRef // a direct ref to select verbatim+ targetNone targetKind = iota+ targetQuery+ targetRef)-// Property is one resolved schema property, ready to match.type Property struct {Name stringType TypeDescription stringRequired boolHint string+ Items *Schema+ Scope string+ MinItems int+ MaxItems int- // hintKindResolved and hintValue are computed by ParseSchema so Resolve- // never re-parses the hint (and so hint errors surface at parse time).- hintKindResolved hintKind- hintValue string+ hint target+ scope target}-// Schema is a parsed object schema with properties in a deterministic order.type Schema struct {Properties []Property}-// UnsupportedError names the schema path that carries an unsupported construct.type UnsupportedError struct {Path stringReason string@@ -63,7 +60,6 @@ func (e *UnsupportedError) Error() string {return fmt.Sprintf("%s: %s", e.Path, e.Reason)}-// rawSchema mirrors the accepted JSON-schema subset for decoding.type rawSchema struct {Type string `json:"type"`Required []string `json:"required"`@@ -74,23 +70,27 @@ type rawProperty struct {Type string `json:"type"`Description string `json:"description"`Hint string `json:"x-pinchtab-hint"`+ Scope string `json:"x-pinchtab-scope"`Properties json.RawMessage `json:"properties"`+ Items json.RawMessage `json:"items"`+ MinItems int `json:"minItems"`+ MaxItems int `json:"maxItems"`}-// ParseSchema parses a flat object schema. Unsupported constructs return an-// *UnsupportedError naming the offending path (e.g.-// "properties.price.type: object is not supported"). Arrays parse successfully-// and are reported as unsupported at resolution time, per the follow-up task.func ParseSchema(data []byte) (Schema, error) {+ return parseObject(data, "", true)+}++func parseObject(data []byte, path string, allowArrays bool) (Schema, error) {var raw rawSchemaif err := json.Unmarshal(data, &raw); err != nil {return Schema{}, fmt.Errorf("parse schema: %w", err)}if raw.Type != "" && raw.Type != "object" {- return Schema{}, &UnsupportedError{Path: "type", Reason: raw.Type + " is not supported"}+ return Schema{}, &UnsupportedError{Path: join(path, "type"), Reason: raw.Type + " is not supported"}}if len(raw.Properties) == 0 {- return Schema{}, &UnsupportedError{Path: "properties", Reason: "an object schema with properties is required"}+ return Schema{}, &UnsupportedError{Path: join(path, "properties"), Reason: "an object schema with properties is required"}}required := make(map[string]bool, len(raw.Required))@@ -106,8 +106,7 @@ func ParseSchema(data []byte) (Schema, error) {props := make([]Property, 0, len(names))for _, name := range names {- rp := raw.Properties[name]- prop, err := parseProperty(name, rp, required[name])+ prop, err := parseProperty(join(path, "properties."+name), name, raw.Properties[name], required[name], allowArrays)if err != nil {return Schema{}, err}@@ -116,11 +115,20 @@ func ParseSchema(data []byte) (Schema, error) {return Schema{Properties: props}, nil}-func parseProperty(name string, rp rawProperty, required bool) (Property, error) {- path := "properties." + name+func join(path, leaf string) string {+ if path == "" {+ return leaf+ }+ return path + "." + leaf+}++func parseProperty(path, name string, rp rawProperty, required, allowArrays bool) (Property, error) {switch Type(rp.Type) {- case TypeString, TypeNumber, TypeInteger, TypeBoolean, TypeArray:- // supported (array resolves to unsupported, but parses)+ case TypeString, TypeNumber, TypeInteger, TypeBoolean:+ case TypeArray:+ if !allowArrays {+ return Property{}, &UnsupportedError{Path: path + ".type", Reason: "nested arrays are not supported"}+ }case "":return Property{}, &UnsupportedError{Path: path + ".type", Reason: "a property type is required"}default:@@ -129,6 +137,9 @@ func parseProperty(name string, rp rawProperty, required bool) (Property, error)if len(rp.Properties) > 0 {return Property{}, &UnsupportedError{Path: path + ".properties", Reason: "nested object properties are not supported"}}+ if rp.MinItems < 0 || rp.MaxItems < 0 {+ return Property{}, &UnsupportedError{Path: path + ".maxItems", Reason: "item bounds must not be negative"}+ }prop := Property{Name: name,@@ -136,50 +147,64 @@ func parseProperty(name string, rp rawProperty, required bool) (Property, error)Description: strings.TrimSpace(rp.Description),Required: required,Hint: strings.TrimSpace(rp.Hint),+ Scope: strings.TrimSpace(rp.Scope),+ MinItems: rp.MinItems,+ MaxItems: rp.MaxItems,+ }+ var err error+ if prop.hint, err = parseTarget(prop.Hint, path+".x-pinchtab-hint"); err != nil {+ return Property{}, err}- if err := resolveHint(&prop, path); err != nil {+ if prop.scope, err = parseTarget(prop.Scope, path+".x-pinchtab-scope"); err != nil {return Property{}, err}+ if prop.Type == TypeArray {+ items, err := parseItems(rp.Items, path+".items")+ if err != nil {+ return Property{}, err+ }+ prop.Items = &items+ }return prop, nil}-// resolveHint validates x-pinchtab-hint against the selector kinds a node list-// can answer and caches the matcher-ready form. css:/xpath: need a browser and-// return an *UnsupportedError naming the property path.-func resolveHint(prop *Property, path string) error {- hint := prop.Hint- if hint == "" {- prop.hintKindResolved = hintNone- return nil+func parseItems(raw json.RawMessage, path string) (Schema, error) {+ if len(raw) == 0 {+ return Schema{}, &UnsupportedError{Path: path, Reason: "array items must be an object schema"}+ }+ var head struct {+ Type string `json:"type"`}+ if err := json.Unmarshal(raw, &head); err != nil {+ return Schema{}, fmt.Errorf("parse schema: %w", err)+ }+ if head.Type != "object" {+ return Schema{}, &UnsupportedError{Path: path + ".type", Reason: "array items must be an object schema"}+ }+ return parseObject(raw, path, false)+}- hintPath := path + ".x-pinchtab-hint"- if !selector.HasKnownPrefix(hint) {- // A bare hint is a natural-language query verbatim.- prop.hintKindResolved = hintQuery- prop.hintValue = hint- return nil+func parseTarget(raw, path string) (target, error) {+ if raw == "" {+ return target{}, nil+ }+ if !selector.HasKnownPrefix(raw) {+ return target{kind: targetQuery, value: raw}, nil}- sel := selector.Parse(hint)+ sel := selector.Parse(raw)switch sel.Kind {case selector.KindCSS, selector.KindXPath:- return &UnsupportedError{Path: hintPath, Reason: string(sel.Kind) + " selectors need a browser and are not supported"}+ return target{}, &UnsupportedError{Path: path, Reason: string(sel.Kind) + " selectors need a browser and are not supported"}case selector.KindText:- prop.hintKindResolved = hintQuery- prop.hintValue = sel.Value- return nil+ return target{kind: targetQuery, value: sel.Value}, nilcase selector.KindRef:- prop.hintKindResolved = hintRef- prop.hintValue = sel.Value- return nil+ return target{kind: targetRef, value: sel.Value}, nil}query, ok := sel.SemanticQuery()if !ok {- return &UnsupportedError{Path: hintPath, Reason: string(sel.Kind) + " hints are not supported"}+ return target{}, &UnsupportedError{Path: path, Reason: string(sel.Kind) + " selectors are not supported"}}- prop.hintKindResolved = hintQuery- prop.hintValue = query- return nil+ return target{kind: targetQuery, value: query}, nil}diff --git a/internal/extract/testdata/README.md b/internal/extract/testdata/README.mdindex 60469236..7ed47d74 100644--- a/internal/extract/testdata/README.md+++ b/internal/extract/testdata/README.md@@ -1,6 +1,7 @@# extract testdata-Accessibility snapshots used by `TestResolve_FromSnapshotFixtures`. Each file is+Accessibility snapshots used by `TestResolve_FromSnapshotFixtures` and the+`TestResolveArray_*` group tests. Each file isthe `nodes` array of a real `pinchtab snap --json`-shaped capture (the `GET/snapshot` node list), so the unit tests run against the exact node shape thee2e fixtures produce — including the `RootWebArea` root, the `StaticText`@@ -11,11 +12,13 @@ filled by DOM-metadata enrichment.| ---------------------- | ----------------------------------------- || `extract-product.json` | `tests/e2e/fixtures/extract-product.html` || `extract-article.json` | `tests/e2e/fixtures/extract-article.html` |+| `extract-list.json` | `tests/e2e/fixtures/extract-list.html` |## How these were producedCaptured from the e2e Docker stack (`tests/e2e/docker-compose.yml`, the-`pinchtab` + `fixtures` services) at PinchTab commit `dca3d7a9`:+`pinchtab` + `fixtures` services) at PinchTab commit `dca3d7a9`+(`extract-list.json` at `f8f9dcb4`):```cd tests/e2e && docker compose up -d pinchtab fixtures@@ -26,7 +29,10 @@ curl -s http://127.0.0.1:9999/snapshot -H 'Authorization: Bearer e2e-token'# → the `nodes` array committed here, wrapped as {url, title, nodes}```-Both fixtures render identically headed and headless (no JS). Re-capture with the+All fixtures render identically headed and headless (no JS). Re-capture with thesame commands when a fixture changes shape; the volatile `nodeId`/`frameId`fields differ per run and are not asserted (the tests key on `ref`, `role`,-`name`, `text`, `checked`).+`name`, `text`, `checked`). Note that the snapshot carries a single `rowgroup`:+in `extract-list.json` it holds the header row and every body+row, which is why the group detector drops header rows from the items rather+than relying on the rowgroup split.diff --git a/internal/extract/testdata/extract-list.json b/internal/extract/testdata/extract-list.jsonnew file mode 100644index 00000000..badc6cbb--- /dev/null+++ b/internal/extract/testdata/extract-list.json@@ -0,0 +1,1113 @@+{+ "url": "http://fixtures/extract-list.html",+ "title": "Shop — Headphones",+ "nodes": [+ {+ "ref": "e0",+ "role": "RootWebArea",+ "name": "Shop — Headphones",+ "depth": 0,+ "nodeId": 5,+ "frameId": "26AD562E468018844C0E69080272D633",+ "frameUrl": "http://fixtures/extract-list.html"+ },+ {+ "ref": "e1",+ "role": "navigation",+ "name": "Site",+ "depth": 3,+ "label": "Site",+ "text": "Home Shop About Contact",+ "tag": "nav",+ "nodeId": 12,+ "frameId": "26AD562E468018844C0E69080272D633",+ "frameUrl": "http://fixtures/extract-list.html"+ },+ {+ "ref": "e2",+ "role": "list",+ "name": "",+ "depth": 4,+ "text": "Home Shop About Contact",+ "tag": "ul",+ "nodeId": 13,+ "frameId": "26AD562E468018844C0E69080272D633",+ "frameUrl": "http://fixtures/extract-list.html"+ },+ {+ "ref": "e3",+ "role": "listitem",+ "name": "",+ "depth": 5,+ "text": "Home",+ "tag": "li",+ "nodeId": 14,+ "frameId": "26AD562E468018844C0E69080272D633",+ "frameUrl": "http://fixtures/extract-list.html"+ },+ {+ "ref": "e4",+ "role": "ListMarker",+ "name": "• ",+ "depth": 6,+ "tag": "::marker",+ "nodeId": 75,+ "frameId": "26AD562E468018844C0E69080272D633",+ "frameUrl": "http://fixtures/extract-list.html"+ },+ {+ "ref": "e5",+ "role": "link",+ "name": "Home",+ "depth": 6,+ "text": "Home",+ "tag": "a",+ "nodeId": 15,+ "frameId": "26AD562E468018844C0E69080272D633",+ "frameUrl": "http://fixtures/extract-list.html"+ },+ {+ "ref": "e6",+ "role": "StaticText",+ "name": "Home",+ "depth": 7,+ "nodeId": 76,+ "frameId": "26AD562E468018844C0E69080272D633",+ "frameUrl": "http://fixtures/extract-list.html"+ },+ {+ "ref": "e7",+ "role": "listitem",+ "name": "",+ "depth": 5,+ "text": "Shop",+ "tag": "li",+ "nodeId": 16,+ "frameId": "26AD562E468018844C0E69080272D633",+ "frameUrl": "http://fixtures/extract-list.html"+ },+ {+ "ref": "e8",+ "role": "ListMarker",+ "name": "• ",+ "depth": 6,+ "tag": "::marker",+ "nodeId": 77,+ "frameId": "26AD562E468018844C0E69080272D633",+ "frameUrl": "http://fixtures/extract-list.html"+ },+ {+ "ref": "e9",+ "role": "link",+ "name": "Shop",+ "depth": 6,+ "text": "Shop",+ "tag": "a",+ "nodeId": 17,+ "frameId": "26AD562E468018844C0E69080272D633",+ "frameUrl": "http://fixtures/extract-list.html"+ },+ {+ "ref": "e10",+ "role": "StaticText",+ "name": "Shop",+ "depth": 7,+ "nodeId": 78,+ "frameId": "26AD562E468018844C0E69080272D633",+ "frameUrl": "http://fixtures/extract-list.html"+ },+ {+ "ref": "e11",+ "role": "listitem",+ "name": "",+ "depth": 5,+ "text": "About",+ "tag": "li",+ "nodeId": 18,+ "frameId": "26AD562E468018844C0E69080272D633",+ "frameUrl": "http://fixtures/extract-list.html"+ },+ {+ "ref": "e12",+ "role": "ListMarker",+ "name": "• ",+ "depth": 6,+ "tag": "::marker",+ "nodeId": 79,+ "frameId": "26AD562E468018844C0E69080272D633",+ "frameUrl": "http://fixtures/extract-list.html"+ },+ {+ "ref": "e13",+ "role": "link",+ "name": "About",+ "depth": 6,+ "text": "About",+ "tag": "a",+ "nodeId": 19,+ "frameId": "26AD562E468018844C0E69080272D633",+ "frameUrl": "http://fixtures/extract-list.html"+ },+ {+ "ref": "e14",+ "role": "StaticText",+ "name": "About",+ "depth": 7,+ "nodeId": 80,+ "frameId": "26AD562E468018844C0E69080272D633",+ "frameUrl": "http://fixtures/extract-list.html"+ },+ {+ "ref": "e15",+ "role": "listitem",+ "name": "",+ "depth": 5,+ "text": "Contact",+ "tag": "li",+ "nodeId": 20,+ "frameId": "26AD562E468018844C0E69080272D633",+ "frameUrl": "http://fixtures/extract-list.html"+ },+ {+ "ref": "e16",+ "role": "ListMarker",+ "name": "• ",+ "depth": 6,+ "tag": "::marker",+ "nodeId": 81,+ "frameId": "26AD562E468018844C0E69080272D633",+ "frameUrl": "http://fixtures/extract-list.html"+ },+ {+ "ref": "e17",+ "role": "link",+ "name": "Contact",+ "depth": 6,+ "text": "Contact",+ "tag": "a",+ "nodeId": 21,+ "frameId": "26AD562E468018844C0E69080272D633",+ "frameUrl": "http://fixtures/extract-list.html"+ },+ {+ "ref": "e18",+ "role": "StaticText",+ "name": "Contact",+ "depth": 7,+ "nodeId": 82,+ "frameId": "26AD562E468018844C0E69080272D633",+ "frameUrl": "http://fixtures/extract-list.html"+ },+ {+ "ref": "e19",+ "role": "main",+ "name": "Catalogue",+ "depth": 3,+ "label": "Catalogue",+ "text": "Sony WH-1000XM5 $399.00 4.7 out of 5 Bose QuietComfort Ultra $429.00 4.5 out of 5 Apple AirPods Max $549.00 4.6 out of 5 Sennheiser Momentum 4 $349.95 4.4 out of 5 Bowers & Wilkins Px8 $699.00 4.3 out of 5 Beats Studio Pro $349.99 4.2 out of 5 Order Customer Total 1001 Alice Johnson $399.00 1002 Bob Smith $429.00 1003 Carol White $549.00 1004 Dan Brown $349.95 1005 Eve Black $699.00",+ "tag": "main",+ "nodeId": 22,+ "frameId": "26AD562E468018844C0E69080272D633",+ "frameUrl": "http://fixtures/extract-list.html"+ },+ {+ "ref": "e20",+ "role": "region",+ "name": "Products",+ "depth": 4,+ "label": "Products",+ "text": "Sony WH-1000XM5 $399.00 4.7 out of 5 Bose QuietComfort Ultra $429.00 4.5 out of 5 Apple AirPods Max $549.00 4.6 out of 5 Sennheiser Momentum 4 $349.95 4.4 out of 5 Bowers & Wilkins Px8 $699.00 4.3 out of 5 Beats Studio Pro $349.99 4.2 out of 5",+ "tag": "section",+ "nodeId": 23,+ "frameId": "26AD562E468018844C0E69080272D633",+ "frameUrl": "http://fixtures/extract-list.html"+ },+ {+ "ref": "e21",+ "role": "article",+ "name": "",+ "depth": 5,+ "text": "Sony WH-1000XM5 $399.00 4.7 out of 5",+ "tag": "article",+ "nodeId": 24,+ "frameId": "26AD562E468018844C0E69080272D633",+ "frameUrl": "http://fixtures/extract-list.html"+ },+ {+ "ref": "e22",+ "role": "heading",+ "name": "Sony WH-1000XM5",+ "depth": 6,+ "text": "Sony WH-1000XM5",+ "tag": "h2",+ "nodeId": 25,+ "frameId": "26AD562E468018844C0E69080272D633",+ "frameUrl": "http://fixtures/extract-list.html"+ },+ {+ "ref": "e23",+ "role": "StaticText",+ "name": "Sony WH-1000XM5",+ "depth": 7,+ "nodeId": 83,+ "frameId": "26AD562E468018844C0E69080272D633",+ "frameUrl": "http://fixtures/extract-list.html"+ },+ {+ "ref": "e24",+ "role": "paragraph",+ "name": "Price",+ "depth": 6,+ "label": "Price",+ "text": "$399.00",+ "tag": "p",+ "nodeId": 26,+ "frameId": "26AD562E468018844C0E69080272D633",+ "frameUrl": "http://fixtures/extract-list.html"+ },+ {+ "ref": "e25",+ "role": "StaticText",+ "name": "$399.00",+ "depth": 7,+ "nodeId": 84,+ "frameId": "26AD562E468018844C0E69080272D633",+ "frameUrl": "http://fixtures/extract-list.html"+ },+ {+ "ref": "e26",+ "role": "paragraph",+ "name": "Rating",+ "depth": 6,+ "label": "Rating",+ "text": "4.7 out of 5",+ "tag": "p",+ "nodeId": 27,+ "frameId": "26AD562E468018844C0E69080272D633",+ "frameUrl": "http://fixtures/extract-list.html"+ },+ {+ "ref": "e27",+ "role": "StaticText",+ "name": "4.7 out of 5",+ "depth": 7,+ "nodeId": 85,+ "frameId": "26AD562E468018844C0E69080272D633",+ "frameUrl": "http://fixtures/extract-list.html"+ },+ {+ "ref": "e28",+ "role": "article",+ "name": "",+ "depth": 5,+ "text": "Bose QuietComfort Ultra $429.00 4.5 out of 5",+ "tag": "article",+ "nodeId": 28,+ "frameId": "26AD562E468018844C0E69080272D633",+ "frameUrl": "http://fixtures/extract-list.html"+ },+ {+ "ref": "e29",+ "role": "heading",+ "name": "Bose QuietComfort Ultra",+ "depth": 6,+ "text": "Bose QuietComfort Ultra",+ "tag": "h2",+ "nodeId": 29,+ "frameId": "26AD562E468018844C0E69080272D633",+ "frameUrl": "http://fixtures/extract-list.html"+ },+ {+ "ref": "e30",+ "role": "StaticText",+ "name": "Bose QuietComfort Ultra",+ "depth": 7,+ "nodeId": 86,+ "frameId": "26AD562E468018844C0E69080272D633",+ "frameUrl": "http://fixtures/extract-list.html"+ },+ {+ "ref": "e31",+ "role": "paragraph",+ "name": "Price",+ "depth": 6,+ "label": "Price",+ "text": "$429.00",+ "tag": "p",+ "nodeId": 30,+ "frameId": "26AD562E468018844C0E69080272D633",+ "frameUrl": "http://fixtures/extract-list.html"+ },+ {+ "ref": "e32",+ "role": "StaticText",+ "name": "$429.00",+ "depth": 7,+ "nodeId": 87,+ "frameId": "26AD562E468018844C0E69080272D633",+ "frameUrl": "http://fixtures/extract-list.html"+ },+ {+ "ref": "e33",+ "role": "paragraph",+ "name": "Rating",+ "depth": 6,+ "label": "Rating",+ "text": "4.5 out of 5",+ "tag": "p",+ "nodeId": 31,+ "frameId": "26AD562E468018844C0E69080272D633",+ "frameUrl": "http://fixtures/extract-list.html"+ },+ {+ "ref": "e34",+ "role": "StaticText",+ "name": "4.5 out of 5",+ "depth": 7,+ "nodeId": 88,+ "frameId": "26AD562E468018844C0E69080272D633",+ "frameUrl": "http://fixtures/extract-list.html"+ },+ {+ "ref": "e35",+ "role": "article",+ "name": "",+ "depth": 5,+ "text": "Apple AirPods Max $549.00 4.6 out of 5",+ "tag": "article",+ "nodeId": 32,+ "frameId": "26AD562E468018844C0E69080272D633",+ "frameUrl": "http://fixtures/extract-list.html"+ },+ {+ "ref": "e36",+ "role": "heading",+ "name": "Apple AirPods Max",+ "depth": 6,+ "text": "Apple AirPods Max",+ "tag": "h2",+ "nodeId": 33,+ "frameId": "26AD562E468018844C0E69080272D633",+ "frameUrl": "http://fixtures/extract-list.html"+ },+ {+ "ref": "e37",+ "role": "StaticText",+ "name": "Apple AirPods Max",+ "depth": 7,+ "nodeId": 89,+ "frameId": "26AD562E468018844C0E69080272D633",+ "frameUrl": "http://fixtures/extract-list.html"+ },+ {+ "ref": "e38",+ "role": "paragraph",+ "name": "Price",+ "depth": 6,+ "label": "Price",+ "text": "$549.00",+ "tag": "p",+ "nodeId": 34,+ "frameId": "26AD562E468018844C0E69080272D633",+ "frameUrl": "http://fixtures/extract-list.html"+ },+ {+ "ref": "e39",+ "role": "StaticText",+ "name": "$549.00",+ "depth": 7,+ "nodeId": 90,+ "frameId": "26AD562E468018844C0E69080272D633",+ "frameUrl": "http://fixtures/extract-list.html"+ },+ {+ "ref": "e40",+ "role": "paragraph",+ "name": "Rating",+ "depth": 6,+ "label": "Rating",+ "text": "4.6 out of 5",+ "tag": "p",+ "nodeId": 35,+ "frameId": "26AD562E468018844C0E69080272D633",+ "frameUrl": "http://fixtures/extract-list.html"+ },+ {+ "ref": "e41",+ "role": "StaticText",+ "name": "4.6 out of 5",+ "depth": 7,+ "nodeId": 91,+ "frameId": "26AD562E468018844C0E69080272D633",+ "frameUrl": "http://fixtures/extract-list.html"+ },+ {+ "ref": "e42",+ "role": "article",+ "name": "",+ "depth": 5,+ "text": "Sennheiser Momentum 4 $349.95 4.4 out of 5",+ "tag": "article",+ "nodeId": 36,+ "frameId": "26AD562E468018844C0E69080272D633",+ "frameUrl": "http://fixtures/extract-list.html"+ },+ {+ "ref": "e43",+ "role": "heading",+ "name": "Sennheiser Momentum 4",+ "depth": 6,+ "text": "Sennheiser Momentum 4",+ "tag": "h2",+ "nodeId": 37,+ "frameId": "26AD562E468018844C0E69080272D633",+ "frameUrl": "http://fixtures/extract-list.html"+ },+ {+ "ref": "e44",+ "role": "StaticText",+ "name": "Sennheiser Momentum 4",+ "depth": 7,+ "nodeId": 92,+ "frameId": "26AD562E468018844C0E69080272D633",+ "frameUrl": "http://fixtures/extract-list.html"+ },+ {+ "ref": "e45",+ "role": "paragraph",+ "name": "Price",+ "depth": 6,+ "label": "Price",+ "text": "$349.95",+ "tag": "p",+ "nodeId": 38,+ "frameId": "26AD562E468018844C0E69080272D633",+ "frameUrl": "http://fixtures/extract-list.html"+ },+ {+ "ref": "e46",+ "role": "StaticText",+ "name": "$349.95",+ "depth": 7,+ "nodeId": 93,+ "frameId": "26AD562E468018844C0E69080272D633",+ "frameUrl": "http://fixtures/extract-list.html"+ },+ {+ "ref": "e47",+ "role": "paragraph",+ "name": "Rating",+ "depth": 6,+ "label": "Rating",+ "text": "4.4 out of 5",+ "tag": "p",+ "nodeId": 39,+ "frameId": "26AD562E468018844C0E69080272D633",+ "frameUrl": "http://fixtures/extract-list.html"+ },+ {+ "ref": "e48",+ "role": "StaticText",+ "name": "4.4 out of 5",+ "depth": 7,+ "nodeId": 94,+ "frameId": "26AD562E468018844C0E69080272D633",+ "frameUrl": "http://fixtures/extract-list.html"+ },+ {+ "ref": "e49",+ "role": "article",+ "name": "",+ "depth": 5,+ "text": "Bowers & Wilkins Px8 $699.00 4.3 out of 5",+ "tag": "article",+ "nodeId": 40,+ "frameId": "26AD562E468018844C0E69080272D633",+ "frameUrl": "http://fixtures/extract-list.html"+ },+ {+ "ref": "e50",+ "role": "heading",+ "name": "Bowers & Wilkins Px8",+ "depth": 6,+ "text": "Bowers & Wilkins Px8",+ "tag": "h2",+ "nodeId": 41,+ "frameId": "26AD562E468018844C0E69080272D633",+ "frameUrl": "http://fixtures/extract-list.html"+ },+ {+ "ref": "e51",+ "role": "StaticText",+ "name": "Bowers & Wilkins Px8",+ "depth": 7,+ "nodeId": 95,+ "frameId": "26AD562E468018844C0E69080272D633",+ "frameUrl": "http://fixtures/extract-list.html"+ },+ {+ "ref": "e52",+ "role": "paragraph",+ "name": "Price",+ "depth": 6,+ "label": "Price",+ "text": "$699.00",+ "tag": "p",+ "nodeId": 42,+ "frameId": "26AD562E468018844C0E69080272D633",+ "frameUrl": "http://fixtures/extract-list.html"+ },+ {+ "ref": "e53",+ "role": "StaticText",+ "name": "$699.00",+ "depth": 7,+ "nodeId": 96,+ "frameId": "26AD562E468018844C0E69080272D633",+ "frameUrl": "http://fixtures/extract-list.html"+ },+ {+ "ref": "e54",+ "role": "paragraph",+ "name": "Rating",+ "depth": 6,+ "label": "Rating",+ "text": "4.3 out of 5",+ "tag": "p",+ "nodeId": 43,+ "frameId": "26AD562E468018844C0E69080272D633",+ "frameUrl": "http://fixtures/extract-list.html"+ },+ {+ "ref": "e55",+ "role": "StaticText",+ "name": "4.3 out of 5",+ "depth": 7,+ "nodeId": 97,+ "frameId": "26AD562E468018844C0E69080272D633",+ "frameUrl": "http://fixtures/extract-list.html"+ },+ {+ "ref": "e56",+ "role": "article",+ "name": "",+ "depth": 5,+ "text": "Beats Studio Pro $349.99 4.2 out of 5",+ "tag": "article",+ "nodeId": 44,+ "frameId": "26AD562E468018844C0E69080272D633",+ "frameUrl": "http://fixtures/extract-list.html"+ },+ {+ "ref": "e57",+ "role": "heading",+ "name": "Beats Studio Pro",+ "depth": 6,+ "text": "Beats Studio Pro",+ "tag": "h2",+ "nodeId": 45,+ "frameId": "26AD562E468018844C0E69080272D633",+ "frameUrl": "http://fixtures/extract-list.html"+ },+ {+ "ref": "e58",+ "role": "StaticText",+ "name": "Beats Studio Pro",+ "depth": 7,+ "nodeId": 98,+ "frameId": "26AD562E468018844C0E69080272D633",+ "frameUrl": "http://fixtures/extract-list.html"+ },+ {+ "ref": "e59",+ "role": "paragraph",+ "name": "Price",+ "depth": 6,+ "label": "Price",+ "text": "$349.99",+ "tag": "p",+ "nodeId": 46,+ "frameId": "26AD562E468018844C0E69080272D633",+ "frameUrl": "http://fixtures/extract-list.html"+ },+ {+ "ref": "e60",+ "role": "StaticText",+ "name": "$349.99",+ "depth": 7,+ "nodeId": 99,+ "frameId": "26AD562E468018844C0E69080272D633",+ "frameUrl": "http://fixtures/extract-list.html"+ },+ {+ "ref": "e61",+ "role": "paragraph",+ "name": "Rating",+ "depth": 6,+ "label": "Rating",+ "text": "4.2 out of 5",+ "tag": "p",+ "nodeId": 47,+ "frameId": "26AD562E468018844C0E69080272D633",+ "frameUrl": "http://fixtures/extract-list.html"+ },+ {+ "ref": "e62",+ "role": "StaticText",+ "name": "4.2 out of 5",+ "depth": 7,+ "nodeId": 100,+ "frameId": "26AD562E468018844C0E69080272D633",+ "frameUrl": "http://fixtures/extract-list.html"+ },+ {+ "ref": "e63",+ "role": "table",+ "name": "Orders",+ "depth": 4,+ "label": "Orders",+ "text": "Order Customer Total 1001 Alice Johnson $399.00 1002 Bob Smith $429.00 1003 Carol White $549.00 1004 Dan Brown $349.95 1005 Eve Black $699.00",+ "tag": "table",+ "nodeId": 48,+ "frameId": "26AD562E468018844C0E69080272D633",+ "frameUrl": "http://fixtures/extract-list.html"+ },+ {+ "ref": "e64",+ "role": "rowgroup",+ "name": "",+ "depth": 5,+ "text": "Order Customer Total",+ "tag": "thead",+ "nodeId": 49,+ "frameId": "26AD562E468018844C0E69080272D633",+ "frameUrl": "http://fixtures/extract-list.html"+ },+ {+ "ref": "e65",+ "role": "row",+ "name": "",+ "depth": 6,+ "text": "Order Customer Total",+ "tag": "tr",+ "nodeId": 50,+ "frameId": "26AD562E468018844C0E69080272D633",+ "frameUrl": "http://fixtures/extract-list.html"+ },+ {+ "ref": "e66",+ "role": "columnheader",+ "name": "Order",+ "depth": 7,+ "text": "Order",+ "tag": "th",+ "nodeId": 51,+ "frameId": "26AD562E468018844C0E69080272D633",+ "frameUrl": "http://fixtures/extract-list.html"+ },+ {+ "ref": "e67",+ "role": "StaticText",+ "name": "Order",+ "depth": 8,+ "nodeId": 101,+ "frameId": "26AD562E468018844C0E69080272D633",+ "frameUrl": "http://fixtures/extract-list.html"+ },+ {+ "ref": "e68",+ "role": "columnheader",+ "name": "Customer",+ "depth": 7,+ "text": "Customer",+ "tag": "th",+ "nodeId": 52,+ "frameId": "26AD562E468018844C0E69080272D633",+ "frameUrl": "http://fixtures/extract-list.html"+ },+ {+ "ref": "e69",+ "role": "StaticText",+ "name": "Customer",+ "depth": 8,+ "nodeId": 102,+ "frameId": "26AD562E468018844C0E69080272D633",+ "frameUrl": "http://fixtures/extract-list.html"+ },+ {+ "ref": "e70",+ "role": "columnheader",+ "name": "Total",+ "depth": 7,+ "text": "Total",+ "tag": "th",+ "nodeId": 53,+ "frameId": "26AD562E468018844C0E69080272D633",+ "frameUrl": "http://fixtures/extract-list.html"+ },+ {+ "ref": "e71",+ "role": "StaticText",+ "name": "Total",+ "depth": 8,+ "nodeId": 103,+ "frameId": "26AD562E468018844C0E69080272D633",+ "frameUrl": "http://fixtures/extract-list.html"+ },+ {+ "ref": "e72",+ "role": "row",+ "name": "",+ "depth": 6,+ "text": "1001 Alice Johnson $399.00",+ "tag": "tr",+ "nodeId": 55,+ "frameId": "26AD562E468018844C0E69080272D633",+ "frameUrl": "http://fixtures/extract-list.html"+ },+ {+ "ref": "e73",+ "role": "cell",+ "name": "1001",+ "depth": 7,+ "text": "1001",+ "tag": "td",+ "nodeId": 56,+ "frameId": "26AD562E468018844C0E69080272D633",+ "frameUrl": "http://fixtures/extract-list.html"+ },+ {+ "ref": "e74",+ "role": "StaticText",+ "name": "1001",+ "depth": 8,+ "nodeId": 104,+ "frameId": "26AD562E468018844C0E69080272D633",+ "frameUrl": "http://fixtures/extract-list.html"+ },+ {+ "ref": "e75",+ "role": "cell",+ "name": "Alice Johnson",+ "depth": 7,+ "text": "Alice Johnson",+ "tag": "td",+ "nodeId": 57,+ "frameId": "26AD562E468018844C0E69080272D633",+ "frameUrl": "http://fixtures/extract-list.html"+ },+ {+ "ref": "e76",+ "role": "StaticText",+ "name": "Alice Johnson",+ "depth": 8,+ "nodeId": 105,+ "frameId": "26AD562E468018844C0E69080272D633",+ "frameUrl": "http://fixtures/extract-list.html"+ },+ {+ "ref": "e77",+ "role": "cell",+ "name": "$399.00",+ "depth": 7,+ "text": "$399.00",+ "tag": "td",+ "nodeId": 58,+ "frameId": "26AD562E468018844C0E69080272D633",+ "frameUrl": "http://fixtures/extract-list.html"+ },+ {+ "ref": "e78",+ "role": "StaticText",+ "name": "$399.00",+ "depth": 8,+ "nodeId": 106,+ "frameId": "26AD562E468018844C0E69080272D633",+ "frameUrl": "http://fixtures/extract-list.html"+ },+ {+ "ref": "e79",+ "role": "row",+ "name": "",+ "depth": 6,+ "text": "1002 Bob Smith $429.00",+ "tag": "tr",+ "nodeId": 59,+ "frameId": "26AD562E468018844C0E69080272D633",+ "frameUrl": "http://fixtures/extract-list.html"+ },+ {+ "ref": "e80",+ "role": "cell",+ "name": "1002",+ "depth": 7,+ "text": "1002",+ "tag": "td",+ "nodeId": 60,+ "frameId": "26AD562E468018844C0E69080272D633",+ "frameUrl": "http://fixtures/extract-list.html"+ },+ {+ "ref": "e81",+ "role": "StaticText",+ "name": "1002",+ "depth": 8,+ "nodeId": 107,+ "frameId": "26AD562E468018844C0E69080272D633",+ "frameUrl": "http://fixtures/extract-list.html"+ },+ {+ "ref": "e82",+ "role": "cell",+ "name": "Bob Smith",+ "depth": 7,+ "text": "Bob Smith",+ "tag": "td",+ "nodeId": 61,+ "frameId": "26AD562E468018844C0E69080272D633",+ "frameUrl": "http://fixtures/extract-list.html"+ },+ {+ "ref": "e83",+ "role": "StaticText",+ "name": "Bob Smith",+ "depth": 8,+ "nodeId": 108,+ "frameId": "26AD562E468018844C0E69080272D633",+ "frameUrl": "http://fixtures/extract-list.html"+ },+ {+ "ref": "e84",+ "role": "cell",+ "name": "$429.00",+ "depth": 7,+ "text": "$429.00",+ "tag": "td",+ "nodeId": 62,+ "frameId": "26AD562E468018844C0E69080272D633",+ "frameUrl": "http://fixtures/extract-list.html"+ },+ {+ "ref": "e85",+ "role": "StaticText",+ "name": "$429.00",+ "depth": 8,+ "nodeId": 109,+ "frameId": "26AD562E468018844C0E69080272D633",+ "frameUrl": "http://fixtures/extract-list.html"+ },+ {+ "ref": "e86",+ "role": "row",+ "name": "",+ "depth": 6,+ "text": "1003 Carol White $549.00",+ "tag": "tr",+ "nodeId": 63,+ "frameId": "26AD562E468018844C0E69080272D633",+ "frameUrl": "http://fixtures/extract-list.html"+ },+ {+ "ref": "e87",+ "role": "cell",+ "name": "1003",+ "depth": 7,+ "text": "1003",+ "tag": "td",+ "nodeId": 64,+ "frameId": "26AD562E468018844C0E69080272D633",+ "frameUrl": "http://fixtures/extract-list.html"+ },+ {+ "ref": "e88",+ "role": "StaticText",+ "name": "1003",+ "depth": 8,+ "nodeId": 110,+ "frameId": "26AD562E468018844C0E69080272D633",+ "frameUrl": "http://fixtures/extract-list.html"+ },+ {+ "ref": "e89",+ "role": "cell",+ "name": "Carol White",+ "depth": 7,+ "text": "Carol White",+ "tag": "td",+ "nodeId": 65,+ "frameId": "26AD562E468018844C0E69080272D633",+ "frameUrl": "http://fixtures/extract-list.html"+ },+ {+ "ref": "e90",+ "role": "StaticText",+ "name": "Carol White",+ "depth": 8,+ "nodeId": 111,+ "frameId": "26AD562E468018844C0E69080272D633",+ "frameUrl": "http://fixtures/extract-list.html"+ },+ {+ "ref": "e91",+ "role": "cell",+ "name": "$549.00",+ "depth": 7,+ "text": "$549.00",+ "tag": "td",+ "nodeId": 66,+ "frameId": "26AD562E468018844C0E69080272D633",+ "frameUrl": "http://fixtures/extract-list.html"+ },+ {+ "ref": "e92",+ "role": "StaticText",+ "name": "$549.00",+ "depth": 8,+ "nodeId": 112,+ "frameId": "26AD562E468018844C0E69080272D633",+ "frameUrl": "http://fixtures/extract-list.html"+ },+ {+ "ref": "e93",+ "role": "row",+ "name": "",+ "depth": 6,+ "text": "1004 Dan Brown $349.95",+ "tag": "tr",+ "nodeId": 67,+ "frameId": "26AD562E468018844C0E69080272D633",+ "frameUrl": "http://fixtures/extract-list.html"+ },+ {+ "ref": "e94",+ "role": "cell",+ "name": "1004",+ "depth": 7,+ "text": "1004",+ "tag": "td",+ "nodeId": 68,+ "frameId": "26AD562E468018844C0E69080272D633",+ "frameUrl": "http://fixtures/extract-list.html"+ },+ {+ "ref": "e95",+ "role": "StaticText",+ "name": "1004",+ "depth": 8,+ "nodeId": 113,+ "frameId": "26AD562E468018844C0E69080272D633",+ "frameUrl": "http://fixtures/extract-list.html"+ },+ {+ "ref": "e96",+ "role": "cell",+ "name": "Dan Brown",+ "depth": 7,+ "text": "Dan Brown",+ "tag": "td",+ "nodeId": 69,+ "frameId": "26AD562E468018844C0E69080272D633",+ "frameUrl": "http://fixtures/extract-list.html"+ },+ {+ "ref": "e97",+ "role": "StaticText",+ "name": "Dan Brown",+ "depth": 8,+ "nodeId": 114,+ "frameId": "26AD562E468018844C0E69080272D633",+ "frameUrl": "http://fixtures/extract-list.html"+ },+ {+ "ref": "e98",+ "role": "cell",+ "name": "$349.95",+ "depth": 7,+ "text": "$349.95",+ "tag": "td",+ "nodeId": 70,+ "frameId": "26AD562E468018844C0E69080272D633",+ "frameUrl": "http://fixtures/extract-list.html"+ },+ {+ "ref": "e99",+ "role": "StaticText",+ "name": "$349.95",+ "depth": 8,+ "nodeId": 115,+ "frameId": "26AD562E468018844C0E69080272D633",+ "frameUrl": "http://fixtures/extract-list.html"+ },+ {+ "ref": "e100",+ "role": "row",+ "name": "",+ "depth": 6,+ "text": "1005 Eve Black $699.00",+ "tag": "tr",+ "nodeId": 71,+ "frameId": "26AD562E468018844C0E69080272D633",+ "frameUrl": "http://fixtures/extract-list.html"+ },+ {+ "ref": "e101",+ "role": "cell",+ "name": "1005",+ "depth": 7,+ "text": "1005",+ "tag": "td",+ "nodeId": 72,+ "frameId": "26AD562E468018844C0E69080272D633",+ "frameUrl": "http://fixtures/extract-list.html"+ },+ {+ "ref": "e102",+ "role": "StaticText",+ "name": "1005",+ "depth": 8,+ "nodeId": 116,+ "frameId": "26AD562E468018844C0E69080272D633",+ "frameUrl": "http://fixtures/extract-list.html"+ },+ {+ "ref": "e103",+ "role": "cell",+ "name": "Eve Black",+ "depth": 7,+ "text": "Eve Black",+ "tag": "td",+ "nodeId": 73,+ "frameId": "26AD562E468018844C0E69080272D633",+ "frameUrl": "http://fixtures/extract-list.html"+ },+ {+ "ref": "e104",+ "role": "StaticText",+ "name": "Eve Black",+ "depth": 8,+ "nodeId": 117,+ "frameId": "26AD562E468018844C0E69080272D633",+ "frameUrl": "http://fixtures/extract-list.html"+ },+ {+ "ref": "e105",+ "role": "cell",+ "name": "$699.00",+ "depth": 7,+ "text": "$699.00",+ "tag": "td",+ "nodeId": 74,+ "frameId": "26AD562E468018844C0E69080272D633",+ "frameUrl": "http://fixtures/extract-list.html"+ },+ {+ "ref": "e106",+ "role": "StaticText",+ "name": "$699.00",+ "depth": 8,+ "nodeId": 118,+ "frameId": "26AD562E468018844C0E69080272D633",+ "frameUrl": "http://fixtures/extract-list.html"+ }+ ]+}\ No newline at end of filediff --git a/tests/e2e/fixtures/extract-list.html b/tests/e2e/fixtures/extract-list.htmlnew file mode 100644index 00000000..b4207bcd--- /dev/null+++ b/tests/e2e/fixtures/extract-list.html@@ -0,0 +1,63 @@+<!doctype html>+<html lang="en">+<head>+ <meta charset="utf-8">+ <title>Shop — Headphones</title>+</head>+<body>+ <nav aria-label="Site">+ <ul>+ <li><a href="/">Home</a></li>+ <li><a href="/shop">Shop</a></li>+ <li><a href="/about">About</a></li>+ <li><a href="/contact">Contact</a></li>+ </ul>+ </nav>+ <main aria-label="Catalogue">+ <section aria-label="Products">+ <article>+ <h2>Sony WH-1000XM5</h2>+ <p aria-label="Price">$399.00</p>+ <p aria-label="Rating">4.7 out of 5</p>+ </article>+ <article>+ <h2>Bose QuietComfort Ultra</h2>+ <p aria-label="Price">$429.00</p>+ <p aria-label="Rating">4.5 out of 5</p>+ </article>+ <article>+ <h2>Apple AirPods Max</h2>+ <p aria-label="Price">$549.00</p>+ <p aria-label="Rating">4.6 out of 5</p>+ </article>+ <article>+ <h2>Sennheiser Momentum 4</h2>+ <p aria-label="Price">$349.95</p>+ <p aria-label="Rating">4.4 out of 5</p>+ </article>+ <article>+ <h2>Bowers & Wilkins Px8</h2>+ <p aria-label="Price">$699.00</p>+ <p aria-label="Rating">4.3 out of 5</p>+ </article>+ <article>+ <h2>Beats Studio Pro</h2>+ <p aria-label="Price">$349.99</p>+ <p aria-label="Rating">4.2 out of 5</p>+ </article>+ </section>+ <table aria-label="Orders">+ <thead>+ <tr><th>Order</th><th>Customer</th><th>Total</th></tr>+ </thead>+ <tbody>+ <tr><td>1001</td><td>Alice Johnson</td><td>$399.00</td></tr>+ <tr><td>1002</td><td>Bob Smith</td><td>$429.00</td></tr>+ <tr><td>1003</td><td>Carol White</td><td>$549.00</td></tr>+ <tr><td>1004</td><td>Dan Brown</td><td>$349.95</td></tr>+ <tr><td>1005</td><td>Eve Black</td><td>$699.00</td></tr>+ </tbody>+ </table>+ </main>+</body>+</html>