# dom-drift-bench [![CI](https://github.com/NotEl1gible/dom-drift-bench/actions/workflows/ci.yml/badge.svg)](https://github.com/NotEl1gible/dom-drift-bench/actions/workflows/ci.yml) Four ways of extracting data from a page, ten ways a frontend changes underneath them, and a scorer that refuses to add up the two kinds of failure. > **A selector that breaks tells you. An extractor that guesses does not.** Every browser agent is one refactor away from silently returning the wrong value, and a single "accuracy" number cannot tell that apart from an honest crash. So every extraction lands in one of three buckets and they are never summed: | outcome | meaning | who finds out | |---|---|---| | **correct** | the expected value | — | | **broke** | nothing came back | the on-call engineer, in minutes | | **silently wrong** | something came back, and it was wrong | a customer, eventually | --- ## The number this was built to produce ``` $ python -m drift.cli silence strategy failures of those silent share xpath_abs 384 192 0.50 css 120 24 0.20 aria 300 24 0.08 structural 96 0 0.00 ``` Half of everything absolute XPath gets wrong, it gets wrong **quietly**. Structural anchoring fails 96 times and announces all 96. **The middle two rows are worth more than the extremes.** By accuracy `css` wins easily — 120 failures against 300. By silence they are identical: 24 quiet failures each. So `css` is more accurate and no safer, and any single percentage would have ranked them and hidden that. ## The drift matrix ``` $ python -m drift.cli matrix 12 pages x 8 fields = 96 per cell mutation css xpath_abs structural aria ok/brk/SIL ok/brk/SIL ok/brk/SIL ok/brk/SIL none 96/0/0 96/0/0 96/0/0 96/0/0 class_churn 0/96/0 96/0/0 96/0/0 96/0/0 wrapper_div 96/0/0 0/96/0 96/0/0 96/0/0 reorder_siblings 96/0/0 0/0/96 96/0/0 96/0/0 <- all silent attr_drop 96/0/0 96/0/0 96/0/0 96/0/0 tag_swap 96/0/0 0/96/0 96/0/0 96/0/0 i18n 96/0/0 96/0/0 0/96/0 12/84/0 whitespace_case 96/0/0 96/0/0 96/0/0 96/0/0 aria_regression 96/0/0 96/0/0 96/0/0 0/96/0 aria_labelledby 96/0/0 96/0/0 96/0/0 0/96/0 duplicate_block 72/0/24 0/0/96 96/0/0 72/0/24 ``` **`reorder_siblings` against `xpath_abs`: 0 correct, 0 broke, 96 silently wrong.** The path still resolves — to a different section. Nothing raises, nothing logs, and every value returned belongs to another field. An accuracy column would score this identically to `wrapper_div`, where the same strategy fails loudly and somebody finds out immediately. **`structural` is the only strategy that survives `duplicate_block`**, and the reason is one extra line: it anchors on the section *heading* before the field label. The archived card carries the same labels and the same classes, so everything anchored on a single label returns the ghost's value with no error at all. Two anchors instead of one is the entire difference. `aria` under `i18n` scores 12 rather than 0, and those 12 are `Status` — spelled the same in Dutch. Left in rather than smoothed away. ## Compounding drift Real refactors are not single-edit. ``` $ python -m drift.cli compound 1 at once 2 at once 3 at once css 0.88 (168/192) 0.00 (0/192) 0.00 (0/192) xpath_abs 0.62 (120/192) 0.62 (120/192) 0.00 (0/192) structural 0.88 (168/192) 0.88 (168/192) 0.88 (168/192) aria 0.77 (147/192) 0.77 (147/192) 0.77 (147/192) ``` **`css` falls off a cliff between one mutation and two.** It has two independent routes — a test attribute and a class — and each is individually survivable. Together they are not: resilience built from two fragile things is not the sum of two fragilities, it is the product. `structural` and `aria` are flat, because each depends on exactly one thing and that thing either survives or does not. ## Recovery cost, in edits rather than opinions ``` $ python -m drift.cli recovery css class_churn 8 of 8 selectors structural i18n 8 of 8 css duplicate_block 2 of 8 aria i18n 7 of 8 xpath_abs wrapper_div 8 of 8 aria aria_regression 8 of 8 xpath_abs reorder_siblings 8 of 8 aria aria_labelledby 8 of 8 xpath_abs tag_swap 8 of 8 aria duplicate_block 2 of 8 xpath_abs duplicate_block 8 of 8 ``` `structural` appears once. `xpath_abs` appears four times. That is the maintenance half of the same story. ## The browser tier, and why it is not optional The default path is lxml and finishes in seconds. A real Chromium is asked exactly two questions a parser cannot answer. **What an accessible name resolves to.** Computing it properly means `aria-label`, then `aria-labelledby` and the chain it points at, then name-from-content, then `title`. Reimplementing that would score the ARIA arm against my reading of the specification, so Chromium is asked instead — the same reasoning that puts the official SDK in `mcp-bitemporal-memory` and pgvector beside hnswlib in `pgvector-rag`. **The oracle should not be the author.** ``` $ python -m drift.cli browser mutation aria (parser) aria (chromium) none 32/0/0 32/0/0 aria_labelledby 0/32/0 32/0/0 aria_regression 0/32/0 0/32/0 ``` One row is the whole argument. `aria_labelledby` swaps a duplicated label for a reference to the visible one — better practice, and a change teams make deliberately. A parser reading `aria-label` finds **nothing**. The browser resolves it exactly as a screen reader would. **And time.** "The panel arrives 400ms later" is not a property of a string. ``` $ python -m drift.cli wait wait=none 0ms 32 correct wait=sleep 0ms 32 correct wait=none 100ms 0 correct wait=sleep 100ms 32 correct wait=none 400ms 0 correct wait=sleep 400ms 0 correct <- wait=none 900ms 0 correct wait=sleep 900ms 0 correct wait=condition every delay 32 correct ``` The fixed 200ms sleep is right until the page is slower than the day somebody picked the number. ## Ground truth without annotation Pages are **rendered from records**, so every value is known by construction and nobody labels anything. Mutations then edit **markup and never values**, which is what keeps the expected answer invariant while the page drifts. A Hypothesis property test asserts it for any combination of mutations in any order, and a CI gate asserts it for the committed fixture. The markup deliberately carries four addressing schemes — class names, document position, a visible label, an accessible name — each genuinely load-bearing and each with a mutation that removes it. A fixture carrying only one would be a rigged comparison dressed as a measurement. Two mutations exist specifically to keep it honest. `aria_regression` is the ARIA arm's own weakness, without which it wins for free. `duplicate_block` renders a similar card *above* the real one, and it is the main source of silently-wrong results — without it the repository's central distinction is unmeasurable. Records, expected values and the mutation catalogue were committed **before any extractor existed**. `git log` is the evidence. The catalogue also states, in the data, which strategy each mutation should break, so a gate checks the mutator still does what it claims rather than trusting my memory. ## The bugs this caught in itself Three times a tool returned an empty result **without raising**, and each time the table read it as a finding about drift. The repository is built to measure exactly that failure, and it kept committing it. 1. **An invalid CSS fallback.** `.field-row:nth-of-type(N)` — cssselect cannot translate that without an explicit tag. It raised, the raise was scored BROKE, and `attr_drop` appeared to destroy the `css` strategy. `score.harness_errors` now separates "raised" from "found nothing", and a gate fails the run on any raise. 2. **A locator that matched nothing.** `get_by_role("definition", name=...)` returns an empty set, because ARIA does not give that role a name from `aria-label`. The arm read `0/32` **on the unmutated page** and would have looked like a devastating result about ARIA locators. `get_by_label` is correct. 3. **A lazy render that was not lazy.** `display: none` leaves the element in the DOM, so every waiting arm scored a perfect 32/32 and the gate said so: *"not waiting never failed, even at the longest delay"*. The content is removed and re-inserted now. The `none` row in every table is what caught all three. A strategy that cannot read the unmutated page has a bug, and every drift number beneath it would be measuring that bug instead. ## Stack — one line each, and what was refused | | the job it does | |---|---| | **lxml + cssselect** | The parser tier. The `css` strategy IS CSS selectors, so cssselect is a dependency of the subject rather than a convenience. | | **Playwright** | The browser tier, and specifically the accessible-name computation, which is the browser's job. | | **pytest + Hypothesis** | The invariant: no combination of mutations may remove a value. | | **Docker + Actions** | Parser tier in a container, browser tier in CI where a browser is affordable. | | **ruff + mypy** | Hygiene. | **Refused, and why.** *Any real website* — no controlled mutations, no exact ground truth, flaky, and someone else's terms of service. *Scrapy* — a crawling framework; crawling is not the subject. *Selenium* — Playwright covers it and two drivers would be noise. *BeautifulSoup* — lxml already does this. **And the automation from the repository this rewrites.** The idea here — addressing content by stable landmarks rather than brittle selectors — comes from a Playwright bot that logged into a live LinkedIn account, liked feed posts and carried an `[anti_detect]` block of randomised delays. The idea was worth keeping. The automation was not: it runs against a platform whose User Agreement forbids it, with deliberate detection evasion. Nothing here touches a third-party site. ## Running it ```bash pip install -r requirements-dev.txt python -m drift.cli check # the fixture is sound, no mutation touches a value pytest -q # 17 tests, no browser python -m drift.cli matrix # the three-way table with its gates python -m drift.cli silence python -m drift.cli compound python -m drift.cli recovery python -m playwright install chromium python -m drift.cli browser # the accessible name, parser against Chromium python -m drift.cli wait ``` ## Limits, stated - **A generated fixture is not the open web.** The ground truth is exact *because* it is generated. What transfers is the METHOD and the three-way split, not the particular percentages. - **Ten mutations are ten guesses about how frontends change.** They are named and committed so a reader can disagree with the list rather than with a number. - **`aria_labelledby` was added after the parser tier had run**, because without a case where a parser and a browser disagree the browser tier would have been measuring nothing. Said here rather than buried, since adding a mutation after seeing results is exactly the move that needs a reason. - **The `llm` arm was planned and is absent.** Measuring how a model fails at extraction — it returns something plausible rather than nothing — needs API credit this account does not have, and no number above depends on it. ## License MIT