test(rtl): add generated Arabic fixtures guarding visual-order extraction - #447
Open
mathurshubham wants to merge 1 commit into
Open
test(rtl): add generated Arabic fixtures guarding visual-order extraction#447mathurshubham wants to merge 1 commit into
mathurshubham wants to merge 1 commit into
Conversation
…tion There are no Arabic/RTL documents in the test matrix and real ones cannot be hosted for licensing reasons (issue firecrawl#218). Rather than depend on headless Chrome in CI, synthesize the PDFs in pure Rust at test time, reusing the hand-rolled %PDF + ToUnicode CMap approach the repo already uses for the checked-in Hebrew fixtures from PR firecrawl#440. The fixtures are the regression guard for firecrawl#440 (visual-order RTL reversal via glyph geometry): base-alphabet Arabic stored in visual order must reverse back to logical reading order, while logical-order storage must be left alone. Both conventions are generated and must extract to the same logical text. Assertions mirror the three the issue calls out: digit groups (126,248.34) embedded in an Arabic line survive intact and unreversed, lam-alef (لا) multi-character ToUnicode expansions round-trip character-identical, and a negative control rejects the raw stored (reversed) output so a run of the pipeline without the fix is caught. Verified the guard fails when fix_visual_order_rtl is neutralized and passes on current main.
There was a problem hiding this comment.
No issues found across 1 file
Shadow auto-approve: would auto-approve. Adds generated Arabic/RTL regression tests to guard visual-order text extraction logic. This test-only change synthesizes PDFs in-memory to verify digit preservation and ligature handling without modifying production code.
Re-trigger cubic
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.
Implements #218: Arabic/RTL regression coverage with fixtures generated at test time — no hosted sample files, no licensing question, and no headless-Chrome dependency in CI.
Why now
#440 just landed geometric visual-order reversal in
fix_visual_order_rtl. As #218 points out, RTL bugs are uniquely prone to silent regression: the output looks like text to a reviewer who doesn't read the script, so a revert or refactor that breaks it is invisible in a diff. These tests are the guard.How the fixtures are generated
Pure Rust, in-test (
tests/rtl_generated_tests.rs, no production source touched).make_rtl_pdf(lines, storage)hand-builds a single-page PDF with a byte-accurate xref — the same pattern as the repo's existingmake_text_pdfhelpers and the same shape as the Hebrew fixtures that landed with #440:/TrueTypefont with a/ToUnicodeCMap maps single-byte codes to Unicode, so no real Arabic glyph program is embedded.Tjwith an absoluteTm. Visual-order storage reverses each Arabic run's characters and paints left-to-right (increasing x — the case fix(extract): reverse visual-order RTL text using glyph geometry #440 must reverse). Logical-order storage stores reading order and paints right-to-left (the case fix(extract): reverse visual-order RTL text using glyph geometry #440 must leave alone). Both the geometric vote andrestore_embedded_ltr_runsare exercised.Assertions (from #218)
126,248.34inside an Arabic line must come out unreversed:arabic_visual_order_keeps_digit_group_intact,arabic_logical_order_keeps_digit_group_intact,arabic_digit_group_intact_in_positioned_items.arabic_visual_order_ligature_round_trip,arabic_logical_order_ligature_round_trip.مالسلا,مالكلا) must be absent from output:visual_order_negative_control_wrong_output_is_rejected.Plus
visual_and_logical_storage_agree: both storage conventions extract to identical reading order. Bothprocess_pdf_mem(markdown) andextract_text_with_positions_mem(positioned items) are covered.Revert check
With
fix_visual_order_rtltemporarily neutralized (early return), the 4 visual-order tests fail with the expected reversed corruption (e.g.## لالخ مالسلا مالكلا) while the 3 logical-order/positioned tests still pass — exactly the split the guard should produce. All 7 pass on currentmain.Verification
Full
cargo testgreen (1015 lib + 165 integration + 7 new rtl_generated + 3 bin + 2 doc-tests, 0 failures);cargo fmtandcargo clippy -- -D warningsclean.Out of scope, per the issue discussion: the synthetic wrong-ToUnicode corruption generator (that targets #214's detection feature, not this reversal guard) and Arabic-Indic digit variants (the ASCII digit-group case from the issue is asserted; #440's logic covers both scripts).
Closes #218.
Summary by cubic
Adds generated Arabic/RTL regression tests that synthesize PDFs at test time to guard visual-order text extraction. Prevents silent regressions in
fix_visual_order_rtl(#440) without hosting sample files or adding headless browser deps. Closes #218.tests/rtl_generated_tests.rsbuilds single-page PDFs in Rust with a/ToUnicodeCMap; exercises both visual and logical storage andrestore_embedded_ltr_runs.126,248.34) remain unreversed inside RTL lines; lam‑alef (لا) multi-characterToUnicodeexpansion round-trips; negative control rejects raw reversed forms; bothprocess_pdf_memandextract_text_with_positions_memagree; visual and logical storage extract to identical reading order.fix_visual_order_rtlmakes visual-order tests fail while logical/positioned tests pass.Written for commit f856f3f. Summary will update on new commits.