High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.
fix(extract): coerce only the first numeric token and run fixture tests on real captured snapshots (PIN-391)
Luigi Agostif303991588b6
diff --git a/docs/architecture/extract.md b/docs/architecture/extract.mdindex aabc1033..882410b4 100644--- a/docs/architecture/extract.md+++ b/docs/architecture/extract.md@@ -84,11 +84,14 @@ field (e.g. a sale price among several prices) without renaming the schema.## Coercion rules- **string** — the trimmed raw value.-- **number / integer** — currency symbols, thousands separators, and trailing- units are stripped; sign and decimal are kept. Both ASCII `-` and the Unicode- minus `−` (U+2212) are honoured. `integer` truncates toward zero. Examples:- `"$1,299.00"` → `1299`, `"−3.5 kg"` → `-3.5`, `"call for price"` → missing- with reason `not_numeric`.+- **number / integer** — only the **first numeric token** is parsed: a leading+ currency symbol and sign are stripped, the token's thousands separators are+ dropped, sign and decimal are kept, and parsing stops at the first character+ after the token so digits from a trailing word are never glued on. Both ASCII+ `-` and the Unicode minus `−` (U+2212) are honoured. `integer` truncates toward+ zero. Examples: `"$1,299.00"` → `1299`, `"−3.5 kg"` → `-3.5`,+ `"4.7 out of 5"` → `4.7` (not `4.75`), `"2 of 3"` → `2`, `"call for price"` →+ missing with reason `not_numeric`.- **boolean** — the accessibility `Checked` state (`true`/`false`) first, thenthe words `yes`/`no`/`true`/`false` in the read value. A `mixed` checkbox or anunrelated string leaves the field missing with reason `not_boolean`.diff --git a/internal/extract/coerce.go b/internal/extract/coerce.goindex 9e74333f..2811b1fb 100644--- a/internal/extract/coerce.go+++ b/internal/extract/coerce.go@@ -7,16 +7,25 @@ import ("github.com/pinchtab/pinchtab/internal/bridge/observe")-// coerceNumber parses a display string into a float64, stripping currency-// symbols, thousands separators, and trailing units while keeping sign and-// decimal. "$1,299.00" -> 1299, "−3.5 kg" -> -3.5 (Unicode minus honoured),-// "call for price" -> not numeric. ok is false when no digit is present.+// 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 := ""seenDigit := falseseenDot := false+ done := falsefor _, r := range s {+ if done {+ break+ }switch {case r >= '0' && r <= '9':b.WriteRune(r)@@ -24,12 +33,18 @@ func coerceNumber(s string) (float64, bool) {case r == '.' && !seenDot:b.WriteRune('.')seenDot = true+ case r == ',' && seenDigit:+ // thousands separator inside the token: droppedcase isMinus(r) && !seenDigit && sign == "":sign = "-"case r == '+' && !seenDigit && sign == "":sign = "+"default:- // currency, letters, spaces, thousands separators: dropped+ // 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+ }}}if !seenDigit {diff --git a/internal/extract/extract_test.go b/internal/extract/extract_test.goindex 82ba9cb4..86e3e531 100644--- a/internal/extract/extract_test.go+++ b/internal/extract/extract_test.go@@ -31,14 +31,14 @@ func TestResolve_FromSnapshotFixtures(t *testing.T) {schema := mustSchema(t, `{"type":"object","required":["name","price","in_stock"],"properties":{"name":{"type":"string","description":"product name","x-pinchtab-hint":"role:heading"},"price":{"type":"number","description":"product price"},- "rating":{"type":"string","description":"product rating"},+ "rating":{"type":"number","description":"product rating out of 5"},"in_stock":{"type":"boolean","description":"in stock availability"},"description":{"type":"string","description":"product description"}}}`)got := Resolve(schema, loadSnapshot(t, "extract-product.json"), Options{})want := map[string]any{"name": "Sony WH-1000XM5 Wireless Headphones","price": 1299.0,- "rating": "4.7 out of 5",+ "rating": 4.7, // "4.7 out of 5" -> first token 4.7, never 4.75"in_stock": true,}for k, v := range want {@@ -232,6 +232,8 @@ func TestCoerceNumber(t *testing.T) {{"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{"", 0, false},}for _, tc := range tests {diff --git a/internal/extract/testdata/README.md b/internal/extract/testdata/README.mdindex 587d7d13..60469236 100644--- a/internal/extract/testdata/README.md+++ b/internal/extract/testdata/README.md@@ -1,19 +1,32 @@# extract testdataAccessibility snapshots used by `TestResolve_FromSnapshotFixtures`. Each file is-the `nodes` array of a `pinchtab snap --json` capture, so the unit tests run-against the same node shape the e2e fixtures produce.+the `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 the+e2e fixtures produce — including the `RootWebArea` root, the `StaticText`+children Chrome emits under each labelled paragraph, and the per-node `text`+filled by DOM-metadata enrichment.-| testdata file | fixture |-| ---------------------- | ---------------------------------------- |+| testdata file | fixture |+| ---------------------- | ----------------------------------------- || `extract-product.json` | `tests/e2e/fixtures/extract-product.html` || `extract-article.json` | `tests/e2e/fixtures/extract-article.html` |-Authored to mirror the committed fixtures at PinchTab commit `c906674b`-(the HEAD when PIN-391 landed). Refresh from a Docker run when a snapshot-changes shape:+## How these were produced++Captured from the e2e Docker stack (`tests/e2e/docker-compose.yml`, the+`pinchtab` + `fixtures` services) at PinchTab commit `dca3d7a9`:```-pinchtab open http://fixtures/extract-product.html-pinchtab snap --json > internal/extract/testdata/extract-product.json+cd tests/e2e && docker compose up -d pinchtab fixtures+curl -s -X POST http://127.0.0.1:9999/navigate \+ -H 'Authorization: Bearer e2e-token' -H 'Content-Type: application/json' \+ -d '{"url":"http://fixtures:80/extract-product.html"}'+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+same 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`).diff --git a/internal/extract/testdata/extract-article.json b/internal/extract/testdata/extract-article.jsonindex bd3fc251..c0bd07b4 100644--- a/internal/extract/testdata/extract-article.json+++ b/internal/extract/testdata/extract-article.json@@ -2,10 +2,109 @@"url": "http://fixtures/extract-article.html","title": "The Rise of Model-Free Extraction","nodes": [- {"ref": "e1", "role": "article", "name": "Story", "depth": 0},- {"ref": "e2", "role": "heading", "name": "The Rise of Model-Free Extraction", "depth": 1},- {"ref": "e3", "role": "paragraph", "name": "Author", "text": "Jane Doe", "depth": 1},- {"ref": "e4", "role": "paragraph", "name": "Date published", "text": "2026-09-12", "depth": 1},- {"ref": "e5", "role": "paragraph", "name": "Body", "text": "Agents have long needed a step between finding one element and scraping a whole page. A schema-driven extractor fills that gap without a model.", "depth": 1}+ {+ "ref": "e0",+ "role": "RootWebArea",+ "name": "The Rise of Model-Free Extraction",+ "depth": 0,+ "nodeId": 5,+ "frameId": "8C30EFBA27DBCAB352EFD24BF56BBBCC",+ "frameUrl": "http://fixtures/extract-article.html"+ },+ {+ "ref": "e1",+ "role": "article",+ "name": "Story",+ "depth": 3,+ "label": "Story",+ "text": "The Rise of Model-Free Extraction Jane Doe 2026-09-12 Agents have long needed a step between finding one element and scraping a whole page. A schema-driven extractor fills that gap without a model.",+ "tag": "article",+ "nodeId": 12,+ "frameId": "8C30EFBA27DBCAB352EFD24BF56BBBCC",+ "frameUrl": "http://fixtures/extract-article.html"+ },+ {+ "ref": "e2",+ "role": "heading",+ "name": "The Rise of Model-Free Extraction",+ "depth": 4,+ "text": "The Rise of Model-Free Extraction",+ "tag": "h1",+ "nodeId": 13,+ "frameId": "8C30EFBA27DBCAB352EFD24BF56BBBCC",+ "frameUrl": "http://fixtures/extract-article.html"+ },+ {+ "ref": "e3",+ "role": "StaticText",+ "name": "The Rise of Model-Free Extraction",+ "depth": 5,+ "nodeId": 17,+ "frameId": "8C30EFBA27DBCAB352EFD24BF56BBBCC",+ "frameUrl": "http://fixtures/extract-article.html"+ },+ {+ "ref": "e4",+ "role": "paragraph",+ "name": "Author",+ "depth": 4,+ "label": "Author",+ "text": "Jane Doe",+ "tag": "p",+ "nodeId": 14,+ "frameId": "8C30EFBA27DBCAB352EFD24BF56BBBCC",+ "frameUrl": "http://fixtures/extract-article.html"+ },+ {+ "ref": "e5",+ "role": "StaticText",+ "name": "Jane Doe",+ "depth": 5,+ "nodeId": 18,+ "frameId": "8C30EFBA27DBCAB352EFD24BF56BBBCC",+ "frameUrl": "http://fixtures/extract-article.html"+ },+ {+ "ref": "e6",+ "role": "paragraph",+ "name": "Date published",+ "depth": 4,+ "label": "Date published",+ "text": "2026-09-12",+ "tag": "p",+ "nodeId": 15,+ "frameId": "8C30EFBA27DBCAB352EFD24BF56BBBCC",+ "frameUrl": "http://fixtures/extract-article.html"+ },+ {+ "ref": "e7",+ "role": "StaticText",+ "name": "2026-09-12",+ "depth": 5,+ "nodeId": 19,+ "frameId": "8C30EFBA27DBCAB352EFD24BF56BBBCC",+ "frameUrl": "http://fixtures/extract-article.html"+ },+ {+ "ref": "e8",+ "role": "paragraph",+ "name": "Body",+ "depth": 4,+ "label": "Body",+ "text": "Agents have long needed a step between finding one element and scraping a whole page. A schema-driven extractor fills that gap without a model.",+ "tag": "p",+ "nodeId": 16,+ "frameId": "8C30EFBA27DBCAB352EFD24BF56BBBCC",+ "frameUrl": "http://fixtures/extract-article.html"+ },+ {+ "ref": "e9",+ "role": "StaticText",+ "name": "Agents have long needed a step between finding one element and scraping a whole page. A schema-driven extractor fills that gap without a model.",+ "depth": 5,+ "nodeId": 20,+ "frameId": "8C30EFBA27DBCAB352EFD24BF56BBBCC",+ "frameUrl": "http://fixtures/extract-article.html"+ }]}diff --git a/internal/extract/testdata/extract-product.json b/internal/extract/testdata/extract-product.jsonindex 381c71d6..79a766c6 100644--- a/internal/extract/testdata/extract-product.json+++ b/internal/extract/testdata/extract-product.json@@ -1,12 +1,143 @@{"url": "http://fixtures/extract-product.html",- "title": "Product — Sony WH-1000XM5",+ "title": "Product \u2014 Sony WH-1000XM5","nodes": [- {"ref": "e1", "role": "main", "name": "Product", "depth": 0},- {"ref": "e2", "role": "heading", "name": "Sony WH-1000XM5 Wireless Headphones", "depth": 1},- {"ref": "e3", "role": "paragraph", "name": "Price", "text": "$1,299.00", "depth": 1},- {"ref": "e4", "role": "paragraph", "name": "Rating", "text": "4.7 out of 5", "depth": 1},- {"ref": "e5", "role": "checkbox", "name": "In stock", "checked": "true", "depth": 1},- {"ref": "e6", "role": "paragraph", "name": "Description", "text": "Industry-leading noise cancellation with up to 30 hours of battery life.", "depth": 1}+ {+ "ref": "e0",+ "role": "RootWebArea",+ "name": "Product \u2014 Sony WH-1000XM5",+ "depth": 0,+ "nodeId": 5,+ "frameId": "CD18D93E3F268485C84D4DD9C09DF95E",+ "frameUrl": "http://fixtures/extract-product.html"+ },+ {+ "ref": "e1",+ "role": "main",+ "name": "Product",+ "depth": 3,+ "label": "Product",+ "text": "Sony WH-1000XM5 Wireless Headphones $1,299.00 4.7 out of 5 In stock Industry-leading noise cancellation with up to 30 hours of battery life.",+ "tag": "main",+ "nodeId": 12,+ "frameId": "CD18D93E3F268485C84D4DD9C09DF95E",+ "frameUrl": "http://fixtures/extract-product.html"+ },+ {+ "ref": "e2",+ "role": "heading",+ "name": "Sony WH-1000XM5 Wireless Headphones",+ "depth": 4,+ "text": "Sony WH-1000XM5 Wireless Headphones",+ "tag": "h1",+ "nodeId": 13,+ "frameId": "CD18D93E3F268485C84D4DD9C09DF95E",+ "frameUrl": "http://fixtures/extract-product.html"+ },+ {+ "ref": "e3",+ "role": "StaticText",+ "name": "Sony WH-1000XM5 Wireless Headphones",+ "depth": 5,+ "nodeId": 19,+ "frameId": "CD18D93E3F268485C84D4DD9C09DF95E",+ "frameUrl": "http://fixtures/extract-product.html"+ },+ {+ "ref": "e4",+ "role": "paragraph",+ "name": "Price",+ "depth": 4,+ "label": "Price",+ "text": "$1,299.00",+ "tag": "p",+ "nodeId": 14,+ "frameId": "CD18D93E3F268485C84D4DD9C09DF95E",+ "frameUrl": "http://fixtures/extract-product.html"+ },+ {+ "ref": "e5",+ "role": "StaticText",+ "name": "$1,299.00",+ "depth": 5,+ "nodeId": 20,+ "frameId": "CD18D93E3F268485C84D4DD9C09DF95E",+ "frameUrl": "http://fixtures/extract-product.html"+ },+ {+ "ref": "e6",+ "role": "paragraph",+ "name": "Rating",+ "depth": 4,+ "label": "Rating",+ "text": "4.7 out of 5",+ "tag": "p",+ "nodeId": 15,+ "frameId": "CD18D93E3F268485C84D4DD9C09DF95E",+ "frameUrl": "http://fixtures/extract-product.html"+ },+ {+ "ref": "e7",+ "role": "StaticText",+ "name": "4.7 out of 5",+ "depth": 5,+ "nodeId": 21,+ "frameId": "CD18D93E3F268485C84D4DD9C09DF95E",+ "frameUrl": "http://fixtures/extract-product.html"+ },+ {+ "ref": "e8",+ "role": "paragraph",+ "name": "",+ "depth": 4,+ "text": "In stock",+ "tag": "p",+ "nodeId": 16,+ "frameId": "CD18D93E3F268485C84D4DD9C09DF95E",+ "frameUrl": "http://fixtures/extract-product.html"+ },+ {+ "ref": "e9",+ "role": "checkbox",+ "name": "In stock",+ "depth": 5,+ "label": "In stock",+ "tag": "input",+ "disabled": true,+ "checked": "true",+ "nodeId": 17,+ "frameId": "CD18D93E3F268485C84D4DD9C09DF95E",+ "frameUrl": "http://fixtures/extract-product.html"+ },+ {+ "ref": "e10",+ "role": "StaticText",+ "name": " In stock",+ "depth": 5,+ "nodeId": 22,+ "frameId": "CD18D93E3F268485C84D4DD9C09DF95E",+ "frameUrl": "http://fixtures/extract-product.html"+ },+ {+ "ref": "e11",+ "role": "paragraph",+ "name": "Description",+ "depth": 4,+ "label": "Description",+ "text": "Industry-leading noise cancellation with up to 30 hours of battery life.",+ "tag": "p",+ "nodeId": 18,+ "frameId": "CD18D93E3F268485C84D4DD9C09DF95E",+ "frameUrl": "http://fixtures/extract-product.html"+ },+ {+ "ref": "e12",+ "role": "StaticText",+ "name": "Industry-leading noise cancellation with up to 30 hours of battery life.",+ "depth": 5,+ "nodeId": 23,+ "frameId": "CD18D93E3F268485C84D4DD9C09DF95E",+ "frameUrl": "http://fixtures/extract-product.html"+ }]}