kreuzberg 4.0.0.pre.rc.7 → 4.0.0.pre.rc.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,374 @@
1
+ //! PDFium linking integration tests.
2
+ //!
3
+ //! This module tests PDF extraction functionality across all PDFium linking strategies
4
+ //! (default, static, bundled, system). Tests verify that:
5
+ //!
6
+ //! 1. PDF extraction works regardless of linking strategy
7
+ //! 2. Extracted content is valid and non-empty
8
+ //! 3. Bundled PDFium extraction works when feature is enabled
9
+ //! 4. Metadata extraction functions correctly
10
+ //! 5. Error handling works for invalid PDFs
11
+ //!
12
+ //! These tests are strategy-agnostic - they verify functionality works with ANY
13
+ //! linking strategy, not implementation details of specific strategies.
14
+ //!
15
+ //! Test philosophy:
16
+ //! - Use small test PDFs from test_documents/
17
+ //! - Assert on extracted content and behavior, not linking internals
18
+ //! - Test both successful extraction and error cases
19
+ //! - Skip tests gracefully if test files are missing
20
+
21
+ #![cfg(feature = "pdf")]
22
+
23
+ mod helpers;
24
+
25
+ use helpers::*;
26
+ use kreuzberg::core::config::ExtractionConfig;
27
+ use kreuzberg::extract_file_sync;
28
+
29
+ /// Test basic PDF extraction works regardless of linking strategy.
30
+ ///
31
+ /// This is the primary integration test - it verifies that PDF extraction
32
+ /// functions correctly with any linking strategy. We use a small test PDF
33
+ /// and verify that:
34
+ /// - Extraction completes successfully
35
+ /// - Content is non-empty and contains expected text
36
+ /// - MIME type is correctly detected
37
+ #[test]
38
+ fn test_pdf_extraction_basic() {
39
+ if skip_if_missing("pdfs_with_tables/tiny.pdf") {
40
+ return;
41
+ }
42
+
43
+ let file_path = get_test_file_path("pdfs_with_tables/tiny.pdf");
44
+ let config = ExtractionConfig::default();
45
+
46
+ let result = extract_file_sync(&file_path, None, &config).expect("Should extract PDF successfully");
47
+
48
+ // Verify MIME type detection
49
+ assert_mime_type(&result, "application/pdf");
50
+
51
+ // Verify content was extracted
52
+ assert_non_empty_content(&result);
53
+
54
+ // Verify reasonable content length for a small PDF
55
+ assert_min_content_length(&result, 10);
56
+ }
57
+
58
+ /// Test PDF extraction with a medium-sized test PDF.
59
+ ///
60
+ /// Verifies that extraction works with slightly larger PDFs and produces
61
+ /// substantive content. This test helps ensure linking strategy works
62
+ /// with real-world document sizes.
63
+ #[test]
64
+ fn test_pdf_extraction_medium() {
65
+ if skip_if_missing("pdfs_with_tables/medium.pdf") {
66
+ return;
67
+ }
68
+
69
+ let file_path = get_test_file_path("pdfs_with_tables/medium.pdf");
70
+ let config = ExtractionConfig::default();
71
+
72
+ let result = extract_file_sync(&file_path, None, &config).expect("Should extract medium PDF successfully");
73
+
74
+ assert_mime_type(&result, "application/pdf");
75
+ assert_non_empty_content(&result);
76
+
77
+ // Medium PDF should have more content than tiny
78
+ assert!(result.content.len() >= 50, "Medium PDF should have substantial content");
79
+ }
80
+
81
+ /// Test PDF extraction with rotated pages.
82
+ ///
83
+ /// Some PDFs have rotated pages. This test verifies that the linking
84
+ /// strategy handles page rotation correctly (PDFium should handle this
85
+ /// transparently). Note: This specific PDF may have OCR-only content,
86
+ /// so we just verify extraction completes without error.
87
+ #[test]
88
+ fn test_pdf_extraction_rotated_pages() {
89
+ if skip_if_missing("pdfs/ocr_test_rotated_90.pdf") {
90
+ return;
91
+ }
92
+
93
+ let file_path = get_test_file_path("pdfs/ocr_test_rotated_90.pdf");
94
+ let config = ExtractionConfig::default();
95
+
96
+ let result = extract_file_sync(&file_path, None, &config).expect("Should extract rotated PDF successfully");
97
+
98
+ assert_mime_type(&result, "application/pdf");
99
+ // Rotated PDFs may have OCR-only content, just verify extraction completes
100
+ }
101
+
102
+ /// Test PDF text extraction with code and formula content.
103
+ ///
104
+ /// Verifies extraction works with technical PDFs containing code blocks,
105
+ /// mathematical formulas, and special formatting.
106
+ #[test]
107
+ fn test_pdf_extraction_code_and_formulas() {
108
+ if skip_if_missing("pdfs/code_and_formula.pdf") {
109
+ return;
110
+ }
111
+
112
+ let file_path = get_test_file_path("pdfs/code_and_formula.pdf");
113
+ let config = ExtractionConfig::default();
114
+
115
+ let result = extract_file_sync(&file_path, None, &config).expect("Should extract PDF with code and formulas");
116
+
117
+ assert_mime_type(&result, "application/pdf");
118
+ assert_non_empty_content(&result);
119
+ }
120
+
121
+ /// Test PDF extraction preserves right-to-left text direction.
122
+ ///
123
+ /// PDFs with RTL text (Arabic, Hebrew, etc.) require special handling.
124
+ /// This verifies extraction works with RTL content.
125
+ #[test]
126
+ fn test_pdf_extraction_right_to_left() {
127
+ if skip_if_missing("pdfs/right_to_left_01.pdf") {
128
+ return;
129
+ }
130
+
131
+ let file_path = get_test_file_path("pdfs/right_to_left_01.pdf");
132
+ let config = ExtractionConfig::default();
133
+
134
+ let result = extract_file_sync(&file_path, None, &config).expect("Should extract RTL PDF successfully");
135
+
136
+ assert_mime_type(&result, "application/pdf");
137
+ // RTL PDFs might have minimal or no extracted text depending on PDF structure
138
+ // Just verify extraction completes without error
139
+ }
140
+
141
+ /// Test PDF metadata extraction.
142
+ ///
143
+ /// Verifies that PDF metadata (title, author, creation date, etc.) can be
144
+ /// extracted correctly, which is independent of linking strategy.
145
+ #[test]
146
+ fn test_pdf_metadata_extraction() {
147
+ if skip_if_missing("pdfs_with_tables/tiny.pdf") {
148
+ return;
149
+ }
150
+
151
+ let file_path = get_test_file_path("pdfs_with_tables/tiny.pdf");
152
+ let config = ExtractionConfig::default();
153
+
154
+ let result = extract_file_sync(&file_path, None, &config).expect("Should extract PDF metadata");
155
+
156
+ // Metadata field is always present (may have empty fields for some PDFs)
157
+ // Just verify the structure exists
158
+ let _metadata = &result.metadata;
159
+ assert!(!result.mime_type.is_empty(), "MIME type should be set");
160
+ }
161
+
162
+ /// Test extraction of byte array from PDF.
163
+ ///
164
+ /// Verifies that extract_bytes_sync works for PDF content, which is
165
+ /// important for in-memory processing.
166
+ #[test]
167
+ fn test_pdf_extraction_from_bytes() {
168
+ if skip_if_missing("pdfs_with_tables/tiny.pdf") {
169
+ return;
170
+ }
171
+
172
+ let file_path = get_test_file_path("pdfs_with_tables/tiny.pdf");
173
+ let pdf_bytes = std::fs::read(&file_path).expect("Should read PDF file");
174
+
175
+ let config = ExtractionConfig::default();
176
+ let result = kreuzberg::extract_bytes_sync(&pdf_bytes, "application/pdf", &config)
177
+ .expect("Should extract PDF from bytes successfully");
178
+
179
+ assert_mime_type(&result, "application/pdf");
180
+ assert_non_empty_content(&result);
181
+ }
182
+
183
+ /// Test bundled PDFium extraction when pdf-bundled feature is enabled.
184
+ ///
185
+ /// When `pdf-bundled` feature is enabled, PDFium is embedded in the binary.
186
+ /// This test verifies the bundled extraction mechanism works correctly.
187
+ #[test]
188
+ #[cfg(feature = "pdf-bundled")]
189
+ fn test_bundled_pdfium_extraction() {
190
+ use kreuzberg::pdf::extract_bundled_pdfium;
191
+
192
+ // Extract bundled PDFium library to temporary directory
193
+ let lib_path = extract_bundled_pdfium().expect("Should extract bundled PDFium library");
194
+
195
+ // Verify extracted library exists and is a file
196
+ assert!(
197
+ lib_path.exists(),
198
+ "Extracted PDFium library should exist at {}",
199
+ lib_path.display()
200
+ );
201
+ assert!(
202
+ lib_path.is_file(),
203
+ "Extracted PDFium library should be a file, not directory"
204
+ );
205
+
206
+ // Verify library has a reasonable file size (at least a few MB)
207
+ let metadata = std::fs::metadata(&lib_path).expect("Should read library metadata");
208
+ assert!(
209
+ metadata.len() > 1_000_000,
210
+ "Bundled PDFium library should be at least 1MB (got {} bytes)",
211
+ metadata.len()
212
+ );
213
+ }
214
+
215
+ /// Test bundled PDFium extracts consistently.
216
+ ///
217
+ /// Verify that repeated calls to extract_bundled_pdfium return the same path
218
+ /// and don't create duplicate extracted libraries.
219
+ #[test]
220
+ #[cfg(feature = "pdf-bundled")]
221
+ fn test_bundled_pdfium_caching() {
222
+ use kreuzberg::pdf::extract_bundled_pdfium;
223
+
224
+ let path1 = extract_bundled_pdfium().expect("First extraction should succeed");
225
+ let path2 = extract_bundled_pdfium().expect("Second extraction should succeed");
226
+
227
+ // Both calls should return the same path (caching in place)
228
+ assert_eq!(path1, path2, "Multiple extractions should return consistent path");
229
+
230
+ // Path should still exist
231
+ assert!(path1.exists(), "Extracted library should still exist");
232
+ }
233
+
234
+ /// Test bundled PDFium works with PDF extraction.
235
+ ///
236
+ /// This integration test verifies that PDFium extracted via bundled mechanism
237
+ /// actually works for PDF content extraction.
238
+ #[test]
239
+ #[cfg(feature = "pdf-bundled")]
240
+ fn test_bundled_pdfium_with_pdf_extraction() {
241
+ if skip_if_missing("pdfs_with_tables/tiny.pdf") {
242
+ return;
243
+ }
244
+
245
+ // Ensure bundled PDFium is extracted and available
246
+ let _lib_path = kreuzberg::pdf::extract_bundled_pdfium().expect("Should extract bundled PDFium library");
247
+
248
+ // Now test that PDF extraction works with the bundled library
249
+ let file_path = get_test_file_path("pdfs_with_tables/tiny.pdf");
250
+ let config = ExtractionConfig::default();
251
+
252
+ let result = extract_file_sync(&file_path, None, &config).expect("Should extract PDF with bundled PDFium");
253
+
254
+ assert_mime_type(&result, "application/pdf");
255
+ assert_non_empty_content(&result);
256
+ }
257
+
258
+ /// Test extraction with custom PDF configuration.
259
+ ///
260
+ /// Verifies that custom PDF extraction settings work correctly.
261
+ #[test]
262
+ fn test_pdf_extraction_with_config() {
263
+ if skip_if_missing("pdfs_with_tables/tiny.pdf") {
264
+ return;
265
+ }
266
+
267
+ let file_path = get_test_file_path("pdfs_with_tables/tiny.pdf");
268
+
269
+ // Create custom extraction config
270
+ let config = ExtractionConfig::default();
271
+
272
+ let result = extract_file_sync(&file_path, None, &config).expect("Should extract PDF with custom config");
273
+
274
+ assert_mime_type(&result, "application/pdf");
275
+ assert_non_empty_content(&result);
276
+
277
+ // Verify metadata is present
278
+ assert!(!result.mime_type.is_empty(), "MIME type should be set in result");
279
+ }
280
+
281
+ /// Test handling of empty or minimal PDFs.
282
+ ///
283
+ /// Some edge case PDFs might be empty or contain no text. Verify extraction
284
+ /// handles these gracefully.
285
+ #[test]
286
+ fn test_pdf_extraction_edge_cases() {
287
+ // Test extraction of a minimal PDF
288
+ if skip_if_missing("pdfs_with_tables/tiny.pdf") {
289
+ return;
290
+ }
291
+
292
+ let file_path = get_test_file_path("pdfs_with_tables/tiny.pdf");
293
+ let config = ExtractionConfig::default();
294
+
295
+ // Should complete without panic, regardless of content
296
+ let result = extract_file_sync(&file_path, None, &config);
297
+ assert!(result.is_ok(), "PDF extraction should succeed");
298
+ }
299
+
300
+ /// Test batch extraction of multiple PDFs.
301
+ ///
302
+ /// Verifies that linking strategy handles batch processing of multiple
303
+ /// PDF files correctly.
304
+ #[test]
305
+ #[cfg(feature = "tokio-runtime")]
306
+ fn test_pdf_batch_extraction() {
307
+ if skip_if_missing("pdfs_with_tables/tiny.pdf") || skip_if_missing("pdfs_with_tables/medium.pdf") {
308
+ return;
309
+ }
310
+
311
+ let paths = vec![
312
+ get_test_file_path("pdfs_with_tables/tiny.pdf"),
313
+ get_test_file_path("pdfs_with_tables/medium.pdf"),
314
+ ];
315
+
316
+ let config = ExtractionConfig::default();
317
+
318
+ // Use synchronous batch extraction
319
+ let results = kreuzberg::batch_extract_file_sync(paths, &config).expect("Should extract PDFs in batch");
320
+
321
+ // Verify all PDFs were extracted
322
+ assert_eq!(results.len(), 2, "Should extract both PDFs");
323
+
324
+ // Verify all results are valid
325
+ for result in &results {
326
+ assert_mime_type(result, "application/pdf");
327
+ assert_non_empty_content(result);
328
+ }
329
+ }
330
+
331
+ /// Test PDF with Unicode content extraction.
332
+ ///
333
+ /// Verifies that PDFium linking strategy handles PDFs with international
334
+ /// characters correctly.
335
+ #[test]
336
+ fn test_pdf_unicode_content() {
337
+ // Right-to-left PDFs often contain Unicode content
338
+ if skip_if_missing("pdfs/right_to_left_01.pdf") {
339
+ return;
340
+ }
341
+
342
+ let file_path = get_test_file_path("pdfs/right_to_left_01.pdf");
343
+ let config = ExtractionConfig::default();
344
+
345
+ let result = extract_file_sync(&file_path, None, &config).expect("Should extract PDF with Unicode content");
346
+
347
+ // Just verify extraction completes - Unicode content handling
348
+ // varies by PDF structure
349
+ assert_mime_type(&result, "application/pdf");
350
+ }
351
+
352
+ /// Verify PDF module compiles with all feature combinations.
353
+ ///
354
+ /// This is a compile-time test that ensures the pdf module and bundled
355
+ /// submodule (when enabled) compile correctly. It's implicitly tested
356
+ /// by the fact that these test functions compile.
357
+ #[test]
358
+ #[cfg(feature = "pdf")]
359
+ fn test_pdf_module_availability() {
360
+ // This test verifies that:
361
+ // 1. The pdf module is available (feature = "pdf")
362
+ // 2. Key functions are accessible
363
+ // 3. pdf-bundled module is available when feature enabled
364
+
365
+ // Verify we can access the text extraction function
366
+ let _ = kreuzberg::pdf::extract_text_from_pdf;
367
+
368
+ // Verify we can access the metadata function
369
+ let _ = kreuzberg::pdf::extract_metadata;
370
+
371
+ // Verify bundled module is available when feature enabled
372
+ #[cfg(feature = "pdf-bundled")]
373
+ let _ = kreuzberg::pdf::extract_bundled_pdfium;
374
+ }
@@ -4,19 +4,18 @@ set -euo pipefail
4
4
  IFS=$'\n\t'
