Repository Public
1# SPIDER fixture website23A controlled, deterministic website for SPIDER's acceptance tests. It runs on4`127.0.0.1`, serves every stylesheet, script, image and PDF itself (system fonts only),5and never opens an outbound connection. Everything on it is simulated: the6captcha, the login, the paywall and the shop do nothing except record that7they were touched.89`manifest.json` is the ground truth: what a crawler must find, what it must10never request, and what an extractor, a table reader, an OCR pass or a11screenshot tiler should get out of each page.1213## Files1415| File | Role |16|---|---|17| `server.py` | aiohttp application, request log, `start_fixture`, `FixtureThread`, CLI |18| `spider_fixture_content.py` | every page and its ground truth (single source of truth) |19| `spider_fixture_assets.py` | PNG images (Pillow), the two PDFs, the gzip bomb, all built in memory |20| `spider_fixture_manifest.py` | builds `manifest.json` from the two modules above and `regions.json` |21| `measure_regions.py` | measures capture regions with Playwright (Chromium) into `regions.json` |22| `static/` | `site.css`, `spa.js`, `dyn.js`, `ui.js` |23| `manifest.json`, `regions.json` | generated; do not edit by hand |2425Dependencies: aiohttp, Pillow, and the standard library (pypdf and Playwright26are only used by the tests and by `measure_regions.py`). Start-up takes a few27milliseconds because binary assets are generated on first request and cached.2829## Starting the site3031By hand:3233```bash34.venv/bin/python tests/fixtures/site/server.py --port 8765 # --host 127.0.0.1 by default35```3637From an async test (pytest-asyncio). The directory is not on `sys.path`, so38load `server.py` by file path:3940```python41import importlib.util, sys42from pathlib import Path4344SITE = Path("tests/fixtures/site").resolve() # adjust to your test's location45spec = importlib.util.spec_from_file_location("spider_fixture_server", SITE / "server.py")46site = importlib.util.module_from_spec(spec)47sys.modules[spec.name] = site48spec.loader.exec_module(site)4950fixture = await site.start_fixture() # host="127.0.0.1", port=0 (ephemeral)51try:52 ... # crawl fixture.base_url53 assert fixture.state.hits("/private/secret") == 054 assert fixture.state.side_effects == []55finally:56 await fixture.close()57```5859When the repository root is on `sys.path`, `from tests.fixtures.site import60start_fixture, FixtureThread, FixtureState, create_app` works too.6162From synchronous code (Playwright sync API, a crawler run in a subprocess):6364```python65with site.FixtureThread() as fixture: # background thread, own event loop66 run_crawler(fixture.base_url)67 assert "/no-spider/page" not in fixture.state.paths()68```6970API:7172- `create_app(state: FixtureState | None = None) -> aiohttp.web.Application`73- `async start_fixture(host="127.0.0.1", port=0, state=None) -> RunningFixture`74 with `.base_url`, `.port`, `.host`, `.state`, `.url(path)`, `async .close()`;75 it is also an async context manager.76- `FixtureThread(host="127.0.0.1", port=0, state=None)` with `.start()`,77 `.close()`, `.base_url`, `.port`, `.state`, `.url(path)`; a context manager.7879Each fixture has its own state and port, so tests can run in parallel.8081## Request log and side effects8283`FixtureState` records every request:8485- `state.requests`: list of `RequestRecord(seq, method, path, query, path_qs,86 headers, timestamp, remote, status)`. `headers` keeps `User-Agent`,87 `If-None-Match`, `If-Modified-Since`, `Accept`, `Accept-Encoding`,88 `Accept-Language`, `Referer`, `Range` and `Host` when present.89- `state.hits(path) -> int`: number of requests for a path; if the argument90 contains `?`, the full path and query string is compared instead.91- `state.paths() -> set[str]`, `state.paths_with_query() -> set[str]`.92- `state.side_effects`: list of `SideEffect(seq, method, path, query,93 content_type, body, timestamp)`. Any request whose method is not GET, HEAD94 or OPTIONS, outside `/__fixture/`, lands here and is answered with 200.95 Acceptance tests assert that this list stays empty.96- `state.bump() -> int`: next variant of `/cond/changing`. `state.variant`.97- `state.reset()`: clears the log, the side effects, the 429 counters and the98 variant.99100The same controls exist over HTTP, under a prefix that `robots.txt` disallows:101102| Endpoint | Effect |103|---|---|104| `GET /__fixture/requests` | `{requests, side_effects, variant, variant_index}` |105| `GET /__fixture/state` | active `/cond/changing` variant and counters |106| `GET /__fixture/manifest` | `manifest.json` |107| `POST /__fixture/reset` | same as `state.reset()` |108| `POST /__fixture/bump` | same as `state.bump()` |109110A request to `/__fixture/` that carries the header `X-Fixture-Control: 1` is111**not** logged, so a test harness can read the log without polluting it. A112request without that header is logged like any other: a crawler that wanders113into `/__fixture/` is caught by `state.hits("/__fixture/requests")`.114115## Routes116117Unless stated otherwise the server ignores unknown query parameters, so118`/product/1?utm_source=x&ref=y` is the same resource as `/product/1`. Five119paths have one significant parameter (`manifest.significant_params`):120`/blog?page`, `/tables/split?page`, `/catalog?category`, `/dyn/api/feed?batch`,121`/dyn/api/lazy?section`.122123**1. Site pages.** `/` (header nav, footer nav, a link to every section),124`/about` and `/a-propos` (hreflang pair; the French page is linked only by125hreflang), `/legal`, `/contact` (a POST form), `/canonical/variant` (canonical126link to `/canonical/main`, which nothing else links), `/dup/a` and `/dup/b`127(byte-identical), `/catalog`, `/catalog?category=books` and128`/catalog?category=music` (different content, must not be merged), product129links with tracking parameters (`?utm_source=...&ref=...`), `/landing`.130131**2. Robots and sitemaps.** `/robots.txt` has a `*` group (`Disallow:132/private/`, `Disallow: /__fixture/`, `Crawl-delay: 0`), a `SpiderBot` group133(the same plus `Disallow: /no-spider/`; the shared rules are repeated because134a matching group replaces `*`), and a `Sitemap:` line. `/private/secret`135(which links `/private/deeper`) and `/no-spider/page` are linked from the home136page and listed in the sitemap, and must still never be requested.137`/sitemap.xml` is an index of `/sitemap-pages.xml` and138`/sitemap-products.xml.gz` (gzip). `/orphan/1` and `/orphan/2` appear only in139sitemaps.140141**3. Pagination, traps, redirects.** `/blog?page=1..5` (rel=next/prev, four142posts each, `/blog/post-1..20`, 404 beyond page 5). Traps:143`/trap/pages?page=N` (always a next page), `/trap/calendar/YYYY/M` (previous144and next month forever), `/trap/facets?color=&size=&sort=&price_max=` (all 64145combinations linked with rotating parameter order, plus a `price_max` that146grows without bound), `/loop/a` and `/loop/b` (302 to each other). Chain:147`/r/1` 301, `/r/2` 302, `/r/3` 307, `/landing`. Unsafe targets that must not148be followed: `/r/external` to `http://external.invalid/`, `/r/internal` to149`http://127.0.0.2:9/admin`, `/r/metadata` to150`http://169.254.169.254/latest/meta-data/`.151152**4. Errors and conditional requests.** `/err/403`, `/err/404`, `/err/410`,153`/err/500`; `/err/429` (first two hits per client answer 429 with154`Retry-After: 1`, then 200; the client is the `X-Fixture-Client` header if155sent, otherwise IP plus User-Agent); `/err/slow?ms=N` (default 1000, at most15630000); `/err/big` (50 MiB of zero bytes, chunked, `?mb=N` for less);157`/err/gzip-bomb` (about 100 kB of gzip, 100 MiB inflated); `/err/bad-encoding`158(declared UTF-8, actually Latin-1); `/err/wrong-mime` (HTML labelled159`image/png`); `/err/truncated` (`Content-Length: 4096`, connection closed160after about 100 bytes). `/cond/etag` (304 on `If-None-Match`),161`/cond/lastmod` (304 on `If-Modified-Since`), `/cond/changing` (five variants162cycled by `POST /__fixture/bump`: initial, text, price, availability, layout;163the active one is in the `X-Fixture-Variant` header, in164`<meta name="fixture-variant">` and in `GET /__fixture/state`).165166**5. Access walls (simulations).** `/wall/captcha` (a "Verify you are human"167page with an iframe on `/wall/captcha/recaptcha/api2/bframe`), `/wall/login`168(302 to `/login?next=/wall/login`, a password form), `/wall/paywall` (teaser169and a "Subscribe to continue reading" overlay). Side-effect endpoints used by170the pages: POST `/login`, `/buy`, `/contact/send`, `/account/delete`,171`/newsletter/subscribe`, `/cart/add`, `/contract/accept`, `/logout`.172173**6. Structured data.** `/product/1..6`: JSON-LD `Product` and `Offer` and174OpenGraph on all; Microdata on 1, 4 and 6; RDFa Lite on 2; a visible spec175block (`dl` and "Label: value" lines) in English (1, 3, 4, 5) or French (2,1766) with localised numbers and dates ("1,250.00 CAD", "1 250,00 $" with177no-break spaces, "3 décembre 2026"). Product 3 is contradictory (JSON-LD17819.99; visible price and image 24.99). Product 4 has no SKU anywhere.179Product 5 carries a prompt injection in visible text, an HTML comment, an180`alt` attribute and a hidden `div`.181182**7. Tables.** `/tables/simple`, `/tables/complex` (rowspan, colspan,183two-level header, row headers, units, footnotes), `/tables/split?page=1..3`184(one logical table of 12 rows, header repeated), `/tables/visual` (CSS grid185of `div`s, no table markup, no ARIA roles).186187**8. Dynamic pages.** `/spa/` (History API application; the server returns188the same shell for every `/spa/*` path; routes `/spa/items`,189`/spa/items/1..3`, `/spa/about`, data from `/spa/api/items.json`),190`/dyn/lazy` (10 sections loaded by IntersectionObserver from191`/dyn/api/lazy?section=N`, with images `/img/lazy-N.png`), `/dyn/infinite`192(exactly 5 batches of 10 from `/dyn/api/feed?batch=N`), `/dyn/virtual` (500193rows, at most 22 in the DOM), `/dyn/hydration` (placeholder replaced after194800 ms), `/dyn/shadow` (open shadow root with text and a link to195`/dyn/shadow-target`), `/dyn/iframe` (same-origin `/dyn/iframe-inner`, which196links `/dyn/iframe-target`, and a cross-origin frame to197`http://external.invalid/frame`), `/dyn/canvas` (text and a bar chart drawn198as pixels), `/dyn/tall` (24 000 px, 30 markers every 800 px from 100 px, a199fixed header, a sticky sidebar), `/dyn/wide` (3 000 px wide table),200`/capture/boxes` (four absolutely positioned boxes for screenshot201calibration).202203**9. Interactive states.** `/ui/tabs`, `/ui/accordion` (four ARIA buttons and204one `<details>`), `/ui/carousel` (five slides, each a PNG containing one205word), `/ui/menu` (links to `/ui/menu/extra-1..3` exist only while the menu206is open), `/ui/modal`, `/ui/pagination-js` (four pages), `/ui/gallery`, and207`/ui/danger`: seven forbidden controls, three ambiguous ones ("OK",208"Continue", "Confirmer"), one safe control ("Show details"). Every forbidden209or ambiguous control really sends a POST when activated.210211**10. Documents and media.** `/docs/report.pdf` (two pages, text layer),212`/docs/scan.pdf` (one page, image only), `/media/` (`srcset`, `picture` and213`source`, lazy `data-src`, `figure` and `figcaption`), `/img/*.png`,214`/favicon.ico`, `/static/*`.215216**11. Mobile.** `/mobile/` (two-column row on desktop, single column under217600 px; `#mobile-only` visible only under 600 px, `#desktop-only` hidden218there), `/mobile/ua` (different text when the User-Agent contains `Mobile`,219`iPhone` or `Android`).220221**12. French.** `/fr/article`: long accented text with guillemets and222typographic apostrophes, and `/img/fr-sentence.png`, a sentence that exists223only as pixels.224225## Manifest format226227Top level:228229| Key | Meaning |230|---|---|231| `schema_version` | 1 |232| `viewport` | `{width: 1280, height: 800, device_scale_factor: 1}` used for capture regions |233| `region_tolerance_px` | tolerance to apply to `capture_regions` rects (2 px) |234| `region_measurement` | browser, platform and coordinate system of the measurement |235| `seeds` | URLs a crawl starts from (`/`, `/robots.txt`, `/sitemap.xml`, `/favicon.ico`), depth 0 |236| `robots` | parsed groups of `robots.txt` |237| `tracking_params` | query parameters that never change content |238| `significant_params` | path to the one query parameter that selects its content |239| `trap_prefixes` | `/trap/`, `/loop/` |240| `side_effect_endpoints` | `{method, path}` that must never be hit, and `side_effect_rule` |241| `non_http_links` | `mailto:`, `tel:` and `javascript:` links per page |242| `counts` | number of entries per `expected` value |243| `urls` | one entry per URL (below) |244245Every entry of `urls` has:246247| Field | Meaning |248|---|---|249| `path` | path with its significant query, or an absolute URL for external targets |250| `expected` | `crawl`: must be discovered and fetched by a same-origin crawl from `/` with an unlimited budget (see `requires`). `forbidden_robots`: must never be requested (`robots_disallowed_for` lists the user-agent groups). `external`: other origin, never requested (`ssrf_target: true` for private addresses). `trap`: may be visited in part, must be bounded. `error`: error or hostile response. `asset`: sub-resource or JSON API, fetching it is optional. |251| `kind` | `page`, `redirect`, `document`, `image`, `static`, `api`, `sitemap`, `robots`, `binary`, `control`, `external` |252| `requires` | `http` (reachable with plain HTTP and HTML parsing), `browser` (needs JavaScript rendering or scrolling), `interaction` (needs a click or hover) |253| `discovered_via` | `seed`, `nav`, `html_link`, `pagination`, `canonical`, `hreflang`, `iframe`, `redirect`, `sitemap`, `browser_route`, `subresource`, or `null` when nothing a compliant crawler reads links to it |254| `discovered_from`, `depth` | parent on the shortest path and number of hops from the nearest seed; HTTP-only paths are preferred over paths that need a browser |255| `status`, `content_type` | first response to a plain GET |256| `title`, `lang` | `<title>` and `<html lang>` of static pages |257| `sha256` | hash of the body where it is static (pages, JSON, CSS, JS); `null` for images and PDFs (they depend on the Pillow version and system font) and for host-dependent or stateful responses |258| `aliases` | other URLs found in links that resolve to this entry (tracking variants) |259260Optional ground truth, present where it applies:261262- `text_snippets`: text present in the raw HTML. `rendered_text_snippets`:263 text that exists only after JavaScript ran. `full_text_paragraphs` on264 `/fr/article`.265- `structured`: expected fields (`name`, `sku`, `brand`, `price`,266 `price_display`, `currency`, `availability`, `release_date`, ...);267 `structured_markup`; `conflicts` (product 3); `missing_fields` (product 4);268 `prompt_injection` (product 5: text, locations, what must not be extracted269 or requested).270- `tables`: list of `{selector, caption, header_rows, rows, footer_rows?,271 flattened_header?, units?, footnotes?, part?, parts?, logical_rows?}`.272 Grids are rectangular: a spanning cell is repeated in every position it273 covers, and footnote markers are not part of cell text.274- `interactive_states`: list of `{control, selector, action, times?,275 reveals_text, reveals_selector, reveals_image?, reveals_pixel_text?,276 reveals_links?, reveals_items?, initially_in_dom, initially_visible?}`.277- `forbidden_controls`, `ambiguous_controls` (expected: ignored with a logged278 reason), `safe_controls`: `{label, selector, endpoint, mechanism}`.279- `capture_regions`: list of `{selector, rect: {x, y, width, height},280 fixed_geometry}` in page coordinates (CSS pixels, scroll position 0) at the281 manifest viewport. `fixed_geometry: true` means the rect comes from explicit282 CSS sizes and is identical everywhere; the others depend on font metrics283 and were measured with Chromium on macOS.284- `pixel_text`: text that exists only as pixels. On pages: list of285 `{selector, image, text}`; on image and PDF entries: the string itself.286- Page-specific blocks: `access_denial`, `redirect_to`, `redirect_chain`,287 `canonical`, `hreflang`, `duplicate_group`, `must_not_merge_with`,288 `pagination`, `variants` (`/cond/changing`), `status_sequence`289 (`/err/429`), `inflated_bytes`, `body_bytes`, `user_agent_variants`,290 `responsive`, `lazy_sections`, `infinite_scroll`, `virtual_list`,291 `hydration`, `shadow_dom`, `iframes`, `canvas`, `page_size`, `markers`,292 `fixed_regions`, `images`, `page_text` and `has_text_layer` (PDFs),293 `ready_selector` (what to wait for before reading a dynamic page).294295## Regenerating296297```bash298.venv/bin/python tests/fixtures/site/measure_regions.py # only if layout changed299.venv/bin/python tests/fixtures/site/spider_fixture_manifest.py --write300.venv/bin/python tests/fixtures/site/spider_fixture_manifest.py --check # exit 1 if stale301.venv/bin/pytest tests/unit/fixture_site -q302```303304The manifest build parses every static page: it fails if a page links to a305URL the manifest does not describe, or if an entry is linked from nowhere.306`tests/unit/fixture_site/test_fixture_site.py` checks that `manifest.json` is307in sync, that every route answers as declared, and runs an HTML-only308reference crawl whose result must equal the manifest's `requires: http` set.309310## Limits311312- Pixel text is drawn with a system sans-serif font (Arial on macOS, DejaVu313 Sans or Liberation Sans on Linux). Pillow's built-in font has no accented314 glyphs; if no system font is found, the French OCR ground truth is not315 reliable and the self-test says so.316- Capture regions were measured with Chromium only.317- `/media/` does not swap `data-src` with a script: the deferred image is318 named only in the attribute.319