Skip to content

Add processing pipeline test spec with golden outputs#434

Open
eyeseast wants to merge 2 commits into
masterfrom
claude/processing-pipeline-test-spec-24amep
Open

Add processing pipeline test spec with golden outputs#434
eyeseast wants to merge 2 commits into
masterfrom
claude/processing-pipeline-test-spec-24amep

Conversation

@eyeseast

Copy link
Copy Markdown
Contributor

Summary

Adds documentcloud/documents/processing/tests/spec/: an executable version of the processing pipeline output contract researched in MuckRock/research/processing-pipeline-spec. The goal is to be able to change processing code and validate that the pipeline's outputs stay the same (or that a diff shows exactly what changed).

For each test document under documents/, an expected/ directory contains every file the current pipeline produces — processed PDF, concatenated and per-page text, txt.json, position.json, all five page image sizes, the .index cache — plus metadata.json recording the database-facing API callbacks (page_count, page_spec, file_hash, status).

How it works

  • harness.py runs the real serverless functions (info_and_image, ocr) in-process against local storage and Redis. Nothing in the pipeline is mocked: pdfium rendering, Tesseract OCR (the LFS-bundled libtesseract), grafting, and pdfplumber positions all run for real. Pubsub topics dispatch through a FIFO queue, mirroring production's one-Lambda-per-message model.
  • test_spec.py (pytest) reruns the pipeline for every case and compares against the goldens. It runs in CI with the existing Redis service; OCR cases skip automatically when the LFS Tesseract libraries or pinned traineddata aren't present (CI doesn't check out LFS, so CI covers the embedded-text cases).
  • generate.py regenerates the goldens after an intentional behavior change; generate.py --check validates without pytest.
  • compare.py encodes the normalization rules for known non-determinism: updated timestamps, PDF bytes (uuid-named XObjects from the grafter, pikepdf /ID), page_spec segment order (Redis set iteration), and the redacted-PDF file_hash.

Test corpus (8 cases)

Embedded text (1 and 3 pages), scanned/image-only, mixed text+scan, force_ocr, mixed page dimensions, blank page, and a redaction pass. Inputs are built deterministically by make_corpus.py and committed (~1.7 MB total including goldens).

Notable pipeline behaviors the goldens capture: pdfium text ends with a trailing \x00, Tesseract text ends with \f (a blank page yields "\f", not ""), force_ocr produces ocr: "tess4_force", and redaction re-sends file_hash/status but not page_spec.

Not covered yet

Textract OCR, non-PDF conversion (needs the LibreOffice LFS bundle), page modifications (needs storage.async_download in local storage), bulk import, set_page_text, and non-English OCR — all documented in the README.

Test plan

  • All 8 cases pass pytest documentcloud/documents/processing/tests/spec/test_spec.py repeatedly across fresh processes
  • generate.py --check reproduces the committed goldens byte-for-byte (modulo the documented normalizations)

🤖 Generated with Claude Code

https://claude.ai/code/session_01Le7iTGKrY5TmE4jL4GhnWU


Generated by Claude Code

claude added 2 commits July 14, 2026 15:58
Add documentcloud/documents/processing/tests/spec/: an executable version
of the processing pipeline output contract researched in
MuckRock/research/processing-pipeline-spec.

Each test document under documents/ has an input PDF and an expected/
directory containing every file the current pipeline produces for it
(processed PDF, concatenated and per-page text, txt.json, position.json,
all five page image sizes, index cache) plus the database-facing metadata
captured from the API callbacks (page_count, page_spec, file_hash, status).

The harness runs the real serverless functions in-process - pdfium
rendering, Tesseract OCR, grafting, and text position extraction are not
mocked - against local storage and Redis, with pubsub topics dispatched
through a FIFO queue to mirror one-Lambda-per-message production behavior.

The corpus covers embedded text, scanned, mixed, force-OCR, mixed page
sizes, blank page, and redaction cases. test_spec.py validates a fresh
pipeline run against the goldens (OCR cases skip when the LFS Tesseract
libraries or pinned traineddata are unavailable); generate.py regenerates
the goldens after intentional behavior changes.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Le7iTGKrY5TmE4jL4GhnWU
Pull the Tesseract LFS libraries in the CI test job (only the ocr/tesseract
directory, to avoid fetching the large LibreOffice bundle) so the OCR test
spec cases run in CI instead of skipping. The pinned eng.traineddata is
downloaded automatically on first use. Also fix pylint findings in the spec
package and drop an unused compare_case parameter.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Le7iTGKrY5TmE4jL4GhnWU
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants