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,1412 +1,1411 @@
1
- //! Comprehensive pipeline integration tests.
2
- //!
3
- //! Tests the post-processing pipeline orchestration: ordering, error handling,
4
- //! metadata/content modifications, and integration with extractors.
5
- //!
6
- //! IMPORTANT: These tests use a global registry and must run serially to avoid interference.
7
-
8
- use async_trait::async_trait;
9
- use kreuzberg::core::config::{ExtractionConfig, PostProcessorConfig};
10
- use kreuzberg::core::pipeline::run_pipeline;
11
- use kreuzberg::plugins::registry::get_post_processor_registry;
12
- use kreuzberg::plugins::{Plugin, PostProcessor, ProcessingStage};
13
- use kreuzberg::types::{ExtractionResult, Metadata};
14
- use kreuzberg::{KreuzbergError, Result};
15
- use serial_test::serial;
16
- use std::sync::Arc;
17
-
18
- struct OrderTrackingProcessor {
19
- name: String,
20
- stage: ProcessingStage,
21
- }
22
-
23
- impl Plugin for OrderTrackingProcessor {
24
- fn name(&self) -> &str {
25
- &self.name
26
- }
27
- fn version(&self) -> String {
28
- "1.0.0".to_string()
29
- }
30
- fn initialize(&self) -> Result<()> {
31
- Ok(())
32
- }
33
- fn shutdown(&self) -> Result<()> {
34
- Ok(())
35
- }
36
- }
37
-
38
- #[async_trait]
39
- impl PostProcessor for OrderTrackingProcessor {
40
- async fn process(&self, result: &mut ExtractionResult, _: &ExtractionConfig) -> Result<()> {
41
- result.content.push_str(&format!("[{}]", self.name));
42
- Ok(())
43
- }
44
-
45
- fn processing_stage(&self) -> ProcessingStage {
46
- self.stage
47
- }
48
- }
49
-
50
- struct MetadataAddingProcessor {
51
- name: String,
52
- key: String,
53
- value: String,
54
- }
55
-
56
- impl Plugin for MetadataAddingProcessor {
57
- fn name(&self) -> &str {
58
- &self.name
59
- }
60
- fn version(&self) -> String {
61
- "1.0.0".to_string()
62
- }
63
- fn initialize(&self) -> Result<()> {
64
- Ok(())
65
- }
66
- fn shutdown(&self) -> Result<()> {
67
- Ok(())
68
- }
69
- }
70
-
71
- #[async_trait]
72
- impl PostProcessor for MetadataAddingProcessor {
73
- async fn process(&self, result: &mut ExtractionResult, _: &ExtractionConfig) -> Result<()> {
74
- result
75
- .metadata
76
- .additional
77
- .insert(self.key.clone(), serde_json::json!(self.value));
78
- Ok(())
79
- }
80
-
81
- fn processing_stage(&self) -> ProcessingStage {
82
- ProcessingStage::Early
83
- }
84
- }
85
-
86
- struct FailingProcessor {
87
- name: String,
88
- error_message: String,
89
- }
90
-
91
- impl Plugin for FailingProcessor {
92
- fn name(&self) -> &str {
93
- &self.name
94
- }
95
- fn version(&self) -> String {
96
- "1.0.0".to_string()
97
- }
98
- fn initialize(&self) -> Result<()> {
99
- Ok(())
100
- }
101
- fn shutdown(&self) -> Result<()> {
102
- Ok(())
103
- }
104
- }
105
-
106
- #[async_trait]
107
- impl PostProcessor for FailingProcessor {
108
- async fn process(&self, _: &mut ExtractionResult, _: &ExtractionConfig) -> Result<()> {
109
- Err(KreuzbergError::Plugin {
110
- message: self.error_message.clone(),
111
- plugin_name: self.name.clone(),
112
- })
113
- }
114
-
115
- fn processing_stage(&self) -> ProcessingStage {
116
- ProcessingStage::Middle
117
- }
118
- }
119
-
120
- fn clear_processor_registry() {
121
- let registry = get_post_processor_registry();
122
- let mut reg = registry
123
- .write()
124
- .expect("Failed to acquire write lock on registry in test");
125
- let _ = reg.shutdown_all();
126
- }
127
-
128
- #[tokio::test]
129
- #[serial]
130
- async fn test_pipeline_empty_no_processors() {
131
- clear_processor_registry();
132
-
133
- let result = ExtractionResult {
134
- content: "original content".to_string(),
135
- mime_type: "text/plain".to_string(),
136
- metadata: Metadata::default(),
137
- tables: vec![],
138
- detected_languages: None,
139
- chunks: None,
140
- images: None,
141
- };
142
- let config = ExtractionConfig::default();
143
-
144
- let processed = run_pipeline(result, &config).await.unwrap();
145
- assert_eq!(processed.content, "original content");
146
- }
147
-
148
- #[tokio::test]
149
- #[serial]
150
- async fn test_pipeline_single_processor_per_stage() {
151
- clear_processor_registry();
152
-
153
- let registry = get_post_processor_registry();
154
- {
155
- let mut reg = registry
156
- .write()
157
- .expect("Failed to acquire write lock on registry in test");
158
-
159
- let early = Arc::new(OrderTrackingProcessor {
160
- name: "early".to_string(),
161
- stage: ProcessingStage::Early,
162
- });
163
- let middle = Arc::new(OrderTrackingProcessor {
164
- name: "middle".to_string(),
165
- stage: ProcessingStage::Middle,
166
- });
167
- let late = Arc::new(OrderTrackingProcessor {
168
- name: "late".to_string(),
169
- stage: ProcessingStage::Late,
170
- });
171
-
172
- reg.register(early, 50).unwrap();
173
- reg.register(middle, 50).unwrap();
174
- reg.register(late, 50).unwrap();
175
- }
176
-
177
- let result = ExtractionResult {
178
- content: "start".to_string(),
179
- mime_type: "text/plain".to_string(),
180
- metadata: Metadata::default(),
181
- tables: vec![],
182
- detected_languages: None,
183
- chunks: None,
184
- images: None,
185
- };
186
- let config = ExtractionConfig::default();
187
-
188
- let processed = run_pipeline(result, &config).await.unwrap();
189
- assert_eq!(processed.content, "start[early][middle][late]");
190
- }
191
-
192
- #[tokio::test]
193
- #[serial]
194
- async fn test_pipeline_multiple_processors_per_stage() {
195
- clear_processor_registry();
196
-
197
- let registry = get_post_processor_registry();
198
- {
199
- let mut reg = registry
200
- .write()
201
- .expect("Failed to acquire write lock on registry in test");
202
-
203
- let early_high = Arc::new(OrderTrackingProcessor {
204
- name: "early-high".to_string(),
205
- stage: ProcessingStage::Early,
206
- });
207
- let early_medium = Arc::new(OrderTrackingProcessor {
208
- name: "early-medium".to_string(),
209
- stage: ProcessingStage::Early,
210
- });
211
- let early_low = Arc::new(OrderTrackingProcessor {
212
- name: "early-low".to_string(),
213
- stage: ProcessingStage::Early,
214
- });
215
-
216
- reg.register(early_low, 10).unwrap();
217
- reg.register(early_high, 100).unwrap();
218
- reg.register(early_medium, 50).unwrap();
219
- }
220
-
221
- let result = ExtractionResult {
222
- content: "start".to_string(),
223
- mime_type: "text/plain".to_string(),
224
- metadata: Metadata::default(),
225
- tables: vec![],
226
- detected_languages: None,
227
- chunks: None,
228
- images: None,
229
- };
230
- let config = ExtractionConfig::default();
231
-
232
- let processed = run_pipeline(result, &config).await.unwrap();
233
- assert_eq!(processed.content, "start[early-high][early-medium][early-low]");
234
- }
235
-
236
- #[tokio::test]
237
- #[serial]
238
- async fn test_pipeline_all_stages_enabled() {
239
- clear_processor_registry();
240
-
241
- let registry = get_post_processor_registry();
242
- {
243
- let mut reg = registry
244
- .write()
245
- .expect("Failed to acquire write lock on registry in test");
246
-
247
- for stage in [ProcessingStage::Early, ProcessingStage::Middle, ProcessingStage::Late] {
248
- let processor = Arc::new(OrderTrackingProcessor {
249
- name: format!("{:?}", stage),
250
- stage,
251
- });
252
- reg.register(processor, 50).unwrap();
253
- }
254
- }
255
-
256
- let result = ExtractionResult {
257
- content: "start".to_string(),
258
- mime_type: "text/plain".to_string(),
259
- metadata: Metadata::default(),
260
- tables: vec![],
261
- detected_languages: None,
262
- chunks: None,
263
- images: None,
264
- };
265
- let config = ExtractionConfig::default();
266
-
267
- let processed = run_pipeline(result, &config).await.unwrap();
268
- assert_eq!(processed.content, "start[Early][Middle][Late]");
269
- }
270
-
271
- #[tokio::test]
272
- #[serial]
273
- async fn test_pipeline_postprocessing_disabled() {
274
- clear_processor_registry();
275
-
276
- let registry = get_post_processor_registry();
277
- {
278
- let mut reg = registry
279
- .write()
280
- .expect("Failed to acquire write lock on registry in test");
281
-
282
- let processor = Arc::new(OrderTrackingProcessor {
283
- name: "processor".to_string(),
284
- stage: ProcessingStage::Early,
285
- });
286
- reg.register(processor, 50).unwrap();
287
- }
288
-
289
- let result = ExtractionResult {
290
- content: "start".to_string(),
291
- mime_type: "text/plain".to_string(),
292
- metadata: Metadata::default(),
293
- tables: vec![],
294
- detected_languages: None,
295
- chunks: None,
296
- images: None,
297
- };
298
- let config = ExtractionConfig {
299
- postprocessor: Some(PostProcessorConfig {
300
- enabled: false,
301
- enabled_processors: None,
302
- disabled_processors: None,
303
- }),
304
- ..Default::default()
305
- };
306
-
307
- let processed = run_pipeline(result, &config).await.unwrap();
308
- assert_eq!(processed.content, "start");
309
- }
310
-
311
- #[tokio::test]
312
- #[serial]
313
- async fn test_pipeline_early_stage_runs_first() {
314
- clear_processor_registry();
315
-
316
- let registry = get_post_processor_registry();
317
- {
318
- let mut reg = registry
319
- .write()
320
- .expect("Failed to acquire write lock on registry in test");
321
-
322
- let late = Arc::new(OrderTrackingProcessor {
323
- name: "late".to_string(),
324
- stage: ProcessingStage::Late,
325
- });
326
- let early = Arc::new(OrderTrackingProcessor {
327
- name: "early".to_string(),
328
- stage: ProcessingStage::Early,
329
- });
330
-
331
- reg.register(late, 50).unwrap();
332
- reg.register(early, 50).unwrap();
333
- }
334
-
335
- let result = ExtractionResult {
336
- content: "start".to_string(),
337
- mime_type: "text/plain".to_string(),
338
- metadata: Metadata::default(),
339
- tables: vec![],
340
- detected_languages: None,
341
- chunks: None,
342
- images: None,
343
- };
344
- let config = ExtractionConfig::default();
345
-
346
- let processed = run_pipeline(result, &config).await.unwrap();
347
- assert_eq!(processed.content, "start[early][late]");
348
- }
349
-
350
- #[tokio::test]
351
- #[serial]
352
- async fn test_pipeline_middle_stage_runs_second() {
353
- clear_processor_registry();
354
-
355
- let registry = get_post_processor_registry();
356
- {
357
- let mut reg = registry
358
- .write()
359
- .expect("Failed to acquire write lock on registry in test");
360
-
361
- let early = Arc::new(OrderTrackingProcessor {
362
- name: "early".to_string(),
363
- stage: ProcessingStage::Early,
364
- });
365
- let middle = Arc::new(OrderTrackingProcessor {
366
- name: "middle".to_string(),
367
- stage: ProcessingStage::Middle,
368
- });
369
-
370
- reg.register(middle, 50).unwrap();
371
- reg.register(early, 50).unwrap();
372
- }
373
-
374
- let result = ExtractionResult {
375
- content: "start".to_string(),
376
- mime_type: "text/plain".to_string(),
377
- metadata: Metadata::default(),
378
- tables: vec![],
379
- detected_languages: None,
380
- chunks: None,
381
- images: None,
382
- };
383
- let config = ExtractionConfig::default();
384
-
385
- let processed = run_pipeline(result, &config).await.unwrap();
386
- assert_eq!(processed.content, "start[early][middle]");
387
- }
388
-
389
- #[tokio::test]
390
- #[serial]
391
- async fn test_pipeline_late_stage_runs_last() {
392
- clear_processor_registry();
393
-
394
- let registry = get_post_processor_registry();
395
- {
396
- let mut reg = registry
397
- .write()
398
- .expect("Failed to acquire write lock on registry in test");
399
-
400
- for stage in [ProcessingStage::Late, ProcessingStage::Early, ProcessingStage::Middle] {
401
- let processor = Arc::new(OrderTrackingProcessor {
402
- name: format!("{:?}", stage),
403
- stage,
404
- });
405
- reg.register(processor, 50).unwrap();
406
- }
407
- }
408
-
409
- let result = ExtractionResult {
410
- content: "start".to_string(),
411
- mime_type: "text/plain".to_string(),
412
- metadata: Metadata::default(),
413
- tables: vec![],
414
- detected_languages: None,
415
- chunks: None,
416
- images: None,
417
- };
418
- let config = ExtractionConfig::default();
419
-
420
- let processed = run_pipeline(result, &config).await.unwrap();
421
- assert_eq!(processed.content, "start[Early][Middle][Late]");
422
- }
423
-
424
- #[tokio::test]
425
- #[serial]
426
- async fn test_pipeline_within_stage_priority_order() {
427
- clear_processor_registry();
428
-
429
- let registry = get_post_processor_registry();
430
- {
431
- let mut reg = registry
432
- .write()
433
- .expect("Failed to acquire write lock on registry in test");
434
-
435
- for (name, priority) in [("p1", 100), ("p2", 10), ("p3", 50), ("p4", 75)] {
436
- let processor = Arc::new(OrderTrackingProcessor {
437
- name: name.to_string(),
438
- stage: ProcessingStage::Early,
439
- });
440
- reg.register(processor, priority).unwrap();
441
- }
442
- }
443
-
444
- let result = ExtractionResult {
445
- content: "start".to_string(),
446
- mime_type: "text/plain".to_string(),
447
- metadata: Metadata::default(),
448
- tables: vec![],
449
- detected_languages: None,
450
- chunks: None,
451
- images: None,
452
- };
453
- let config = ExtractionConfig::default();
454
-
455
- let processed = run_pipeline(result, &config).await.unwrap();
456
- assert_eq!(processed.content, "start[p1][p4][p3][p2]");
457
- }
458
-
459
- #[tokio::test]
460
- #[serial]
461
- async fn test_pipeline_cross_stage_data_flow() {
462
- clear_processor_registry();
463
-
464
- let registry = get_post_processor_registry();
465
- {
466
- let mut reg = registry
467
- .write()
468
- .expect("Failed to acquire write lock on registry in test");
469
-
470
- let early = Arc::new(MetadataAddingProcessor {
471
- name: "early".to_string(),
472
- key: "stage".to_string(),
473
- value: "early".to_string(),
474
- });
475
-
476
- struct MiddleProcessor;
477
- impl Plugin for MiddleProcessor {
478
- fn name(&self) -> &str {
479
- "middle"
480
- }
481
- fn version(&self) -> String {
482
- "1.0.0".to_string()
483
- }
484
- fn initialize(&self) -> Result<()> {
485
- Ok(())
486
- }
487
- fn shutdown(&self) -> Result<()> {
488
- Ok(())
489
- }
490
- }
491
- #[async_trait]
492
- impl PostProcessor for MiddleProcessor {
493
- async fn process(&self, result: &mut ExtractionResult, _: &ExtractionConfig) -> Result<()> {
494
- if let Some(stage) = result.metadata.additional.get("stage") {
495
- result.content.push_str(&format!("[saw:{}]", stage.as_str().unwrap()));
496
- }
497
- Ok(())
498
- }
499
- fn processing_stage(&self) -> ProcessingStage {
500
- ProcessingStage::Middle
501
- }
502
- }
503
-
504
- reg.register(early, 50).unwrap();
505
- reg.register(Arc::new(MiddleProcessor), 50).unwrap();
506
- }
507
-
508
- let result = ExtractionResult {
509
- content: "start".to_string(),
510
- mime_type: "text/plain".to_string(),
511
- metadata: Metadata::default(),
512
- tables: vec![],
513
- detected_languages: None,
514
- chunks: None,
515
- images: None,
516
- };
517
- let config = ExtractionConfig::default();
518
-
519
- let processed = run_pipeline(result, &config).await.unwrap();
520
- assert!(processed.content.contains("[saw:early]"));
521
- }
522
-
523
- #[tokio::test]
524
- #[serial]
525
- async fn test_pipeline_early_stage_error_recorded() {
526
- clear_processor_registry();
527
-
528
- struct EarlyFailingProcessor;
529
- impl Plugin for EarlyFailingProcessor {
530
- fn name(&self) -> &str {
531
- "early-failing"
532
- }
533
- fn version(&self) -> String {
534
- "1.0.0".to_string()
535
- }
536
- fn initialize(&self) -> Result<()> {
537
- Ok(())
538
- }
539
- fn shutdown(&self) -> Result<()> {
540
- Ok(())
541
- }
542
- }
543
- #[async_trait]
544
- impl PostProcessor for EarlyFailingProcessor {
545
- async fn process(&self, _: &mut ExtractionResult, _: &ExtractionConfig) -> Result<()> {
546
- Err(KreuzbergError::Plugin {
547
- message: "Early error".to_string(),
548
- plugin_name: "early-failing".to_string(),
549
- })
550
- }
551
- fn processing_stage(&self) -> ProcessingStage {
552
- ProcessingStage::Early
553
- }
554
- }
555
-
556
- let registry = get_post_processor_registry();
557
- {
558
- let mut reg = registry
559
- .write()
560
- .expect("Failed to acquire write lock on registry in test");
561
- reg.register(Arc::new(EarlyFailingProcessor), 50).unwrap();
562
- }
563
-
564
- let result = ExtractionResult {
565
- content: "content".to_string(),
566
- mime_type: "text/plain".to_string(),
567
- metadata: Metadata::default(),
568
- tables: vec![],
569
- detected_languages: None,
570
- chunks: None,
571
- images: None,
572
- };
573
- let config = ExtractionConfig::default();
574
-
575
- let result = run_pipeline(result, &config).await;
576
- assert!(result.is_err(), "Expected pipeline to return error");
577
- match result {
578
- Err(KreuzbergError::Plugin { message, plugin_name }) => {
579
- assert_eq!(message, "Early error");
580
- assert_eq!(plugin_name, "early-failing");
581
- }
582
- _ => panic!("Expected Plugin error"),
583
- }
584
- }
585
-
586
- #[tokio::test]
587
- #[serial]
588
- async fn test_pipeline_middle_stage_error_propagation() {
589
- clear_processor_registry();
590
-
591
- let registry = get_post_processor_registry();
592
- {
593
- let mut reg = registry
594
- .write()
595
- .expect("Failed to acquire write lock on registry in test");
596
-
597
- let failing = Arc::new(FailingProcessor {
598
- name: "middle-failing".to_string(),
599
- error_message: "Middle stage error".to_string(),
600
- });
601
-
602
- reg.register(failing, 50).unwrap();
603
- }
604
-
605
- let result = ExtractionResult {
606
- content: "content".to_string(),
607
- mime_type: "text/plain".to_string(),
608
- metadata: Metadata::default(),
609
- tables: vec![],
610
- detected_languages: None,
611
- chunks: None,
612
- images: None,
613
- };
614
- let config = ExtractionConfig::default();
615
-
616
- let result = run_pipeline(result, &config).await;
617
- assert!(result.is_err(), "Expected pipeline to return error");
618
- match result {
619
- Err(KreuzbergError::Plugin { message, plugin_name }) => {
620
- assert_eq!(message, "Middle stage error");
621
- assert_eq!(plugin_name, "middle-failing");
622
- }
623
- _ => panic!("Expected Plugin error"),
624
- }
625
- }
626
-
627
- #[tokio::test]
628
- #[serial]
629
- async fn test_pipeline_late_stage_error_doesnt_affect_earlier_stages() {
630
- clear_processor_registry();
631
-
632
- struct LateFailingProcessor;
633
- impl Plugin for LateFailingProcessor {
634
- fn name(&self) -> &str {
635
- "late-failing"
636
- }
637
- fn version(&self) -> String {
638
- "1.0.0".to_string()
639
- }
640
- fn initialize(&self) -> Result<()> {
641
- Ok(())
642
- }
643
- fn shutdown(&self) -> Result<()> {
644
- Ok(())
645
- }
646
- }
647
- #[async_trait]
648
- impl PostProcessor for LateFailingProcessor {
649
- async fn process(&self, _: &mut ExtractionResult, _: &ExtractionConfig) -> Result<()> {
650
- Err(KreuzbergError::Plugin {
651
- message: "Late error".to_string(),
652
- plugin_name: "late-failing".to_string(),
653
- })
654
- }
655
- fn processing_stage(&self) -> ProcessingStage {
656
- ProcessingStage::Late
657
- }
658
- }
659
-
660
- let registry = get_post_processor_registry();
661
- {
662
- let mut reg = registry
663
- .write()
664
- .expect("Failed to acquire write lock on registry in test");
665
-
666
- let early = Arc::new(OrderTrackingProcessor {
667
- name: "early".to_string(),
668
- stage: ProcessingStage::Early,
669
- });
670
- let late_failing = Arc::new(LateFailingProcessor);
671
-
672
- reg.register(early, 50).unwrap();
673
- reg.register(late_failing, 50).unwrap();
674
- }
675
-
676
- let result = ExtractionResult {
677
- content: "start".to_string(),
678
- mime_type: "text/plain".to_string(),
679
- metadata: Metadata::default(),
680
- tables: vec![],
681
- detected_languages: None,
682
- chunks: None,
683
- images: None,
684
- };
685
- let config = ExtractionConfig::default();
686
-
687
- let result = run_pipeline(result, &config).await;
688
- assert!(result.is_err(), "Expected pipeline to return error");
689
- match result {
690
- Err(KreuzbergError::Plugin { message, plugin_name }) => {
691
- assert_eq!(message, "Late error");
692
- assert_eq!(plugin_name, "late-failing");
693
- }
694
- _ => panic!("Expected Plugin error"),
695
- }
696
- }
697
-
698
- #[tokio::test]
699
- #[serial]
700
- async fn test_pipeline_processor_error_doesnt_stop_other_processors() {
701
- clear_processor_registry();
702
-
703
- let registry = get_post_processor_registry();
704
- {
705
- let mut reg = registry
706
- .write()
707
- .expect("Failed to acquire write lock on registry in test");
708
-
709
- let p1 = Arc::new(OrderTrackingProcessor {
710
- name: "p1".to_string(),
711
- stage: ProcessingStage::Early,
712
- });
713
- let _p2_failing = Arc::new(FailingProcessor {
714
- name: "p2-failing".to_string(),
715
- error_message: "Test error".to_string(),
716
- });
717
- let p3 = Arc::new(OrderTrackingProcessor {
718
- name: "p3".to_string(),
719
- stage: ProcessingStage::Late,
720
- });
721
-
722
- struct EarlyFailingProcessor {
723
- name: String,
724
- }
725
- impl Plugin for EarlyFailingProcessor {
726
- fn name(&self) -> &str {
727
- &self.name
728
- }
729
- fn version(&self) -> String {
730
- "1.0.0".to_string()
731
- }
732
- fn initialize(&self) -> Result<()> {
733
- Ok(())
734
- }
735
- fn shutdown(&self) -> Result<()> {
736
- Ok(())
737
- }
738
- }
739
- #[async_trait]
740
- impl PostProcessor for EarlyFailingProcessor {
741
- async fn process(&self, _: &mut ExtractionResult, _: &ExtractionConfig) -> Result<()> {
742
- Err(KreuzbergError::Plugin {
743
- message: "Test error".to_string(),
744
- plugin_name: self.name.clone(),
745
- })
746
- }
747
- fn processing_stage(&self) -> ProcessingStage {
748
- ProcessingStage::Early
749
- }
750
- }
751
-
752
- reg.register(p1, 100).unwrap();
753
- reg.register(
754
- Arc::new(EarlyFailingProcessor {
755
- name: "p2-failing".to_string(),
756
- }),
757
- 50,
758
- )
759
- .unwrap();
760
- reg.register(p3, 50).unwrap();
761
- }
762
-
763
- let result = ExtractionResult {
764
- content: "start".to_string(),
765
- mime_type: "text/plain".to_string(),
766
- metadata: Metadata::default(),
767
- tables: vec![],
768
- detected_languages: None,
769
- chunks: None,
770
- images: None,
771
- };
772
- let config = ExtractionConfig::default();
773
-
774
- let result = run_pipeline(result, &config).await;
775
- assert!(result.is_err(), "Expected pipeline to return error");
776
- match result {
777
- Err(KreuzbergError::Plugin { message, plugin_name }) => {
778
- assert_eq!(message, "Test error");
779
- assert_eq!(plugin_name, "p2-failing");
780
- }
781
- _ => panic!("Expected Plugin error"),
782
- }
783
- }
784
-
785
- #[tokio::test]
786
- #[serial]
787
- async fn test_pipeline_multiple_processor_errors() {
788
- clear_processor_registry();
789
-
790
- struct MultiFailingProcessor {
791
- name: String,
792
- stage: ProcessingStage,
793
- }
794
- impl Plugin for MultiFailingProcessor {
795
- fn name(&self) -> &str {
796
- &self.name
797
- }
798
- fn version(&self) -> String {
799
- "1.0.0".to_string()
800
- }
801
- fn initialize(&self) -> Result<()> {
802
- Ok(())
803
- }
804
- fn shutdown(&self) -> Result<()> {
805
- Ok(())
806
- }
807
- }
808
- #[async_trait]
809
- impl PostProcessor for MultiFailingProcessor {
810
- async fn process(&self, _: &mut ExtractionResult, _: &ExtractionConfig) -> Result<()> {
811
- Err(KreuzbergError::Plugin {
812
- message: format!("{} error", self.name),
813
- plugin_name: self.name.clone(),
814
- })
815
- }
816
- fn processing_stage(&self) -> ProcessingStage {
817
- self.stage
818
- }
819
- }
820
-
821
- let registry = get_post_processor_registry();
822
- {
823
- let mut reg = registry
824
- .write()
825
- .expect("Failed to acquire write lock on registry in test");
826
-
827
- for (name, stage) in [
828
- ("fail1", ProcessingStage::Early),
829
- ("fail2", ProcessingStage::Middle),
830
- ("fail3", ProcessingStage::Late),
831
- ] {
832
- let processor = Arc::new(MultiFailingProcessor {
833
- name: name.to_string(),
834
- stage,
835
- });
836
- reg.register(processor, 50).unwrap();
837
- }
838
- }
839
-
840
- let result = ExtractionResult {
841
- content: "start".to_string(),
842
- mime_type: "text/plain".to_string(),
843
- metadata: Metadata::default(),
844
- tables: vec![],
845
- detected_languages: None,
846
- chunks: None,
847
- images: None,
848
- };
849
- let config = ExtractionConfig::default();
850
-
851
- let result = run_pipeline(result, &config).await;
852
- assert!(result.is_err(), "Expected pipeline to return error");
853
- // First failing processor (fail1 in Early stage) will cause pipeline to fail
854
- match result {
855
- Err(KreuzbergError::Plugin { message, plugin_name }) => {
856
- assert_eq!(message, "fail1 error");
857
- assert_eq!(plugin_name, "fail1");
858
- }
859
- _ => panic!("Expected Plugin error"),
860
- }
861
- }
862
-
863
- #[tokio::test]
864
- #[serial]
865
- async fn test_pipeline_error_context_preservation() {
866
- clear_processor_registry();
867
-
868
- let registry = get_post_processor_registry();
869
- {
870
- let mut reg = registry
871
- .write()
872
- .expect("Failed to acquire write lock on registry in test");
873
-
874
- let failing = Arc::new(FailingProcessor {
875
- name: "context-test".to_string(),
876
- error_message: "Detailed error message with context".to_string(),
877
- });
878
-
879
- reg.register(failing, 50).unwrap();
880
- }
881
-
882
- let result = ExtractionResult {
883
- content: "content".to_string(),
884
- mime_type: "text/plain".to_string(),
885
- metadata: Metadata::default(),
886
- tables: vec![],
887
- detected_languages: None,
888
- chunks: None,
889
- images: None,
890
- };
891
- let config = ExtractionConfig::default();
892
-
893
- let result = run_pipeline(result, &config).await;
894
- assert!(result.is_err(), "Expected pipeline to return error");
895
- match result {
896
- Err(KreuzbergError::Plugin { message, plugin_name }) => {
897
- assert_eq!(message, "Detailed error message with context");
898
- assert_eq!(plugin_name, "context-test");
899
- }
900
- _ => panic!("Expected Plugin error"),
901
- }
902
- }
903
-
904
- #[tokio::test]
905
- #[serial]
906
- async fn test_pipeline_metadata_added_in_early_visible_in_middle() {
907
- clear_processor_registry();
908
-
909
- let registry = get_post_processor_registry();
910
- {
911
- let mut reg = registry
912
- .write()
913
- .expect("Failed to acquire write lock on registry in test");
914
-
915
- let early = Arc::new(MetadataAddingProcessor {
916
- name: "early".to_string(),
917
- key: "early_key".to_string(),
918
- value: "early_value".to_string(),
919
- });
920
-
921
- struct MiddleReadingProcessor;
922
- impl Plugin for MiddleReadingProcessor {
923
- fn name(&self) -> &str {
924
- "middle"
925
- }
926
- fn version(&self) -> String {
927
- "1.0.0".to_string()
928
- }
929
- fn initialize(&self) -> Result<()> {
930
- Ok(())
931
- }
932
- fn shutdown(&self) -> Result<()> {
933
- Ok(())
934
- }
935
- }
936
- #[async_trait]
937
- impl PostProcessor for MiddleReadingProcessor {
938
- async fn process(&self, result: &mut ExtractionResult, _: &ExtractionConfig) -> Result<()> {
939
- if let Some(val) = result.metadata.additional.get("early_key") {
940
- result.metadata.additional.insert("middle_saw".to_string(), val.clone());
941
- }
942
- Ok(())
943
- }
944
- fn processing_stage(&self) -> ProcessingStage {
945
- ProcessingStage::Middle
946
- }
947
- }
948
-
949
- reg.register(early, 50).unwrap();
950
- reg.register(Arc::new(MiddleReadingProcessor), 50).unwrap();
951
- }
952
-
953
- let result = ExtractionResult {
954
- content: "content".to_string(),
955
- mime_type: "text/plain".to_string(),
956
- metadata: Metadata::default(),
957
- tables: vec![],
958
- detected_languages: None,
959
- chunks: None,
960
- images: None,
961
- };
962
- let config = ExtractionConfig::default();
963
-
964
- let processed = run_pipeline(result, &config).await.unwrap();
965
- assert_eq!(
966
- processed
967
- .metadata
968
- .additional
969
- .get("middle_saw")
970
- .unwrap()
971
- .as_str()
972
- .unwrap(),
973
- "early_value"
974
- );
975
- }
976
-
977
- #[tokio::test]
978
- #[serial]
979
- async fn test_pipeline_content_modified_in_middle_visible_in_late() {
980
- clear_processor_registry();
981
-
982
- let registry = get_post_processor_registry();
983
- {
984
- let mut reg = registry
985
- .write()
986
- .expect("Failed to acquire write lock on registry in test");
987
-
988
- let middle = Arc::new(OrderTrackingProcessor {
989
- name: "middle-content".to_string(),
990
- stage: ProcessingStage::Middle,
991
- });
992
-
993
- struct LateReadingProcessor;
994
- impl Plugin for LateReadingProcessor {
995
- fn name(&self) -> &str {
996
- "late"
997
- }
998
- fn version(&self) -> String {
999
- "1.0.0".to_string()
1000
- }
1001
- fn initialize(&self) -> Result<()> {
1002
- Ok(())
1003
- }
1004
- fn shutdown(&self) -> Result<()> {
1005
- Ok(())
1006
- }
1007
- }
1008
- #[async_trait]
1009
- impl PostProcessor for LateReadingProcessor {
1010
- async fn process(&self, result: &mut ExtractionResult, _: &ExtractionConfig) -> Result<()> {
1011
- result.content.push_str("[late-saw-middle]");
1012
- Ok(())
1013
- }
1014
- fn processing_stage(&self) -> ProcessingStage {
1015
- ProcessingStage::Late
1016
- }
1017
- }
1018
-
1019
- reg.register(middle, 50).unwrap();
1020
- reg.register(Arc::new(LateReadingProcessor), 50).unwrap();
1021
- }
1022
-
1023
- let result = ExtractionResult {
1024
- content: "start".to_string(),
1025
- mime_type: "text/plain".to_string(),
1026
- metadata: Metadata::default(),
1027
- tables: vec![],
1028
- detected_languages: None,
1029
- chunks: None,
1030
- images: None,
1031
- };
1032
- let config = ExtractionConfig::default();
1033
-
1034
- let processed = run_pipeline(result, &config).await.unwrap();
1035
- assert!(processed.content.contains("[middle-content]"));
1036
- assert!(processed.content.contains("[late-saw-middle]"));
1037
- }
1038
-
1039
- #[tokio::test]
1040
- #[serial]
1041
- async fn test_pipeline_multiple_processors_modifying_same_metadata() {
1042
- clear_processor_registry();
1043
-
1044
- let registry = get_post_processor_registry();
1045
- {
1046
- let mut reg = registry
1047
- .write()
1048
- .expect("Failed to acquire write lock on registry in test");
1049
-
1050
- for i in 1..=3 {
1051
- struct MetadataOverwritingProcessor {
1052
- name: String,
1053
- value: String,
1054
- }
1055
- impl Plugin for MetadataOverwritingProcessor {
1056
- fn name(&self) -> &str {
1057
- &self.name
1058
- }
1059
- fn version(&self) -> String {
1060
- "1.0.0".to_string()
1061
- }
1062
- fn initialize(&self) -> Result<()> {
1063
- Ok(())
1064
- }
1065
- fn shutdown(&self) -> Result<()> {
1066
- Ok(())
1067
- }
1068
- }
1069
- #[async_trait]
1070
- impl PostProcessor for MetadataOverwritingProcessor {
1071
- async fn process(&self, result: &mut ExtractionResult, _: &ExtractionConfig) -> Result<()> {
1072
- result
1073
- .metadata
1074
- .additional
1075
- .insert("shared_key".to_string(), serde_json::json!(self.value));
1076
- Ok(())
1077
- }
1078
- fn processing_stage(&self) -> ProcessingStage {
1079
- ProcessingStage::Early
1080
- }
1081
- }
1082
-
1083
- let processor = Arc::new(MetadataOverwritingProcessor {
1084
- name: format!("proc{}", i),
1085
- value: format!("value{}", i),
1086
- });
1087
- reg.register(processor, 100 - i * 10).unwrap();
1088
- }
1089
- }
1090
-
1091
- let result = ExtractionResult {
1092
- content: "content".to_string(),
1093
- mime_type: "text/plain".to_string(),
1094
- metadata: Metadata::default(),
1095
- tables: vec![],
1096
- detected_languages: None,
1097
- chunks: None,
1098
- images: None,
1099
- };
1100
- let config = ExtractionConfig::default();
1101
-
1102
- let processed = run_pipeline(result, &config).await.unwrap();
1103
- assert_eq!(
1104
- processed
1105
- .metadata
1106
- .additional
1107
- .get("shared_key")
1108
- .unwrap()
1109
- .as_str()
1110
- .unwrap(),
1111
- "value3"
1112
- );
1113
- }
1114
-
1115
- #[tokio::test]
1116
- #[serial]
1117
- async fn test_pipeline_processors_reading_previous_output() {
1118
- clear_processor_registry();
1119
-
1120
- let registry = get_post_processor_registry();
1121
- {
1122
- let mut reg = registry
1123
- .write()
1124
- .expect("Failed to acquire write lock on registry in test");
1125
-
1126
- struct CountingProcessor {
1127
- name: String,
1128
- stage: ProcessingStage,
1129
- }
1130
- impl Plugin for CountingProcessor {
1131
- fn name(&self) -> &str {
1132
- &self.name
1133
- }
1134
- fn version(&self) -> String {
1135
- "1.0.0".to_string()
1136
- }
1137
- fn initialize(&self) -> Result<()> {
1138
- Ok(())
1139
- }
1140
- fn shutdown(&self) -> Result<()> {
1141
- Ok(())
1142
- }
1143
- }
1144
- #[async_trait]
1145
- impl PostProcessor for CountingProcessor {
1146
- async fn process(&self, result: &mut ExtractionResult, _: &ExtractionConfig) -> Result<()> {
1147
- let current_count = result
1148
- .metadata
1149
- .additional
1150
- .get("count")
1151
- .and_then(|v| v.as_i64())
1152
- .unwrap_or(0);
1153
- result
1154
- .metadata
1155
- .additional
1156
- .insert("count".to_string(), serde_json::json!(current_count + 1));
1157
- Ok(())
1158
- }
1159
- fn processing_stage(&self) -> ProcessingStage {
1160
- self.stage
1161
- }
1162
- }
1163
-
1164
- for (name, stage) in [
1165
- ("early1", ProcessingStage::Early),
1166
- ("early2", ProcessingStage::Early),
1167
- ("middle1", ProcessingStage::Middle),
1168
- ("late1", ProcessingStage::Late),
1169
- ] {
1170
- let processor = Arc::new(CountingProcessor {
1171
- name: name.to_string(),
1172
- stage,
1173
- });
1174
- reg.register(processor, 50).unwrap();
1175
- }
1176
- }
1177
-
1178
- let result = ExtractionResult {
1179
- content: "content".to_string(),
1180
- mime_type: "text/plain".to_string(),
1181
- metadata: Metadata::default(),
1182
- tables: vec![],
1183
- detected_languages: None,
1184
- chunks: None,
1185
- images: None,
1186
- };
1187
- let config = ExtractionConfig::default();
1188
-
1189
- let processed = run_pipeline(result, &config).await.unwrap();
1190
- assert_eq!(processed.metadata.additional.get("count").unwrap().as_i64().unwrap(), 4);
1191
- }
1192
-
1193
- #[tokio::test]
1194
- #[serial]
1195
- async fn test_pipeline_large_content_modification() {
1196
- clear_processor_registry();
1197
-
1198
- struct LargeContentProcessor;
1199
- impl Plugin for LargeContentProcessor {
1200
- fn name(&self) -> &str {
1201
- "large"
1202
- }
1203
- fn version(&self) -> String {
1204
- "1.0.0".to_string()
1205
- }
1206
- fn initialize(&self) -> Result<()> {
1207
- Ok(())
1208
- }
1209
- fn shutdown(&self) -> Result<()> {
1210
- Ok(())
1211
- }
1212
- }
1213
- #[async_trait]
1214
- impl PostProcessor for LargeContentProcessor {
1215
- async fn process(&self, result: &mut ExtractionResult, _: &ExtractionConfig) -> Result<()> {
1216
- result.content.push_str(&"x".repeat(10000));
1217
- Ok(())
1218
- }
1219
- fn processing_stage(&self) -> ProcessingStage {
1220
- ProcessingStage::Early
1221
- }
1222
- }
1223
-
1224
- let registry = get_post_processor_registry();
1225
- {
1226
- let mut reg = registry
1227
- .write()
1228
- .expect("Failed to acquire write lock on registry in test");
1229
- reg.register(Arc::new(LargeContentProcessor), 50).unwrap();
1230
- }
1231
-
1232
- let result = ExtractionResult {
1233
- content: "start".to_string(),
1234
- mime_type: "text/plain".to_string(),
1235
- metadata: Metadata::default(),
1236
- tables: vec![],
1237
- detected_languages: None,
1238
- chunks: None,
1239
- images: None,
1240
- };
1241
- let config = ExtractionConfig::default();
1242
-
1243
- let processed = run_pipeline(result, &config).await.unwrap();
1244
- assert!(processed.content.len() > 10000);
1245
- }
1246
-
1247
- #[tokio::test]
1248
- #[serial]
1249
- async fn test_pipeline_enabled_processors_whitelist() {
1250
- clear_processor_registry();
1251
-
1252
- let registry = get_post_processor_registry();
1253
- {
1254
- let mut reg = registry
1255
- .write()
1256
- .expect("Failed to acquire write lock on registry in test");
1257
-
1258
- for name in ["proc1", "proc2", "proc3"] {
1259
- let processor = Arc::new(OrderTrackingProcessor {
1260
- name: name.to_string(),
1261
- stage: ProcessingStage::Early,
1262
- });
1263
- reg.register(processor, 50).unwrap();
1264
- }
1265
- }
1266
-
1267
- let result = ExtractionResult {
1268
- content: "start".to_string(),
1269
- mime_type: "text/plain".to_string(),
1270
- metadata: Metadata::default(),
1271
- tables: vec![],
1272
- detected_languages: None,
1273
- chunks: None,
1274
- images: None,
1275
- };
1276
- let config = ExtractionConfig {
1277
- postprocessor: Some(PostProcessorConfig {
1278
- enabled: true,
1279
- enabled_processors: Some(vec!["proc1".to_string(), "proc3".to_string()]),
1280
- disabled_processors: None,
1281
- }),
1282
- ..Default::default()
1283
- };
1284
-
1285
- let processed = run_pipeline(result, &config).await.unwrap();
1286
- assert!(processed.content.contains("[proc1]"));
1287
- assert!(!processed.content.contains("[proc2]"));
1288
- assert!(processed.content.contains("[proc3]"));
1289
- }
1290
-
1291
- #[tokio::test]
1292
- #[serial]
1293
- async fn test_pipeline_disabled_processors_blacklist() {
1294
- clear_processor_registry();
1295
-
1296
- let registry = get_post_processor_registry();
1297
- {
1298
- let mut reg = registry
1299
- .write()
1300
- .expect("Failed to acquire write lock on registry in test");
1301
-
1302
- for name in ["proc1", "proc2", "proc3"] {
1303
- let processor = Arc::new(OrderTrackingProcessor {
1304
- name: name.to_string(),
1305
- stage: ProcessingStage::Early,
1306
- });
1307
- reg.register(processor, 50).unwrap();
1308
- }
1309
- }
1310
-
1311
- let result = ExtractionResult {
1312
- content: "start".to_string(),
1313
- mime_type: "text/plain".to_string(),
1314
- metadata: Metadata::default(),
1315
- tables: vec![],
1316
- detected_languages: None,
1317
- chunks: None,
1318
- images: None,
1319
- };
1320
- let config = ExtractionConfig {
1321
- postprocessor: Some(PostProcessorConfig {
1322
- enabled: true,
1323
- enabled_processors: None,
1324
- disabled_processors: Some(vec!["proc2".to_string()]),
1325
- }),
1326
- ..Default::default()
1327
- };
1328
-
1329
- let processed = run_pipeline(result, &config).await.unwrap();
1330
- assert!(processed.content.contains("[proc1]"));
1331
- assert!(!processed.content.contains("[proc2]"));
1332
- assert!(processed.content.contains("[proc3]"));
1333
- }
1334
-
1335
- #[tokio::test]
1336
- #[serial]
1337
- async fn test_pipeline_no_filtering_runs_all() {
1338
- clear_processor_registry();
1339
-
1340
- let registry = get_post_processor_registry();
1341
- {
1342
- let mut reg = registry
1343
- .write()
1344
- .expect("Failed to acquire write lock on registry in test");
1345
-
1346
- for name in ["proc1", "proc2", "proc3"] {
1347
- let processor = Arc::new(OrderTrackingProcessor {
1348
- name: name.to_string(),
1349
- stage: ProcessingStage::Early,
1350
- });
1351
- reg.register(processor, 50).unwrap();
1352
- }
1353
- }
1354
-
1355
- let result = ExtractionResult {
1356
- content: "start".to_string(),
1357
- mime_type: "text/plain".to_string(),
1358
- metadata: Metadata::default(),
1359
- tables: vec![],
1360
- detected_languages: None,
1361
- chunks: None,
1362
- images: None,
1363
- };
1364
- let config = ExtractionConfig::default();
1365
-
1366
- let processed = run_pipeline(result, &config).await.unwrap();
1367
- assert!(processed.content.contains("[proc1]"));
1368
- assert!(processed.content.contains("[proc2]"));
1369
- assert!(processed.content.contains("[proc3]"));
1370
- }
1371
-
1372
- #[tokio::test]
1373
- #[serial]
1374
- async fn test_pipeline_empty_whitelist_runs_none() {
1375
- clear_processor_registry();
1376
-
1377
- let registry = get_post_processor_registry();
1378
- {
1379
- let mut reg = registry
1380
- .write()
1381
- .expect("Failed to acquire write lock on registry in test");
1382
-
1383
- for name in ["proc1", "proc2"] {
1384
- let processor = Arc::new(OrderTrackingProcessor {
1385
- name: name.to_string(),
1386
- stage: ProcessingStage::Early,
1387
- });
1388
- reg.register(processor, 50).unwrap();
1389
- }
1390
- }
1391
-
1392
- let result = ExtractionResult {
1393
- content: "start".to_string(),
1394
- mime_type: "text/plain".to_string(),
1395
- metadata: Metadata::default(),
1396
- tables: vec![],
1397
- detected_languages: None,
1398
- chunks: None,
1399
- images: None,
1400
- };
1401
- let config = ExtractionConfig {
1402
- postprocessor: Some(PostProcessorConfig {
1403
- enabled: true,
1404
- enabled_processors: Some(vec![]),
1405
- disabled_processors: None,
1406
- }),
1407
- ..Default::default()
1408
- };
1409
-
1410
- let processed = run_pipeline(result, &config).await.unwrap();
1411
- assert_eq!(processed.content, "start");
1412
- }
1
+ //! Comprehensive pipeline integration tests.
2
+ //!
3
+ //! Tests the post-processing pipeline orchestration: ordering, error handling,
4
+ //! metadata/content modifications, and integration with extractors.
5
+ //!
6
+ //! IMPORTANT: These tests use a global registry and must run serially to avoid interference.
7
+
8
+ use async_trait::async_trait;
9
+ use kreuzberg::core::config::{ExtractionConfig, PostProcessorConfig};
10
+ use kreuzberg::core::pipeline::run_pipeline;
11
+ use kreuzberg::plugins::registry::get_post_processor_registry;
12
+ use kreuzberg::plugins::{Plugin, PostProcessor, ProcessingStage};
13
+ use kreuzberg::types::{ExtractionResult, Metadata};
14
+ use kreuzberg::{KreuzbergError, Result};
15
+ use serial_test::serial;
16
+ use std::sync::Arc;
17
+
18
+ struct OrderTrackingProcessor {
19
+ name: String,
20
+ stage: ProcessingStage,
21
+ }
22
+
23
+ impl Plugin for OrderTrackingProcessor {
24
+ fn name(&self) -> &str {
25
+ &self.name
26
+ }
27
+ fn version(&self) -> String {
28
+ "1.0.0".to_string()
29
+ }
30
+ fn initialize(&self) -> Result<()> {
31
+ Ok(())
32
+ }
33
+ fn shutdown(&self) -> Result<()> {
34
+ Ok(())
35
+ }
36
+ }
37
+
38
+ #[async_trait]
39
+ impl PostProcessor for OrderTrackingProcessor {
40
+ async fn process(&self, result: &mut ExtractionResult, _: &ExtractionConfig) -> Result<()> {
41
+ result.content.push_str(&format!("[{}]", self.name));
42
+ Ok(())
43
+ }
44
+
45
+ fn processing_stage(&self) -> ProcessingStage {
46
+ self.stage
47
+ }
48
+ }
49
+
50
+ struct MetadataAddingProcessor {
51
+ name: String,
52
+ key: String,
53
+ value: String,
54
+ }
55
+
56
+ impl Plugin for MetadataAddingProcessor {
57
+ fn name(&self) -> &str {
58
+ &self.name
59
+ }
60
+ fn version(&self) -> String {
61
+ "1.0.0".to_string()
62
+ }
63
+ fn initialize(&self) -> Result<()> {
64
+ Ok(())
65
+ }
66
+ fn shutdown(&self) -> Result<()> {
67
+ Ok(())
68
+ }
69
+ }
70
+
71
+ #[async_trait]
72
+ impl PostProcessor for MetadataAddingProcessor {
73
+ async fn process(&self, result: &mut ExtractionResult, _: &ExtractionConfig) -> Result<()> {
74
+ result
75
+ .metadata
76
+ .additional
77
+ .insert(self.key.clone(), serde_json::json!(self.value));
78
+ Ok(())
79
+ }
80
+
81
+ fn processing_stage(&self) -> ProcessingStage {
82
+ ProcessingStage::Early
83
+ }
84
+ }
85
+
86
+ struct FailingProcessor {
87
+ name: String,
88
+ error_message: String,
89
+ }
90
+
91
+ impl Plugin for FailingProcessor {
92
+ fn name(&self) -> &str {
93
+ &self.name
94
+ }
95
+ fn version(&self) -> String {
96
+ "1.0.0".to_string()
97
+ }
98
+ fn initialize(&self) -> Result<()> {
99
+ Ok(())
100
+ }
101
+ fn shutdown(&self) -> Result<()> {
102
+ Ok(())
103
+ }
104
+ }
105
+
106
+ #[async_trait]
107
+ impl PostProcessor for FailingProcessor {
108
+ async fn process(&self, _: &mut ExtractionResult, _: &ExtractionConfig) -> Result<()> {
109
+ Err(KreuzbergError::Plugin {
110
+ message: self.error_message.clone(),
111
+ plugin_name: self.name.clone(),
112
+ })
113
+ }
114
+
115
+ fn processing_stage(&self) -> ProcessingStage {
116
+ ProcessingStage::Middle
117
+ }
118
+ }
119
+
120
+ fn clear_processor_registry() {
121
+ let registry = get_post_processor_registry();
122
+ let mut reg = registry
123
+ .write()
124
+ .expect("Failed to acquire write lock on registry in test");
125
+ let _ = reg.shutdown_all();
126
+ }
127
+
128
+ #[tokio::test]
129
+ #[serial]
130
+ async fn test_pipeline_empty_no_processors() {
131
+ clear_processor_registry();
132
+
133
+ let result = ExtractionResult {
134
+ content: "original content".to_string(),
135
+ mime_type: "text/plain".to_string(),
136
+ metadata: Metadata::default(),
137
+ tables: vec![],
138
+ detected_languages: None,
139
+ chunks: None,
140
+ images: None,
141
+ };
142
+ let config = ExtractionConfig::default();
143
+
144
+ let processed = run_pipeline(result, &config).await.unwrap();
145
+ assert_eq!(processed.content, "original content");
146
+ }
147
+
148
+ #[tokio::test]
149
+ #[serial]
150
+ async fn test_pipeline_single_processor_per_stage() {
151
+ clear_processor_registry();
152
+
153
+ let registry = get_post_processor_registry();
154
+ {
155
+ let mut reg = registry
156
+ .write()
157
+ .expect("Failed to acquire write lock on registry in test");
158
+
159
+ let early = Arc::new(OrderTrackingProcessor {
160
+ name: "early".to_string(),
161
+ stage: ProcessingStage::Early,
162
+ });
163
+ let middle = Arc::new(OrderTrackingProcessor {
164
+ name: "middle".to_string(),
165
+ stage: ProcessingStage::Middle,
166
+ });
167
+ let late = Arc::new(OrderTrackingProcessor {
168
+ name: "late".to_string(),
169
+ stage: ProcessingStage::Late,
170
+ });
171
+
172
+ reg.register(early, 50).unwrap();
173
+ reg.register(middle, 50).unwrap();
174
+ reg.register(late, 50).unwrap();
175
+ }
176
+
177
+ let result = ExtractionResult {
178
+ content: "start".to_string(),
179
+ mime_type: "text/plain".to_string(),
180
+ metadata: Metadata::default(),
181
+ tables: vec![],
182
+ detected_languages: None,
183
+ chunks: None,
184
+ images: None,
185
+ };
186
+ let config = ExtractionConfig::default();
187
+
188
+ let processed = run_pipeline(result, &config).await.unwrap();
189
+ assert_eq!(processed.content, "start[early][middle][late]");
190
+ }
191
+
192
+ #[tokio::test]
193
+ #[serial]
194
+ async fn test_pipeline_multiple_processors_per_stage() {
195
+ clear_processor_registry();
196
+
197
+ let registry = get_post_processor_registry();
198
+ {
199
+ let mut reg = registry
200
+ .write()
201
+ .expect("Failed to acquire write lock on registry in test");
202
+
203
+ let early_high = Arc::new(OrderTrackingProcessor {
204
+ name: "early-high".to_string(),
205
+ stage: ProcessingStage::Early,
206
+ });
207
+ let early_medium = Arc::new(OrderTrackingProcessor {
208
+ name: "early-medium".to_string(),
209
+ stage: ProcessingStage::Early,
210
+ });
211
+ let early_low = Arc::new(OrderTrackingProcessor {
212
+ name: "early-low".to_string(),
213
+ stage: ProcessingStage::Early,
214
+ });
215
+
216
+ reg.register(early_low, 10).unwrap();
217
+ reg.register(early_high, 100).unwrap();
218
+ reg.register(early_medium, 50).unwrap();
219
+ }
220
+
221
+ let result = ExtractionResult {
222
+ content: "start".to_string(),
223
+ mime_type: "text/plain".to_string(),
224
+ metadata: Metadata::default(),
225
+ tables: vec![],
226
+ detected_languages: None,
227
+ chunks: None,
228
+ images: None,
229
+ };
230
+ let config = ExtractionConfig::default();
231
+
232
+ let processed = run_pipeline(result, &config).await.unwrap();
233
+ assert_eq!(processed.content, "start[early-high][early-medium][early-low]");
234
+ }
235
+
236
+ #[tokio::test]
237
+ #[serial]
238
+ async fn test_pipeline_all_stages_enabled() {
239
+ clear_processor_registry();
240
+
241
+ let registry = get_post_processor_registry();
242
+ {
243
+ let mut reg = registry
244
+ .write()
245
+ .expect("Failed to acquire write lock on registry in test");
246
+
247
+ for stage in [ProcessingStage::Early, ProcessingStage::Middle, ProcessingStage::Late] {
248
+ let processor = Arc::new(OrderTrackingProcessor {
249
+ name: format!("{:?}", stage),
250
+ stage,
251
+ });
252
+ reg.register(processor, 50).unwrap();
253
+ }
254
+ }
255
+
256
+ let result = ExtractionResult {
257
+ content: "start".to_string(),
258
+ mime_type: "text/plain".to_string(),
259
+ metadata: Metadata::default(),
260
+ tables: vec![],
261
+ detected_languages: None,
262
+ chunks: None,
263
+ images: None,
264
+ };
265
+ let config = ExtractionConfig::default();
266
+
267
+ let processed = run_pipeline(result, &config).await.unwrap();
268
+ assert_eq!(processed.content, "start[Early][Middle][Late]");
269
+ }
270
+
271
+ #[tokio::test]
272
+ #[serial]
273
+ async fn test_pipeline_postprocessing_disabled() {
274
+ clear_processor_registry();
275
+
276
+ let registry = get_post_processor_registry();
277
+ {
278
+ let mut reg = registry
279
+ .write()
280
+ .expect("Failed to acquire write lock on registry in test");
281
+
282
+ let processor = Arc::new(OrderTrackingProcessor {
283
+ name: "processor".to_string(),
284
+ stage: ProcessingStage::Early,
285
+ });
286
+ reg.register(processor, 50).unwrap();
287
+ }
288
+
289
+ let result = ExtractionResult {
290
+ content: "start".to_string(),
291
+ mime_type: "text/plain".to_string(),
292
+ metadata: Metadata::default(),
293
+ tables: vec![],
294
+ detected_languages: None,
295
+ chunks: None,
296
+ images: None,
297
+ };
298
+ let config = ExtractionConfig {
299
+ postprocessor: Some(PostProcessorConfig {
300
+ enabled: false,
301
+ enabled_processors: None,
302
+ disabled_processors: None,
303
+ }),
304
+ ..Default::default()
305
+ };
306
+
307
+ let processed = run_pipeline(result, &config).await.unwrap();
308
+ assert_eq!(processed.content, "start");
309
+ }
310
+
311
+ #[tokio::test]
312
+ #[serial]
313
+ async fn test_pipeline_early_stage_runs_first() {
314
+ clear_processor_registry();
315
+
316
+ let registry = get_post_processor_registry();
317
+ {
318
+ let mut reg = registry
319
+ .write()
320
+ .expect("Failed to acquire write lock on registry in test");
321
+
322
+ let late = Arc::new(OrderTrackingProcessor {
323
+ name: "late".to_string(),
324
+ stage: ProcessingStage::Late,
325
+ });
326
+ let early = Arc::new(OrderTrackingProcessor {
327
+ name: "early".to_string(),
328
+ stage: ProcessingStage::Early,
329
+ });
330
+
331
+ reg.register(late, 50).unwrap();
332
+ reg.register(early, 50).unwrap();
333
+ }
334
+
335
+ let result = ExtractionResult {
336
+ content: "start".to_string(),
337
+ mime_type: "text/plain".to_string(),
338
+ metadata: Metadata::default(),
339
+ tables: vec![],
340
+ detected_languages: None,
341
+ chunks: None,
342
+ images: None,
343
+ };
344
+ let config = ExtractionConfig::default();
345
+
346
+ let processed = run_pipeline(result, &config).await.unwrap();
347
+ assert_eq!(processed.content, "start[early][late]");
348
+ }
349
+
350
+ #[tokio::test]
351
+ #[serial]
352
+ async fn test_pipeline_middle_stage_runs_second() {
353
+ clear_processor_registry();
354
+
355
+ let registry = get_post_processor_registry();
356
+ {
357
+ let mut reg = registry
358
+ .write()
359
+ .expect("Failed to acquire write lock on registry in test");
360
+
361
+ let early = Arc::new(OrderTrackingProcessor {
362
+ name: "early".to_string(),
363
+ stage: ProcessingStage::Early,
364
+ });
365
+ let middle = Arc::new(OrderTrackingProcessor {
366
+ name: "middle".to_string(),
367
+ stage: ProcessingStage::Middle,
368
+ });
369
+
370
+ reg.register(middle, 50).unwrap();
371
+ reg.register(early, 50).unwrap();
372
+ }
373
+
374
+ let result = ExtractionResult {
375
+ content: "start".to_string(),
376
+ mime_type: "text/plain".to_string(),
377
+ metadata: Metadata::default(),
378
+ tables: vec![],
379
+ detected_languages: None,
380
+ chunks: None,
381
+ images: None,
382
+ };
383
+ let config = ExtractionConfig::default();
384
+
385
+ let processed = run_pipeline(result, &config).await.unwrap();
386
+ assert_eq!(processed.content, "start[early][middle]");
387
+ }
388
+
389
+ #[tokio::test]
390
+ #[serial]
391
+ async fn test_pipeline_late_stage_runs_last() {
392
+ clear_processor_registry();
393
+
394
+ let registry = get_post_processor_registry();
395
+ {
396
+ let mut reg = registry
397
+ .write()
398
+ .expect("Failed to acquire write lock on registry in test");
399
+
400
+ for stage in [ProcessingStage::Late, ProcessingStage::Early, ProcessingStage::Middle] {
401
+ let processor = Arc::new(OrderTrackingProcessor {
402
+ name: format!("{:?}", stage),
403
+ stage,
404
+ });
405
+ reg.register(processor, 50).unwrap();
406
+ }
407
+ }
408
+
409
+ let result = ExtractionResult {
410
+ content: "start".to_string(),
411
+ mime_type: "text/plain".to_string(),
412
+ metadata: Metadata::default(),
413
+ tables: vec![],
414
+ detected_languages: None,
415
+ chunks: None,
416
+ images: None,
417
+ };
418
+ let config = ExtractionConfig::default();
419
+
420
+ let processed = run_pipeline(result, &config).await.unwrap();
421
+ assert_eq!(processed.content, "start[Early][Middle][Late]");
422
+ }
423
+
424
+ #[tokio::test]
425
+ #[serial]
426
+ async fn test_pipeline_within_stage_priority_order() {
427
+ clear_processor_registry();
428
+
429
+ let registry = get_post_processor_registry();
430
+ {
431
+ let mut reg = registry
432
+ .write()
433
+ .expect("Failed to acquire write lock on registry in test");
434
+
435
+ for (name, priority) in [("p1", 100), ("p2", 10), ("p3", 50), ("p4", 75)] {
436
+ let processor = Arc::new(OrderTrackingProcessor {
437
+ name: name.to_string(),
438
+ stage: ProcessingStage::Early,
439
+ });
440
+ reg.register(processor, priority).unwrap();
441
+ }
442
+ }
443
+
444
+ let result = ExtractionResult {
445
+ content: "start".to_string(),
446
+ mime_type: "text/plain".to_string(),
447
+ metadata: Metadata::default(),
448
+ tables: vec![],
449
+ detected_languages: None,
450
+ chunks: None,
451
+ images: None,
452
+ };
453
+ let config = ExtractionConfig::default();
454
+
455
+ let processed = run_pipeline(result, &config).await.unwrap();
456
+ assert_eq!(processed.content, "start[p1][p4][p3][p2]");
457
+ }
458
+
459
+ #[tokio::test]
460
+ #[serial]
461
+ async fn test_pipeline_cross_stage_data_flow() {
462
+ clear_processor_registry();
463
+
464
+ let registry = get_post_processor_registry();
465
+ {
466
+ let mut reg = registry
467
+ .write()
468
+ .expect("Failed to acquire write lock on registry in test");
469
+
470
+ let early = Arc::new(MetadataAddingProcessor {
471
+ name: "early".to_string(),
472
+ key: "stage".to_string(),
473
+ value: "early".to_string(),
474
+ });
475
+
476
+ struct MiddleProcessor;
477
+ impl Plugin for MiddleProcessor {
478
+ fn name(&self) -> &str {
479
+ "middle"
480
+ }
481
+ fn version(&self) -> String {
482
+ "1.0.0".to_string()
483
+ }
484
+ fn initialize(&self) -> Result<()> {
485
+ Ok(())
486
+ }
487
+ fn shutdown(&self) -> Result<()> {
488
+ Ok(())
489
+ }
490
+ }
491
+ #[async_trait]
492
+ impl PostProcessor for MiddleProcessor {
493
+ async fn process(&self, result: &mut ExtractionResult, _: &ExtractionConfig) -> Result<()> {
494
+ if let Some(stage) = result.metadata.additional.get("stage") {
495
+ result.content.push_str(&format!("[saw:{}]", stage.as_str().unwrap()));
496
+ }
497
+ Ok(())
498
+ }
499
+ fn processing_stage(&self) -> ProcessingStage {
500
+ ProcessingStage::Middle
501
+ }
502
+ }
503
+
504
+ reg.register(early, 50).unwrap();
505
+ reg.register(Arc::new(MiddleProcessor), 50).unwrap();
506
+ }
507
+
508
+ let result = ExtractionResult {
509
+ content: "start".to_string(),
510
+ mime_type: "text/plain".to_string(),
511
+ metadata: Metadata::default(),
512
+ tables: vec![],
513
+ detected_languages: None,
514
+ chunks: None,
515
+ images: None,
516
+ };
517
+ let config = ExtractionConfig::default();
518
+
519
+ let processed = run_pipeline(result, &config).await.unwrap();
520
+ assert!(processed.content.contains("[saw:early]"));
521
+ }
522
+
523
+ #[tokio::test]
524
+ #[serial]
525
+ async fn test_pipeline_early_stage_error_recorded() {
526
+ clear_processor_registry();
527
+
528
+ struct EarlyFailingProcessor;
529
+ impl Plugin for EarlyFailingProcessor {
530
+ fn name(&self) -> &str {
531
+ "early-failing"
532
+ }
533
+ fn version(&self) -> String {
534
+ "1.0.0".to_string()
535
+ }
536
+ fn initialize(&self) -> Result<()> {
537
+ Ok(())
538
+ }
539
+ fn shutdown(&self) -> Result<()> {
540
+ Ok(())
541
+ }
542
+ }
543
+ #[async_trait]
544
+ impl PostProcessor for EarlyFailingProcessor {
545
+ async fn process(&self, _: &mut ExtractionResult, _: &ExtractionConfig) -> Result<()> {
546
+ Err(KreuzbergError::Plugin {
547
+ message: "Early error".to_string(),
548
+ plugin_name: "early-failing".to_string(),
549
+ })
550
+ }
551
+ fn processing_stage(&self) -> ProcessingStage {
552
+ ProcessingStage::Early
553
+ }
554
+ }
555
+
556
+ let registry = get_post_processor_registry();
557
+ {
558
+ let mut reg = registry
559
+ .write()
560
+ .expect("Failed to acquire write lock on registry in test");
561
+ reg.register(Arc::new(EarlyFailingProcessor), 50).unwrap();
562
+ }
563
+
564
+ let result = ExtractionResult {
565
+ content: "content".to_string(),
566
+ mime_type: "text/plain".to_string(),
567
+ metadata: Metadata::default(),
568
+ tables: vec![],
569
+ detected_languages: None,
570
+ chunks: None,
571
+ images: None,
572
+ };
573
+ let config = ExtractionConfig::default();
574
+
575
+ let result = run_pipeline(result, &config).await;
576
+ assert!(result.is_err(), "Expected pipeline to return error");
577
+ match result {
578
+ Err(KreuzbergError::Plugin { message, plugin_name }) => {
579
+ assert_eq!(message, "Early error");
580
+ assert_eq!(plugin_name, "early-failing");
581
+ }
582
+ _ => panic!("Expected Plugin error"),
583
+ }
584
+ }
585
+
586
+ #[tokio::test]
587
+ #[serial]
588
+ async fn test_pipeline_middle_stage_error_propagation() {
589
+ clear_processor_registry();
590
+
591
+ let registry = get_post_processor_registry();
592
+ {
593
+ let mut reg = registry
594
+ .write()
595
+ .expect("Failed to acquire write lock on registry in test");
596
+
597
+ let failing = Arc::new(FailingProcessor {
598
+ name: "middle-failing".to_string(),
599
+ error_message: "Middle stage error".to_string(),
600
+ });
601
+
602
+ reg.register(failing, 50).unwrap();
603
+ }
604
+
605
+ let result = ExtractionResult {
606
+ content: "content".to_string(),
607
+ mime_type: "text/plain".to_string(),
608
+ metadata: Metadata::default(),
609
+ tables: vec![],
610
+ detected_languages: None,
611
+ chunks: None,
612
+ images: None,
613
+ };
614
+ let config = ExtractionConfig::default();
615
+
616
+ let result = run_pipeline(result, &config).await;
617
+ assert!(result.is_err(), "Expected pipeline to return error");
618
+ match result {
619
+ Err(KreuzbergError::Plugin { message, plugin_name }) => {
620
+ assert_eq!(message, "Middle stage error");
621
+ assert_eq!(plugin_name, "middle-failing");
622
+ }
623
+ _ => panic!("Expected Plugin error"),
624
+ }
625
+ }
626
+
627
+ #[tokio::test]
628
+ #[serial]
629
+ async fn test_pipeline_late_stage_error_doesnt_affect_earlier_stages() {
630
+ clear_processor_registry();
631
+
632
+ struct LateFailingProcessor;
633
+ impl Plugin for LateFailingProcessor {
634
+ fn name(&self) -> &str {
635
+ "late-failing"
636
+ }
637
+ fn version(&self) -> String {
638
+ "1.0.0".to_string()
639
+ }
640
+ fn initialize(&self) -> Result<()> {
641
+ Ok(())
642
+ }
643
+ fn shutdown(&self) -> Result<()> {
644
+ Ok(())
645
+ }
646
+ }
647
+ #[async_trait]
648
+ impl PostProcessor for LateFailingProcessor {
649
+ async fn process(&self, _: &mut ExtractionResult, _: &ExtractionConfig) -> Result<()> {
650
+ Err(KreuzbergError::Plugin {
651
+ message: "Late error".to_string(),
652
+ plugin_name: "late-failing".to_string(),
653
+ })
654
+ }
655
+ fn processing_stage(&self) -> ProcessingStage {
656
+ ProcessingStage::Late
657
+ }
658
+ }
659
+
660
+ let registry = get_post_processor_registry();
661
+ {
662
+ let mut reg = registry
663
+ .write()
664
+ .expect("Failed to acquire write lock on registry in test");
665
+
666
+ let early = Arc::new(OrderTrackingProcessor {
667
+ name: "early".to_string(),
668
+ stage: ProcessingStage::Early,
669
+ });
670
+ let late_failing = Arc::new(LateFailingProcessor);
671
+
672
+ reg.register(early, 50).unwrap();
673
+ reg.register(late_failing, 50).unwrap();
674
+ }
675
+
676
+ let result = ExtractionResult {
677
+ content: "start".to_string(),
678
+ mime_type: "text/plain".to_string(),
679
+ metadata: Metadata::default(),
680
+ tables: vec![],
681
+ detected_languages: None,
682
+ chunks: None,
683
+ images: None,
684
+ };
685
+ let config = ExtractionConfig::default();
686
+
687
+ let result = run_pipeline(result, &config).await;
688
+ assert!(result.is_err(), "Expected pipeline to return error");
689
+ match result {
690
+ Err(KreuzbergError::Plugin { message, plugin_name }) => {
691
+ assert_eq!(message, "Late error");
692
+ assert_eq!(plugin_name, "late-failing");
693
+ }
694
+ _ => panic!("Expected Plugin error"),
695
+ }
696
+ }
697
+
698
+ #[tokio::test]
699
+ #[serial]
700
+ async fn test_pipeline_processor_error_doesnt_stop_other_processors() {
701
+ clear_processor_registry();
702
+
703
+ let registry = get_post_processor_registry();
704
+ {
705
+ let mut reg = registry
706
+ .write()
707
+ .expect("Failed to acquire write lock on registry in test");
708
+
709
+ let p1 = Arc::new(OrderTrackingProcessor {
710
+ name: "p1".to_string(),
711
+ stage: ProcessingStage::Early,
712
+ });
713
+ let _p2_failing = Arc::new(FailingProcessor {
714
+ name: "p2-failing".to_string(),
715
+ error_message: "Test error".to_string(),
716
+ });
717
+ let p3 = Arc::new(OrderTrackingProcessor {
718
+ name: "p3".to_string(),
719
+ stage: ProcessingStage::Late,
720
+ });
721
+
722
+ struct EarlyFailingProcessor {
723
+ name: String,
724
+ }
725
+ impl Plugin for EarlyFailingProcessor {
726
+ fn name(&self) -> &str {
727
+ &self.name
728
+ }
729
+ fn version(&self) -> String {
730
+ "1.0.0".to_string()
731
+ }
732
+ fn initialize(&self) -> Result<()> {
733
+ Ok(())
734
+ }
735
+ fn shutdown(&self) -> Result<()> {
736
+ Ok(())
737
+ }
738
+ }
739
+ #[async_trait]
740
+ impl PostProcessor for EarlyFailingProcessor {
741
+ async fn process(&self, _: &mut ExtractionResult, _: &ExtractionConfig) -> Result<()> {
742
+ Err(KreuzbergError::Plugin {
743
+ message: "Test error".to_string(),
744
+ plugin_name: self.name.clone(),
745
+ })
746
+ }
747
+ fn processing_stage(&self) -> ProcessingStage {
748
+ ProcessingStage::Early
749
+ }
750
+ }
751
+
752
+ reg.register(p1, 100).unwrap();
753
+ reg.register(
754
+ Arc::new(EarlyFailingProcessor {
755
+ name: "p2-failing".to_string(),
756
+ }),
757
+ 50,
758
+ )
759
+ .unwrap();
760
+ reg.register(p3, 50).unwrap();
761
+ }
762
+
763
+ let result = ExtractionResult {
764
+ content: "start".to_string(),
765
+ mime_type: "text/plain".to_string(),
766
+ metadata: Metadata::default(),
767
+ tables: vec![],
768
+ detected_languages: None,
769
+ chunks: None,
770
+ images: None,
771
+ };
772
+ let config = ExtractionConfig::default();
773
+
774
+ let result = run_pipeline(result, &config).await;
775
+ assert!(result.is_err(), "Expected pipeline to return error");
776
+ match result {
777
+ Err(KreuzbergError::Plugin { message, plugin_name }) => {
778
+ assert_eq!(message, "Test error");
779
+ assert_eq!(plugin_name, "p2-failing");
780
+ }
781
+ _ => panic!("Expected Plugin error"),
782
+ }
783
+ }
784
+
785
+ #[tokio::test]
786
+ #[serial]
787
+ async fn test_pipeline_multiple_processor_errors() {
788
+ clear_processor_registry();
789
+
790
+ struct MultiFailingProcessor {
791
+ name: String,
792
+ stage: ProcessingStage,
793
+ }
794
+ impl Plugin for MultiFailingProcessor {
795
+ fn name(&self) -> &str {
796
+ &self.name
797
+ }
798
+ fn version(&self) -> String {
799
+ "1.0.0".to_string()
800
+ }
801
+ fn initialize(&self) -> Result<()> {
802
+ Ok(())
803
+ }
804
+ fn shutdown(&self) -> Result<()> {
805
+ Ok(())
806
+ }
807
+ }
808
+ #[async_trait]
809
+ impl PostProcessor for MultiFailingProcessor {
810
+ async fn process(&self, _: &mut ExtractionResult, _: &ExtractionConfig) -> Result<()> {
811
+ Err(KreuzbergError::Plugin {
812
+ message: format!("{} error", self.name),
813
+ plugin_name: self.name.clone(),
814
+ })
815
+ }
816
+ fn processing_stage(&self) -> ProcessingStage {
817
+ self.stage
818
+ }
819
+ }
820
+
821
+ let registry = get_post_processor_registry();
822
+ {
823
+ let mut reg = registry
824
+ .write()
825
+ .expect("Failed to acquire write lock on registry in test");
826
+
827
+ for (name, stage) in [
828
+ ("fail1", ProcessingStage::Early),
829
+ ("fail2", ProcessingStage::Middle),
830
+ ("fail3", ProcessingStage::Late),
831
+ ] {
832
+ let processor = Arc::new(MultiFailingProcessor {
833
+ name: name.to_string(),
834
+ stage,
835
+ });
836
+ reg.register(processor, 50).unwrap();
837
+ }
838
+ }
839
+
840
+ let result = ExtractionResult {
841
+ content: "start".to_string(),
842
+ mime_type: "text/plain".to_string(),
843
+ metadata: Metadata::default(),
844
+ tables: vec![],
845
+ detected_languages: None,
846
+ chunks: None,
847
+ images: None,
848
+ };
849
+ let config = ExtractionConfig::default();
850
+
851
+ let result = run_pipeline(result, &config).await;
852
+ assert!(result.is_err(), "Expected pipeline to return error");
853
+ match result {
854
+ Err(KreuzbergError::Plugin { message, plugin_name }) => {
855
+ assert_eq!(message, "fail1 error");
856
+ assert_eq!(plugin_name, "fail1");
857
+ }
858
+ _ => panic!("Expected Plugin error"),
859
+ }
860
+ }
861
+
862
+ #[tokio::test]
863
+ #[serial]
864
+ async fn test_pipeline_error_context_preservation() {
865
+ clear_processor_registry();
866
+
867
+ let registry = get_post_processor_registry();
868
+ {
869
+ let mut reg = registry
870
+ .write()
871
+ .expect("Failed to acquire write lock on registry in test");
872
+
873
+ let failing = Arc::new(FailingProcessor {
874
+ name: "context-test".to_string(),
875
+ error_message: "Detailed error message with context".to_string(),
876
+ });
877
+
878
+ reg.register(failing, 50).unwrap();
879
+ }
880
+
881
+ let result = ExtractionResult {
882
+ content: "content".to_string(),
883
+ mime_type: "text/plain".to_string(),
884
+ metadata: Metadata::default(),
885
+ tables: vec![],
886
+ detected_languages: None,
887
+ chunks: None,
888
+ images: None,
889
+ };
890
+ let config = ExtractionConfig::default();
891
+
892
+ let result = run_pipeline(result, &config).await;
893
+ assert!(result.is_err(), "Expected pipeline to return error");
894
+ match result {
895
+ Err(KreuzbergError::Plugin { message, plugin_name }) => {
896
+ assert_eq!(message, "Detailed error message with context");
897
+ assert_eq!(plugin_name, "context-test");
898
+ }
899
+ _ => panic!("Expected Plugin error"),
900
+ }
901
+ }
902
+
903
+ #[tokio::test]
904
+ #[serial]
905
+ async fn test_pipeline_metadata_added_in_early_visible_in_middle() {
906
+ clear_processor_registry();
907
+
908
+ let registry = get_post_processor_registry();
909
+ {
910
+ let mut reg = registry
911
+ .write()
912
+ .expect("Failed to acquire write lock on registry in test");
913
+
914
+ let early = Arc::new(MetadataAddingProcessor {
915
+ name: "early".to_string(),
916
+ key: "early_key".to_string(),
917
+ value: "early_value".to_string(),
918
+ });
919
+
920
+ struct MiddleReadingProcessor;
921
+ impl Plugin for MiddleReadingProcessor {
922
+ fn name(&self) -> &str {
923
+ "middle"
924
+ }
925
+ fn version(&self) -> String {
926
+ "1.0.0".to_string()
927
+ }
928
+ fn initialize(&self) -> Result<()> {
929
+ Ok(())
930
+ }
931
+ fn shutdown(&self) -> Result<()> {
932
+ Ok(())
933
+ }
934
+ }
935
+ #[async_trait]
936
+ impl PostProcessor for MiddleReadingProcessor {
937
+ async fn process(&self, result: &mut ExtractionResult, _: &ExtractionConfig) -> Result<()> {
938
+ if let Some(val) = result.metadata.additional.get("early_key") {
939
+ result.metadata.additional.insert("middle_saw".to_string(), val.clone());
940
+ }
941
+ Ok(())
942
+ }
943
+ fn processing_stage(&self) -> ProcessingStage {
944
+ ProcessingStage::Middle
945
+ }
946
+ }
947
+
948
+ reg.register(early, 50).unwrap();
949
+ reg.register(Arc::new(MiddleReadingProcessor), 50).unwrap();
950
+ }
951
+
952
+ let result = ExtractionResult {
953
+ content: "content".to_string(),
954
+ mime_type: "text/plain".to_string(),
955
+ metadata: Metadata::default(),
956
+ tables: vec![],
957
+ detected_languages: None,
958
+ chunks: None,
959
+ images: None,
960
+ };
961
+ let config = ExtractionConfig::default();
962
+
963
+ let processed = run_pipeline(result, &config).await.unwrap();
964
+ assert_eq!(
965
+ processed
966
+ .metadata
967
+ .additional
968
+ .get("middle_saw")
969
+ .unwrap()
970
+ .as_str()
971
+ .unwrap(),
972
+ "early_value"
973
+ );
974
+ }
975
+
976
+ #[tokio::test]
977
+ #[serial]
978
+ async fn test_pipeline_content_modified_in_middle_visible_in_late() {
979
+ clear_processor_registry();
980
+
981
+ let registry = get_post_processor_registry();
982
+ {
983
+ let mut reg = registry
984
+ .write()
985
+ .expect("Failed to acquire write lock on registry in test");
986
+
987
+ let middle = Arc::new(OrderTrackingProcessor {
988
+ name: "middle-content".to_string(),
989
+ stage: ProcessingStage::Middle,
990
+ });
991
+
992
+ struct LateReadingProcessor;
993
+ impl Plugin for LateReadingProcessor {
994
+ fn name(&self) -> &str {
995
+ "late"
996
+ }
997
+ fn version(&self) -> String {
998
+ "1.0.0".to_string()
999
+ }
1000
+ fn initialize(&self) -> Result<()> {
1001
+ Ok(())
1002
+ }
1003
+ fn shutdown(&self) -> Result<()> {
1004
+ Ok(())
1005
+ }
1006
+ }
1007
+ #[async_trait]
1008
+ impl PostProcessor for LateReadingProcessor {
1009
+ async fn process(&self, result: &mut ExtractionResult, _: &ExtractionConfig) -> Result<()> {
1010
+ result.content.push_str("[late-saw-middle]");
1011
+ Ok(())
1012
+ }
1013
+ fn processing_stage(&self) -> ProcessingStage {
1014
+ ProcessingStage::Late
1015
+ }
1016
+ }
1017
+
1018
+ reg.register(middle, 50).unwrap();
1019
+ reg.register(Arc::new(LateReadingProcessor), 50).unwrap();
1020
+ }
1021
+
1022
+ let result = ExtractionResult {
1023
+ content: "start".to_string(),
1024
+ mime_type: "text/plain".to_string(),
1025
+ metadata: Metadata::default(),
1026
+ tables: vec![],
1027
+ detected_languages: None,
1028
+ chunks: None,
1029
+ images: None,
1030
+ };
1031
+ let config = ExtractionConfig::default();
1032
+
1033
+ let processed = run_pipeline(result, &config).await.unwrap();
1034
+ assert!(processed.content.contains("[middle-content]"));
1035
+ assert!(processed.content.contains("[late-saw-middle]"));
1036
+ }
1037
+
1038
+ #[tokio::test]
1039
+ #[serial]
1040
+ async fn test_pipeline_multiple_processors_modifying_same_metadata() {
1041
+ clear_processor_registry();
1042
+
1043
+ let registry = get_post_processor_registry();
1044
+ {
1045
+ let mut reg = registry
1046
+ .write()
1047
+ .expect("Failed to acquire write lock on registry in test");
1048
+
1049
+ for i in 1..=3 {
1050
+ struct MetadataOverwritingProcessor {
1051
+ name: String,
1052
+ value: String,
1053
+ }
1054
+ impl Plugin for MetadataOverwritingProcessor {
1055
+ fn name(&self) -> &str {
1056
+ &self.name
1057
+ }
1058
+ fn version(&self) -> String {
1059
+ "1.0.0".to_string()
1060
+ }
1061
+ fn initialize(&self) -> Result<()> {
1062
+ Ok(())
1063
+ }
1064
+ fn shutdown(&self) -> Result<()> {
1065
+ Ok(())
1066
+ }
1067
+ }
1068
+ #[async_trait]
1069
+ impl PostProcessor for MetadataOverwritingProcessor {
1070
+ async fn process(&self, result: &mut ExtractionResult, _: &ExtractionConfig) -> Result<()> {
1071
+ result
1072
+ .metadata
1073
+ .additional
1074
+ .insert("shared_key".to_string(), serde_json::json!(self.value));
1075
+ Ok(())
1076
+ }
1077
+ fn processing_stage(&self) -> ProcessingStage {
1078
+ ProcessingStage::Early
1079
+ }
1080
+ }
1081
+
1082
+ let processor = Arc::new(MetadataOverwritingProcessor {
1083
+ name: format!("proc{}", i),
1084
+ value: format!("value{}", i),
1085
+ });
1086
+ reg.register(processor, 100 - i * 10).unwrap();
1087
+ }
1088
+ }
1089
+
1090
+ let result = ExtractionResult {
1091
+ content: "content".to_string(),
1092
+ mime_type: "text/plain".to_string(),
1093
+ metadata: Metadata::default(),
1094
+ tables: vec![],
1095
+ detected_languages: None,
1096
+ chunks: None,
1097
+ images: None,
1098
+ };
1099
+ let config = ExtractionConfig::default();
1100
+
1101
+ let processed = run_pipeline(result, &config).await.unwrap();
1102
+ assert_eq!(
1103
+ processed
1104
+ .metadata
1105
+ .additional
1106
+ .get("shared_key")
1107
+ .unwrap()
1108
+ .as_str()
1109
+ .unwrap(),
1110
+ "value3"
1111
+ );
1112
+ }
1113
+
1114
+ #[tokio::test]
1115
+ #[serial]
1116
+ async fn test_pipeline_processors_reading_previous_output() {
1117
+ clear_processor_registry();
1118
+
1119
+ let registry = get_post_processor_registry();
1120
+ {
1121
+ let mut reg = registry
1122
+ .write()
1123
+ .expect("Failed to acquire write lock on registry in test");
1124
+
1125
+ struct CountingProcessor {
1126
+ name: String,
1127
+ stage: ProcessingStage,
1128
+ }
1129
+ impl Plugin for CountingProcessor {
1130
+ fn name(&self) -> &str {
1131
+ &self.name
1132
+ }
1133
+ fn version(&self) -> String {
1134
+ "1.0.0".to_string()
1135
+ }
1136
+ fn initialize(&self) -> Result<()> {
1137
+ Ok(())
1138
+ }
1139
+ fn shutdown(&self) -> Result<()> {
1140
+ Ok(())
1141
+ }
1142
+ }
1143
+ #[async_trait]
1144
+ impl PostProcessor for CountingProcessor {
1145
+ async fn process(&self, result: &mut ExtractionResult, _: &ExtractionConfig) -> Result<()> {
1146
+ let current_count = result
1147
+ .metadata
1148
+ .additional
1149
+ .get("count")
1150
+ .and_then(|v| v.as_i64())
1151
+ .unwrap_or(0);
1152
+ result
1153
+ .metadata
1154
+ .additional
1155
+ .insert("count".to_string(), serde_json::json!(current_count + 1));
1156
+ Ok(())
1157
+ }
1158
+ fn processing_stage(&self) -> ProcessingStage {
1159
+ self.stage
1160
+ }
1161
+ }
1162
+
1163
+ for (name, stage) in [
1164
+ ("early1", ProcessingStage::Early),
1165
+ ("early2", ProcessingStage::Early),
1166
+ ("middle1", ProcessingStage::Middle),
1167
+ ("late1", ProcessingStage::Late),
1168
+ ] {
1169
+ let processor = Arc::new(CountingProcessor {
1170
+ name: name.to_string(),
1171
+ stage,
1172
+ });
1173
+ reg.register(processor, 50).unwrap();
1174
+ }
1175
+ }
1176
+
1177
+ let result = ExtractionResult {
1178
+ content: "content".to_string(),
1179
+ mime_type: "text/plain".to_string(),
1180
+ metadata: Metadata::default(),
1181
+ tables: vec![],
1182
+ detected_languages: None,
1183
+ chunks: None,
1184
+ images: None,
1185
+ };
1186
+ let config = ExtractionConfig::default();
1187
+
1188
+ let processed = run_pipeline(result, &config).await.unwrap();
1189
+ assert_eq!(processed.metadata.additional.get("count").unwrap().as_i64().unwrap(), 4);
1190
+ }
1191
+
1192
+ #[tokio::test]
1193
+ #[serial]
1194
+ async fn test_pipeline_large_content_modification() {
1195
+ clear_processor_registry();
1196
+
1197
+ struct LargeContentProcessor;
1198
+ impl Plugin for LargeContentProcessor {
1199
+ fn name(&self) -> &str {
1200
+ "large"
1201
+ }
1202
+ fn version(&self) -> String {
1203
+ "1.0.0".to_string()
1204
+ }
1205
+ fn initialize(&self) -> Result<()> {
1206
+ Ok(())
1207
+ }
1208
+ fn shutdown(&self) -> Result<()> {
1209
+ Ok(())
1210
+ }
1211
+ }
1212
+ #[async_trait]
1213
+ impl PostProcessor for LargeContentProcessor {
1214
+ async fn process(&self, result: &mut ExtractionResult, _: &ExtractionConfig) -> Result<()> {
1215
+ result.content.push_str(&"x".repeat(10000));
1216
+ Ok(())
1217
+ }
1218
+ fn processing_stage(&self) -> ProcessingStage {
1219
+ ProcessingStage::Early
1220
+ }
1221
+ }
1222
+
1223
+ let registry = get_post_processor_registry();
1224
+ {
1225
+ let mut reg = registry
1226
+ .write()
1227
+ .expect("Failed to acquire write lock on registry in test");
1228
+ reg.register(Arc::new(LargeContentProcessor), 50).unwrap();
1229
+ }
1230
+
1231
+ let result = ExtractionResult {
1232
+ content: "start".to_string(),
1233
+ mime_type: "text/plain".to_string(),
1234
+ metadata: Metadata::default(),
1235
+ tables: vec![],
1236
+ detected_languages: None,
1237
+ chunks: None,
1238
+ images: None,
1239
+ };
1240
+ let config = ExtractionConfig::default();
1241
+
1242
+ let processed = run_pipeline(result, &config).await.unwrap();
1243
+ assert!(processed.content.len() > 10000);
1244
+ }
1245
+
1246
+ #[tokio::test]
1247
+ #[serial]
1248
+ async fn test_pipeline_enabled_processors_whitelist() {
1249
+ clear_processor_registry();
1250
+
1251
+ let registry = get_post_processor_registry();
1252
+ {
1253
+ let mut reg = registry
1254
+ .write()
1255
+ .expect("Failed to acquire write lock on registry in test");
1256
+
1257
+ for name in ["proc1", "proc2", "proc3"] {
1258
+ let processor = Arc::new(OrderTrackingProcessor {
1259
+ name: name.to_string(),
1260
+ stage: ProcessingStage::Early,
1261
+ });
1262
+ reg.register(processor, 50).unwrap();
1263
+ }
1264
+ }
1265
+
1266
+ let result = ExtractionResult {
1267
+ content: "start".to_string(),
1268
+ mime_type: "text/plain".to_string(),
1269
+ metadata: Metadata::default(),
1270
+ tables: vec![],
1271
+ detected_languages: None,
1272
+ chunks: None,
1273
+ images: None,
1274
+ };
1275
+ let config = ExtractionConfig {
1276
+ postprocessor: Some(PostProcessorConfig {
1277
+ enabled: true,
1278
+ enabled_processors: Some(vec!["proc1".to_string(), "proc3".to_string()]),
1279
+ disabled_processors: None,
1280
+ }),
1281
+ ..Default::default()
1282
+ };
1283
+
1284
+ let processed = run_pipeline(result, &config).await.unwrap();
1285
+ assert!(processed.content.contains("[proc1]"));
1286
+ assert!(!processed.content.contains("[proc2]"));
1287
+ assert!(processed.content.contains("[proc3]"));
1288
+ }
1289
+
1290
+ #[tokio::test]
1291
+ #[serial]
1292
+ async fn test_pipeline_disabled_processors_blacklist() {
1293
+ clear_processor_registry();
1294
+
1295
+ let registry = get_post_processor_registry();
1296
+ {
1297
+ let mut reg = registry
1298
+ .write()
1299
+ .expect("Failed to acquire write lock on registry in test");
1300
+
1301
+ for name in ["proc1", "proc2", "proc3"] {
1302
+ let processor = Arc::new(OrderTrackingProcessor {
1303
+ name: name.to_string(),
1304
+ stage: ProcessingStage::Early,
1305
+ });
1306
+ reg.register(processor, 50).unwrap();
1307
+ }
1308
+ }
1309
+
1310
+ let result = ExtractionResult {
1311
+ content: "start".to_string(),
1312
+ mime_type: "text/plain".to_string(),
1313
+ metadata: Metadata::default(),
1314
+ tables: vec![],
1315
+ detected_languages: None,
1316
+ chunks: None,
1317
+ images: None,
1318
+ };
1319
+ let config = ExtractionConfig {
1320
+ postprocessor: Some(PostProcessorConfig {
1321
+ enabled: true,
1322
+ enabled_processors: None,
1323
+ disabled_processors: Some(vec!["proc2".to_string()]),
1324
+ }),
1325
+ ..Default::default()
1326
+ };
1327
+
1328
+ let processed = run_pipeline(result, &config).await.unwrap();
1329
+ assert!(processed.content.contains("[proc1]"));
1330
+ assert!(!processed.content.contains("[proc2]"));
1331
+ assert!(processed.content.contains("[proc3]"));
1332
+ }
1333
+
1334
+ #[tokio::test]
1335
+ #[serial]
1336
+ async fn test_pipeline_no_filtering_runs_all() {
1337
+ clear_processor_registry();
1338
+
1339
+ let registry = get_post_processor_registry();
1340
+ {
1341
+ let mut reg = registry
1342
+ .write()
1343
+ .expect("Failed to acquire write lock on registry in test");
1344
+
1345
+ for name in ["proc1", "proc2", "proc3"] {
1346
+ let processor = Arc::new(OrderTrackingProcessor {
1347
+ name: name.to_string(),
1348
+ stage: ProcessingStage::Early,
1349
+ });
1350
+ reg.register(processor, 50).unwrap();
1351
+ }
1352
+ }
1353
+
1354
+ let result = ExtractionResult {
1355
+ content: "start".to_string(),
1356
+ mime_type: "text/plain".to_string(),
1357
+ metadata: Metadata::default(),
1358
+ tables: vec![],
1359
+ detected_languages: None,
1360
+ chunks: None,
1361
+ images: None,
1362
+ };
1363
+ let config = ExtractionConfig::default();
1364
+
1365
+ let processed = run_pipeline(result, &config).await.unwrap();
1366
+ assert!(processed.content.contains("[proc1]"));
1367
+ assert!(processed.content.contains("[proc2]"));
1368
+ assert!(processed.content.contains("[proc3]"));
1369
+ }
1370
+
1371
+ #[tokio::test]
1372
+ #[serial]
1373
+ async fn test_pipeline_empty_whitelist_runs_none() {
1374
+ clear_processor_registry();
1375
+
1376
+ let registry = get_post_processor_registry();
1377
+ {
1378
+ let mut reg = registry
1379
+ .write()
1380
+ .expect("Failed to acquire write lock on registry in test");
1381
+
1382
+ for name in ["proc1", "proc2"] {
1383
+ let processor = Arc::new(OrderTrackingProcessor {
1384
+ name: name.to_string(),
1385
+ stage: ProcessingStage::Early,
1386
+ });
1387
+ reg.register(processor, 50).unwrap();
1388
+ }
1389
+ }
1390
+
1391
+ let result = ExtractionResult {
1392
+ content: "start".to_string(),
1393
+ mime_type: "text/plain".to_string(),
1394
+ metadata: Metadata::default(),
1395
+ tables: vec![],
1396
+ detected_languages: None,
1397
+ chunks: None,
1398
+ images: None,
1399
+ };
1400
+ let config = ExtractionConfig {
1401
+ postprocessor: Some(PostProcessorConfig {
1402
+ enabled: true,
1403
+ enabled_processors: Some(vec![]),
1404
+ disabled_processors: None,
1405
+ }),
1406
+ ..Default::default()
1407
+ };
1408
+
1409
+ let processed = run_pipeline(result, &config).await.unwrap();
1410
+ assert_eq!(processed.content, "start");
1411
+ }