5
5
 
6
6
  if ! git diff-index --quiet HEAD --; then
7
- echo "There are git changes, cannot release"
8
- exit 1
7
+ echo "There are git changes, cannot release"
8
+ exit 1
9
9
  fi
10
10
 
11
-
12
11
  read -rp "What version would you like to release? (current $(grep version Cargo.toml)): " version
13
12
  read -rp "Are you sure you want to bump to v$version? <y/N> " prompt
14
13
 
15
14
  if [[ $prompt =~ [yY](es)* ]]; then
16
- sed -i '' "s/^version = .*/version = \"$version\"/g" Cargo.toml
17
- cargo build
18
- git add Cargo.lock Cargo.toml ../../Cargo.lock
19
- git commit -am "Bump to v$version"
20
- git tag "v$version"
21
- git push --atomic origin main "v$version"
15
+ sed -i '' "s/^version = .*/version = \"$version\"/g" Cargo.toml
16
+ cargo build
17
+ git add Cargo.lock Cargo.toml ../../Cargo.lock
18
+ git commit -am "Bump to v$version"
19
+ git tag "v$version"
20
+ git push --atomic origin main "v$version"
22
21
  fi
@@ -1,4 +1,5 @@
1
1
  #![allow(rustdoc::bare_urls)]
2
+ #![allow(unpredictable_function_pointer_comparisons)]
2
3
  #![doc = include_str!("../readme.md")]
