kreuzberg 4.0.0.rc1 → 4.0.0.rc2

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.
Files changed (342) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +14 -8
  3. data/.rspec +3 -3
  4. data/.rubocop.yaml +1 -534
  5. data/.rubocop.yml +538 -0
  6. data/Gemfile +8 -9
  7. data/Gemfile.lock +9 -109
  8. data/README.md +426 -421
  9. data/Rakefile +25 -25
  10. data/Steepfile +47 -47
  11. data/examples/async_patterns.rb +341 -340
  12. data/ext/kreuzberg_rb/extconf.rb +45 -35
  13. data/ext/kreuzberg_rb/native/Cargo.lock +6535 -0
  14. data/ext/kreuzberg_rb/native/Cargo.toml +44 -36
  15. data/ext/kreuzberg_rb/native/README.md +425 -425
  16. data/ext/kreuzberg_rb/native/build.rs +15 -17
  17. data/ext/kreuzberg_rb/native/include/ieeefp.h +11 -11
  18. data/ext/kreuzberg_rb/native/include/msvc_compat/strings.h +14 -14
  19. data/ext/kreuzberg_rb/native/include/strings.h +20 -20
  20. data/ext/kreuzberg_rb/native/include/unistd.h +47 -47
  21. data/ext/kreuzberg_rb/native/src/lib.rs +2998 -2939
  22. data/extconf.rb +28 -28
  23. data/kreuzberg.gemspec +148 -105
  24. data/lib/kreuzberg/api_proxy.rb +142 -142
  25. data/lib/kreuzberg/cache_api.rb +46 -45
  26. data/lib/kreuzberg/cli.rb +55 -55
  27. data/lib/kreuzberg/cli_proxy.rb +127 -127
  28. data/lib/kreuzberg/config.rb +691 -684
  29. data/lib/kreuzberg/error_context.rb +32 -0
  30. data/lib/kreuzberg/errors.rb +118 -50
  31. data/lib/kreuzberg/extraction_api.rb +85 -84
  32. data/lib/kreuzberg/mcp_proxy.rb +186 -186
  33. data/lib/kreuzberg/ocr_backend_protocol.rb +113 -113
  34. data/lib/kreuzberg/post_processor_protocol.rb +86 -86
  35. data/lib/kreuzberg/result.rb +216 -216
  36. data/lib/kreuzberg/setup_lib_path.rb +80 -79
  37. data/lib/kreuzberg/validator_protocol.rb +89 -89
  38. data/lib/kreuzberg/version.rb +5 -5
  39. data/lib/kreuzberg.rb +103 -82
  40. data/sig/kreuzberg/internal.rbs +184 -184
  41. data/sig/kreuzberg.rbs +520 -468
  42. data/spec/binding/cache_spec.rb +227 -227
  43. data/spec/binding/cli_proxy_spec.rb +85 -87
  44. data/spec/binding/cli_spec.rb +55 -54
  45. data/spec/binding/config_spec.rb +345 -345
  46. data/spec/binding/config_validation_spec.rb +283 -283
  47. data/spec/binding/error_handling_spec.rb +213 -213
  48. data/spec/binding/errors_spec.rb +66 -66
  49. data/spec/binding/plugins/ocr_backend_spec.rb +307 -307
  50. data/spec/binding/plugins/postprocessor_spec.rb +269 -269
  51. data/spec/binding/plugins/validator_spec.rb +274 -274
  52. data/spec/fixtures/config.toml +39 -39
  53. data/spec/fixtures/config.yaml +41 -42
  54. data/spec/fixtures/invalid_config.toml +4 -4
  55. data/spec/smoke/package_spec.rb +178 -178
  56. data/spec/spec_helper.rb +42 -42
  57. data/vendor/kreuzberg/Cargo.toml +204 -134
  58. data/vendor/kreuzberg/README.md +175 -175
  59. data/vendor/kreuzberg/benches/otel_overhead.rs +48 -0
  60. data/vendor/kreuzberg/build.rs +474 -460
  61. data/vendor/kreuzberg/src/api/error.rs +81 -81
  62. data/vendor/kreuzberg/src/api/handlers.rs +199 -199
  63. data/vendor/kreuzberg/src/api/mod.rs +79 -79
  64. data/vendor/kreuzberg/src/api/server.rs +353 -353
  65. data/vendor/kreuzberg/src/api/types.rs +170 -170
  66. data/vendor/kreuzberg/src/cache/mod.rs +1167 -1143
  67. data/vendor/kreuzberg/src/chunking/mod.rs +677 -677
  68. data/vendor/kreuzberg/src/core/batch_mode.rs +95 -35
  69. data/vendor/kreuzberg/src/core/config.rs +1032 -1032
  70. data/vendor/kreuzberg/src/core/extractor.rs +1024 -903
  71. data/vendor/kreuzberg/src/core/io.rs +329 -327
  72. data/vendor/kreuzberg/src/core/mime.rs +605 -615
  73. data/vendor/kreuzberg/src/core/mod.rs +45 -42
  74. data/vendor/kreuzberg/src/core/pipeline.rs +984 -906
  75. data/vendor/kreuzberg/src/embeddings.rs +432 -323
  76. data/vendor/kreuzberg/src/error.rs +431 -431
  77. data/vendor/kreuzberg/src/extraction/archive.rs +954 -954
  78. data/vendor/kreuzberg/src/extraction/docx.rs +40 -40
  79. data/vendor/kreuzberg/src/extraction/email.rs +854 -854
  80. data/vendor/kreuzberg/src/extraction/excel.rs +688 -688
  81. data/vendor/kreuzberg/src/extraction/html.rs +553 -553
  82. data/vendor/kreuzberg/src/extraction/image.rs +368 -368
  83. data/vendor/kreuzberg/src/extraction/libreoffice.rs +563 -564
  84. data/vendor/kreuzberg/src/extraction/markdown.rs +213 -0
  85. data/vendor/kreuzberg/src/extraction/mod.rs +81 -77
  86. data/vendor/kreuzberg/src/extraction/office_metadata/app_properties.rs +398 -398
  87. data/vendor/kreuzberg/src/extraction/office_metadata/core_properties.rs +247 -247
  88. data/vendor/kreuzberg/src/extraction/office_metadata/custom_properties.rs +240 -240
  89. data/vendor/kreuzberg/src/extraction/office_metadata/mod.rs +130 -128
  90. data/vendor/kreuzberg/src/extraction/office_metadata/odt_properties.rs +287 -0
  91. data/vendor/kreuzberg/src/extraction/pptx.rs +3000 -3000
  92. data/vendor/kreuzberg/src/extraction/structured.rs +490 -490
  93. data/vendor/kreuzberg/src/extraction/table.rs +328 -328
  94. data/vendor/kreuzberg/src/extraction/text.rs +269 -269
  95. data/vendor/kreuzberg/src/extraction/xml.rs +333 -333
  96. data/vendor/kreuzberg/src/extractors/archive.rs +446 -425
  97. data/vendor/kreuzberg/src/extractors/bibtex.rs +469 -0
  98. data/vendor/kreuzberg/src/extractors/docbook.rs +502 -0
  99. data/vendor/kreuzberg/src/extractors/docx.rs +367 -479
  100. data/vendor/kreuzberg/src/extractors/email.rs +143 -129
  101. data/vendor/kreuzberg/src/extractors/epub.rs +707 -0
  102. data/vendor/kreuzberg/src/extractors/excel.rs +343 -344
  103. data/vendor/kreuzberg/src/extractors/fictionbook.rs +491 -0
  104. data/vendor/kreuzberg/src/extractors/fictionbook.rs.backup2 +738 -0
  105. data/vendor/kreuzberg/src/extractors/html.rs +393 -410
  106. data/vendor/kreuzberg/src/extractors/image.rs +198 -195
  107. data/vendor/kreuzberg/src/extractors/jats.rs +1051 -0
  108. data/vendor/kreuzberg/src/extractors/jupyter.rs +367 -0
  109. data/vendor/kreuzberg/src/extractors/latex.rs +652 -0
  110. data/vendor/kreuzberg/src/extractors/markdown.rs +700 -0
  111. data/vendor/kreuzberg/src/extractors/mod.rs +365 -268
  112. data/vendor/kreuzberg/src/extractors/odt.rs +628 -0
  113. data/vendor/kreuzberg/src/extractors/opml.rs +634 -0
  114. data/vendor/kreuzberg/src/extractors/orgmode.rs +528 -0
  115. data/vendor/kreuzberg/src/extractors/pdf.rs +493 -496
  116. data/vendor/kreuzberg/src/extractors/pptx.rs +248 -234
  117. data/vendor/kreuzberg/src/extractors/rst.rs +576 -0
  118. data/vendor/kreuzberg/src/extractors/rtf.rs +810 -0
  119. data/vendor/kreuzberg/src/extractors/security.rs +484 -0
  120. data/vendor/kreuzberg/src/extractors/security_tests.rs +367 -0
  121. data/vendor/kreuzberg/src/extractors/structured.rs +140 -126
  122. data/vendor/kreuzberg/src/extractors/text.rs +260 -242
  123. data/vendor/kreuzberg/src/extractors/typst.rs +650 -0
  124. data/vendor/kreuzberg/src/extractors/xml.rs +135 -128
  125. data/vendor/kreuzberg/src/image/dpi.rs +164 -164
  126. data/vendor/kreuzberg/src/image/mod.rs +6 -6
  127. data/vendor/kreuzberg/src/image/preprocessing.rs +417 -417
  128. data/vendor/kreuzberg/src/image/resize.rs +89 -89
  129. data/vendor/kreuzberg/src/keywords/config.rs +154 -154
  130. data/vendor/kreuzberg/src/keywords/mod.rs +237 -237
  131. data/vendor/kreuzberg/src/keywords/processor.rs +267 -267
  132. data/vendor/kreuzberg/src/keywords/rake.rs +293 -294
  133. data/vendor/kreuzberg/src/keywords/types.rs +68 -68
  134. data/vendor/kreuzberg/src/keywords/yake.rs +163 -163
  135. data/vendor/kreuzberg/src/language_detection/mod.rs +942 -942
  136. data/vendor/kreuzberg/src/lib.rs +105 -102
  137. data/vendor/kreuzberg/src/mcp/mod.rs +32 -32
  138. data/vendor/kreuzberg/src/mcp/server.rs +1968 -1966
  139. data/vendor/kreuzberg/src/ocr/cache.rs +469 -469
  140. data/vendor/kreuzberg/src/ocr/error.rs +37 -37
  141. data/vendor/kreuzberg/src/ocr/hocr.rs +216 -216
  142. data/vendor/kreuzberg/src/ocr/mod.rs +58 -58
  143. data/vendor/kreuzberg/src/ocr/processor.rs +863 -847
  144. data/vendor/kreuzberg/src/ocr/table/mod.rs +4 -4
  145. data/vendor/kreuzberg/src/ocr/table/tsv_parser.rs +144 -144
  146. data/vendor/kreuzberg/src/ocr/tesseract_backend.rs +450 -450
  147. data/vendor/kreuzberg/src/ocr/types.rs +393 -393
  148. data/vendor/kreuzberg/src/ocr/utils.rs +47 -47
  149. data/vendor/kreuzberg/src/ocr/validation.rs +206 -206
  150. data/vendor/kreuzberg/src/panic_context.rs +154 -0
  151. data/vendor/kreuzberg/src/pdf/error.rs +122 -122
  152. data/vendor/kreuzberg/src/pdf/images.rs +139 -139
  153. data/vendor/kreuzberg/src/pdf/metadata.rs +346 -346
  154. data/vendor/kreuzberg/src/pdf/mod.rs +50 -50
  155. data/vendor/kreuzberg/src/pdf/rendering.rs +369 -369
  156. data/vendor/kreuzberg/src/pdf/table.rs +393 -420
  157. data/vendor/kreuzberg/src/pdf/text.rs +158 -161
  158. data/vendor/kreuzberg/src/plugins/extractor.rs +1013 -1010
  159. data/vendor/kreuzberg/src/plugins/mod.rs +209 -209
  160. data/vendor/kreuzberg/src/plugins/ocr.rs +620 -629
  161. data/vendor/kreuzberg/src/plugins/processor.rs +642 -641
  162. data/vendor/kreuzberg/src/plugins/registry.rs +1337 -1324
  163. data/vendor/kreuzberg/src/plugins/traits.rs +258 -258
  164. data/vendor/kreuzberg/src/plugins/validator.rs +956 -955
  165. data/vendor/kreuzberg/src/stopwords/mod.rs +1470 -1470
  166. data/vendor/kreuzberg/src/text/mod.rs +19 -19
  167. data/vendor/kreuzberg/src/text/quality.rs +697 -697
  168. data/vendor/kreuzberg/src/text/string_utils.rs +217 -217
  169. data/vendor/kreuzberg/src/text/token_reduction/cjk_utils.rs +164 -164
  170. data/vendor/kreuzberg/src/text/token_reduction/config.rs +100 -100
  171. data/vendor/kreuzberg/src/text/token_reduction/core.rs +796 -796
  172. data/vendor/kreuzberg/src/text/token_reduction/filters.rs +902 -902
  173. data/vendor/kreuzberg/src/text/token_reduction/mod.rs +160 -160
  174. data/vendor/kreuzberg/src/text/token_reduction/semantic.rs +619 -619
  175. data/vendor/kreuzberg/src/text/token_reduction/simd_text.rs +147 -147
  176. data/vendor/kreuzberg/src/types.rs +903 -873
  177. data/vendor/kreuzberg/src/utils/mod.rs +17 -17
  178. data/vendor/kreuzberg/src/utils/quality.rs +959 -959
  179. data/vendor/kreuzberg/src/utils/string_utils.rs +381 -381
  180. data/vendor/kreuzberg/stopwords/af_stopwords.json +53 -53
  181. data/vendor/kreuzberg/stopwords/ar_stopwords.json +482 -482
  182. data/vendor/kreuzberg/stopwords/bg_stopwords.json +261 -261
  183. data/vendor/kreuzberg/stopwords/bn_stopwords.json +400 -400
  184. data/vendor/kreuzberg/stopwords/br_stopwords.json +1205 -1205
  185. data/vendor/kreuzberg/stopwords/ca_stopwords.json +280 -280
  186. data/vendor/kreuzberg/stopwords/cs_stopwords.json +425 -425
  187. data/vendor/kreuzberg/stopwords/da_stopwords.json +172 -172
  188. data/vendor/kreuzberg/stopwords/de_stopwords.json +622 -622
  189. data/vendor/kreuzberg/stopwords/el_stopwords.json +849 -849
  190. data/vendor/kreuzberg/stopwords/en_stopwords.json +1300 -1300
  191. data/vendor/kreuzberg/stopwords/eo_stopwords.json +175 -175
  192. data/vendor/kreuzberg/stopwords/es_stopwords.json +734 -734
  193. data/vendor/kreuzberg/stopwords/et_stopwords.json +37 -37
  194. data/vendor/kreuzberg/stopwords/eu_stopwords.json +100 -100
  195. data/vendor/kreuzberg/stopwords/fa_stopwords.json +801 -801
  196. data/vendor/kreuzberg/stopwords/fi_stopwords.json +849 -849
  197. data/vendor/kreuzberg/stopwords/fr_stopwords.json +693 -693
  198. data/vendor/kreuzberg/stopwords/ga_stopwords.json +111 -111
  199. data/vendor/kreuzberg/stopwords/gl_stopwords.json +162 -162
  200. data/vendor/kreuzberg/stopwords/gu_stopwords.json +226 -226
  201. data/vendor/kreuzberg/stopwords/ha_stopwords.json +41 -41
  202. data/vendor/kreuzberg/stopwords/he_stopwords.json +196 -196
  203. data/vendor/kreuzberg/stopwords/hi_stopwords.json +227 -227
  204. data/vendor/kreuzberg/stopwords/hr_stopwords.json +181 -181
  205. data/vendor/kreuzberg/stopwords/hu_stopwords.json +791 -791
  206. data/vendor/kreuzberg/stopwords/hy_stopwords.json +47 -47
  207. data/vendor/kreuzberg/stopwords/id_stopwords.json +760 -760
  208. data/vendor/kreuzberg/stopwords/it_stopwords.json +634 -634
  209. data/vendor/kreuzberg/stopwords/ja_stopwords.json +136 -136
  210. data/vendor/kreuzberg/stopwords/kn_stopwords.json +84 -84
  211. data/vendor/kreuzberg/stopwords/ko_stopwords.json +681 -681
  212. data/vendor/kreuzberg/stopwords/ku_stopwords.json +64 -64
  213. data/vendor/kreuzberg/stopwords/la_stopwords.json +51 -51
  214. data/vendor/kreuzberg/stopwords/lt_stopwords.json +476 -476
  215. data/vendor/kreuzberg/stopwords/lv_stopwords.json +163 -163
  216. data/vendor/kreuzberg/stopwords/ml_stopwords.json +1 -1
  217. data/vendor/kreuzberg/stopwords/mr_stopwords.json +101 -101
  218. data/vendor/kreuzberg/stopwords/ms_stopwords.json +477 -477
  219. data/vendor/kreuzberg/stopwords/ne_stopwords.json +490 -490
  220. data/vendor/kreuzberg/stopwords/nl_stopwords.json +415 -415
  221. data/vendor/kreuzberg/stopwords/no_stopwords.json +223 -223
  222. data/vendor/kreuzberg/stopwords/pl_stopwords.json +331 -331
  223. data/vendor/kreuzberg/stopwords/pt_stopwords.json +562 -562
  224. data/vendor/kreuzberg/stopwords/ro_stopwords.json +436 -436
  225. data/vendor/kreuzberg/stopwords/ru_stopwords.json +561 -561
  226. data/vendor/kreuzberg/stopwords/si_stopwords.json +193 -193
  227. data/vendor/kreuzberg/stopwords/sk_stopwords.json +420 -420
  228. data/vendor/kreuzberg/stopwords/sl_stopwords.json +448 -448
  229. data/vendor/kreuzberg/stopwords/so_stopwords.json +32 -32
  230. data/vendor/kreuzberg/stopwords/st_stopwords.json +33 -33
  231. data/vendor/kreuzberg/stopwords/sv_stopwords.json +420 -420
  232. data/vendor/kreuzberg/stopwords/sw_stopwords.json +76 -76
  233. data/vendor/kreuzberg/stopwords/ta_stopwords.json +129 -129
  234. data/vendor/kreuzberg/stopwords/te_stopwords.json +54 -54
  235. data/vendor/kreuzberg/stopwords/th_stopwords.json +118 -118
  236. data/vendor/kreuzberg/stopwords/tl_stopwords.json +149 -149
  237. data/vendor/kreuzberg/stopwords/tr_stopwords.json +506 -506
  238. data/vendor/kreuzberg/stopwords/uk_stopwords.json +75 -75
  239. data/vendor/kreuzberg/stopwords/ur_stopwords.json +519 -519
  240. data/vendor/kreuzberg/stopwords/vi_stopwords.json +647 -647
  241. data/vendor/kreuzberg/stopwords/yo_stopwords.json +62 -62
  242. data/vendor/kreuzberg/stopwords/zh_stopwords.json +796 -796
  243. data/vendor/kreuzberg/stopwords/zu_stopwords.json +31 -31
  244. data/vendor/kreuzberg/tests/api_extract_multipart.rs +52 -0
  245. data/vendor/kreuzberg/tests/api_tests.rs +966 -966
  246. data/vendor/kreuzberg/tests/archive_integration.rs +543 -543
  247. data/vendor/kreuzberg/tests/batch_orchestration.rs +556 -542
  248. data/vendor/kreuzberg/tests/batch_processing.rs +316 -304
  249. data/vendor/kreuzberg/tests/bibtex_parity_test.rs +421 -0
  250. data/vendor/kreuzberg/tests/concurrency_stress.rs +525 -509
  251. data/vendor/kreuzberg/tests/config_features.rs +598 -580
  252. data/vendor/kreuzberg/tests/config_loading_tests.rs +415 -439
  253. data/vendor/kreuzberg/tests/core_integration.rs +510 -493
  254. data/vendor/kreuzberg/tests/csv_integration.rs +414 -424
  255. data/vendor/kreuzberg/tests/docbook_extractor_tests.rs +498 -0
  256. data/vendor/kreuzberg/tests/docx_metadata_extraction_test.rs +122 -124
  257. data/vendor/kreuzberg/tests/docx_vs_pandoc_comparison.rs +370 -0
  258. data/vendor/kreuzberg/tests/email_integration.rs +325 -325
  259. data/vendor/kreuzberg/tests/epub_native_extractor_tests.rs +275 -0
  260. data/vendor/kreuzberg/tests/error_handling.rs +393 -393
  261. data/vendor/kreuzberg/tests/fictionbook_extractor_tests.rs +228 -0
  262. data/vendor/kreuzberg/tests/format_integration.rs +159 -159
  263. data/vendor/kreuzberg/tests/helpers/mod.rs +142 -142
  264. data/vendor/kreuzberg/tests/html_table_test.rs +551 -0
  265. data/vendor/kreuzberg/tests/image_integration.rs +253 -253
  266. data/vendor/kreuzberg/tests/instrumentation_test.rs +139 -0
  267. data/vendor/kreuzberg/tests/jats_extractor_tests.rs +639 -0
  268. data/vendor/kreuzberg/tests/jupyter_extractor_tests.rs +704 -0
  269. data/vendor/kreuzberg/tests/keywords_integration.rs +479 -479
  270. data/vendor/kreuzberg/tests/keywords_quality.rs +509 -509
  271. data/vendor/kreuzberg/tests/latex_extractor_tests.rs +496 -0
  272. data/vendor/kreuzberg/tests/markdown_extractor_tests.rs +490 -0
  273. data/vendor/kreuzberg/tests/mime_detection.rs +428 -428
  274. data/vendor/kreuzberg/tests/ocr_configuration.rs +510 -510
  275. data/vendor/kreuzberg/tests/ocr_errors.rs +676 -676
  276. data/vendor/kreuzberg/tests/ocr_quality.rs +627 -627
  277. data/vendor/kreuzberg/tests/ocr_stress.rs +469 -469
  278. data/vendor/kreuzberg/tests/odt_extractor_tests.rs +695 -0
  279. data/vendor/kreuzberg/tests/opml_extractor_tests.rs +616 -0
  280. data/vendor/kreuzberg/tests/orgmode_extractor_tests.rs +822 -0
  281. data/vendor/kreuzberg/tests/pdf_integration.rs +43 -43
  282. data/vendor/kreuzberg/tests/pipeline_integration.rs +1411 -1412
  283. data/vendor/kreuzberg/tests/plugin_ocr_backend_test.rs +771 -771
  284. data/vendor/kreuzberg/tests/plugin_postprocessor_test.rs +560 -561
  285. data/vendor/kreuzberg/tests/plugin_system.rs +921 -921
  286. data/vendor/kreuzberg/tests/plugin_validator_test.rs +783 -783
  287. data/vendor/kreuzberg/tests/registry_integration_tests.rs +586 -607
  288. data/vendor/kreuzberg/tests/rst_extractor_tests.rs +692 -0
  289. data/vendor/kreuzberg/tests/rtf_extractor_tests.rs +776 -0
  290. data/vendor/kreuzberg/tests/security_validation.rs +415 -404
  291. data/vendor/kreuzberg/tests/stopwords_integration_test.rs +888 -888
  292. data/vendor/kreuzberg/tests/test_fastembed.rs +609 -609
  293. data/vendor/kreuzberg/tests/typst_behavioral_tests.rs +1259 -0
  294. data/vendor/kreuzberg/tests/typst_extractor_tests.rs +647 -0
  295. data/vendor/kreuzberg/tests/xlsx_metadata_extraction_test.rs +87 -87
  296. data/vendor/rb-sys/.cargo-ok +1 -0
  297. data/vendor/rb-sys/.cargo_vcs_info.json +6 -0
  298. data/vendor/rb-sys/Cargo.lock +393 -0
  299. data/vendor/rb-sys/Cargo.toml +70 -0
  300. data/vendor/rb-sys/Cargo.toml.orig +57 -0
  301. data/vendor/rb-sys/LICENSE-APACHE +190 -0
  302. data/vendor/rb-sys/LICENSE-MIT +21 -0
  303. data/vendor/rb-sys/bin/release.sh +21 -0
  304. data/vendor/rb-sys/build/features.rs +108 -0
  305. data/vendor/rb-sys/build/main.rs +246 -0
  306. data/vendor/rb-sys/build/stable_api_config.rs +153 -0
  307. data/vendor/rb-sys/build/version.rs +48 -0
  308. data/vendor/rb-sys/readme.md +36 -0
  309. data/vendor/rb-sys/src/bindings.rs +21 -0
  310. data/vendor/rb-sys/src/hidden.rs +11 -0
  311. data/vendor/rb-sys/src/lib.rs +34 -0
  312. data/vendor/rb-sys/src/macros.rs +371 -0
  313. data/vendor/rb-sys/src/memory.rs +53 -0
  314. data/vendor/rb-sys/src/ruby_abi_version.rs +38 -0
  315. data/vendor/rb-sys/src/special_consts.rs +31 -0
  316. data/vendor/rb-sys/src/stable_api/compiled.c +179 -0
  317. data/vendor/rb-sys/src/stable_api/compiled.rs +257 -0
  318. data/vendor/rb-sys/src/stable_api/ruby_2_6.rs +316 -0
  319. data/vendor/rb-sys/src/stable_api/ruby_2_7.rs +316 -0
  320. data/vendor/rb-sys/src/stable_api/ruby_3_0.rs +324 -0
  321. data/vendor/rb-sys/src/stable_api/ruby_3_1.rs +317 -0
  322. data/vendor/rb-sys/src/stable_api/ruby_3_2.rs +315 -0
  323. data/vendor/rb-sys/src/stable_api/ruby_3_3.rs +326 -0
  324. data/vendor/rb-sys/src/stable_api/ruby_3_4.rs +327 -0
  325. data/vendor/rb-sys/src/stable_api.rs +261 -0
  326. data/vendor/rb-sys/src/symbol.rs +31 -0
  327. data/vendor/rb-sys/src/tracking_allocator.rs +332 -0
  328. data/vendor/rb-sys/src/utils.rs +89 -0
  329. data/vendor/rb-sys/src/value_type.rs +7 -0
  330. metadata +90 -95
  331. data/pkg/kreuzberg-4.0.0.rc1.gem +0 -0
  332. data/spec/examples.txt +0 -104
  333. data/vendor/kreuzberg/src/bin/profile_extract.rs +0 -455
  334. data/vendor/kreuzberg/src/extraction/pandoc/batch.rs +0 -275
  335. data/vendor/kreuzberg/src/extraction/pandoc/mime_types.rs +0 -178
  336. data/vendor/kreuzberg/src/extraction/pandoc/mod.rs +0 -491
  337. data/vendor/kreuzberg/src/extraction/pandoc/server.rs +0 -496
  338. data/vendor/kreuzberg/src/extraction/pandoc/subprocess.rs +0 -1188
  339. data/vendor/kreuzberg/src/extraction/pandoc/version.rs +0 -162
  340. data/vendor/kreuzberg/src/extractors/pandoc.rs +0 -201
  341. data/vendor/kreuzberg/tests/chunking_offset_demo.rs +0 -92
  342. data/vendor/kreuzberg/tests/pandoc_integration.rs +0 -503
