Skip to content

test(parsers): pin loader structure with golden-file tests - #104

Merged
mrsibe merged 1 commit into
mainfrom
test/parser-golden-files
Sep 25, 2026
Merged

mrsibe merged 1 commit into
mainfrom
test/parser-golden-files

Conversation

@mrsibe

@mrsibe mrsibe commented Sep 25, 2026

Copy link
Copy Markdown
Owner

What does this PR do?

Adds test/parsers.test.ts, a golden-file suite that parses the committed fixtures in test/fixtures/ and asserts the structure each loader emits — page counts, page boundaries, heading outlines, and offset arithmetic — rather than the extracted prose.

Why?

test/fixtures/ already shipped sample.pdf, sample.docx and sample.html, but no test under test/ exercised a loader at all. The provenance work in #66/#67 is about to start trusting DocumentLoadResult.structure, and there was no regression net if a loader silently stopped emitting it.

Related issue

Fixes #64

What changed?

  • test/parsers.test.ts — 8 tests covering PDF pages, DOCX sections, Markdown sections, HTML structure, preserveStructure: false, and FileParserService dispatch. Assertions are structural (counts, level outlines, offset monotonicity/containment/slice-consistency), not full-text equality.
  • Fixtures — reused sample.pdf/sample.docx/sample.html; added three small ones where the existing set could not exercise a required case:
    Fixture Loader it exercises Why
    sample.pdf PdfLoader existing single-page smoke fixture; text + page box
    multipage.pdf PdfLoader 3 pages, so page boundaries/offsets are tested across pages
    sample.docx DocxLoader existing heading-less fixture; structure must still be present
    headings.docx DocxLoader minimal OOXML with Heading1/Heading2 styles
    sample.md MarkdownLoader one h1 + two h2
    sample.html WebLoader existing Readability smoke fixture
  • package.json — npm test now passes --experimental-transform-types. Node's strip-only type support rejects the enum in src/shared/utils/logger.ts, which is on every loader's import path; transforming lets the tests import the real loaders instead of a test-only copy. The rationale is recorded under the //test key.

How was this tested?

  • npm test — 92 tests pass (84 existing + 8 new); no network required.
  • npm run typecheck — node/web/test projects all pass.
  • npx eslint test/parsers.test.ts — clean.
  • npx prettier --check on the touched files — clean.
  • Negative check: temporarily forced PdfLoader to return structure: undefined; 3 parser tests failed as intended, then reverted. This verifies the "a loader that stops populating structure fails" acceptance criterion.

Screenshots / recordings

Not applicable (test-only change).

Checklist

  • I have reviewed my own changes.
  • npm run typecheck passes.
  • npm run build passes. (not run — no production code changed; CI will run it)
  • I have tested the affected user workflow. (test suite)
  • I have not included unrelated changes.
  • I have updated documentation when necessary.

Desktop / build changes

  • Not applicable

`test/fixtures/` shipped sample.pdf/docx/html but no test under `test/`
ever exercised a loader, so nothing caught a loader dropping
`DocumentLoadResult.structure` — which the provenance work in #66/#67 is
about to start trusting.

Add `test/parsers.test.ts`, which parses the fixtures and asserts the
shape of the result (page counts, page boundaries, heading outlines,
offset arithmetic) rather than the extracted prose, so minor extraction
differences still pass while lost structure fails.

Fixtures:
- sample.pdf / sample.html / sample.docx: reused as-is.
- multipage.pdf: new, three pages, so page boundaries are exercised
  across pages rather than on a single page.
- headings.docx: new, minimal OOXML with Heading1/Heading2 styles;
  sample.docx is heading-less and only proves structure is still emitted.
- sample.md: new, one h1 and two h2.

`npm test` now passes `--experimental-transform-types`: Node's strip-only
type support rejects the enums on every loader's import path
(`src/shared/utils/logger.ts`), and transforming lets the tests import the
real loaders instead of a test-only copy. The rationale is recorded under
package.json's `//test` key.

Refs #64
@github-actions github-actions Bot added the skip-changelog Exclude from generated release notes label Sep 25, 2026
@mrsibe
mrsibe merged commit 070d23d into main Sep 25, 2026
4 checks passed
@mrsibe
mrsibe deleted the test/parser-golden-files branch September 25, 2026 05:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip-changelog Exclude from generated release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Test] Parser golden-file tests asserting structure (pages/sections), not just text

1 participant