3
4
 
4
5
  pub mod bindings;
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kreuzberg
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.0.pre.rc.7
4
+ version: 4.0.0.pre.rc.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Na'aman Hirschfeld
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-12-13 00:00:00.000000000 Z
11
+ date: 2025-12-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -326,6 +326,7 @@ files:
326
326
  - vendor/kreuzberg/src/ocr/utils.rs
327
327
  - vendor/kreuzberg/src/ocr/validation.rs
328
328
  - vendor/kreuzberg/src/panic_context.rs
329
+ - vendor/kreuzberg/src/pdf/bundled.rs
329
330
  - vendor/kreuzberg/src/pdf/error.rs
330
331
  - vendor/kreuzberg/src/pdf/images.rs
331
332
  - vendor/kreuzberg/src/pdf/metadata.rs
@@ -458,6 +459,7 @@ files:
458
459
  - vendor/kreuzberg/tests/opml_extractor_tests.rs
459
460
  - vendor/kreuzberg/tests/orgmode_extractor_tests.rs
460
461
  - vendor/kreuzberg/tests/pdf_integration.rs
462
+ - vendor/kreuzberg/tests/pdfium_linking.rs
461
463
  - vendor/kreuzberg/tests/pipeline_integration.rs
462
464
  - vendor/kreuzberg/tests/plugin_ocr_backend_test.rs
463
465
  - vendor/kreuzberg/tests/plugin_postprocessor_test.rs