kreuzberg 4.0.0.rc2 → 4.0.0

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 (446) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +14 -14
  3. data/.rspec +3 -3
  4. data/.rubocop.yaml +1 -1
  5. data/.rubocop.yml +543 -538
  6. data/Gemfile +8 -8
  7. data/Gemfile.lock +194 -6
  8. data/README.md +396 -426
  9. data/Rakefile +34 -25
  10. data/Steepfile +51 -47
  11. data/examples/async_patterns.rb +283 -341
  12. data/ext/kreuzberg_rb/extconf.rb +65 -45
  13. data/ext/kreuzberg_rb/native/.cargo/config.toml +23 -0
  14. data/ext/kreuzberg_rb/native/Cargo.lock +7619 -6535
  15. data/ext/kreuzberg_rb/native/Cargo.toml +75 -44
  16. data/ext/kreuzberg_rb/native/README.md +425 -425
  17. data/ext/kreuzberg_rb/native/build.rs +15 -15
  18. data/ext/kreuzberg_rb/native/include/ieeefp.h +11 -11
  19. data/ext/kreuzberg_rb/native/include/msvc_compat/strings.h +14 -14
  20. data/ext/kreuzberg_rb/native/include/strings.h +20 -20
  21. data/ext/kreuzberg_rb/native/include/unistd.h +47 -47
  22. data/ext/kreuzberg_rb/native/src/lib.rs +3802 -2998
  23. data/extconf.rb +60 -28
  24. data/kreuzberg.gemspec +199 -148
  25. data/lib/kreuzberg/api_proxy.rb +126 -142
  26. data/lib/kreuzberg/cache_api.rb +67 -46
  27. data/lib/kreuzberg/cli.rb +47 -55
  28. data/lib/kreuzberg/cli_proxy.rb +117 -127
  29. data/lib/kreuzberg/config.rb +936 -691
  30. data/lib/kreuzberg/error_context.rb +136 -32
  31. data/lib/kreuzberg/errors.rb +116 -118
  32. data/lib/kreuzberg/extraction_api.rb +313 -85
  33. data/lib/kreuzberg/mcp_proxy.rb +177 -186
  34. data/lib/kreuzberg/ocr_backend_protocol.rb +40 -113
  35. data/lib/kreuzberg/post_processor_protocol.rb +15 -86
  36. data/lib/kreuzberg/result.rb +334 -216
  37. data/lib/kreuzberg/setup_lib_path.rb +99 -80
  38. data/lib/kreuzberg/types.rb +170 -0
  39. data/lib/kreuzberg/validator_protocol.rb +16 -89
  40. data/lib/kreuzberg/version.rb +5 -5
  41. data/lib/kreuzberg.rb +96 -103
  42. data/lib/libpdfium.so +0 -0
  43. data/sig/kreuzberg/internal.rbs +184 -184
  44. data/sig/kreuzberg.rbs +561 -520
  45. data/spec/binding/async_operations_spec.rb +473 -0
  46. data/spec/binding/batch_operations_spec.rb +595 -0
  47. data/spec/binding/batch_spec.rb +359 -0
  48. data/spec/binding/cache_spec.rb +227 -227
  49. data/spec/binding/cli_proxy_spec.rb +85 -85
  50. data/spec/binding/cli_spec.rb +55 -55
  51. data/spec/binding/config_result_spec.rb +377 -0
  52. data/spec/binding/config_spec.rb +419 -345
  53. data/spec/binding/config_validation_spec.rb +377 -283
  54. data/spec/binding/embeddings_spec.rb +816 -0
  55. data/spec/binding/error_handling_spec.rb +399 -213
  56. data/spec/binding/error_recovery_spec.rb +488 -0
  57. data/spec/binding/errors_spec.rb +66 -66
  58. data/spec/binding/font_config_spec.rb +220 -0
  59. data/spec/binding/images_spec.rb +738 -0
  60. data/spec/binding/keywords_extraction_spec.rb +600 -0
  61. data/spec/binding/metadata_types_spec.rb +1228 -0
  62. data/spec/binding/pages_extraction_spec.rb +471 -0
  63. data/spec/binding/plugins/ocr_backend_spec.rb +307 -307
  64. data/spec/binding/plugins/postprocessor_spec.rb +269 -269
  65. data/spec/binding/plugins/validator_spec.rb +273 -274
  66. data/spec/binding/tables_spec.rb +641 -0
  67. data/spec/fixtures/config.toml +38 -39
  68. data/spec/fixtures/config.yaml +41 -41
  69. data/spec/fixtures/invalid_config.toml +3 -4
  70. data/spec/smoke/package_spec.rb +177 -178
  71. data/spec/spec_helper.rb +40 -42
  72. data/spec/unit/config/chunking_config_spec.rb +213 -0
  73. data/spec/unit/config/embedding_config_spec.rb +343 -0
  74. data/spec/unit/config/extraction_config_spec.rb +438 -0
  75. data/spec/unit/config/font_config_spec.rb +285 -0
  76. data/spec/unit/config/hierarchy_config_spec.rb +314 -0
  77. data/spec/unit/config/image_extraction_config_spec.rb +209 -0
  78. data/spec/unit/config/image_preprocessing_config_spec.rb +249 -0
  79. data/spec/unit/config/keyword_config_spec.rb +229 -0
  80. data/spec/unit/config/language_detection_config_spec.rb +258 -0
  81. data/spec/unit/config/ocr_config_spec.rb +171 -0
  82. data/spec/unit/config/page_config_spec.rb +221 -0
  83. data/spec/unit/config/pdf_config_spec.rb +267 -0
  84. data/spec/unit/config/postprocessor_config_spec.rb +290 -0
  85. data/spec/unit/config/tesseract_config_spec.rb +181 -0
  86. data/spec/unit/config/token_reduction_config_spec.rb +251 -0
  87. data/test/metadata_types_test.rb +959 -0
  88. data/vendor/Cargo.toml +61 -0
  89. data/vendor/kreuzberg/Cargo.toml +259 -204
  90. data/vendor/kreuzberg/README.md +263 -175
  91. data/vendor/kreuzberg/build.rs +782 -474
  92. data/vendor/kreuzberg/examples/bench_fixes.rs +71 -0
  93. data/vendor/kreuzberg/examples/test_pdfium_fork.rs +62 -0
  94. data/vendor/kreuzberg/src/api/error.rs +81 -81
  95. data/vendor/kreuzberg/src/api/handlers.rs +320 -199
  96. data/vendor/kreuzberg/src/api/mod.rs +94 -79
  97. data/vendor/kreuzberg/src/api/server.rs +518 -353
  98. data/vendor/kreuzberg/src/api/types.rs +206 -170
  99. data/vendor/kreuzberg/src/cache/mod.rs +1167 -1167
  100. data/vendor/kreuzberg/src/chunking/mod.rs +2303 -677
  101. data/vendor/kreuzberg/src/chunking/processor.rs +219 -0
  102. data/vendor/kreuzberg/src/core/batch_mode.rs +95 -95
  103. data/vendor/kreuzberg/src/core/batch_optimizations.rs +385 -0
  104. data/vendor/kreuzberg/src/core/config.rs +1914 -1032
  105. data/vendor/kreuzberg/src/core/config_validation.rs +949 -0
  106. data/vendor/kreuzberg/src/core/extractor.rs +1200 -1024
  107. data/vendor/kreuzberg/src/core/formats.rs +235 -0
  108. data/vendor/kreuzberg/src/core/io.rs +329 -329
  109. data/vendor/kreuzberg/src/core/mime.rs +605 -605
  110. data/vendor/kreuzberg/src/core/mod.rs +61 -45
  111. data/vendor/kreuzberg/src/core/pipeline.rs +1223 -984
  112. data/vendor/kreuzberg/src/core/server_config.rs +1220 -0
  113. data/vendor/kreuzberg/src/embeddings.rs +471 -432
  114. data/vendor/kreuzberg/src/error.rs +431 -431
  115. data/vendor/kreuzberg/src/extraction/archive.rs +959 -954
  116. data/vendor/kreuzberg/src/extraction/capacity.rs +263 -0
  117. data/vendor/kreuzberg/src/extraction/docx.rs +404 -40
  118. data/vendor/kreuzberg/src/extraction/email.rs +855 -854
  119. data/vendor/kreuzberg/src/extraction/excel.rs +697 -688
  120. data/vendor/kreuzberg/src/extraction/html.rs +1830 -553
  121. data/vendor/kreuzberg/src/extraction/image.rs +492 -368
  122. data/vendor/kreuzberg/src/extraction/libreoffice.rs +574 -563
  123. data/vendor/kreuzberg/src/extraction/markdown.rs +216 -213
  124. data/vendor/kreuzberg/src/extraction/mod.rs +93 -81
  125. data/vendor/kreuzberg/src/extraction/office_metadata/app_properties.rs +398 -398
  126. data/vendor/kreuzberg/src/extraction/office_metadata/core_properties.rs +247 -247
  127. data/vendor/kreuzberg/src/extraction/office_metadata/custom_properties.rs +240 -240
  128. data/vendor/kreuzberg/src/extraction/office_metadata/mod.rs +130 -130
  129. data/vendor/kreuzberg/src/extraction/office_metadata/odt_properties.rs +284 -287
  130. data/vendor/kreuzberg/src/extraction/pptx.rs +3102 -3000
  131. data/vendor/kreuzberg/src/extraction/structured.rs +491 -490
  132. data/vendor/kreuzberg/src/extraction/table.rs +329 -328
  133. data/vendor/kreuzberg/src/extraction/text.rs +277 -269
  134. data/vendor/kreuzberg/src/extraction/xml.rs +333 -333
  135. data/vendor/kreuzberg/src/extractors/archive.rs +447 -446
  136. data/vendor/kreuzberg/src/extractors/bibtex.rs +470 -469
  137. data/vendor/kreuzberg/src/extractors/docbook.rs +504 -502
  138. data/vendor/kreuzberg/src/extractors/docx.rs +400 -367
  139. data/vendor/kreuzberg/src/extractors/email.rs +157 -143
  140. data/vendor/kreuzberg/src/extractors/epub.rs +696 -707
  141. data/vendor/kreuzberg/src/extractors/excel.rs +385 -343
  142. data/vendor/kreuzberg/src/extractors/fictionbook.rs +492 -491
  143. data/vendor/kreuzberg/src/extractors/html.rs +419 -393
  144. data/vendor/kreuzberg/src/extractors/image.rs +219 -198
  145. data/vendor/kreuzberg/src/extractors/jats.rs +1054 -1051
  146. data/vendor/kreuzberg/src/extractors/jupyter.rs +368 -367
  147. data/vendor/kreuzberg/src/extractors/latex.rs +653 -652
  148. data/vendor/kreuzberg/src/extractors/markdown.rs +701 -700
  149. data/vendor/kreuzberg/src/extractors/mod.rs +429 -365
  150. data/vendor/kreuzberg/src/extractors/odt.rs +628 -628
  151. data/vendor/kreuzberg/src/extractors/opml.rs +635 -634
  152. data/vendor/kreuzberg/src/extractors/orgmode.rs +529 -528
  153. data/vendor/kreuzberg/src/extractors/pdf.rs +761 -493
  154. data/vendor/kreuzberg/src/extractors/pptx.rs +279 -248
  155. data/vendor/kreuzberg/src/extractors/rst.rs +577 -576
  156. data/vendor/kreuzberg/src/extractors/rtf.rs +809 -810
  157. data/vendor/kreuzberg/src/extractors/security.rs +484 -484
  158. data/vendor/kreuzberg/src/extractors/security_tests.rs +367 -367
  159. data/vendor/kreuzberg/src/extractors/structured.rs +142 -140
  160. data/vendor/kreuzberg/src/extractors/text.rs +265 -260
  161. data/vendor/kreuzberg/src/extractors/typst.rs +651 -650
  162. data/vendor/kreuzberg/src/extractors/xml.rs +147 -135
  163. data/vendor/kreuzberg/src/image/dpi.rs +164 -164
  164. data/vendor/kreuzberg/src/image/mod.rs +6 -6
  165. data/vendor/kreuzberg/src/image/preprocessing.rs +417 -417
  166. data/vendor/kreuzberg/src/image/resize.rs +89 -89
  167. data/vendor/kreuzberg/src/keywords/config.rs +154 -154
  168. data/vendor/kreuzberg/src/keywords/mod.rs +237 -237
  169. data/vendor/kreuzberg/src/keywords/processor.rs +275 -267
  170. data/vendor/kreuzberg/src/keywords/rake.rs +293 -293
  171. data/vendor/kreuzberg/src/keywords/types.rs +68 -68
  172. data/vendor/kreuzberg/src/keywords/yake.rs +163 -163
  173. data/vendor/kreuzberg/src/language_detection/mod.rs +985 -942
  174. data/vendor/kreuzberg/src/language_detection/processor.rs +218 -0
  175. data/vendor/kreuzberg/src/lib.rs +114 -105
  176. data/vendor/kreuzberg/src/mcp/mod.rs +35 -32
  177. data/vendor/kreuzberg/src/mcp/server.rs +2090 -1968
  178. data/vendor/kreuzberg/src/ocr/cache.rs +469 -469
  179. data/vendor/kreuzberg/src/ocr/error.rs +37 -37
  180. data/vendor/kreuzberg/src/ocr/hocr.rs +216 -216
  181. data/vendor/kreuzberg/src/ocr/language_registry.rs +520 -0
  182. data/vendor/kreuzberg/src/ocr/mod.rs +60 -58
  183. data/vendor/kreuzberg/src/ocr/processor.rs +858 -863
  184. data/vendor/kreuzberg/src/ocr/table/mod.rs +4 -4
  185. data/vendor/kreuzberg/src/ocr/table/tsv_parser.rs +144 -144
  186. data/vendor/kreuzberg/src/ocr/tesseract_backend.rs +456 -450
  187. data/vendor/kreuzberg/src/ocr/types.rs +393 -393
  188. data/vendor/kreuzberg/src/ocr/utils.rs +47 -47
  189. data/vendor/kreuzberg/src/ocr/validation.rs +206 -206
  190. data/vendor/kreuzberg/src/panic_context.rs +154 -154
  191. data/vendor/kreuzberg/src/pdf/bindings.rs +306 -0
  192. data/vendor/kreuzberg/src/pdf/bundled.rs +408 -0
  193. data/vendor/kreuzberg/src/pdf/error.rs +214 -122
  194. data/vendor/kreuzberg/src/pdf/fonts.rs +358 -0
  195. data/vendor/kreuzberg/src/pdf/hierarchy.rs +903 -0
  196. data/vendor/kreuzberg/src/pdf/images.rs +139 -139
  197. data/vendor/kreuzberg/src/pdf/metadata.rs +509 -346
  198. data/vendor/kreuzberg/src/pdf/mod.rs +81 -50
  199. data/vendor/kreuzberg/src/pdf/rendering.rs +369 -369
  200. data/vendor/kreuzberg/src/pdf/table.rs +417 -393
  201. data/vendor/kreuzberg/src/pdf/text.rs +553 -158
  202. data/vendor/kreuzberg/src/plugins/extractor.rs +1042 -1013
  203. data/vendor/kreuzberg/src/plugins/mod.rs +212 -209
  204. data/vendor/kreuzberg/src/plugins/ocr.rs +637 -620
  205. data/vendor/kreuzberg/src/plugins/processor.rs +650 -642
  206. data/vendor/kreuzberg/src/plugins/registry.rs +1339 -1337
  207. data/vendor/kreuzberg/src/plugins/traits.rs +258 -258
  208. data/vendor/kreuzberg/src/plugins/validator.rs +967 -956
  209. data/vendor/kreuzberg/src/stopwords/mod.rs +1470 -1470
  210. data/vendor/kreuzberg/src/text/mod.rs +27 -19
  211. data/vendor/kreuzberg/src/text/quality.rs +710 -697
  212. data/vendor/kreuzberg/src/text/quality_processor.rs +231 -0
  213. data/vendor/kreuzberg/src/text/string_utils.rs +229 -217
  214. data/vendor/kreuzberg/src/text/token_reduction/cjk_utils.rs +164 -164
  215. data/vendor/kreuzberg/src/text/token_reduction/config.rs +100 -100
  216. data/vendor/kreuzberg/src/text/token_reduction/core.rs +832 -796
  217. data/vendor/kreuzberg/src/text/token_reduction/filters.rs +923 -902
  218. data/vendor/kreuzberg/src/text/token_reduction/mod.rs +160 -160
  219. data/vendor/kreuzberg/src/text/token_reduction/semantic.rs +619 -619
  220. data/vendor/kreuzberg/src/text/token_reduction/simd_text.rs +148 -147
  221. data/vendor/kreuzberg/src/text/utf8_validation.rs +193 -0
  222. data/vendor/kreuzberg/src/types.rs +1713 -903
  223. data/vendor/kreuzberg/src/utils/mod.rs +31 -17
  224. data/vendor/kreuzberg/src/utils/pool.rs +503 -0
  225. data/vendor/kreuzberg/src/utils/pool_sizing.rs +364 -0
  226. data/vendor/kreuzberg/src/utils/quality.rs +968 -959
  227. data/vendor/kreuzberg/src/utils/string_pool.rs +761 -0
  228. data/vendor/kreuzberg/src/utils/string_utils.rs +381 -381
  229. data/vendor/kreuzberg/stopwords/af_stopwords.json +53 -53
  230. data/vendor/kreuzberg/stopwords/ar_stopwords.json +482 -482
  231. data/vendor/kreuzberg/stopwords/bg_stopwords.json +261 -261
  232. data/vendor/kreuzberg/stopwords/bn_stopwords.json +400 -400
  233. data/vendor/kreuzberg/stopwords/br_stopwords.json +1205 -1205
  234. data/vendor/kreuzberg/stopwords/ca_stopwords.json +280 -280
  235. data/vendor/kreuzberg/stopwords/cs_stopwords.json +425 -425
  236. data/vendor/kreuzberg/stopwords/da_stopwords.json +172 -172
  237. data/vendor/kreuzberg/stopwords/de_stopwords.json +622 -622
  238. data/vendor/kreuzberg/stopwords/el_stopwords.json +849 -849
  239. data/vendor/kreuzberg/stopwords/en_stopwords.json +1300 -1300
  240. data/vendor/kreuzberg/stopwords/eo_stopwords.json +175 -175
  241. data/vendor/kreuzberg/stopwords/es_stopwords.json +734 -734
  242. data/vendor/kreuzberg/stopwords/et_stopwords.json +37 -37
  243. data/vendor/kreuzberg/stopwords/eu_stopwords.json +100 -100
  244. data/vendor/kreuzberg/stopwords/fa_stopwords.json +801 -801
  245. data/vendor/kreuzberg/stopwords/fi_stopwords.json +849 -849
  246. data/vendor/kreuzberg/stopwords/fr_stopwords.json +693 -693
  247. data/vendor/kreuzberg/stopwords/ga_stopwords.json +111 -111
  248. data/vendor/kreuzberg/stopwords/gl_stopwords.json +162 -162
  249. data/vendor/kreuzberg/stopwords/gu_stopwords.json +226 -226
  250. data/vendor/kreuzberg/stopwords/ha_stopwords.json +41 -41
  251. data/vendor/kreuzberg/stopwords/he_stopwords.json +196 -196
  252. data/vendor/kreuzberg/stopwords/hi_stopwords.json +227 -227
  253. data/vendor/kreuzberg/stopwords/hr_stopwords.json +181 -181
  254. data/vendor/kreuzberg/stopwords/hu_stopwords.json +791 -791
  255. data/vendor/kreuzberg/stopwords/hy_stopwords.json +47 -47
  256. data/vendor/kreuzberg/stopwords/id_stopwords.json +760 -760
  257. data/vendor/kreuzberg/stopwords/it_stopwords.json +634 -634
  258. data/vendor/kreuzberg/stopwords/ja_stopwords.json +136 -136
  259. data/vendor/kreuzberg/stopwords/kn_stopwords.json +84 -84
  260. data/vendor/kreuzberg/stopwords/ko_stopwords.json +681 -681
  261. data/vendor/kreuzberg/stopwords/ku_stopwords.json +64 -64
  262. data/vendor/kreuzberg/stopwords/la_stopwords.json +51 -51
  263. data/vendor/kreuzberg/stopwords/lt_stopwords.json +476 -476
  264. data/vendor/kreuzberg/stopwords/lv_stopwords.json +163 -163
  265. data/vendor/kreuzberg/stopwords/ml_stopwords.json +1 -1
  266. data/vendor/kreuzberg/stopwords/mr_stopwords.json +101 -101
  267. data/vendor/kreuzberg/stopwords/ms_stopwords.json +477 -477
  268. data/vendor/kreuzberg/stopwords/ne_stopwords.json +490 -490
  269. data/vendor/kreuzberg/stopwords/nl_stopwords.json +415 -415
  270. data/vendor/kreuzberg/stopwords/no_stopwords.json +223 -223
  271. data/vendor/kreuzberg/stopwords/pl_stopwords.json +331 -331
  272. data/vendor/kreuzberg/stopwords/pt_stopwords.json +562 -562
  273. data/vendor/kreuzberg/stopwords/ro_stopwords.json +436 -436
  274. data/vendor/kreuzberg/stopwords/ru_stopwords.json +561 -561
  275. data/vendor/kreuzberg/stopwords/si_stopwords.json +193 -193
  276. data/vendor/kreuzberg/stopwords/sk_stopwords.json +420 -420
  277. data/vendor/kreuzberg/stopwords/sl_stopwords.json +448 -448
  278. data/vendor/kreuzberg/stopwords/so_stopwords.json +32 -32
  279. data/vendor/kreuzberg/stopwords/st_stopwords.json +33 -33
  280. data/vendor/kreuzberg/stopwords/sv_stopwords.json +420 -420
  281. data/vendor/kreuzberg/stopwords/sw_stopwords.json +76 -76
  282. data/vendor/kreuzberg/stopwords/ta_stopwords.json +129 -129
  283. data/vendor/kreuzberg/stopwords/te_stopwords.json +54 -54
  284. data/vendor/kreuzberg/stopwords/th_stopwords.json +118 -118
  285. data/vendor/kreuzberg/stopwords/tl_stopwords.json +149 -149
  286. data/vendor/kreuzberg/stopwords/tr_stopwords.json +506 -506
  287. data/vendor/kreuzberg/stopwords/uk_stopwords.json +75 -75
  288. data/vendor/kreuzberg/stopwords/ur_stopwords.json +519 -519
  289. data/vendor/kreuzberg/stopwords/vi_stopwords.json +647 -647
  290. data/vendor/kreuzberg/stopwords/yo_stopwords.json +62 -62
  291. data/vendor/kreuzberg/stopwords/zh_stopwords.json +796 -796
  292. data/vendor/kreuzberg/stopwords/zu_stopwords.json +31 -31
  293. data/vendor/kreuzberg/tests/api_embed.rs +360 -0
  294. data/vendor/kreuzberg/tests/api_extract_multipart.rs +52 -52
  295. data/vendor/kreuzberg/tests/api_large_pdf_extraction.rs +471 -0
  296. data/vendor/kreuzberg/tests/api_large_pdf_extraction_diagnostics.rs +289 -0
  297. data/vendor/kreuzberg/tests/api_tests.rs +1472 -966
  298. data/vendor/kreuzberg/tests/archive_integration.rs +545 -543
  299. data/vendor/kreuzberg/tests/batch_orchestration.rs +587 -556
  300. data/vendor/kreuzberg/tests/batch_pooling_benchmark.rs +154 -0
  301. data/vendor/kreuzberg/tests/batch_processing.rs +328 -316
  302. data/vendor/kreuzberg/tests/bibtex_parity_test.rs +421 -421
  303. data/vendor/kreuzberg/tests/concurrency_stress.rs +541 -525
  304. data/vendor/kreuzberg/tests/config_features.rs +612 -598
  305. data/vendor/kreuzberg/tests/config_integration_test.rs +753 -0
  306. data/vendor/kreuzberg/tests/config_loading_tests.rs +416 -415
  307. data/vendor/kreuzberg/tests/core_integration.rs +519 -510
  308. data/vendor/kreuzberg/tests/csv_integration.rs +414 -414
  309. data/vendor/kreuzberg/tests/data/hierarchy_ground_truth.json +294 -0
  310. data/vendor/kreuzberg/tests/docbook_extractor_tests.rs +500 -498
  311. data/vendor/kreuzberg/tests/docx_metadata_extraction_test.rs +122 -122
  312. data/vendor/kreuzberg/tests/docx_vs_pandoc_comparison.rs +370 -370
  313. data/vendor/kreuzberg/tests/email_integration.rs +327 -325
  314. data/vendor/kreuzberg/tests/epub_native_extractor_tests.rs +275 -275
  315. data/vendor/kreuzberg/tests/error_handling.rs +402 -393
  316. data/vendor/kreuzberg/tests/fictionbook_extractor_tests.rs +228 -228
  317. data/vendor/kreuzberg/tests/format_integration.rs +165 -159
  318. data/vendor/kreuzberg/tests/helpers/mod.rs +202 -142
  319. data/vendor/kreuzberg/tests/html_table_test.rs +551 -551
  320. data/vendor/kreuzberg/tests/image_integration.rs +255 -253
  321. data/vendor/kreuzberg/tests/instrumentation_test.rs +139 -139
  322. data/vendor/kreuzberg/tests/jats_extractor_tests.rs +639 -639
  323. data/vendor/kreuzberg/tests/jupyter_extractor_tests.rs +704 -704
  324. data/vendor/kreuzberg/tests/keywords_integration.rs +479 -479
  325. data/vendor/kreuzberg/tests/keywords_quality.rs +509 -509
  326. data/vendor/kreuzberg/tests/latex_extractor_tests.rs +496 -496
  327. data/vendor/kreuzberg/tests/markdown_extractor_tests.rs +490 -490
  328. data/vendor/kreuzberg/tests/mime_detection.rs +429 -428
  329. data/vendor/kreuzberg/tests/ocr_configuration.rs +514 -510
  330. data/vendor/kreuzberg/tests/ocr_errors.rs +698 -676
  331. data/vendor/kreuzberg/tests/ocr_language_registry.rs +191 -0
  332. data/vendor/kreuzberg/tests/ocr_quality.rs +629 -627
  333. data/vendor/kreuzberg/tests/ocr_stress.rs +469 -469
  334. data/vendor/kreuzberg/tests/odt_extractor_tests.rs +674 -695
  335. data/vendor/kreuzberg/tests/opml_extractor_tests.rs +616 -616
  336. data/vendor/kreuzberg/tests/orgmode_extractor_tests.rs +822 -822
  337. data/vendor/kreuzberg/tests/page_markers.rs +297 -0
  338. data/vendor/kreuzberg/tests/pdf_hierarchy_detection.rs +301 -0
  339. data/vendor/kreuzberg/tests/pdf_hierarchy_quality.rs +589 -0
  340. data/vendor/kreuzberg/tests/pdf_integration.rs +45 -43
  341. data/vendor/kreuzberg/tests/pdf_ocr_triggering.rs +301 -0
  342. data/vendor/kreuzberg/tests/pdf_text_merging.rs +475 -0
  343. data/vendor/kreuzberg/tests/pdfium_linking.rs +340 -0
  344. data/vendor/kreuzberg/tests/pipeline_integration.rs +1446 -1411
  345. data/vendor/kreuzberg/tests/plugin_ocr_backend_test.rs +776 -771
  346. data/vendor/kreuzberg/tests/plugin_postprocessor_test.rs +577 -560
  347. data/vendor/kreuzberg/tests/plugin_system.rs +927 -921
  348. data/vendor/kreuzberg/tests/plugin_validator_test.rs +783 -783
  349. data/vendor/kreuzberg/tests/registry_integration_tests.rs +587 -586
  350. data/vendor/kreuzberg/tests/rst_extractor_tests.rs +694 -692
  351. data/vendor/kreuzberg/tests/rtf_extractor_tests.rs +775 -776
  352. data/vendor/kreuzberg/tests/security_validation.rs +416 -415
  353. data/vendor/kreuzberg/tests/stopwords_integration_test.rs +888 -888
  354. data/vendor/kreuzberg/tests/test_fastembed.rs +631 -609
  355. data/vendor/kreuzberg/tests/typst_behavioral_tests.rs +1260 -1259
  356. data/vendor/kreuzberg/tests/typst_extractor_tests.rs +648 -647
  357. data/vendor/kreuzberg/tests/xlsx_metadata_extraction_test.rs +87 -87
  358. data/vendor/kreuzberg-ffi/Cargo.toml +67 -0
  359. data/vendor/kreuzberg-ffi/README.md +851 -0
  360. data/vendor/kreuzberg-ffi/benches/result_view_benchmark.rs +227 -0
  361. data/vendor/kreuzberg-ffi/build.rs +168 -0
  362. data/vendor/kreuzberg-ffi/cbindgen.toml +37 -0
  363. data/vendor/kreuzberg-ffi/kreuzberg-ffi.pc.in +12 -0
  364. data/vendor/kreuzberg-ffi/kreuzberg.h +3012 -0
  365. data/vendor/kreuzberg-ffi/src/batch_streaming.rs +588 -0
  366. data/vendor/kreuzberg-ffi/src/config.rs +1341 -0
  367. data/vendor/kreuzberg-ffi/src/error.rs +901 -0
  368. data/vendor/kreuzberg-ffi/src/extraction.rs +555 -0
  369. data/vendor/kreuzberg-ffi/src/helpers.rs +879 -0
  370. data/vendor/kreuzberg-ffi/src/lib.rs +977 -0
  371. data/vendor/kreuzberg-ffi/src/memory.rs +493 -0
  372. data/vendor/kreuzberg-ffi/src/mime.rs +329 -0
  373. data/vendor/kreuzberg-ffi/src/panic_shield.rs +265 -0
  374. data/vendor/kreuzberg-ffi/src/plugins/document_extractor.rs +442 -0
  375. data/vendor/kreuzberg-ffi/src/plugins/mod.rs +14 -0
  376. data/vendor/kreuzberg-ffi/src/plugins/ocr_backend.rs +628 -0
  377. data/vendor/kreuzberg-ffi/src/plugins/post_processor.rs +438 -0
  378. data/vendor/kreuzberg-ffi/src/plugins/validator.rs +329 -0
  379. data/vendor/kreuzberg-ffi/src/result.rs +510 -0
  380. data/vendor/kreuzberg-ffi/src/result_pool.rs +639 -0
  381. data/vendor/kreuzberg-ffi/src/result_view.rs +773 -0
  382. data/vendor/kreuzberg-ffi/src/string_intern.rs +568 -0
  383. data/vendor/kreuzberg-ffi/src/types.rs +363 -0
  384. data/vendor/kreuzberg-ffi/src/util.rs +210 -0
  385. data/vendor/kreuzberg-ffi/src/validation.rs +848 -0
  386. data/vendor/kreuzberg-ffi/tests.disabled/README.md +48 -0
  387. data/vendor/kreuzberg-ffi/tests.disabled/config_loading_tests.rs +299 -0
  388. data/vendor/kreuzberg-ffi/tests.disabled/config_tests.rs +346 -0
  389. data/vendor/kreuzberg-ffi/tests.disabled/extractor_tests.rs +232 -0
  390. data/vendor/kreuzberg-ffi/tests.disabled/plugin_registration_tests.rs +470 -0
  391. data/vendor/kreuzberg-tesseract/.commitlintrc.json +13 -0
  392. data/vendor/kreuzberg-tesseract/.crate-ignore +2 -0
  393. data/vendor/kreuzberg-tesseract/Cargo.lock +2933 -0
  394. data/vendor/kreuzberg-tesseract/Cargo.toml +57 -0
  395. data/vendor/{rb-sys/LICENSE-MIT → kreuzberg-tesseract/LICENSE} +22 -21
  396. data/vendor/kreuzberg-tesseract/README.md +399 -0
  397. data/vendor/kreuzberg-tesseract/build.rs +1127 -0
  398. data/vendor/kreuzberg-tesseract/patches/README.md +71 -0
  399. data/vendor/kreuzberg-tesseract/patches/tesseract.diff +199 -0
  400. data/vendor/kreuzberg-tesseract/src/api.rs +1371 -0
  401. data/vendor/kreuzberg-tesseract/src/choice_iterator.rs +77 -0
  402. data/vendor/kreuzberg-tesseract/src/enums.rs +297 -0
  403. data/vendor/kreuzberg-tesseract/src/error.rs +81 -0
  404. data/vendor/kreuzberg-tesseract/src/lib.rs +145 -0
  405. data/vendor/kreuzberg-tesseract/src/monitor.rs +57 -0
  406. data/vendor/kreuzberg-tesseract/src/mutable_iterator.rs +197 -0
  407. data/vendor/kreuzberg-tesseract/src/page_iterator.rs +253 -0
  408. data/vendor/kreuzberg-tesseract/src/result_iterator.rs +286 -0
  409. data/vendor/kreuzberg-tesseract/src/result_renderer.rs +183 -0
  410. data/vendor/kreuzberg-tesseract/tests/integration_test.rs +211 -0
  411. metadata +196 -45
  412. data/vendor/kreuzberg/benches/otel_overhead.rs +0 -48
  413. data/vendor/kreuzberg/src/extractors/fictionbook.rs.backup2 +0 -738
  414. data/vendor/rb-sys/.cargo-ok +0 -1
  415. data/vendor/rb-sys/.cargo_vcs_info.json +0 -6
  416. data/vendor/rb-sys/Cargo.lock +0 -393
  417. data/vendor/rb-sys/Cargo.toml +0 -70
  418. data/vendor/rb-sys/Cargo.toml.orig +0 -57
  419. data/vendor/rb-sys/LICENSE-APACHE +0 -190
  420. data/vendor/rb-sys/bin/release.sh +0 -21
  421. data/vendor/rb-sys/build/features.rs +0 -108
  422. data/vendor/rb-sys/build/main.rs +0 -246
  423. data/vendor/rb-sys/build/stable_api_config.rs +0 -153
  424. data/vendor/rb-sys/build/version.rs +0 -48
  425. data/vendor/rb-sys/readme.md +0 -36
  426. data/vendor/rb-sys/src/bindings.rs +0 -21
  427. data/vendor/rb-sys/src/hidden.rs +0 -11
  428. data/vendor/rb-sys/src/lib.rs +0 -34
  429. data/vendor/rb-sys/src/macros.rs +0 -371
  430. data/vendor/rb-sys/src/memory.rs +0 -53
  431. data/vendor/rb-sys/src/ruby_abi_version.rs +0 -38
  432. data/vendor/rb-sys/src/special_consts.rs +0 -31
  433. data/vendor/rb-sys/src/stable_api/compiled.c +0 -179
  434. data/vendor/rb-sys/src/stable_api/compiled.rs +0 -257
  435. data/vendor/rb-sys/src/stable_api/ruby_2_6.rs +0 -316
  436. data/vendor/rb-sys/src/stable_api/ruby_2_7.rs +0 -316
  437. data/vendor/rb-sys/src/stable_api/ruby_3_0.rs +0 -324
  438. data/vendor/rb-sys/src/stable_api/ruby_3_1.rs +0 -317
  439. data/vendor/rb-sys/src/stable_api/ruby_3_2.rs +0 -315
  440. data/vendor/rb-sys/src/stable_api/ruby_3_3.rs +0 -326
  441. data/vendor/rb-sys/src/stable_api/ruby_3_4.rs +0 -327
  442. data/vendor/rb-sys/src/stable_api.rs +0 -261
  443. data/vendor/rb-sys/src/symbol.rs +0 -31
  444. data/vendor/rb-sys/src/tracking_allocator.rs +0 -332
  445. data/vendor/rb-sys/src/utils.rs +0 -89
  446. data/vendor/rb-sys/src/value_type.rs +0 -7
