SPIDER fixture website
A controlled, deterministic website for SPIDER's acceptance tests. It runs on
127.0.0.1, serves every stylesheet, script, image and PDF itself (system fonts only),
and never opens an outbound connection. Everything on it is simulated: the
captcha, the login, the paywall and the shop do nothing except record that
they were touched.
manifest.json is the ground truth: what a crawler must find, what it must
never request, and what an extractor, a table reader, an OCR pass or a
screenshot tiler should get out of each page.
Files
| File | Role |
|---|---|
server.py |
aiohttp application, request log, start_fixture, FixtureThread, CLI |
spider_fixture_content.py |
every page and its ground truth (single source of truth) |
spider_fixture_assets.py |
PNG images (Pillow), the two PDFs, the gzip bomb, all built in memory |
spider_fixture_manifest.py |
builds manifest.json from the two modules above and regions.json |
measure_regions.py |
measures capture regions with Playwright (Chromium) into regions.json |
static/ |
site.css, spa.js, dyn.js, ui.js |
manifest.json, regions.json |
generated; do not edit by hand |
Dependencies: aiohttp, Pillow, and the standard library (pypdf and Playwright
are only used by the tests and by measure_regions.py). Start-up takes a few
milliseconds because binary assets are generated on first request and cached.
Starting the site
By hand:
.venv/bin/python tests/fixtures/site/server.py --port 8765 # --host 127.0.0.1 by defaultFrom an async test (pytest-asyncio). The directory is not on sys.path, so
load server.py by file path:
import importlib.util, sys
from pathlib import Path
SITE = Path("tests/fixtures/site").resolve() # adjust to your test's location
spec = importlib.util.spec_from_file_location("spider_fixture_server", SITE / "server.py")
site = importlib.util.module_from_spec(spec)
sys.modules[spec.name] = site
spec.loader.exec_module(site)
fixture = await site.start_fixture() # host="127.0.0.1", port=0 (ephemeral)
try:
... # crawl fixture.base_url
assert fixture.state.hits("/private/secret") == 0
assert fixture.state.side_effects == []
finally:
await fixture.close()When the repository root is on sys.path, from tests.fixtures.site import start_fixture, FixtureThread, FixtureState, create_app works too.
From synchronous code (Playwright sync API, a crawler run in a subprocess):
with site.FixtureThread() as fixture: # background thread, own event loop
run_crawler(fixture.base_url)
assert "/no-spider/page" not in fixture.state.paths()API:
create_app(state: FixtureState | None = None) -> aiohttp.web.Applicationasync start_fixture(host="127.0.0.1", port=0, state=None) -> RunningFixturewith.base_url,.port,.host,.state,.url(path),async .close(); it is also an async context manager.FixtureThread(host="127.0.0.1", port=0, state=None)with.start(),.close(),.base_url,.port,.state,.url(path); a context manager.
Each fixture has its own state and port, so tests can run in parallel.
Request log and side effects
FixtureState records every request:
state.requests: list ofRequestRecord(seq, method, path, query, path_qs, headers, timestamp, remote, status).headerskeepsUser-Agent,If-None-Match,If-Modified-Since,Accept,Accept-Encoding,Accept-Language,Referer,RangeandHostwhen present.state.hits(path) -> int: number of requests for a path; if the argument contains?, the full path and query string is compared instead.state.paths() -> set[str],state.paths_with_query() -> set[str].state.side_effects: list ofSideEffect(seq, method, path, query, content_type, body, timestamp). Any request whose method is not GET, HEAD or OPTIONS, outside/__fixture/, lands here and is answered with 200. Acceptance tests assert that this list stays empty.state.bump() -> int: next variant of/cond/changing.state.variant.state.reset(): clears the log, the side effects, the 429 counters and the variant.
The same controls exist over HTTP, under a prefix that robots.txt disallows:
| Endpoint | Effect |
|---|---|
GET /__fixture/requests |
{requests, side_effects, variant, variant_index} |
GET /__fixture/state |
active /cond/changing variant and counters |
GET /__fixture/manifest |
manifest.json |
POST /__fixture/reset |
same as state.reset() |
POST /__fixture/bump |
same as state.bump() |
A request to /__fixture/ that carries the header X-Fixture-Control: 1 is
not logged, so a test harness can read the log without polluting it. A
request without that header is logged like any other: a crawler that wanders
into /__fixture/ is caught by state.hits("/__fixture/requests").
Routes
Unless stated otherwise the server ignores unknown query parameters, so
/product/1?utm_source=x&ref=y is the same resource as /product/1. Five
paths have one significant parameter (manifest.significant_params):
/blog?page, /tables/split?page, /catalog?category, /dyn/api/feed?batch,
/dyn/api/lazy?section.
1. Site pages. / (header nav, footer nav, a link to every section),
/about and /a-propos (hreflang pair; the French page is linked only by
hreflang), /legal, /contact (a POST form), /canonical/variant (canonical
link to /canonical/main, which nothing else links), /dup/a and /dup/b
(byte-identical), /catalog, /catalog?category=books and
/catalog?category=music (different content, must not be merged), product
links with tracking parameters (?utm_source=...&ref=...), /landing.
2. Robots and sitemaps. /robots.txt has a * group (Disallow: /private/, Disallow: /__fixture/, Crawl-delay: 0), a SpiderBot group
(the same plus Disallow: /no-spider/; the shared rules are repeated because
a matching group replaces *), and a Sitemap: line. /private/secret
(which links /private/deeper) and /no-spider/page are linked from the home
page and listed in the sitemap, and must still never be requested.
/sitemap.xml is an index of /sitemap-pages.xml and
/sitemap-products.xml.gz (gzip). /orphan/1 and /orphan/2 appear only in
sitemaps.
3. Pagination, traps, redirects. /blog?page=1..5 (rel=next/prev, four
posts each, /blog/post-1..20, 404 beyond page 5). Traps:
/trap/pages?page=N (always a next page), /trap/calendar/YYYY/M (previous
and next month forever), /trap/facets?color=&size=&sort=&price_max= (all 64
combinations linked with rotating parameter order, plus a price_max that
grows without bound), /loop/a and /loop/b (302 to each other). Chain:
/r/1 301, /r/2 302, /r/3 307, /landing. Unsafe targets that must not
be followed: /r/external to http://external.invalid/, /r/internal to
http://127.0.0.2:9/admin, /r/metadata to
http://169.254.169.254/latest/meta-data/.
4. Errors and conditional requests. /err/403, /err/404, /err/410,
/err/500; /err/429 (first two hits per client answer 429 with
Retry-After: 1, then 200; the client is the X-Fixture-Client header if
sent, otherwise IP plus User-Agent); /err/slow?ms=N (default 1000, at most
30000); /err/big (50 MiB of zero bytes, chunked, ?mb=N for less);
/err/gzip-bomb (about 100 kB of gzip, 100 MiB inflated); /err/bad-encoding
(declared UTF-8, actually Latin-1); /err/wrong-mime (HTML labelled
image/png); /err/truncated (Content-Length: 4096, connection closed
after about 100 bytes). /cond/etag (304 on If-None-Match),
/cond/lastmod (304 on If-Modified-Since), /cond/changing (five variants
cycled by POST /__fixture/bump: initial, text, price, availability, layout;
the active one is in the X-Fixture-Variant header, in
<meta name="fixture-variant"> and in GET /__fixture/state).
5. Access walls (simulations). /wall/captcha (a "Verify you are human"
page with an iframe on /wall/captcha/recaptcha/api2/bframe), /wall/login
(302 to /login?next=/wall/login, a password form), /wall/paywall (teaser
and a "Subscribe to continue reading" overlay). Side-effect endpoints used by
the pages: POST /login, /buy, /contact/send, /account/delete,
/newsletter/subscribe, /cart/add, /contract/accept, /logout.
6. Structured data. /product/1..6: JSON-LD Product and Offer and
OpenGraph on all; Microdata on 1, 4 and 6; RDFa Lite on 2; a visible spec
block (dl and "Label: value" lines) in English (1, 3, 4, 5) or French (2,
6) with localised numbers and dates ("1,250.00 CAD", "1 250,00 $" with
no-break spaces, "3 décembre 2026"). Product 3 is contradictory (JSON-LD
19.99; visible price and image 24.99). Product 4 has no SKU anywhere.
Product 5 carries a prompt injection in visible text, an HTML comment, an
alt attribute and a hidden div.
7. Tables. /tables/simple, /tables/complex (rowspan, colspan,
two-level header, row headers, units, footnotes), /tables/split?page=1..3
(one logical table of 12 rows, header repeated), /tables/visual (CSS grid
of divs, no table markup, no ARIA roles).
8. Dynamic pages. /spa/ (History API application; the server returns
the same shell for every /spa/* path; routes /spa/items,
/spa/items/1..3, /spa/about, data from /spa/api/items.json),
/dyn/lazy (10 sections loaded by IntersectionObserver from
/dyn/api/lazy?section=N, with images /img/lazy-N.png), /dyn/infinite
(exactly 5 batches of 10 from /dyn/api/feed?batch=N), /dyn/virtual (500
rows, at most 22 in the DOM), /dyn/hydration (placeholder replaced after
800 ms), /dyn/shadow (open shadow root with text and a link to
/dyn/shadow-target), /dyn/iframe (same-origin /dyn/iframe-inner, which
links /dyn/iframe-target, and a cross-origin frame to
http://external.invalid/frame), /dyn/canvas (text and a bar chart drawn
as pixels), /dyn/tall (24 000 px, 30 markers every 800 px from 100 px, a
fixed header, a sticky sidebar), /dyn/wide (3 000 px wide table),
/capture/boxes (four absolutely positioned boxes for screenshot
calibration).
9. Interactive states. /ui/tabs, /ui/accordion (four ARIA buttons and
one <details>), /ui/carousel (five slides, each a PNG containing one
word), /ui/menu (links to /ui/menu/extra-1..3 exist only while the menu
is open), /ui/modal, /ui/pagination-js (four pages), /ui/gallery, and
/ui/danger: seven forbidden controls, three ambiguous ones ("OK",
"Continue", "Confirmer"), one safe control ("Show details"). Every forbidden
or ambiguous control really sends a POST when activated.
10. Documents and media. /docs/report.pdf (two pages, text layer),
/docs/scan.pdf (one page, image only), /media/ (srcset, picture and
source, lazy data-src, figure and figcaption), /img/*.png,
/favicon.ico, /static/*.
11. Mobile. /mobile/ (two-column row on desktop, single column under
600 px; #mobile-only visible only under 600 px, #desktop-only hidden
there), /mobile/ua (different text when the User-Agent contains Mobile,
iPhone or Android).
12. French. /fr/article: long accented text with guillemets and
typographic apostrophes, and /img/fr-sentence.png, a sentence that exists
only as pixels.
Manifest format
Top level:
| Key | Meaning |
|---|---|
schema_version |
1 |
viewport |
{width: 1280, height: 800, device_scale_factor: 1} used for capture regions |
region_tolerance_px |
tolerance to apply to capture_regions rects (2 px) |
region_measurement |
browser, platform and coordinate system of the measurement |
seeds |
URLs a crawl starts from (/, /robots.txt, /sitemap.xml, /favicon.ico), depth 0 |
robots |
parsed groups of robots.txt |
tracking_params |
query parameters that never change content |
significant_params |
path to the one query parameter that selects its content |
trap_prefixes |
/trap/, /loop/ |
side_effect_endpoints |
{method, path} that must never be hit, and side_effect_rule |
non_http_links |
mailto:, tel: and javascript: links per page |
counts |
number of entries per expected value |
urls |
one entry per URL (below) |
Every entry of urls has:
| Field | Meaning |
|---|---|
path |
path with its significant query, or an absolute URL for external targets |
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. |
kind |
page, redirect, document, image, static, api, sitemap, robots, binary, control, external |
requires |
http (reachable with plain HTTP and HTML parsing), browser (needs JavaScript rendering or scrolling), interaction (needs a click or hover) |
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 |
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 |
status, content_type |
first response to a plain GET |
title, lang |
<title> and <html lang> of static pages |
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 |
aliases |
other URLs found in links that resolve to this entry (tracking variants) |
Optional ground truth, present where it applies:
text_snippets: text present in the raw HTML.rendered_text_snippets: text that exists only after JavaScript ran.full_text_paragraphson/fr/article.structured: expected fields (name,sku,brand,price,price_display,currency,availability,release_date, ...);structured_markup;conflicts(product 3);missing_fields(product 4);prompt_injection(product 5: text, locations, what must not be extracted or requested).tables: list of{selector, caption, header_rows, rows, footer_rows?, flattened_header?, units?, footnotes?, part?, parts?, logical_rows?}. Grids are rectangular: a spanning cell is repeated in every position it covers, and footnote markers are not part of cell text.interactive_states: list of{control, selector, action, times?, reveals_text, reveals_selector, reveals_image?, reveals_pixel_text?, reveals_links?, reveals_items?, initially_in_dom, initially_visible?}.forbidden_controls,ambiguous_controls(expected: ignored with a logged reason),safe_controls:{label, selector, endpoint, mechanism}.capture_regions: list of{selector, rect: {x, y, width, height}, fixed_geometry}in page coordinates (CSS pixels, scroll position 0) at the manifest viewport.fixed_geometry: truemeans the rect comes from explicit CSS sizes and is identical everywhere; the others depend on font metrics and were measured with Chromium on macOS.pixel_text: text that exists only as pixels. On pages: list of{selector, image, text}; on image and PDF entries: the string itself.- Page-specific blocks:
access_denial,redirect_to,redirect_chain,canonical,hreflang,duplicate_group,must_not_merge_with,pagination,variants(/cond/changing),status_sequence(/err/429),inflated_bytes,body_bytes,user_agent_variants,responsive,lazy_sections,infinite_scroll,virtual_list,hydration,shadow_dom,iframes,canvas,page_size,markers,fixed_regions,images,page_textandhas_text_layer(PDFs),ready_selector(what to wait for before reading a dynamic page).
Regenerating
.venv/bin/python tests/fixtures/site/measure_regions.py # only if layout changed
.venv/bin/python tests/fixtures/site/spider_fixture_manifest.py --write
.venv/bin/python tests/fixtures/site/spider_fixture_manifest.py --check # exit 1 if stale
.venv/bin/pytest tests/unit/fixture_site -qThe manifest build parses every static page: it fails if a page links to a
URL the manifest does not describe, or if an entry is linked from nowhere.
tests/unit/fixture_site/test_fixture_site.py checks that manifest.json is
in sync, that every route answers as declared, and runs an HTML-only
reference crawl whose result must equal the manifest's requires: http set.
Limits
- Pixel text is drawn with a system sans-serif font (Arial on macOS, DejaVu Sans or Liberation Sans on Linux). Pillow's built-in font has no accented glyphs; if no system font is found, the French OCR ground truth is not reliable and the self-test says so.
- Capture regions were measured with Chromium only.
/media/does not swapdata-srcwith a script: the deferred image is named only in the attribute.