@@ -1,509 +1,525 @@
1
- //! Comprehensive concurrency and parallelism stress tests.
2
- //!
3
- //! Validates that the Kreuzberg core handles concurrent operations correctly:
4
- //! - Parallel extractions don't interfere with each other
5
- //! - OCR processing is thread-safe and efficient
6
- //! - Pipeline processing works correctly under concurrent load
7
- //! - Cache access is safe with multiple readers/writers
8
- //! - Registry access is thread-safe
9
- //!
10
- //! These tests ensure production workloads with high concurrency work correctly.
11
-
12
- use async_trait::async_trait;
13
- use kreuzberg::Result;
14
- use kreuzberg::core::config::{ExtractionConfig, PostProcessorConfig};
15
- use kreuzberg::core::extractor::{batch_extract_bytes, extract_bytes};
16
- use kreuzberg::core::pipeline::run_pipeline;
17
- use kreuzberg::plugins::registry::{get_document_extractor_registry, get_post_processor_registry};
18
- use kreuzberg::plugins::{Plugin, PostProcessor, ProcessingStage};
19
- use kreuzberg::types::{ExtractionResult, Metadata};
20
- use std::sync::Arc;
21
- use std::sync::atomic::{AtomicUsize, Ordering};
22
-
23
- #[cfg(feature = "ocr")]
24
- use kreuzberg::core::config::OcrConfig;
25
-
26
- #[cfg(feature = "ocr")]
27
- use kreuzberg::core::extractor::extract_file_sync;
28
- use std::time::Duration;
29
- use tokio::time::timeout;
30
-
31
- mod helpers;
32
-
33
- /// Test many concurrent extractions of different MIME types.
34
- ///
35
- /// Validates that:
36
- /// - Registry lookups don't block each other unnecessarily
37
- /// - Different extractors can run in parallel
38
- /// - No data races or corruption
39
- #[tokio::test]
40
- async fn test_concurrent_extractions_mixed_formats() {
41
- let config = ExtractionConfig::default();
42
-
43
- let test_cases = vec![
44
- (b"Plain text content" as &[u8], "text/plain"),
45
- (b"{\"key\": \"value\"}", "application/json"),
46
- (b"<root><item>XML content</item></root>", "application/xml"),
47
- (b"# Markdown\n\nContent here", "text/markdown"),
48
- ];
49
-
50
- let mut handles = vec![];
51
- for _ in 0..10 {
52
- for (data, mime_type) in &test_cases {
53
- let config = config.clone();
54
- let data = data.to_vec();
55
- let mime_type = mime_type.to_string();
56
-
57
- handles.push(tokio::spawn(
58
- async move { extract_bytes(&data, &mime_type, &config).await },
59
- ));
60
- }
61
- }
62
-
63
- let results = timeout(Duration::from_secs(30), async {
64
- let mut results = vec![];
65
- for handle in handles {
66
- results.push(handle.await.expect("Task should not panic"));
67
- }
68
- results
69
- })
70
- .await
71
- .expect("All extractions should complete within 30s");
72
-
73
- for result in results {
74
- assert!(
75
- result.is_ok(),
76
- "Concurrent extraction should succeed: {:?}",
77
- result.err()
78
- );
79
- }
80
- }
81
-
82
- /// Test concurrent batch extractions.
83
- ///
84
- /// Validates that batch processing correctly handles parallelism internally.
85
- #[tokio::test]
86
- async fn test_concurrent_batch_extractions() {
87
- let config = ExtractionConfig::default();
88
-
89
- let contents: Vec<Vec<u8>> = (0..20).map(|i| format!("Content {}", i).into_bytes()).collect();
90
-
91
- let mut handles = vec![];
92
- for _ in 0..5 {
93
- let config = config.clone();
94
- let contents_clone = contents.clone();
95
-
96
- handles.push(tokio::spawn(async move {
97
- let data: Vec<(&[u8], &str)> = contents_clone.iter().map(|c| (c.as_slice(), "text/plain")).collect();
98
- batch_extract_bytes(data, &config).await
99
- }));
100
- }
101
-
102
- for handle in handles {
103
- let results = handle.await.expect("Task should not panic");
104
- assert!(results.is_ok(), "Batch extraction should succeed");
105
- let results = results.unwrap();
106
- assert_eq!(results.len(), 20, "Should return all results");
107
- }
108
- }
109
-
110
- /// Test concurrent extractions with caching enabled.
111
- ///
112
- /// Validates that:
113
- /// - Cache reads/writes are thread-safe
114
- /// - No cache corruption under concurrent access
115
- /// - Cache hits work correctly across threads
116
- #[tokio::test]
117
- async fn test_concurrent_extractions_with_cache() {
118
- let config = ExtractionConfig {
119
- use_cache: true,
120
- postprocessor: Some(PostProcessorConfig {
121
- enabled: false,
122
- enabled_processors: None,
123
- disabled_processors: None,
124
- }),
125
- ..Default::default()
126
- };
127
-
128
- let test_data = b"Cached content for concurrent access test";
129
-
130
- let _ = extract_bytes(test_data, "text/plain", &config).await.unwrap();
131
-
132
- let mut handles = vec![];
133
- for _ in 0..100 {
134
- let config = config.clone();
135
- let data = test_data.to_vec();
136
-
137
- handles.push(tokio::spawn(async move {
138
- extract_bytes(&data, "text/plain", &config).await
139
- }));
140
- }
141
-
142
- let expected_content = "Cached content for concurrent access test";
143
- for handle in handles {
144
- let result = handle.await.expect("Task should not panic");
145
- assert!(result.is_ok(), "Cache read should succeed");
146
- let extraction = result.unwrap();
147
- assert_eq!(extraction.content, expected_content);
148
- }
149
- }
150
-
151
- /// Test concurrent OCR processing of different images.
152
- ///
153
- /// Validates that:
154
- /// - OCR backend is thread-safe
155
- /// - Multiple OCR operations don't interfere
156
- /// - OCR cache handles concurrent access correctly
157
- #[cfg(feature = "ocr")]
158
- #[tokio::test]
159
- async fn test_concurrent_ocr_processing() {
160
- use helpers::{get_test_file_path, skip_if_missing};
161
-
162
- if skip_if_missing("images/ocr_image.jpg") {
163
- tracing::debug!("Skipping concurrent OCR test: test file not available");
164
- return;
165
- }
166
-
167
- let config = ExtractionConfig {
168
- ocr: Some(OcrConfig {
169
- backend: "tesseract".to_string(),
170
- language: "eng".to_string(),
171
- tesseract_config: None,
172
- }),
173
- force_ocr: false,
174
- use_cache: true,
175
- ..Default::default()
176
- };
177
-
178
- let file_path = get_test_file_path("images/ocr_image.jpg");
179
-
180
- let mut handles = vec![];
181
- for _ in 0..20 {
182
- let file_path = file_path.clone();
183
- let config = config.clone();
184
-
185
- handles.push(tokio::task::spawn_blocking(move || {
186
- extract_file_sync(&file_path, None, &config)
187
- }));
188
- }
189
-
190
- let results = timeout(Duration::from_secs(60), async {
191
- let mut results = vec![];
192
- for handle in handles {
193
- results.push(handle.await.expect("Task should not panic"));
194
- }
195
- results
196
- })
197
- .await
198
- .expect("All OCR operations should complete within 60s");
199
-
200
- let mut extracted_texts = vec![];
201
- for result in results {
202
- assert!(result.is_ok(), "OCR should succeed: {:?}", result.err());
203
- let extraction = result.unwrap();
204
- assert!(!extraction.content.is_empty(), "OCR should extract text");
205
- extracted_texts.push(extraction.content);
206
- }
207
-
208
- let first_text = &extracted_texts[0];
209
- for text in &extracted_texts[1..] {
210
- assert_eq!(text, first_text, "Concurrent OCR should produce identical results");
211
- }
212
- }
213
-
214
- /// Test concurrent OCR with cache warming.
215
- ///
216
- /// Validates cache performance under concurrent load.
217
- ///
218
- /// Note: This test is simplified to avoid runtime nesting issues.
219
- /// It validates that concurrent OCR extractions work correctly with caching.
220
- ///
221
- /// WARNING: This test uses timing heuristics (<500ms = cache hit) which are unreliable
222
- /// in CI environments where even cached operations may exceed the threshold on slow runners.
223
- /// Ignored to prevent flaky failures - cache hit rates vary significantly across platforms.
224
- #[cfg(feature = "ocr")]
225
- #[ignore = "flaky timing-based cache heuristic - cache hit rates vary significantly across platforms"]
226
- #[test]
227
- fn test_concurrent_ocr_cache_stress() {
228
- use helpers::{get_test_file_path, skip_if_missing};
229
-
230
- if skip_if_missing("images/ocr_image.jpg") {
231
- tracing::debug!("Skipping OCR cache stress test: test file not available");
232
- return;
233
- }
234
-
235
- let config = ExtractionConfig {
236
- ocr: Some(OcrConfig {
237
- backend: "tesseract".to_string(),
238
- language: "eng".to_string(),
239
- tesseract_config: None,
240
- }),
241
- force_ocr: false,
242
- use_cache: true,
243
- ..Default::default()
244
- };
245
-
246
- let file_path = get_test_file_path("images/ocr_image.jpg");
247
-
248
- let first_result = extract_file_sync(&file_path, None, &config);
249
- assert!(first_result.is_ok(), "Initial OCR should succeed");
250
-
251
- let cache_hit_count = Arc::new(AtomicUsize::new(0));
252
-
253
- let mut handles = vec![];
254
- for _ in 0..50 {
255
- let file_path = file_path.clone();
256
- let config = config.clone();
257
- let hit_count = Arc::clone(&cache_hit_count);
258
-
259
- handles.push(std::thread::spawn(move || {
260
- let start = std::time::Instant::now();
261
- let result = extract_file_sync(&file_path, None, &config);
262
- let duration = start.elapsed();
263
-
264
- if duration < Duration::from_millis(500) {
265
- hit_count.fetch_add(1, Ordering::Relaxed);
266
- }
267
-
268
- result
269
- }));
270
- }
271
-
272
- for handle in handles {
273
- let result = handle.join().expect("Thread should not panic");
274
- assert!(result.is_ok(), "Cached OCR should succeed");
275
- }
276
-
277
- let hits = cache_hit_count.load(Ordering::Relaxed);
278
- assert!(
279
- hits >= 20,
280
- "At least 20/50 requests should hit cache, got {} hits",
281
- hits
282
- );
283
- }
284
-
285
- /// Test concurrent pipeline processing.
286
- ///
287
- /// Validates that:
288
- /// - Pipeline can process multiple results in parallel
289
- /// - Processors don't interfere with each other
290
- /// - Registry reads are thread-safe
291
- #[tokio::test]
292
- async fn test_concurrent_pipeline_processing() {
293
- struct ConcurrentTestProcessor;
294
-
295
- impl Plugin for ConcurrentTestProcessor {
296
- fn name(&self) -> &str {
297
- "concurrent-test"
298
- }
299
- fn version(&self) -> String {
300
- "1.0.0".to_string()
301
- }
302
- fn initialize(&self) -> Result<()> {
303
- Ok(())
304
- }
305
- fn shutdown(&self) -> Result<()> {
306
- Ok(())
307
- }
308
- }
309
-
310
- #[async_trait]
311
- impl PostProcessor for ConcurrentTestProcessor {
312
- async fn process(&self, result: &mut ExtractionResult, _: &ExtractionConfig) -> Result<()> {
313
- tokio::time::sleep(Duration::from_millis(10)).await;
314
- result.content.push_str("[processed]");
315
- Ok(())
316
- }
317
-
318
- fn processing_stage(&self) -> ProcessingStage {
319
- ProcessingStage::Early
320
- }
321
- }
322
-
323
- let registry = get_post_processor_registry();
324
- {
325
- let mut reg = registry.write().expect("Should acquire write lock");
326
- let processor = Arc::new(ConcurrentTestProcessor);
327
- let _ = reg.remove("concurrent-test");
328
- reg.register(processor, 50).expect("Should register processor");
329
- }
330
-
331
- let config = ExtractionConfig {
332
- postprocessor: Some(PostProcessorConfig {
333
- enabled: true,
334
- enabled_processors: Some(vec!["concurrent-test".to_string()]),
335
- disabled_processors: None,
336
- }),
337
- ..Default::default()
338
- };
339
-
340
- let mut handles = vec![];
341
- for i in 0..50 {
342
- let config = config.clone();
343
-
344
- handles.push(tokio::spawn(async move {
345
- let result = ExtractionResult {
346
- content: format!("Content {}", i),
347
- mime_type: "text/plain".to_string(),
348
- metadata: Metadata::default(),
349
- tables: vec![],
350
- detected_languages: None,
351
- chunks: None,
352
- images: None,
353
- };
354
-
355
- run_pipeline(result, &config).await
356
- }));
357
- }
358
-
359
- for handle in handles {
360
- let result = handle.await.expect("Task should not panic");
361
- assert!(result.is_ok(), "Pipeline should succeed");
362
- let processed = result.unwrap();
363
- assert!(processed.content.contains("[processed]"), "Processor should run");
364
- }
365
-
366
- {
367
- let mut reg = registry.write().expect("Should acquire write lock");
368
- let _ = reg.remove("concurrent-test");
369
- }
370
- }
371
-
372
- /// Test concurrent registry reads don't block unnecessarily.
373
- ///
374
- /// Validates that:
375
- /// - Multiple readers can access registry simultaneously
376
- /// - Registry lookups are fast under concurrent load
377
- #[tokio::test]
378
- async fn test_concurrent_registry_reads() {
379
- let registry = get_document_extractor_registry();
380
-
381
- let mut handles = vec![];
382
- for _ in 0..200 {
383
- let registry_clone = Arc::clone(&registry);
384
- handles.push(tokio::spawn(async move {
385
- let start = std::time::Instant::now();
386
-
387
- let reg = registry_clone.read().expect("Should acquire read lock");
388
- let _extractor = reg.get("text/plain");
389
-
390
- start.elapsed()
391
- }));
392
- }
393
-
394
- let mut max_duration = Duration::from_secs(0);
395
- for handle in handles {
396
- let duration = handle.await.expect("Task should not panic");
397
- if duration > max_duration {
398
- max_duration = duration;
399
- }
400
- }
401
-
402
- assert!(
403
- max_duration < Duration::from_millis(10),
404
- "Registry reads should be fast, max duration: {:?}",
405
- max_duration
406
- );
407
- }
408
-
409
- /// Test that extraction throughput scales with concurrency.
410
- ///
411
- /// Validates that:
412
- /// - Parallel extractions are actually running in parallel
413
- /// - No global bottlenecks limiting throughput
414
- ///
415
- /// Note: This is a performance benchmark that can be flaky based on system load,
416
- /// CPU availability, and other factors. Marked as #[ignore] to run only on demand.
417
- #[tokio::test]
418
- #[ignore]
419
- async fn test_extraction_throughput_scales() {
420
- let config = ExtractionConfig::default();
421
- let test_data = b"Throughput test content";
422
-
423
- let sequential_start = std::time::Instant::now();
424
- for _ in 0..20 {
425
- let _ = extract_bytes(test_data, "text/plain", &config).await.unwrap();
426
- }
427
- let sequential_duration = sequential_start.elapsed();
428
-
429
- let parallel_start = std::time::Instant::now();
430
- let mut handles = vec![];
431
- for _ in 0..20 {
432
- let config = config.clone();
433
- let data = test_data.to_vec();
434
-
435
- handles.push(tokio::spawn(async move {
436
- extract_bytes(&data, "text/plain", &config).await
437
- }));
438
- }
439
-
440
- for handle in handles {
441
- let _ = handle.await.expect("Task should not panic");
442
- }
443
- let parallel_duration = parallel_start.elapsed();
444
-
445
- println!(
446
- "Sequential: {:?}, Parallel: {:?}, Speedup: {:.2}x",
447
- sequential_duration,
448
- parallel_duration,
449
- sequential_duration.as_secs_f64() / parallel_duration.as_secs_f64()
450
- );
451
-
452
- let speedup = sequential_duration.as_secs_f64() / parallel_duration.as_secs_f64();
453
-
454
- assert!(
455
- speedup > 0.5,
456
- "Parallel execution should not be significantly slower than sequential. Sequential: {:?}, Parallel: {:?}, Speedup: {:.2}x",
457
- sequential_duration,
458
- parallel_duration,
459
- speedup
460
- );
461
- }
462
-
463
- /// High-load stress test with many concurrent operations.
464
- ///
465
- /// Validates system stability under sustained concurrent load.
466
- #[tokio::test]
467
- async fn test_high_concurrency_stress() {
468
- let config = ExtractionConfig {
469
- use_cache: true,
470
- ..Default::default()
471
- };
472
-
473
- let formats = vec![
474
- (b"Text content" as &[u8], "text/plain"),
475
- (b"{\"json\": true}", "application/json"),
476
- (b"<xml><item>content</item></xml>", "application/xml"),
477
- (b"# Markdown\n\nContent", "text/markdown"),
478
- ];
479
-
480
- let mut handles = vec![];
481
- for _ in 0..100 {
482
- for (data, mime_type) in &formats {
483
- let config = config.clone();
484
- let data = data.to_vec();
485
- let mime_type = mime_type.to_string();
486
-
487
- handles.push(tokio::spawn(
488
- async move { extract_bytes(&data, &mime_type, &config).await },
489
- ));
490
- }
491
- }
492
-
493
- let results = timeout(Duration::from_secs(60), async {
494
- let mut results = vec![];
495
- for handle in handles {
496
- results.push(handle.await.expect("Task should not panic"));
497
- }
498
- results
499
- })
500
- .await
501
- .expect("High-load stress test should complete within 60s");
502
-
503
- let success_count = results.iter().filter(|r| r.is_ok()).count();
504
- assert_eq!(
505
- success_count, 400,
506
- "All extractions should succeed under stress, got {} successes",
507
- success_count
508
- );
509
- }
1
+ //! Comprehensive concurrency and parallelism stress tests.
2
+ //!
3
+ //! Validates that the Kreuzberg core handles concurrent operations correctly:
4
+ //! - Parallel extractions don't interfere with each other
5
+ //! - OCR processing is thread-safe and efficient
6
+ //! - Pipeline processing works correctly under concurrent load
7
+ //! - Cache access is safe with multiple readers/writers
8
+ //! - Registry access is thread-safe
9
+ //!
10
+ //! These tests ensure production workloads with high concurrency work correctly.
11
+
12
+ use async_trait::async_trait;
13
+ use kreuzberg::Result;
14
+ use kreuzberg::core::config::{ExtractionConfig, PostProcessorConfig};
15
+ use kreuzberg::core::extractor::{batch_extract_bytes, extract_bytes};
16
+ use kreuzberg::core::pipeline::run_pipeline;
17
+ use kreuzberg::plugins::registry::{get_document_extractor_registry, get_post_processor_registry};
18
+ use kreuzberg::plugins::{Plugin, PostProcessor, ProcessingStage};
19
+ use kreuzberg::types::{ExtractionResult, Metadata};
20
+ use std::sync::Arc;
21
+ use std::sync::atomic::{AtomicUsize, Ordering};
22
+
23
+ #[cfg(feature = "ocr")]
24
+ use kreuzberg::core::config::OcrConfig;
25
+
26
+ #[cfg(feature = "ocr")]
27
+ use kreuzberg::core::extractor::extract_file_sync;
28
+ use std::time::Duration;
29
+ use tokio::time::timeout;
30
+
31
+ mod helpers;
32
+
33
+ fn trim_trailing_newlines(value: &str) -> &str {
34
+ value.trim_end_matches(['\n', '\r'])
35
+ }
36
+
37
+ fn assert_text_content(actual: &str, expected: &str) {
38
+ assert_eq!(
39
+ trim_trailing_newlines(actual),
40
+ expected,
41
+ "Content mismatch after trimming trailing newlines"
42
+ );
43
+ }
44
+
45
+ /// Test many concurrent extractions of different MIME types.
46
+ ///
47
+ /// Validates that:
48
+ /// - Registry lookups don't block each other unnecessarily
49
+ /// - Different extractors can run in parallel
50
+ /// - No data races or corruption
51
+ #[tokio::test]
52
+ async fn test_concurrent_extractions_mixed_formats() {
53
+ let config = ExtractionConfig::default();
54
+
55
+ let test_cases = vec![
56
+ (b"Plain text content" as &[u8], "text/plain"),
57
+ (b"{\"key\": \"value\"}", "application/json"),
58
+ (b"<root><item>XML content</item></root>", "application/xml"),
59
+ (b"# Markdown\n\nContent here", "text/markdown"),
60
+ ];
61
+
62
+ let mut handles = vec![];
63
+ for _ in 0..10 {
64
+ for (data, mime_type) in &test_cases {
65
+ let config = config.clone();
66
+ let data = data.to_vec();
67
+ let mime_type = mime_type.to_string();
68
+
69
+ handles.push(tokio::spawn(
70
+ async move { extract_bytes(&data, &mime_type, &config).await },
71
+ ));
72
+ }
73
+ }
74
+
75
+ let results = timeout(Duration::from_secs(30), async {
76
+ let mut results = vec![];
77
+ for handle in handles {
78
+ results.push(handle.await.expect("Task should not panic"));
79
+ }
80
+ results
81
+ })
82
+ .await
83
+ .expect("All extractions should complete within 30s");
84
+
85
+ for result in results {
86
+ assert!(
87
+ result.is_ok(),
88
+ "Concurrent extraction should succeed: {:?}",
89
+ result.err()
90
+ );
91
+ }
92
+ }
93
+
94
+ /// Test concurrent batch extractions.
95
+ ///
96
+ /// Validates that batch processing correctly handles parallelism internally.
97
+ #[tokio::test]
98
+ async fn test_concurrent_batch_extractions() {
99
+ let config = ExtractionConfig::default();
100
+
101
+ let contents: Vec<Vec<u8>> = (0..20).map(|i| format!("Content {}", i).into_bytes()).collect();
102
+
103
+ let mut handles = vec![];
104
+ for _ in 0..5 {
105
+ let config = config.clone();
106
+ let contents_clone = contents.clone();
107
+
108
+ handles.push(tokio::spawn(async move {
109
+ let data: Vec<(&[u8], &str)> = contents_clone.iter().map(|c| (c.as_slice(), "text/plain")).collect();
110
+ batch_extract_bytes(data, &config).await
111
+ }));
112
+ }
113
+
114
+ for handle in handles {
115
+ let results = handle.await.expect("Task should not panic");
116
+ assert!(results.is_ok(), "Batch extraction should succeed");
117
+ let results = results.unwrap();
118
+ assert_eq!(results.len(), 20, "Should return all results");
119
+ }
120
+ }
121
+
122
+ /// Test concurrent extractions with caching enabled.
123
+ ///
124
+ /// Validates that:
125
+ /// - Cache reads/writes are thread-safe
126
+ /// - No cache corruption under concurrent access
127
+ /// - Cache hits work correctly across threads
128
+ #[tokio::test]
129
+ async fn test_concurrent_extractions_with_cache() {
130
+ let config = ExtractionConfig {
131
+ use_cache: true,
132
+ postprocessor: Some(PostProcessorConfig {
133
+ enabled: false,
134
+ enabled_processors: None,
135
+ disabled_processors: None,
136
+ }),
137
+ ..Default::default()
138
+ };
139
+
140
+ let test_data = b"Cached content for concurrent access test";
141
+
142
+ let _ = extract_bytes(test_data, "text/plain", &config).await.unwrap();
143
+
144
+ let mut handles = vec![];
145
+ for _ in 0..100 {
146
+ let config = config.clone();
147
+ let data = test_data.to_vec();
148
+
149
+ handles.push(tokio::spawn(async move {
150
+ extract_bytes(&data, "text/plain", &config).await
151
+ }));
152
+ }
153
+
154
+ let expected_content = "Cached content for concurrent access test";
155
+ for handle in handles {
156
+ let result = handle.await.expect("Task should not panic");
157
+ assert!(result.is_ok(), "Cache read should succeed");
158
+ let extraction = result.unwrap();
159
+ assert_text_content(&extraction.content, expected_content);
160
+ }
161
+ }
162
+
163
+ /// Test concurrent OCR processing of different images.
164
+ ///
165
+ /// Validates that:
166
+ /// - OCR backend is thread-safe
167
+ /// - Multiple OCR operations don't interfere
168
+ /// - OCR cache handles concurrent access correctly
169
+ #[cfg(feature = "ocr")]
170
+ #[tokio::test]
171
+ async fn test_concurrent_ocr_processing() {
172
+ use helpers::{get_test_file_path, skip_if_missing};
173
+
174
+ if cfg!(windows) {
175
+ return;
176
+ }
177
+
178
+ if skip_if_missing("images/ocr_image.jpg") {
179
+ tracing::debug!("Skipping concurrent OCR test: test file not available");
180
+ return;
181
+ }
182
+
183
+ let config = ExtractionConfig {
184
+ ocr: Some(OcrConfig {
185
+ backend: "tesseract".to_string(),
186
+ language: "eng".to_string(),
187
+ tesseract_config: None,
188
+ }),
189
+ force_ocr: false,
190
+ use_cache: true,
191
+ ..Default::default()
192
+ };
193
+
194
+ let file_path = get_test_file_path("images/ocr_image.jpg");
195
+
196
+ let mut handles = vec![];
197
+ for _ in 0..20 {
198
+ let file_path = file_path.clone();
199
+ let config = config.clone();
200
+
201
+ handles.push(tokio::task::spawn_blocking(move || {
202
+ extract_file_sync(&file_path, None, &config)
203
+ }));
204
+ }
205
+
206
+ let results = timeout(Duration::from_secs(60), async {
207
+ let mut results = vec![];
208
+ for handle in handles {
209
+ results.push(handle.await.expect("Task should not panic"));
210
+ }
211
+ results
212
+ })
213
+ .await
214
+ .expect("All OCR operations should complete within 60s");
215
+
216
+ let mut extracted_texts = vec![];
217
+ for result in results {
218
+ assert!(result.is_ok(), "OCR should succeed: {:?}", result.err());
219
+ let extraction = result.unwrap();
220
+ assert!(!extraction.content.is_empty(), "OCR should extract text");
221
+ extracted_texts.push(extraction.content);
222
+ }
223
+
224
+ let first_text = &extracted_texts[0];
225
+ for text in &extracted_texts[1..] {
226
+ assert_eq!(text, first_text, "Concurrent OCR should produce identical results");
227
+ }
228
+ }
229
+
230
+ /// Test concurrent OCR with cache warming.
231
+ ///
232
+ /// Validates cache performance under concurrent load.
233
+ ///
234
+ /// Note: This test is simplified to avoid runtime nesting issues.
235
+ /// It validates that concurrent OCR extractions work correctly with caching.
236
+ ///
237
+ /// WARNING: This test uses timing heuristics (<500ms = cache hit) which are unreliable
238
+ /// in CI environments where even cached operations may exceed the threshold on slow runners.
239
+ /// Ignored to prevent flaky failures - cache hit rates vary significantly across platforms.
240
+ #[cfg(feature = "ocr")]
241
+ #[ignore = "flaky timing-based cache heuristic - cache hit rates vary significantly across platforms"]
242
+ #[test]
243
+ fn test_concurrent_ocr_cache_stress() {
244
+ use helpers::{get_test_file_path, skip_if_missing};
245
+
246
+ if skip_if_missing("images/ocr_image.jpg") {
247
+ tracing::debug!("Skipping OCR cache stress test: test file not available");
248
+ return;
249
+ }
250
+
251
+ let config = ExtractionConfig {
252
+ ocr: Some(OcrConfig {
253
+ backend: "tesseract".to_string(),
254
+ language: "eng".to_string(),
255
+ tesseract_config: None,
256
+ }),
257
+ force_ocr: false,
258
+ use_cache: true,
259
+ ..Default::default()
260
+ };
261
+
262
+ let file_path = get_test_file_path("images/ocr_image.jpg");
263
+
264
+ let first_result = extract_file_sync(&file_path, None, &config);
265
+ assert!(first_result.is_ok(), "Initial OCR should succeed");
266
+
267
+ let cache_hit_count = Arc::new(AtomicUsize::new(0));
268
+
269
+ let mut handles = vec![];
270
+ for _ in 0..50 {
271
+ let file_path = file_path.clone();
272
+ let config = config.clone();
273
+ let hit_count = Arc::clone(&cache_hit_count);
274
+
275
+ handles.push(std::thread::spawn(move || {
276
+ let start = std::time::Instant::now();
277
+ let result = extract_file_sync(&file_path, None, &config);
278
+ let duration = start.elapsed();
279
+
280
+ if duration < Duration::from_millis(500) {
281
+ hit_count.fetch_add(1, Ordering::Relaxed);
282
+ }
283
+
284
+ result
285
+ }));
286
+ }
287
+
288
+ for handle in handles {
289
+ let result = handle.join().expect("Thread should not panic");
290
+ assert!(result.is_ok(), "Cached OCR should succeed");
291
+ }
292
+
293
+ let hits = cache_hit_count.load(Ordering::Relaxed);
294
+ assert!(
295
+ hits >= 20,
296
+ "At least 20/50 requests should hit cache, got {} hits",
297
+ hits
298
+ );
299
+ }
300
+
301
+ /// Test concurrent pipeline processing.
302
+ ///
303
+ /// Validates that:
304
+ /// - Pipeline can process multiple results in parallel
305
+ /// - Processors don't interfere with each other
306
+ /// - Registry reads are thread-safe
307
+ #[tokio::test]
308
+ async fn test_concurrent_pipeline_processing() {
309
+ struct ConcurrentTestProcessor;
310
+
311
+ impl Plugin for ConcurrentTestProcessor {
312
+ fn name(&self) -> &str {
313
+ "concurrent-test"
314
+ }
315
+ fn version(&self) -> String {
316
+ "1.0.0".to_string()
317
+ }
318
+ fn initialize(&self) -> Result<()> {
319
+ Ok(())
320
+ }
321
+ fn shutdown(&self) -> Result<()> {
322
+ Ok(())
323
+ }
324
+ }
325
+
326
+ #[async_trait]
327
+ impl PostProcessor for ConcurrentTestProcessor {
328
+ async fn process(&self, result: &mut ExtractionResult, _: &ExtractionConfig) -> Result<()> {
329
+ tokio::time::sleep(Duration::from_millis(10)).await;
330
+ result.content.push_str("[processed]");
331
+ Ok(())
332
+ }
333
+
334
+ fn processing_stage(&self) -> ProcessingStage {
335
+ ProcessingStage::Early
336
+ }
337
+ }
338
+
339
+ let registry = get_post_processor_registry();
340
+ {
341
+ let mut reg = registry.write().expect("Should acquire write lock");
342
+ let processor = Arc::new(ConcurrentTestProcessor);
343
+ let _ = reg.remove("concurrent-test");
344
+ reg.register(processor, 50).expect("Should register processor");
345
+ }
346
+
347
+ let config = ExtractionConfig {
348
+ postprocessor: Some(PostProcessorConfig {
349
+ enabled: true,
350
+ enabled_processors: Some(vec!["concurrent-test".to_string()]),
351
+ disabled_processors: None,
352
+ }),
353
+ ..Default::default()
354
+ };
355
+
356
+ let mut handles = vec![];
357
+ for i in 0..50 {
358
+ let config = config.clone();
359
+
360
+ handles.push(tokio::spawn(async move {
361
+ let result = ExtractionResult {
362
+ content: format!("Content {}", i),
363
+ mime_type: "text/plain".to_string(),
364
+ metadata: Metadata::default(),
365
+ tables: vec![],
366
+ detected_languages: None,
367
+ chunks: None,
368
+ images: None,
369
+ };
370
+
371
+ run_pipeline(result, &config).await
372
+ }));
373
+ }
374
+
375
+ for handle in handles {
376
+ let result = handle.await.expect("Task should not panic");
377
+ assert!(result.is_ok(), "Pipeline should succeed");
378
+ let processed = result.unwrap();
379
+ assert!(processed.content.contains("[processed]"), "Processor should run");
380
+ }
381
+
382
+ {
383
+ let mut reg = registry.write().expect("Should acquire write lock");
384
+ let _ = reg.remove("concurrent-test");
385
+ }
386
+ }
387
+
388
+ /// Test concurrent registry reads don't block unnecessarily.
389
+ ///
390
+ /// Validates that:
391
+ /// - Multiple readers can access registry simultaneously
392
+ /// - Registry lookups are fast under concurrent load
393
+ #[tokio::test]
394
+ async fn test_concurrent_registry_reads() {
395
+ let registry = get_document_extractor_registry();
396
+
397
+ let mut handles = vec![];
398
+ for _ in 0..200 {
399
+ let registry_clone = Arc::clone(&registry);
400
+ handles.push(tokio::spawn(async move {
401
+ let start = std::time::Instant::now();
402
+
403
+ let reg = registry_clone.read().expect("Should acquire read lock");
404
+ let _extractor = reg.get("text/plain");
405
+
406
+ start.elapsed()
407
+ }));
408
+ }
409
+
410
+ let mut max_duration = Duration::from_secs(0);
411
+ for handle in handles {
412
+ let duration = handle.await.expect("Task should not panic");
413
+ if duration > max_duration {
414
+ max_duration = duration;
415
+ }
416
+ }
417
+
418
+ assert!(
419
+ max_duration < Duration::from_millis(10),
420
+ "Registry reads should be fast, max duration: {:?}",
421
+ max_duration
422
+ );
423
+ }
424
+
425
+ /// Test that extraction throughput scales with concurrency.
426
+ ///
427
+ /// Validates that:
428
+ /// - Parallel extractions are actually running in parallel
429
+ /// - No global bottlenecks limiting throughput
430
+ ///
431
+ /// Note: This is a performance benchmark that can be flaky based on system load,
432
+ /// CPU availability, and other factors. Marked as #[ignore] to run only on demand.
433
+ #[tokio::test]
434
+ #[ignore]
435
+ async fn test_extraction_throughput_scales() {
436
+ let config = ExtractionConfig::default();
437
+ let test_data = b"Throughput test content";
438
+
439
+ let sequential_start = std::time::Instant::now();
440
+ for _ in 0..20 {
441
+ let _ = extract_bytes(test_data, "text/plain", &config).await.unwrap();
442
+ }
443
+ let sequential_duration = sequential_start.elapsed();
444
+
445
+ let parallel_start = std::time::Instant::now();
446
+ let mut handles = vec![];
447
+ for _ in 0..20 {
448
+ let config = config.clone();
449
+ let data = test_data.to_vec();
450
+
451
+ handles.push(tokio::spawn(async move {
452
+ extract_bytes(&data, "text/plain", &config).await
453
+ }));
454
+ }
455
+
456
+ for handle in handles {
457
+ let _ = handle.await.expect("Task should not panic");
458
+ }
459
+ let parallel_duration = parallel_start.elapsed();
460
+
461
+ println!(
462
+ "Sequential: {:?}, Parallel: {:?}, Speedup: {:.2}x",
463
+ sequential_duration,
464
+ parallel_duration,
465
+ sequential_duration.as_secs_f64() / parallel_duration.as_secs_f64()
466
+ );
467
+
468
+ let speedup = sequential_duration.as_secs_f64() / parallel_duration.as_secs_f64();
469
+
470
+ assert!(
471
+ speedup > 0.5,
472
+ "Parallel execution should not be significantly slower than sequential. Sequential: {:?}, Parallel: {:?}, Speedup: {:.2}x",
473
+ sequential_duration,
474
+ parallel_duration,
475
+ speedup
476
+ );
477
+ }
478
+
479
+ /// High-load stress test with many concurrent operations.
480
+ ///
481
+ /// Validates system stability under sustained concurrent load.
482
+ #[tokio::test]
483
+ async fn test_high_concurrency_stress() {
484
+ let config = ExtractionConfig {
485
+ use_cache: true,
486
+ ..Default::default()
487
+ };
488
+
489
+ let formats = vec![
490
+ (b"Text content" as &[u8], "text/plain"),
491
+ (b"{\"json\": true}", "application/json"),
492
+ (b"<xml><item>content</item></xml>", "application/xml"),
493
+ (b"# Markdown\n\nContent", "text/markdown"),
494
+ ];
495
+
496
+ let mut handles = vec![];
497
+ for _ in 0..100 {
498
+ for (data, mime_type) in &formats {
499
+ let config = config.clone();
500
+ let data = data.to_vec();
501
+ let mime_type = mime_type.to_string();
502
+
503
+ handles.push(tokio::spawn(
504
+ async move { extract_bytes(&data, &mime_type, &config).await },
505
+ ));
506
+ }
507
+ }
508
+
509
+ let results = timeout(Duration::from_secs(60), async {
510
+ let mut results = vec![];
511
+ for handle in handles {
512
+ results.push(handle.await.expect("Task should not panic"));
513
+ }
514
+ results
515
+ })
516
+ .await
517
+ .expect("High-load stress test should complete within 60s");
518
+
519
+ let success_count = results.iter().filter(|r| r.is_ok()).count();
520
+ assert_eq!(
521
+ success_count, 400,
522
+ "All extractions should succeed under stress, got {} successes",
523
+ success_count
524
+ );
525
+ }