@@ -1,1411 +1,1446 @@
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
- }
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::{clear_processor_cache, 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
+ drop(reg);
127
+ let _ = clear_processor_cache();
128
+ }
129
+
130
+ #[tokio::test]
131
+ #[serial]
132
+ async fn test_pipeline_empty_no_processors() {
133
+ clear_processor_registry();
134
+
135
+ let result = ExtractionResult {
136
+ content: "original content".to_string(),
137
+ mime_type: "text/plain".to_string(),
138
+ metadata: Metadata::default(),
139
+ tables: vec![],
140
+ detected_languages: None,
141
+ chunks: None,
142
+ images: None,
143
+ pages: None,
144
+ };
145
+ let config = ExtractionConfig::default();
146
+
147
+ let processed = run_pipeline(result, &config).await.unwrap();
148
+ assert_eq!(processed.content, "original content");
149
+ }
150
+
151
+ #[tokio::test]
152
+ #[serial]
153
+ async fn test_pipeline_single_processor_per_stage() {
154
+ clear_processor_registry();
155
+
156
+ let registry = get_post_processor_registry();
157
+ {
158
+ let mut reg = registry
159
+ .write()
160
+ .expect("Failed to acquire write lock on registry in test");
161
+
162
+ let early = Arc::new(OrderTrackingProcessor {
163
+ name: "early".to_string(),
164
+ stage: ProcessingStage::Early,
165
+ });
166
+ let middle = Arc::new(OrderTrackingProcessor {
167
+ name: "middle".to_string(),
168
+ stage: ProcessingStage::Middle,
169
+ });
170
+ let late = Arc::new(OrderTrackingProcessor {
171
+ name: "late".to_string(),
172
+ stage: ProcessingStage::Late,
173
+ });
174
+
175
+ reg.register(early, 50).unwrap();
176
+ reg.register(middle, 50).unwrap();
177
+ reg.register(late, 50).unwrap();
178
+ }
179
+
180
+ let result = ExtractionResult {
181
+ content: "start".to_string(),
182
+ mime_type: "text/plain".to_string(),
183
+ metadata: Metadata::default(),
184
+ tables: vec![],
185
+ detected_languages: None,
186
+ chunks: None,
187
+ images: None,
188
+ pages: None,
189
+ };
190
+ let config = ExtractionConfig::default();
191
+
192
+ let processed = run_pipeline(result, &config).await.unwrap();
193
+ assert_eq!(processed.content, "start[early][middle][late]");
194
+ }
195
+
196
+ #[tokio::test]
197
+ #[serial]
198
+ async fn test_pipeline_multiple_processors_per_stage() {
199
+ clear_processor_registry();
200
+
201
+ let registry = get_post_processor_registry();
202
+ {
203
+ let mut reg = registry
204
+ .write()
205
+ .expect("Failed to acquire write lock on registry in test");
206
+
207
+ let early_high = Arc::new(OrderTrackingProcessor {
208
+ name: "early-high".to_string(),
209
+ stage: ProcessingStage::Early,
210
+ });
211
+ let early_medium = Arc::new(OrderTrackingProcessor {
212
+ name: "early-medium".to_string(),
213
+ stage: ProcessingStage::Early,
214
+ });
215
+ let early_low = Arc::new(OrderTrackingProcessor {
216
+ name: "early-low".to_string(),
217
+ stage: ProcessingStage::Early,
218
+ });
219
+
220
+ reg.register(early_low, 10).unwrap();
221
+ reg.register(early_high, 100).unwrap();
222
+ reg.register(early_medium, 50).unwrap();
223
+ }
224
+
225
+ let result = ExtractionResult {
226
+ content: "start".to_string(),
227
+ mime_type: "text/plain".to_string(),
228
+ metadata: Metadata::default(),
229
+ tables: vec![],
230
+ detected_languages: None,
231
+ chunks: None,
232
+ images: None,
233
+ pages: None,
234
+ };
235
+ let config = ExtractionConfig::default();
236
+
237
+ let processed = run_pipeline(result, &config).await.unwrap();
238
+ assert_eq!(processed.content, "start[early-high][early-medium][early-low]");
239
+ }
240
+
241
+ #[tokio::test]
242
+ #[serial]
243
+ async fn test_pipeline_all_stages_enabled() {
244
+ clear_processor_registry();
245
+
246
+ let registry = get_post_processor_registry();
247
+ {
248
+ let mut reg = registry
249
+ .write()
250
+ .expect("Failed to acquire write lock on registry in test");
251
+
252
+ for stage in [ProcessingStage::Early, ProcessingStage::Middle, ProcessingStage::Late] {
253
+ let processor = Arc::new(OrderTrackingProcessor {
254
+ name: format!("{:?}", stage),
255
+ stage,
256
+ });
257
+ reg.register(processor, 50).unwrap();
258
+ }
259
+ }
260
+
261
+ let result = ExtractionResult {
262
+ content: "start".to_string(),
263
+ mime_type: "text/plain".to_string(),
264
+ metadata: Metadata::default(),
265
+ tables: vec![],
266
+ detected_languages: None,
267
+ chunks: None,
268
+ images: None,
269
+ pages: None,
270
+ };
271
+ let config = ExtractionConfig::default();
272
+
273
+ let processed = run_pipeline(result, &config).await.unwrap();
274
+ assert_eq!(processed.content, "start[Early][Middle][Late]");
275
+ }
276
+
277
+ #[tokio::test]
278
+ #[serial]
279
+ async fn test_pipeline_postprocessing_disabled() {
280
+ clear_processor_registry();
281
+
282
+ let registry = get_post_processor_registry();
283
+ {
284
+ let mut reg = registry
285
+ .write()
286
+ .expect("Failed to acquire write lock on registry in test");
287
+
288
+ let processor = Arc::new(OrderTrackingProcessor {
289
+ name: "processor".to_string(),
290
+ stage: ProcessingStage::Early,
291
+ });
292
+ reg.register(processor, 50).unwrap();
293
+ }
294
+
295
+ let result = ExtractionResult {
296
+ content: "start".to_string(),
297
+ mime_type: "text/plain".to_string(),
298
+ metadata: Metadata::default(),
299
+ tables: vec![],
300
+ detected_languages: None,
301
+ chunks: None,
302
+ images: None,
303
+ pages: None,
304
+ };
305
+ let config = ExtractionConfig {
306
+ postprocessor: Some(PostProcessorConfig {
307
+ enabled: false,
308
+ enabled_processors: None,
309
+ disabled_processors: None,
310
+ enabled_set: None,
311
+ disabled_set: None,
312
+ }),
313
+ ..Default::default()
314
+ };
315
+
316
+ let processed = run_pipeline(result, &config).await.unwrap();
317
+ assert_eq!(processed.content, "start");
318
+ }
319
+
320
+ #[tokio::test]
321
+ #[serial]
322
+ async fn test_pipeline_early_stage_runs_first() {
323
+ clear_processor_registry();
324
+
325
+ let registry = get_post_processor_registry();
326
+ {
327
+ let mut reg = registry
328
+ .write()
329
+ .expect("Failed to acquire write lock on registry in test");
330
+
331
+ let late = Arc::new(OrderTrackingProcessor {
332
+ name: "late".to_string(),
333
+ stage: ProcessingStage::Late,
334
+ });
335
+ let early = Arc::new(OrderTrackingProcessor {
336
+ name: "early".to_string(),
337
+ stage: ProcessingStage::Early,
338
+ });
339
+
340
+ reg.register(late, 50).unwrap();
341
+ reg.register(early, 50).unwrap();
342
+ }
343
+
344
+ let result = ExtractionResult {
345
+ content: "start".to_string(),
346
+ mime_type: "text/plain".to_string(),
347
+ metadata: Metadata::default(),
348
+ tables: vec![],
349
+ detected_languages: None,
350
+ chunks: None,
351
+ images: None,
352
+ pages: None,
353
+ };
354
+ let config = ExtractionConfig::default();
355
+
356
+ let processed = run_pipeline(result, &config).await.unwrap();
357
+ assert_eq!(processed.content, "start[early][late]");
358
+ }
359
+
360
+ #[tokio::test]
361
+ #[serial]
362
+ async fn test_pipeline_middle_stage_runs_second() {
363
+ clear_processor_registry();
364
+
365
+ let registry = get_post_processor_registry();
366
+ {
367
+ let mut reg = registry
368
+ .write()
369
+ .expect("Failed to acquire write lock on registry in test");
370
+
371
+ let early = Arc::new(OrderTrackingProcessor {
372
+ name: "early".to_string(),
373
+ stage: ProcessingStage::Early,
374
+ });
375
+ let middle = Arc::new(OrderTrackingProcessor {
376
+ name: "middle".to_string(),
377
+ stage: ProcessingStage::Middle,
378
+ });
379
+
380
+ reg.register(middle, 50).unwrap();
381
+ reg.register(early, 50).unwrap();
382
+ }
383
+
384
+ let result = ExtractionResult {
385
+ content: "start".to_string(),
386
+ mime_type: "text/plain".to_string(),
387
+ metadata: Metadata::default(),
388
+ tables: vec![],
389
+ detected_languages: None,
390
+ chunks: None,
391
+ images: None,
392
+ pages: None,
393
+ };
394
+ let config = ExtractionConfig::default();
395
+
396
+ let processed = run_pipeline(result, &config).await.unwrap();
397
+ assert_eq!(processed.content, "start[early][middle]");
398
+ }
399
+
400
+ #[tokio::test]
401
+ #[serial]
402
+ async fn test_pipeline_late_stage_runs_last() {
403
+ clear_processor_registry();
404
+
405
+ let registry = get_post_processor_registry();
406
+ {
407
+ let mut reg = registry
408
+ .write()
409
+ .expect("Failed to acquire write lock on registry in test");
410
+
411
+ for stage in [ProcessingStage::Late, ProcessingStage::Early, ProcessingStage::Middle] {
412
+ let processor = Arc::new(OrderTrackingProcessor {
413
+ name: format!("{:?}", stage),
414
+ stage,
415
+ });
416
+ reg.register(processor, 50).unwrap();
417
+ }
418
+ }
419
+
420
+ let result = ExtractionResult {
421
+ content: "start".to_string(),
422
+ mime_type: "text/plain".to_string(),
423
+ metadata: Metadata::default(),
424
+ tables: vec![],
425
+ detected_languages: None,
426
+ chunks: None,
427
+ images: None,
428
+ pages: None,
429
+ };
430
+ let config = ExtractionConfig::default();
431
+
432
+ let processed = run_pipeline(result, &config).await.unwrap();
433
+ assert_eq!(processed.content, "start[Early][Middle][Late]");
434
+ }
435
+
436
+ #[tokio::test]
437
+ #[serial]
438
+ async fn test_pipeline_within_stage_priority_order() {
439
+ clear_processor_registry();
440
+
441
+ let registry = get_post_processor_registry();
442
+ {
443
+ let mut reg = registry
444
+ .write()
445
+ .expect("Failed to acquire write lock on registry in test");
446
+
447
+ for (name, priority) in [("p1", 100), ("p2", 10), ("p3", 50), ("p4", 75)] {
448
+ let processor = Arc::new(OrderTrackingProcessor {
449
+ name: name.to_string(),
450
+ stage: ProcessingStage::Early,
451
+ });
452
+ reg.register(processor, priority).unwrap();
453
+ }
454
+ }
455
+
456
+ let result = ExtractionResult {
457
+ content: "start".to_string(),
458
+ mime_type: "text/plain".to_string(),
459
+ metadata: Metadata::default(),
460
+ tables: vec![],
461
+ detected_languages: None,
462
+ chunks: None,
463
+ images: None,
464
+ pages: None,
465
+ };
466
+ let config = ExtractionConfig::default();
467
+
468
+ let processed = run_pipeline(result, &config).await.unwrap();
469
+ assert_eq!(processed.content, "start[p1][p4][p3][p2]");
470
+ }
471
+
472
+ #[tokio::test]
473
+ #[serial]
474
+ async fn test_pipeline_cross_stage_data_flow() {
475
+ clear_processor_registry();
476
+
477
+ let registry = get_post_processor_registry();
478
+ {
479
+ let mut reg = registry
480
+ .write()
481
+ .expect("Failed to acquire write lock on registry in test");
482
+
483
+ let early = Arc::new(MetadataAddingProcessor {
484
+ name: "early".to_string(),
485
+ key: "stage".to_string(),
486
+ value: "early".to_string(),
487
+ });
488
+
489
+ struct MiddleProcessor;
490
+ impl Plugin for MiddleProcessor {
491
+ fn name(&self) -> &str {
492
+ "middle"
493
+ }
494
+ fn version(&self) -> String {
495
+ "1.0.0".to_string()
496
+ }
497
+ fn initialize(&self) -> Result<()> {
498
+ Ok(())
499
+ }
500
+ fn shutdown(&self) -> Result<()> {
501
+ Ok(())
502
+ }
503
+ }
504
+ #[async_trait]
505
+ impl PostProcessor for MiddleProcessor {
506
+ async fn process(&self, result: &mut ExtractionResult, _: &ExtractionConfig) -> Result<()> {
507
+ if let Some(stage) = result.metadata.additional.get("stage") {
508
+ result.content.push_str(&format!("[saw:{}]", stage.as_str().unwrap()));
509
+ }
510
+ Ok(())
511
+ }
512
+ fn processing_stage(&self) -> ProcessingStage {
513
+ ProcessingStage::Middle
514
+ }
515
+ }
516
+
517
+ reg.register(early, 50).unwrap();
518
+ reg.register(Arc::new(MiddleProcessor), 50).unwrap();
519
+ }
520
+
521
+ let result = ExtractionResult {
522
+ content: "start".to_string(),
523
+ mime_type: "text/plain".to_string(),
524
+ metadata: Metadata::default(),
525
+ tables: vec![],
526
+ detected_languages: None,
527
+ chunks: None,
528
+ images: None,
529
+ pages: None,
530
+ };
531
+ let config = ExtractionConfig::default();
532
+
533
+ let processed = run_pipeline(result, &config).await.unwrap();
534
+ assert!(processed.content.contains("[saw:early]"));
535
+ }
536
+
537
+ #[tokio::test]
538
+ #[serial]
539
+ async fn test_pipeline_early_stage_error_recorded() {
540
+ clear_processor_registry();
541
+
542
+ struct EarlyFailingProcessor;
543
+ impl Plugin for EarlyFailingProcessor {
544
+ fn name(&self) -> &str {
545
+ "early-failing"
546
+ }
547
+ fn version(&self) -> String {
548
+ "1.0.0".to_string()
549
+ }
550
+ fn initialize(&self) -> Result<()> {
551
+ Ok(())
552
+ }
553
+ fn shutdown(&self) -> Result<()> {
554
+ Ok(())
555
+ }
556
+ }
557
+ #[async_trait]
558
+ impl PostProcessor for EarlyFailingProcessor {
559
+ async fn process(&self, _: &mut ExtractionResult, _: &ExtractionConfig) -> Result<()> {
560
+ Err(KreuzbergError::Plugin {
561
+ message: "Early error".to_string(),
562
+ plugin_name: "early-failing".to_string(),
563
+ })
564
+ }
565
+ fn processing_stage(&self) -> ProcessingStage {
566
+ ProcessingStage::Early
567
+ }
568
+ }
569
+
570
+ let registry = get_post_processor_registry();
571
+ {
572
+ let mut reg = registry
573
+ .write()
574
+ .expect("Failed to acquire write lock on registry in test");
575
+ reg.register(Arc::new(EarlyFailingProcessor), 50).unwrap();
576
+ }
577
+
578
+ let result = ExtractionResult {
579
+ content: "content".to_string(),
580
+ mime_type: "text/plain".to_string(),
581
+ metadata: Metadata::default(),
582
+ tables: vec![],
583
+ detected_languages: None,
584
+ chunks: None,
585
+ images: None,
586
+ pages: None,
587
+ };
588
+ let config = ExtractionConfig::default();
589
+
590
+ let result = run_pipeline(result, &config).await;
591
+ assert!(result.is_err(), "Expected pipeline to return error");
592
+ match result {
593
+ Err(KreuzbergError::Plugin { message, plugin_name }) => {
594
+ assert_eq!(message, "Early error");
595
+ assert_eq!(plugin_name, "early-failing");
596
+ }
597
+ _ => panic!("Expected Plugin error"),
598
+ }
599
+ }
600
+
601
+ #[tokio::test]
602
+ #[serial]
603
+ async fn test_pipeline_middle_stage_error_propagation() {
604
+ clear_processor_registry();
605
+
606
+ let registry = get_post_processor_registry();
607
+ {
608
+ let mut reg = registry
609
+ .write()
610
+ .expect("Failed to acquire write lock on registry in test");
611
+
612
+ let failing = Arc::new(FailingProcessor {
613
+ name: "middle-failing".to_string(),
614
+ error_message: "Middle stage error".to_string(),
615
+ });
616
+
617
+ reg.register(failing, 50).unwrap();
618
+ }
619
+
620
+ let result = ExtractionResult {
621
+ content: "content".to_string(),
622
+ mime_type: "text/plain".to_string(),
623
+ metadata: Metadata::default(),
624
+ tables: vec![],
625
+ detected_languages: None,
626
+ chunks: None,
627
+ images: None,
628
+ pages: None,
629
+ };
630
+ let config = ExtractionConfig::default();
631
+
632
+ let result = run_pipeline(result, &config).await;
633
+ assert!(result.is_err(), "Expected pipeline to return error");
634
+ match result {
635
+ Err(KreuzbergError::Plugin { message, plugin_name }) => {
636
+ assert_eq!(message, "Middle stage error");
637
+ assert_eq!(plugin_name, "middle-failing");
638
+ }
639
+ _ => panic!("Expected Plugin error"),
640
+ }
641
+ }
642
+
643
+ #[tokio::test]
644
+ #[serial]
645
+ async fn test_pipeline_late_stage_error_doesnt_affect_earlier_stages() {
646
+ clear_processor_registry();
647
+
648
+ struct LateFailingProcessor;
649
+ impl Plugin for LateFailingProcessor {
650
+ fn name(&self) -> &str {
651
+ "late-failing"
652
+ }
653
+ fn version(&self) -> String {
654
+ "1.0.0".to_string()
655
+ }
656
+ fn initialize(&self) -> Result<()> {
657
+ Ok(())
658
+ }
659
+ fn shutdown(&self) -> Result<()> {
660
+ Ok(())
661
+ }
662
+ }
663
+ #[async_trait]
664
+ impl PostProcessor for LateFailingProcessor {
665
+ async fn process(&self, _: &mut ExtractionResult, _: &ExtractionConfig) -> Result<()> {
666
+ Err(KreuzbergError::Plugin {
667
+ message: "Late error".to_string(),
668
+ plugin_name: "late-failing".to_string(),
669
+ })
670
+ }
671
+ fn processing_stage(&self) -> ProcessingStage {
672
+ ProcessingStage::Late
673
+ }
674
+ }
675
+
676
+ let registry = get_post_processor_registry();
677
+ {
678
+ let mut reg = registry
679
+ .write()
680
+ .expect("Failed to acquire write lock on registry in test");
681
+
682
+ let early = Arc::new(OrderTrackingProcessor {
683
+ name: "early".to_string(),
684
+ stage: ProcessingStage::Early,
685
+ });
686
+ let late_failing = Arc::new(LateFailingProcessor);
687
+
688
+ reg.register(early, 50).unwrap();
689
+ reg.register(late_failing, 50).unwrap();
690
+ }
691
+
692
+ let result = ExtractionResult {
693
+ content: "start".to_string(),
694
+ mime_type: "text/plain".to_string(),
695
+ metadata: Metadata::default(),
696
+ tables: vec![],
697
+ detected_languages: None,
698
+ chunks: None,
699
+ images: None,
700
+ pages: None,
701
+ };
702
+ let config = ExtractionConfig::default();
703
+
704
+ let result = run_pipeline(result, &config).await;
705
+ assert!(result.is_err(), "Expected pipeline to return error");
706
+ match result {
707
+ Err(KreuzbergError::Plugin { message, plugin_name }) => {
708
+ assert_eq!(message, "Late error");
709
+ assert_eq!(plugin_name, "late-failing");
710
+ }
711
+ _ => panic!("Expected Plugin error"),
712
+ }
713
+ }
714
+
715
+ #[tokio::test]
716
+ #[serial]
717
+ async fn test_pipeline_processor_error_doesnt_stop_other_processors() {
718
+ clear_processor_registry();
719
+
720
+ let registry = get_post_processor_registry();
721
+ {
722
+ let mut reg = registry
723
+ .write()
724
+ .expect("Failed to acquire write lock on registry in test");
725
+
726
+ let p1 = Arc::new(OrderTrackingProcessor {
727
+ name: "p1".to_string(),
728
+ stage: ProcessingStage::Early,
729
+ });
730
+ let _p2_failing = Arc::new(FailingProcessor {
731
+ name: "p2-failing".to_string(),
732
+ error_message: "Test error".to_string(),
733
+ });
734
+ let p3 = Arc::new(OrderTrackingProcessor {
735
+ name: "p3".to_string(),
736
+ stage: ProcessingStage::Late,
737
+ });
738
+
739
+ struct EarlyFailingProcessor {
740
+ name: String,
741
+ }
742
+ impl Plugin for EarlyFailingProcessor {
743
+ fn name(&self) -> &str {
744
+ &self.name
745
+ }
746
+ fn version(&self) -> String {
747
+ "1.0.0".to_string()
748
+ }
749
+ fn initialize(&self) -> Result<()> {
750
+ Ok(())
751
+ }
752
+ fn shutdown(&self) -> Result<()> {
753
+ Ok(())
754
+ }
755
+ }
756
+ #[async_trait]
757
+ impl PostProcessor for EarlyFailingProcessor {
758
+ async fn process(&self, _: &mut ExtractionResult, _: &ExtractionConfig) -> Result<()> {
759
+ Err(KreuzbergError::Plugin {
760
+ message: "Test error".to_string(),
761
+ plugin_name: self.name.clone(),
762
+ })
763
+ }
764
+ fn processing_stage(&self) -> ProcessingStage {
765
+ ProcessingStage::Early
766
+ }
767
+ }
768
+
769
+ reg.register(p1, 100).unwrap();
770
+ reg.register(
771
+ Arc::new(EarlyFailingProcessor {
772
+ name: "p2-failing".to_string(),
773
+ }),
774
+ 50,
775
+ )
776
+ .unwrap();
777
+ reg.register(p3, 50).unwrap();
778
+ }
779
+
780
+ let result = ExtractionResult {
781
+ content: "start".to_string(),
782
+ mime_type: "text/plain".to_string(),
783
+ metadata: Metadata::default(),
784
+ tables: vec![],
785
+ detected_languages: None,
786
+ chunks: None,
787
+ images: None,
788
+ pages: None,
789
+ };
790
+ let config = ExtractionConfig::default();
791
+
792
+ let result = run_pipeline(result, &config).await;
793
+ assert!(result.is_err(), "Expected pipeline to return error");
794
+ match result {
795
+ Err(KreuzbergError::Plugin { message, plugin_name }) => {
796
+ assert_eq!(message, "Test error");
797
+ assert_eq!(plugin_name, "p2-failing");
798
+ }
799
+ _ => panic!("Expected Plugin error"),
800
+ }
801
+ }
802
+
803
+ #[tokio::test]
804
+ #[serial]
805
+ async fn test_pipeline_multiple_processor_errors() {
806
+ clear_processor_registry();
807
+
808
+ struct MultiFailingProcessor {
809
+ name: String,
810
+ stage: ProcessingStage,
811
+ }
812
+ impl Plugin for MultiFailingProcessor {
813
+ fn name(&self) -> &str {
814
+ &self.name
815
+ }
816
+ fn version(&self) -> String {
817
+ "1.0.0".to_string()
818
+ }
819
+ fn initialize(&self) -> Result<()> {
820
+ Ok(())
821
+ }
822
+ fn shutdown(&self) -> Result<()> {
823
+ Ok(())
824
+ }
825
+ }
826
+ #[async_trait]
827
+ impl PostProcessor for MultiFailingProcessor {
828
+ async fn process(&self, _: &mut ExtractionResult, _: &ExtractionConfig) -> Result<()> {
829
+ Err(KreuzbergError::Plugin {
830
+ message: format!("{} error", self.name),
831
+ plugin_name: self.name.clone(),
832
+ })
833
+ }
834
+ fn processing_stage(&self) -> ProcessingStage {
835
+ self.stage
836
+ }
837
+ }
838
+
839
+ let registry = get_post_processor_registry();
840
+ {
841
+ let mut reg = registry
842
+ .write()
843
+ .expect("Failed to acquire write lock on registry in test");
844
+
845
+ for (name, stage) in [
846
+ ("fail1", ProcessingStage::Early),
847
+ ("fail2", ProcessingStage::Middle),
848
+ ("fail3", ProcessingStage::Late),
849
+ ] {
850
+ let processor = Arc::new(MultiFailingProcessor {
851
+ name: name.to_string(),
852
+ stage,
853
+ });
854
+ reg.register(processor, 50).unwrap();
855
+ }
856
+ }
857
+
858
+ let result = ExtractionResult {
859
+ content: "start".to_string(),
860
+ mime_type: "text/plain".to_string(),
861
+ metadata: Metadata::default(),
862
+ tables: vec![],
863
+ detected_languages: None,
864
+ chunks: None,
865
+ images: None,
866
+ pages: None,
867
+ };
868
+ let config = ExtractionConfig::default();
869
+
870
+ let result = run_pipeline(result, &config).await;
871
+ assert!(result.is_err(), "Expected pipeline to return error");
872
+ match result {
873
+ Err(KreuzbergError::Plugin { message, plugin_name }) => {
874
+ assert_eq!(message, "fail1 error");
875
+ assert_eq!(plugin_name, "fail1");
876
+ }
877
+ _ => panic!("Expected Plugin error"),
878
+ }
879
+ }
880
+
881
+ #[tokio::test]
882
+ #[serial]
883
+ async fn test_pipeline_error_context_preservation() {
884
+ clear_processor_registry();
885
+
886
+ let registry = get_post_processor_registry();
887
+ {
888
+ let mut reg = registry
889
+ .write()
890
+ .expect("Failed to acquire write lock on registry in test");
891
+
892
+ let failing = Arc::new(FailingProcessor {
893
+ name: "context-test".to_string(),
894
+ error_message: "Detailed error message with context".to_string(),
895
+ });
896
+
897
+ reg.register(failing, 50).unwrap();
898
+ }
899
+
900
+ let result = ExtractionResult {
901
+ content: "content".to_string(),
902
+ mime_type: "text/plain".to_string(),
903
+ metadata: Metadata::default(),
904
+ tables: vec![],
905
+ detected_languages: None,
906
+ chunks: None,
907
+ images: None,
908
+ pages: None,
909
+ };
910
+ let config = ExtractionConfig::default();
911
+
912
+ let result = run_pipeline(result, &config).await;
913
+ assert!(result.is_err(), "Expected pipeline to return error");
914
+ match result {
915
+ Err(KreuzbergError::Plugin { message, plugin_name }) => {
916
+ assert_eq!(message, "Detailed error message with context");
917
+ assert_eq!(plugin_name, "context-test");
918
+ }
919
+ _ => panic!("Expected Plugin error"),
920
+ }
921
+ }
922
+
923
+ #[tokio::test]
924
+ #[serial]
925
+ async fn test_pipeline_metadata_added_in_early_visible_in_middle() {
926
+ clear_processor_registry();
927
+
928
+ let registry = get_post_processor_registry();
929
+ {
930
+ let mut reg = registry
931
+ .write()
932
+ .expect("Failed to acquire write lock on registry in test");
933
+
934
+ let early = Arc::new(MetadataAddingProcessor {
935
+ name: "early".to_string(),
936
+ key: "early_key".to_string(),
937
+ value: "early_value".to_string(),
938
+ });
939
+
940
+ struct MiddleReadingProcessor;
941
+ impl Plugin for MiddleReadingProcessor {
942
+ fn name(&self) -> &str {
943
+ "middle"
944
+ }
945
+ fn version(&self) -> String {
946
+ "1.0.0".to_string()
947
+ }
948
+ fn initialize(&self) -> Result<()> {
949
+ Ok(())
950
+ }
951
+ fn shutdown(&self) -> Result<()> {
952
+ Ok(())
953
+ }
954
+ }
955
+ #[async_trait]
956
+ impl PostProcessor for MiddleReadingProcessor {
957
+ async fn process(&self, result: &mut ExtractionResult, _: &ExtractionConfig) -> Result<()> {
958
+ if let Some(val) = result.metadata.additional.get("early_key") {
959
+ result.metadata.additional.insert("middle_saw".to_string(), val.clone());
960
+ }
961
+ Ok(())
962
+ }
963
+ fn processing_stage(&self) -> ProcessingStage {
964
+ ProcessingStage::Middle
965
+ }
966
+ }
967
+
968
+ reg.register(early, 50).unwrap();
969
+ reg.register(Arc::new(MiddleReadingProcessor), 50).unwrap();
970
+ }
971
+
972
+ let result = ExtractionResult {
973
+ content: "content".to_string(),
974
+ mime_type: "text/plain".to_string(),
975
+ metadata: Metadata::default(),
976
+ tables: vec![],
977
+ detected_languages: None,
978
+ chunks: None,
979
+ images: None,
980
+ pages: None,
981
+ };
982
+ let config = ExtractionConfig::default();
983
+
984
+ let processed = run_pipeline(result, &config).await.unwrap();
985
+ assert_eq!(
986
+ processed
987
+ .metadata
988
+ .additional
989
+ .get("middle_saw")
990
+ .unwrap()
991
+ .as_str()
992
+ .unwrap(),
993
+ "early_value"
994
+ );
995
+ }
996
+
997
+ #[tokio::test]
998
+ #[serial]
999
+ async fn test_pipeline_content_modified_in_middle_visible_in_late() {
1000
+ clear_processor_registry();
1001
+
1002
+ let registry = get_post_processor_registry();
1003
+ {
1004
+ let mut reg = registry
1005
+ .write()
1006
+ .expect("Failed to acquire write lock on registry in test");
1007
+
1008
+ let middle = Arc::new(OrderTrackingProcessor {
1009
+ name: "middle-content".to_string(),
1010
+ stage: ProcessingStage::Middle,
1011
+ });
1012
+
1013
+ struct LateReadingProcessor;
1014
+ impl Plugin for LateReadingProcessor {
1015
+ fn name(&self) -> &str {
1016
+ "late"
1017
+ }
1018
+ fn version(&self) -> String {
1019
+ "1.0.0".to_string()
1020
+ }
1021
+ fn initialize(&self) -> Result<()> {
1022
+ Ok(())
1023
+ }
1024
+ fn shutdown(&self) -> Result<()> {
1025
+ Ok(())
1026
+ }
1027
+ }
1028
+ #[async_trait]
1029
+ impl PostProcessor for LateReadingProcessor {
1030
+ async fn process(&self, result: &mut ExtractionResult, _: &ExtractionConfig) -> Result<()> {
1031
+ result.content.push_str("[late-saw-middle]");
1032
+ Ok(())
1033
+ }
1034
+ fn processing_stage(&self) -> ProcessingStage {
1035
+ ProcessingStage::Late
1036
+ }
1037
+ }
1038
+
1039
+ reg.register(middle, 50).unwrap();
1040
+ reg.register(Arc::new(LateReadingProcessor), 50).unwrap();
1041
+ }
1042
+
1043
+ let result = ExtractionResult {
1044
+ content: "start".to_string(),
1045
+ mime_type: "text/plain".to_string(),
1046
+ metadata: Metadata::default(),
1047
+ tables: vec![],
1048
+ detected_languages: None,
1049
+ chunks: None,
1050
+ images: None,
1051
+ pages: None,
1052
+ };
1053
+ let config = ExtractionConfig::default();
1054
+
1055
+ let processed = run_pipeline(result, &config).await.unwrap();
1056
+ assert!(processed.content.contains("[middle-content]"));
1057
+ assert!(processed.content.contains("[late-saw-middle]"));
1058
+ }
1059
+
1060
+ #[tokio::test]
1061
+ #[serial]
1062
+ async fn test_pipeline_multiple_processors_modifying_same_metadata() {
1063
+ clear_processor_registry();
1064
+
1065
+ let registry = get_post_processor_registry();
1066
+ {
1067
+ let mut reg = registry
1068
+ .write()
1069
+ .expect("Failed to acquire write lock on registry in test");
1070
+
1071
+ for i in 1..=3 {
1072
+ struct MetadataOverwritingProcessor {
1073
+ name: String,
1074
+ value: String,
1075
+ }
1076
+ impl Plugin for MetadataOverwritingProcessor {
1077
+ fn name(&self) -> &str {
1078
+ &self.name
1079
+ }
1080
+ fn version(&self) -> String {
1081
+ "1.0.0".to_string()
1082
+ }
1083
+ fn initialize(&self) -> Result<()> {
1084
+ Ok(())
1085
+ }
1086
+ fn shutdown(&self) -> Result<()> {
1087
+ Ok(())
1088
+ }
1089
+ }
1090
+ #[async_trait]
1091
+ impl PostProcessor for MetadataOverwritingProcessor {
1092
+ async fn process(&self, result: &mut ExtractionResult, _: &ExtractionConfig) -> Result<()> {
1093
+ result
1094
+ .metadata
1095
+ .additional
1096
+ .insert("shared_key".to_string(), serde_json::json!(self.value));
1097
+ Ok(())
1098
+ }
1099
+ fn processing_stage(&self) -> ProcessingStage {
1100
+ ProcessingStage::Early
1101
+ }
1102
+ }
1103
+
1104
+ let processor = Arc::new(MetadataOverwritingProcessor {
1105
+ name: format!("proc{}", i),
1106
+ value: format!("value{}", i),
1107
+ });
1108
+ reg.register(processor, 100 - i * 10).unwrap();
1109
+ }
1110
+ }
1111
+
1112
+ let result = ExtractionResult {
1113
+ content: "content".to_string(),
1114
+ mime_type: "text/plain".to_string(),
1115
+ metadata: Metadata::default(),
1116
+ tables: vec![],
1117
+ detected_languages: None,
1118
+ chunks: None,
1119
+ images: None,
1120
+ pages: None,
1121
+ };
1122
+ let config = ExtractionConfig::default();
1123
+
1124
+ let processed = run_pipeline(result, &config).await.unwrap();
1125
+ assert_eq!(
1126
+ processed
1127
+ .metadata
1128
+ .additional
1129
+ .get("shared_key")
1130
+ .unwrap()
1131
+ .as_str()
1132
+ .unwrap(),
1133
+ "value3"
1134
+ );
1135
+ }
1136
+
1137
+ #[tokio::test]
1138
+ #[serial]
1139
+ async fn test_pipeline_processors_reading_previous_output() {
1140
+ clear_processor_registry();
1141
+
1142
+ let registry = get_post_processor_registry();
1143
+ {
1144
+ let mut reg = registry
1145
+ .write()
1146
+ .expect("Failed to acquire write lock on registry in test");
1147
+
1148
+ struct CountingProcessor {
1149
+ name: String,
1150
+ stage: ProcessingStage,
1151
+ }
1152
+ impl Plugin for CountingProcessor {
1153
+ fn name(&self) -> &str {
1154
+ &self.name
1155
+ }
1156
+ fn version(&self) -> String {
1157
+ "1.0.0".to_string()
1158
+ }
1159
+ fn initialize(&self) -> Result<()> {
1160
+ Ok(())
1161
+ }
1162
+ fn shutdown(&self) -> Result<()> {
1163
+ Ok(())
1164
+ }
1165
+ }
1166
+ #[async_trait]
1167
+ impl PostProcessor for CountingProcessor {
1168
+ async fn process(&self, result: &mut ExtractionResult, _: &ExtractionConfig) -> Result<()> {
1169
+ let current_count = result
1170
+ .metadata
1171
+ .additional
1172
+ .get("count")
1173
+ .and_then(|v| v.as_i64())
1174
+ .unwrap_or(0);
1175
+ result
1176
+ .metadata
1177
+ .additional
1178
+ .insert("count".to_string(), serde_json::json!(current_count + 1));
1179
+ Ok(())
1180
+ }
1181
+ fn processing_stage(&self) -> ProcessingStage {
1182
+ self.stage
1183
+ }
1184
+ }
1185
+
1186
+ for (name, stage) in [
1187
+ ("early1", ProcessingStage::Early),
1188
+ ("early2", ProcessingStage::Early),
1189
+ ("middle1", ProcessingStage::Middle),
1190
+ ("late1", ProcessingStage::Late),
1191
+ ] {
1192
+ let processor = Arc::new(CountingProcessor {
1193
+ name: name.to_string(),
1194
+ stage,
1195
+ });
1196
+ reg.register(processor, 50).unwrap();
1197
+ }
1198
+ }
1199
+
1200
+ let result = ExtractionResult {
1201
+ content: "content".to_string(),
1202
+ mime_type: "text/plain".to_string(),
1203
+ metadata: Metadata::default(),
1204
+ tables: vec![],
1205
+ detected_languages: None,
1206
+ chunks: None,
1207
+ images: None,
1208
+ pages: None,
1209
+ };
1210
+ let config = ExtractionConfig::default();
1211
+
1212
+ let processed = run_pipeline(result, &config).await.unwrap();
1213
+ assert_eq!(processed.metadata.additional.get("count").unwrap().as_i64().unwrap(), 4);
1214
+ }
1215
+
1216
+ #[tokio::test]
1217
+ #[serial]
1218
+ async fn test_pipeline_large_content_modification() {
1219
+ clear_processor_registry();
1220
+
1221
+ struct LargeContentProcessor;
1222
+ impl Plugin for LargeContentProcessor {
1223
+ fn name(&self) -> &str {
1224
+ "large"
1225
+ }
1226
+ fn version(&self) -> String {
1227
+ "1.0.0".to_string()
1228
+ }
1229
+ fn initialize(&self) -> Result<()> {
1230
+ Ok(())
1231
+ }
1232
+ fn shutdown(&self) -> Result<()> {
1233
+ Ok(())
1234
+ }
1235
+ }
1236
+ #[async_trait]
1237
+ impl PostProcessor for LargeContentProcessor {
1238
+ async fn process(&self, result: &mut ExtractionResult, _: &ExtractionConfig) -> Result<()> {
1239
+ result.content.push_str(&"x".repeat(10000));
1240
+ Ok(())
1241
+ }
1242
+ fn processing_stage(&self) -> ProcessingStage {
1243
+ ProcessingStage::Early
1244
+ }
1245
+ }
1246
+
1247
+ let registry = get_post_processor_registry();
1248
+ {
1249
+ let mut reg = registry
1250
+ .write()
1251
+ .expect("Failed to acquire write lock on registry in test");
1252
+ reg.register(Arc::new(LargeContentProcessor), 50).unwrap();
1253
+ }
1254
+
1255
+ let result = ExtractionResult {
1256
+ content: "start".to_string(),
1257
+ mime_type: "text/plain".to_string(),
1258
+ metadata: Metadata::default(),
1259
+ tables: vec![],
1260
+ detected_languages: None,
1261
+ chunks: None,
1262
+ images: None,
1263
+ pages: None,
1264
+ };
1265
+ let config = ExtractionConfig::default();
1266
+
1267
+ let processed = run_pipeline(result, &config).await.unwrap();
1268
+ assert!(processed.content.len() > 10000);
1269
+ }
1270
+
1271
+ #[tokio::test]
1272
+ #[serial]
1273
+ async fn test_pipeline_enabled_processors_whitelist() {
1274
+ clear_processor_registry();
1275
+
1276
+ let registry = get_post_processor_registry();
1277
+ {
1278
+ let mut reg = registry
1279
+ .write()
1280
+ .expect("Failed to acquire write lock on registry in test");
1281
+
1282
+ for name in ["proc1", "proc2", "proc3"] {
1283
+ let processor = Arc::new(OrderTrackingProcessor {
1284
+ name: name.to_string(),
1285
+ stage: ProcessingStage::Early,
1286
+ });
1287
+ reg.register(processor, 50).unwrap();
1288
+ }
1289
+ }
1290
+
1291
+ let result = ExtractionResult {
1292
+ content: "start".to_string(),
1293
+ mime_type: "text/plain".to_string(),
1294
+ metadata: Metadata::default(),
1295
+ tables: vec![],
1296
+ detected_languages: None,
1297
+ chunks: None,
1298
+ images: None,
1299
+ pages: None,
1300
+ };
1301
+ let config = ExtractionConfig {
1302
+ postprocessor: Some(PostProcessorConfig {
1303
+ enabled: true,
1304
+ enabled_processors: Some(vec!["proc1".to_string(), "proc3".to_string()]),
1305
+ disabled_processors: None,
1306
+ enabled_set: None,
1307
+ disabled_set: None,
1308
+ }),
1309
+ ..Default::default()
1310
+ };
1311
+
1312
+ let processed = run_pipeline(result, &config).await.unwrap();
1313
+ assert!(processed.content.contains("[proc1]"));
1314
+ assert!(!processed.content.contains("[proc2]"));
1315
+ assert!(processed.content.contains("[proc3]"));
1316
+ }
1317
+
1318
+ #[tokio::test]
1319
+ #[serial]
1320
+ async fn test_pipeline_disabled_processors_blacklist() {
1321
+ clear_processor_registry();
1322
+
1323
+ let registry = get_post_processor_registry();
1324
+ {
1325
+ let mut reg = registry
1326
+ .write()
1327
+ .expect("Failed to acquire write lock on registry in test");
1328
+
1329
+ for name in ["proc1", "proc2", "proc3"] {
1330
+ let processor = Arc::new(OrderTrackingProcessor {
1331
+ name: name.to_string(),
1332
+ stage: ProcessingStage::Early,
1333
+ });
1334
+ reg.register(processor, 50).unwrap();
1335
+ }
1336
+ }
1337
+
1338
+ let result = ExtractionResult {
1339
+ content: "start".to_string(),
1340
+ mime_type: "text/plain".to_string(),
1341
+ metadata: Metadata::default(),
1342
+ tables: vec![],
1343
+ detected_languages: None,
1344
+ chunks: None,
1345
+ images: None,
1346
+ pages: None,
1347
+ };
1348
+ let config = ExtractionConfig {
1349
+ postprocessor: Some(PostProcessorConfig {
1350
+ enabled: true,
1351
+ enabled_processors: None,
1352
+ disabled_processors: Some(vec!["proc2".to_string()]),
1353
+ enabled_set: None,
1354
+ disabled_set: None,
1355
+ }),
1356
+ ..Default::default()
1357
+ };
1358
+
1359
+ let processed = run_pipeline(result, &config).await.unwrap();
1360
+ assert!(processed.content.contains("[proc1]"));
1361
+ assert!(!processed.content.contains("[proc2]"));
1362
+ assert!(processed.content.contains("[proc3]"));
1363
+ }
1364
+
1365
+ #[tokio::test]
1366
+ #[serial]
1367
+ async fn test_pipeline_no_filtering_runs_all() {
1368
+ clear_processor_registry();
1369
+
1370
+ let registry = get_post_processor_registry();
1371
+ {
1372
+ let mut reg = registry
1373
+ .write()
1374
+ .expect("Failed to acquire write lock on registry in test");
1375
+
1376
+ for name in ["proc1", "proc2", "proc3"] {
1377
+ let processor = Arc::new(OrderTrackingProcessor {
1378
+ name: name.to_string(),
1379
+ stage: ProcessingStage::Early,
1380
+ });
1381
+ reg.register(processor, 50).unwrap();
1382
+ }
1383
+ }
1384
+
1385
+ let result = ExtractionResult {
1386
+ content: "start".to_string(),
1387
+ mime_type: "text/plain".to_string(),
1388
+ metadata: Metadata::default(),
1389
+ tables: vec![],
1390
+ detected_languages: None,
1391
+ chunks: None,
1392
+ images: None,
1393
+ pages: None,
1394
+ };
1395
+ let config = ExtractionConfig::default();
1396
+
1397
+ let processed = run_pipeline(result, &config).await.unwrap();
1398
+ assert!(processed.content.contains("[proc1]"));
1399
+ assert!(processed.content.contains("[proc2]"));
1400
+ assert!(processed.content.contains("[proc3]"));
1401
+ }
1402
+
1403
+ #[tokio::test]
1404
+ #[serial]
1405
+ async fn test_pipeline_empty_whitelist_runs_none() {
1406
+ clear_processor_registry();
1407
+
1408
+ let registry = get_post_processor_registry();
1409
+ {
1410
+ let mut reg = registry
1411
+ .write()
1412
+ .expect("Failed to acquire write lock on registry in test");
1413
+
1414
+ for name in ["proc1", "proc2"] {
1415
+ let processor = Arc::new(OrderTrackingProcessor {
1416
+ name: name.to_string(),
1417
+ stage: ProcessingStage::Early,
1418
+ });
1419
+ reg.register(processor, 50).unwrap();
1420
+ }
1421
+ }
1422
+
1423
+ let result = ExtractionResult {
1424
+ content: "start".to_string(),
1425
+ mime_type: "text/plain".to_string(),
1426
+ metadata: Metadata::default(),
1427
+ tables: vec![],
1428
+ detected_languages: None,
1429
+ chunks: None,
1430
+ images: None,
1431
+ pages: None,
1432
+ };
1433
+ let config = ExtractionConfig {
1434
+ postprocessor: Some(PostProcessorConfig {
1435
+ enabled: true,
1436
+ enabled_processors: Some(vec![]),
1437
+ disabled_processors: None,
1438
+ enabled_set: None,
1439
+ disabled_set: None,
1440
+ }),
1441
+ ..Default::default()
1442
+ };
1443
+
1444
+ let processed = run_pipeline(result, &config).await.unwrap();
1445
+ assert_eq!(processed.content, "start");
1446
+ }