Add processing pipeline test spec with golden outputs#434
Open
eyeseast wants to merge 2 commits into
Open
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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/, anexpected/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.indexcache — plusmetadata.jsonrecording the database-facing API callbacks (page_count,page_spec,file_hash,status).How it works
harness.pyruns 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-bundledlibtesseract), 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.pyregenerates the goldens after an intentional behavior change;generate.py --checkvalidates without pytest.compare.pyencodes the normalization rules for known non-determinism:updatedtimestamps, PDF bytes (uuid-named XObjects from the grafter, pikepdf/ID),page_specsegment order (Redis set iteration), and the redacted-PDFfile_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 bymake_corpus.pyand 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_ocrproducesocr: "tess4_force", and redaction re-sendsfile_hash/statusbut notpage_spec.Not covered yet
Textract OCR, non-PDF conversion (needs the LibreOffice LFS bundle), page modifications (needs
storage.async_downloadin local storage), bulk import,set_page_text, and non-English OCR — all documented in the README.Test plan
pytest documentcloud/documents/processing/tests/spec/test_spec.pyrepeatedly across fresh processesgenerate.py --checkreproduces the committed goldens byte-for-byte (modulo the documented normalizations)🤖 Generated with Claude Code
https://claude.ai/code/session_01Le7iTGKrY5TmE4jL4GhnWU
Generated by Claude Code