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,966 +1,1472 @@
1
- //! Integration tests for the API module.
2
-
3
- #![cfg(feature = "api")]
4
-
5
- use axum::{
6
- body::Body,
7
- http::{Request, StatusCode},
8
- };
9
- use serde_json::json;
10
- use tower::ServiceExt;
11
-
12
- use kreuzberg::{
13
- ExtractionConfig,
14
- api::{HealthResponse, InfoResponse, create_router},
15
- };
16
-
17
- /// Test the health check endpoint.
18
- #[tokio::test]
19
- async fn test_health_endpoint() {
20
- let app = create_router(ExtractionConfig::default());
21
-
22
- let response = app
23
- .oneshot(Request::builder().uri("/health").body(Body::empty()).unwrap())
24
- .await
25
- .unwrap();
26
-
27
- assert_eq!(response.status(), StatusCode::OK);
28
-
29
- let body = axum::body::to_bytes(response.into_body(), usize::MAX).await.unwrap();
30
- let health: HealthResponse = serde_json::from_slice(&body).unwrap();
31
-
32
- assert_eq!(health.status, "healthy");
33
- assert!(!health.version.is_empty());
34
- }
35
-
36
- /// Test the info endpoint.
37
- #[tokio::test]
38
- async fn test_info_endpoint() {
39
- let app = create_router(ExtractionConfig::default());
40
-
41
- let response = app
42
- .oneshot(Request::builder().uri("/info").body(Body::empty()).unwrap())
43
- .await
44
- .unwrap();
45
-
46
- assert_eq!(response.status(), StatusCode::OK);
47
-
48
- let body = axum::body::to_bytes(response.into_body(), usize::MAX).await.unwrap();
49
- let info: InfoResponse = serde_json::from_slice(&body).unwrap();
50
-
51
- assert!(!info.version.is_empty());
52
- assert!(info.rust_backend);
53
- }
54
-
55
- /// Test extract endpoint with no files returns 400.
56
- #[tokio::test]
57
- async fn test_extract_no_files() {
58
- let app = create_router(ExtractionConfig::default());
59
-
60
- let boundary = "----boundary";
61
- let body_content = format!("--{}--\r\n", boundary);
62
-
63
- let response = app
64
- .oneshot(
65
- Request::builder()
66
- .method("POST")
67
- .uri("/extract")
68
- .header("content-type", format!("multipart/form-data; boundary={}", boundary))
69
- .body(Body::from(body_content))
70
- .unwrap(),
71
- )
72
- .await
73
- .unwrap();
74
-
75
- assert_eq!(response.status(), StatusCode::BAD_REQUEST);
76
- }
77
-
78
- /// Test extract endpoint with a simple text file.
79
- #[tokio::test]
80
- async fn test_extract_text_file() {
81
- let app = create_router(ExtractionConfig::default());
82
-
83
- let boundary = "----boundary";
84
- let file_content = "Hello, world!";
85
-
86
- let body_content = format!(
87
- "--{}\r\n\
88
- Content-Disposition: form-data; name=\"files\"; filename=\"test.txt\"\r\n\
89
- Content-Type: text/plain\r\n\
90
- \r\n\
91
- {}\r\n\
92
- --{}--\r\n",
93
- boundary, file_content, boundary
94
- );
95
-
96
- let response = app
97
- .oneshot(
98
- Request::builder()
99
- .method("POST")
100
- .uri("/extract")
101
- .header("content-type", format!("multipart/form-data; boundary={}", boundary))
102
- .body(Body::from(body_content))
103
- .unwrap(),
104
- )
105
- .await
106
- .unwrap();
107
-
108
- assert_eq!(response.status(), StatusCode::OK);
109
-
110
- let body = axum::body::to_bytes(response.into_body(), usize::MAX).await.unwrap();
111
- let results: Vec<serde_json::Value> = serde_json::from_slice(&body).unwrap();
112
-
113
- assert_eq!(results.len(), 1);
114
- assert_eq!(results[0]["mime_type"], "text/plain");
115
- assert!(results[0]["content"].as_str().unwrap().contains("Hello, world!"));
116
-
117
- assert!(
118
- results[0]["chunks"].is_null(),
119
- "Chunks should be null without chunking config"
120
- );
121
- assert!(
122
- results[0]["detected_languages"].is_null(),
123
- "Language detection not enabled"
124
- );
125
- assert!(results[0]["tables"].is_array(), "Tables field should be present");
126
- assert!(results[0]["metadata"].is_object(), "Metadata field should be present");
127
- }
128
-
129
- /// Test extract endpoint with JSON config.
130
- #[tokio::test]
131
- async fn test_extract_with_config() {
132
- let app = create_router(ExtractionConfig::default());
133
-
134
- let boundary = "----boundary";
135
- let file_content = "Hello, world!";
136
- let config = json!({
137
- "force_ocr": false
138
- });
139
-
140
- let body_content = format!(
141
- "--{}\r\n\
142
- Content-Disposition: form-data; name=\"files\"; filename=\"test.txt\"\r\n\
143
- Content-Type: text/plain\r\n\
144
- \r\n\
145
- {}\r\n\
146
- --{}\r\n\
147
- Content-Disposition: form-data; name=\"config\"\r\n\
148
- \r\n\
149
- {}\r\n\
150
- --{}--\r\n",
151
- boundary, file_content, boundary, config, boundary
152
- );
153
-
154
- let response = app
155
- .oneshot(
156
- Request::builder()
157
- .method("POST")
158
- .uri("/extract")
159
- .header("content-type", format!("multipart/form-data; boundary={}", boundary))
160
- .body(Body::from(body_content))
161
- .unwrap(),
162
- )
163
- .await
164
- .unwrap();
165
-
166
- assert_eq!(response.status(), StatusCode::OK);
167
-
168
- let body = axum::body::to_bytes(response.into_body(), usize::MAX).await.unwrap();
169
- let results: Vec<serde_json::Value> = serde_json::from_slice(&body).unwrap();
170
-
171
- assert_eq!(results.len(), 1);
172
- assert_eq!(results[0]["mime_type"], "text/plain");
173
- assert!(results[0]["content"].as_str().unwrap().contains("Hello, world!"));
174
-
175
- assert!(
176
- results[0]["chunks"].is_null(),
177
- "Chunks should be null without chunking config"
178
- );
179
- assert!(
180
- results[0]["detected_languages"].is_null(),
181
- "Language detection not enabled"
182
- );
183
- assert!(results[0]["tables"].is_array(), "Tables field should be present");
184
- assert!(results[0]["metadata"].is_object(), "Metadata field should be present");
185
- }
186
-
187
- /// Test extract endpoint with invalid config returns 400.
188
- #[tokio::test]
189
- async fn test_extract_invalid_config() {
190
- let app = create_router(ExtractionConfig::default());
191
-
192
- let boundary = "----boundary";
193
- let file_content = "Hello, world!";
194
- let invalid_config = "not valid json";
195
-
196
- let body_content = format!(
197
- "--{}\r\n\
198
- Content-Disposition: form-data; name=\"files\"; filename=\"test.txt\"\r\n\
199
- Content-Type: text/plain\r\n\
200
- \r\n\
201
- {}\r\n\
202
- --{}\r\n\
203
- Content-Disposition: form-data; name=\"config\"\r\n\
204
- \r\n\
205
- {}\r\n\
206
- --{}--\r\n",
207
- boundary, file_content, boundary, invalid_config, boundary
208
- );
209
-
210
- let response = app
211
- .oneshot(
212
- Request::builder()
213
- .method("POST")
214
- .uri("/extract")
215
- .header("content-type", format!("multipart/form-data; boundary={}", boundary))
216
- .body(Body::from(body_content))
217
- .unwrap(),
218
- )
219
- .await
220
- .unwrap();
221
-
222
- assert_eq!(response.status(), StatusCode::BAD_REQUEST);
223
- }
224
-
225
- /// Test extract endpoint with multiple files.
226
- #[tokio::test]
227
- async fn test_extract_multiple_files() {
228
- let app = create_router(ExtractionConfig::default());
229
-
230
- let boundary = "----boundary";
231
- let file1_content = "First file content";
232
- let file2_content = "Second file content";
233
-
234
- let body_content = format!(
235
- "--{}\r\n\
236
- Content-Disposition: form-data; name=\"files\"; filename=\"test1.txt\"\r\n\
237
- Content-Type: text/plain\r\n\
238
- \r\n\
239
- {}\r\n\
240
- --{}\r\n\
241
- Content-Disposition: form-data; name=\"files\"; filename=\"test2.txt\"\r\n\
242
- Content-Type: text/plain\r\n\
243
- \r\n\
244
- {}\r\n\
245
- --{}--\r\n",
246
- boundary, file1_content, boundary, file2_content, boundary
247
- );
248
-
249
- let response = app
250
- .oneshot(
251
- Request::builder()
252
- .method("POST")
253
- .uri("/extract")
254
- .header("content-type", format!("multipart/form-data; boundary={}", boundary))
255
- .body(Body::from(body_content))
256
- .unwrap(),
257
- )
258
- .await
259
- .unwrap();
260
-
261
- assert_eq!(response.status(), StatusCode::OK);
262
-
263
- let body = axum::body::to_bytes(response.into_body(), usize::MAX).await.unwrap();
264
- let results: Vec<serde_json::Value> = serde_json::from_slice(&body).unwrap();
265
-
266
- assert_eq!(results.len(), 2);
267
- assert!(results[0]["content"].as_str().unwrap().contains("First file"));
268
- assert!(results[1]["content"].as_str().unwrap().contains("Second file"));
269
-
270
- for result in &results {
271
- assert!(
272
- result["chunks"].is_null(),
273
- "Chunks should be null without chunking config"
274
- );
275
- assert!(result["detected_languages"].is_null(), "Language detection not enabled");
276
- assert!(result["tables"].is_array(), "Tables field should be present");
277
- assert!(result["metadata"].is_object(), "Metadata field should be present");
278
- assert_eq!(result["mime_type"], "text/plain");
279
- }
280
- }
281
-
282
- /// Test extract endpoint with markdown content.
283
- #[tokio::test]
284
- async fn test_extract_markdown_file() {
285
- let app = create_router(ExtractionConfig::default());
286
-
287
- let boundary = "----boundary";
288
- let file_content = "# Heading\n\nSome **bold** text.";
289
-
290
- let body_content = format!(
291
- "--{}\r\n\
292
- Content-Disposition: form-data; name=\"files\"; filename=\"test.md\"\r\n\
293
- Content-Type: text/markdown\r\n\
294
- \r\n\
295
- {}\r\n\
296
- --{}--\r\n",
297
- boundary, file_content, boundary
298
- );
299
-
300
- let response = app
301
- .oneshot(
302
- Request::builder()
303
- .method("POST")
304
- .uri("/extract")
305
- .header("content-type", format!("multipart/form-data; boundary={}", boundary))
306
- .body(Body::from(body_content))
307
- .unwrap(),
308
- )
309
- .await
310
- .unwrap();
311
-
312
- assert_eq!(response.status(), StatusCode::OK);
313
-
314
- let body = axum::body::to_bytes(response.into_body(), usize::MAX).await.unwrap();
315
- let results: Vec<serde_json::Value> = serde_json::from_slice(&body).unwrap();
316
-
317
- assert_eq!(results.len(), 1);
318
- assert_eq!(results[0]["mime_type"], "text/markdown");
319
- assert!(results[0]["content"].as_str().unwrap().contains("Heading"));
320
- }
321
-
322
- /// Test extract endpoint with JSON content.
323
- #[tokio::test]
324
- async fn test_extract_json_file() {
325
- let app = create_router(ExtractionConfig::default());
326
-
327
- let boundary = "----boundary";
328
- let file_content = r#"{"key": "value", "number": 42}"#;
329
-
330
- let body_content = format!(
331
- "--{}\r\n\
332
- Content-Disposition: form-data; name=\"files\"; filename=\"test.json\"\r\n\
333
- Content-Type: application/json\r\n\
334
- \r\n\
335
- {}\r\n\
336
- --{}--\r\n",
337
- boundary, file_content, boundary
338
- );
339
-
340
- let response = app
341
- .oneshot(
342
- Request::builder()
343
- .method("POST")
344
- .uri("/extract")
345
- .header("content-type", format!("multipart/form-data; boundary={}", boundary))
346
- .body(Body::from(body_content))
347
- .unwrap(),
348
- )
349
- .await
350
- .unwrap();
351
-
352
- assert_eq!(response.status(), StatusCode::OK);
353
-
354
- let body = axum::body::to_bytes(response.into_body(), usize::MAX).await.unwrap();
355
- let results: Vec<serde_json::Value> = serde_json::from_slice(&body).unwrap();
356
-
357
- assert_eq!(results.len(), 1);
358
- assert_eq!(results[0]["mime_type"], "application/json");
359
- }
360
-
361
- /// Test extract endpoint with XML content.
362
- #[tokio::test]
363
- #[cfg(feature = "xml")]
364
- async fn test_extract_xml_file() {
365
- let app = create_router(ExtractionConfig::default());
366
-
367
- let boundary = "----boundary";
368
- let file_content = r#"<?xml version="1.0"?><root><item>test</item></root>"#;
369
-
370
- let body_content = format!(
371
- "--{}\r\n\
372
- Content-Disposition: form-data; name=\"files\"; filename=\"test.xml\"\r\n\
373
- Content-Type: application/xml\r\n\
374
- \r\n\
375
- {}\r\n\
376
- --{}--\r\n",
377
- boundary, file_content, boundary
378
- );
379
-
380
- let response = app
381
- .oneshot(
382
- Request::builder()
383
- .method("POST")
384
- .uri("/extract")
385
- .header("content-type", format!("multipart/form-data; boundary={}", boundary))
386
- .body(Body::from(body_content))
387
- .unwrap(),
388
- )
389
- .await
390
- .unwrap();
391
-
392
- assert_eq!(response.status(), StatusCode::OK);
393
-
394
- let body = axum::body::to_bytes(response.into_body(), usize::MAX).await.unwrap();
395
- let results: Vec<serde_json::Value> = serde_json::from_slice(&body).unwrap();
396
-
397
- assert_eq!(results.len(), 1);
398
- assert_eq!(results[0]["mime_type"], "application/xml");
399
- assert!(results[0]["content"].as_str().unwrap().contains("test"));
400
- }
401
-
402
- /// Test extract endpoint with HTML content.
403
- #[tokio::test]
404
- #[cfg(feature = "html")]
405
- async fn test_extract_html_file() {
406
- let app = create_router(ExtractionConfig::default());
407
-
408
- let boundary = "----boundary";
409
- let file_content = r#"<html><body><h1>Title</h1><p>Content</p></body></html>"#;
410
-
411
- let body_content = format!(
412
- "--{}\r\n\
413
- Content-Disposition: form-data; name=\"files\"; filename=\"test.html\"\r\n\
414
- Content-Type: text/html\r\n\
415
- \r\n\
416
- {}\r\n\
417
- --{}--\r\n",
418
- boundary, file_content, boundary
419
- );
420
-
421
- let response = app
422
- .oneshot(
423
- Request::builder()
424
- .method("POST")
425
- .uri("/extract")
426
- .header("content-type", format!("multipart/form-data; boundary={}", boundary))
427
- .body(Body::from(body_content))
428
- .unwrap(),
429
- )
430
- .await
431
- .unwrap();
432
-
433
- assert_eq!(response.status(), StatusCode::OK);
434
-
435
- let body = axum::body::to_bytes(response.into_body(), usize::MAX).await.unwrap();
436
- let results: Vec<serde_json::Value> = serde_json::from_slice(&body).unwrap();
437
-
438
- assert_eq!(results.len(), 1);
439
- assert_eq!(results[0]["mime_type"], "text/html");
440
- assert!(results[0]["content"].as_str().unwrap().contains("Title"));
441
- }
442
-
443
- /// Test extract endpoint with missing Content-Type header.
444
- #[tokio::test]
445
- async fn test_extract_missing_content_type() {
446
- let app = create_router(ExtractionConfig::default());
447
-
448
- let response = app
449
- .oneshot(
450
- Request::builder()
451
- .method("POST")
452
- .uri("/extract")
453
- .body(Body::from("some data"))
454
- .unwrap(),
455
- )
456
- .await
457
- .unwrap();
458
-
459
- assert!(response.status() == StatusCode::BAD_REQUEST || response.status() == StatusCode::UNSUPPORTED_MEDIA_TYPE);
460
- }
461
-
462
- /// Test extract endpoint with empty file.
463
- #[tokio::test]
464
- async fn test_extract_empty_file() {
465
- let app = create_router(ExtractionConfig::default());
466
-
467
- let boundary = "----boundary";
468
- let file_content = "";
469
-
470
- let body_content = format!(
471
- "--{}\r\n\
472
- Content-Disposition: form-data; name=\"files\"; filename=\"empty.txt\"\r\n\
473
- Content-Type: text/plain\r\n\
474
- \r\n\
475
- {}\r\n\
476
- --{}--\r\n",
477
- boundary, file_content, boundary
478
- );
479
-
480
- let response = app
481
- .oneshot(
482
- Request::builder()
483
- .method("POST")
484
- .uri("/extract")
485
- .header("content-type", format!("multipart/form-data; boundary={}", boundary))
486
- .body(Body::from(body_content))
487
- .unwrap(),
488
- )
489
- .await
490
- .unwrap();
491
-
492
- assert_eq!(response.status(), StatusCode::OK);
493
-
494
- let body = axum::body::to_bytes(response.into_body(), usize::MAX).await.unwrap();
495
- let results: Vec<serde_json::Value> = serde_json::from_slice(&body).unwrap();
496
-
497
- assert_eq!(results.len(), 1);
498
- assert_eq!(results[0]["mime_type"], "text/plain");
499
- }
500
-
501
- /// Test extract endpoint with unsupported MIME type.
502
- #[tokio::test]
503
- async fn test_extract_unsupported_mime_type() {
504
- let app = create_router(ExtractionConfig::default());
505
-
506
- let boundary = "----boundary";
507
- let file_content = "Binary data";
508
-
509
- let body_content = format!(
510
- "--{}\r\n\
511
- Content-Disposition: form-data; name=\"files\"; filename=\"test.bin\"\r\n\
512
- Content-Type: application/x-unknown-binary\r\n\
513
- \r\n\
514
- {}\r\n\
515
- --{}--\r\n",
516
- boundary, file_content, boundary
517
- );
518
-
519
- let response = app
520
- .oneshot(
521
- Request::builder()
522
- .method("POST")
523
- .uri("/extract")
524
- .header("content-type", format!("multipart/form-data; boundary={}", boundary))
525
- .body(Body::from(body_content))
526
- .unwrap(),
527
- )
528
- .await
529
- .unwrap();
530
-
531
- assert!(
532
- response.status() == StatusCode::UNPROCESSABLE_ENTITY || response.status() == StatusCode::INTERNAL_SERVER_ERROR
533
- );
534
- }
535
-
536
- /// Test extract endpoint without filename in multipart field.
537
- #[tokio::test]
538
- async fn test_extract_without_filename() {
539
- let app = create_router(ExtractionConfig::default());
540
-
541
- let boundary = "----boundary";
542
- let file_content = "Test content";
543
-
544
- let body_content = format!(
545
- "--{}\r\n\
546
- Content-Disposition: form-data; name=\"files\"\r\n\
547
- Content-Type: text/plain\r\n\
548
- \r\n\
549
- {}\r\n\
550
- --{}--\r\n",
551
- boundary, file_content, boundary
552
- );
553
-
554
- let response = app
555
- .oneshot(
556
- Request::builder()
557
- .method("POST")
558
- .uri("/extract")
559
- .header("content-type", format!("multipart/form-data; boundary={}", boundary))
560
- .body(Body::from(body_content))
561
- .unwrap(),
562
- )
563
- .await
564
- .unwrap();
565
-
566
- assert_eq!(response.status(), StatusCode::OK);
567
- }
568
-
569
- /// Test extract endpoint with malformed multipart data.
570
- #[tokio::test]
571
- async fn test_extract_malformed_multipart() {
572
- let app = create_router(ExtractionConfig::default());
573
-
574
- let boundary = "----boundary";
575
- let body_content = format!("--{}\r\nmalformed data\r\n", boundary);
576
-
577
- let response = app
578
- .oneshot(
579
- Request::builder()
580
- .method("POST")
581
- .uri("/extract")
582
- .header("content-type", format!("multipart/form-data; boundary={}", boundary))
583
- .body(Body::from(body_content))
584
- .unwrap(),
585
- )
586
- .await
587
- .unwrap();
588
-
589
- assert!(response.status().is_client_error() || response.status().is_server_error());
590
- }
591
-
592
- /// Test CORS headers are present.
593
- #[tokio::test]
594
- async fn test_cors_headers() {
595
- let app = create_router(ExtractionConfig::default());
596
-
597
- let response = app
598
- .oneshot(Request::builder().uri("/health").body(Body::empty()).unwrap())
599
- .await
600
- .unwrap();
601
-
602
- assert_eq!(response.status(), StatusCode::OK);
603
-
604
- let headers = response.headers();
605
- assert!(headers.contains_key("access-control-allow-origin") || headers.contains_key("Access-Control-Allow-Origin"));
606
- }
607
-
608
- /// Test OPTIONS preflight request for CORS.
609
- #[tokio::test]
610
- async fn test_cors_preflight() {
611
- let app = create_router(ExtractionConfig::default());
612
-
613
- let response = app
614
- .oneshot(
615
- Request::builder()
616
- .method("OPTIONS")
617
- .uri("/extract")
618
- .header("origin", "http://example.com")
619
- .header("access-control-request-method", "POST")
620
- .body(Body::empty())
621
- .unwrap(),
622
- )
623
- .await
624
- .unwrap();
625
-
626
- assert!(response.status().is_success() || response.status() == StatusCode::NO_CONTENT);
627
- }
628
-
629
- /// Test error response format for validation errors.
630
- #[tokio::test]
631
- async fn test_error_response_format_validation() {
632
- let app = create_router(ExtractionConfig::default());
633
-
634
- let boundary = "----boundary";
635
- let body_content = format!("--{}--\r\n", boundary);
636
-
637
- let response = app
638
- .oneshot(
639
- Request::builder()
640
- .method("POST")
641
- .uri("/extract")
642
- .header("content-type", format!("multipart/form-data; boundary={}", boundary))
643
- .body(Body::from(body_content))
644
- .unwrap(),
645
- )
646
- .await
647
- .unwrap();
648
-
649
- assert_eq!(response.status(), StatusCode::BAD_REQUEST);
650
-
651
- let body = axum::body::to_bytes(response.into_body(), usize::MAX).await.unwrap();
652
- let error: serde_json::Value = serde_json::from_slice(&body).unwrap();
653
-
654
- assert!(error["error_type"].is_string());
655
- assert!(error["message"].is_string());
656
- assert_eq!(error["status_code"], 400);
657
- assert_eq!(error["error_type"], "ValidationError");
658
- }
659
-
660
- /// Test error response format for parsing errors.
661
- #[tokio::test]
662
- async fn test_error_response_format_parsing() {
663
- let app = create_router(ExtractionConfig::default());
664
-
665
- let boundary = "----boundary";
666
- let invalid_config = "not valid json";
667
-
668
- let body_content = format!(
669
- "--{}\r\n\
670
- Content-Disposition: form-data; name=\"files\"; filename=\"test.txt\"\r\n\
671
- Content-Type: text/plain\r\n\
672
- \r\n\
673
- content\r\n\
674
- --{}\r\n\
675
- Content-Disposition: form-data; name=\"config\"\r\n\
676
- \r\n\
677
- {}\r\n\
678
- --{}--\r\n",
679
- boundary, boundary, invalid_config, boundary
680
- );
681
-
682
- let response = app
683
- .oneshot(
684
- Request::builder()
685
- .method("POST")
686
- .uri("/extract")
687
- .header("content-type", format!("multipart/form-data; boundary={}", boundary))
688
- .body(Body::from(body_content))
689
- .unwrap(),
690
- )
691
- .await
692
- .unwrap();
693
-
694
- assert_eq!(response.status(), StatusCode::BAD_REQUEST);
695
-
696
- let body = axum::body::to_bytes(response.into_body(), usize::MAX).await.unwrap();
697
- let error: serde_json::Value = serde_json::from_slice(&body).unwrap();
698
-
699
- assert_eq!(error["error_type"], "ValidationError");
700
- assert!(error["message"].as_str().unwrap().contains("configuration"));
701
- }
702
-
703
- /// Test 404 error for non-existent endpoint.
704
- #[tokio::test]
705
- async fn test_not_found_endpoint() {
706
- let app = create_router(ExtractionConfig::default());
707
-
708
- let response = app
709
- .oneshot(Request::builder().uri("/nonexistent").body(Body::empty()).unwrap())
710
- .await
711
- .unwrap();
712
-
713
- assert_eq!(response.status(), StatusCode::NOT_FOUND);
714
- }
715
-
716
- /// Test extract endpoint with very large text content.
717
- #[tokio::test]
718
- async fn test_extract_large_file() {
719
- let app = create_router(ExtractionConfig::default());
720
-
721
- let boundary = "----boundary";
722
- let large_content = "A".repeat(1024 * 1024);
723
-
724
- let body_content = format!(
725
- "--{}\r\n\
726
- Content-Disposition: form-data; name=\"files\"; filename=\"large.txt\"\r\n\
727
- Content-Type: text/plain\r\n\
728
- \r\n\
729
- {}\r\n\
730
- --{}--\r\n",
731
- boundary, large_content, boundary
732
- );
733
-
734
- let response = app
735
- .oneshot(
736
- Request::builder()
737
- .method("POST")
738
- .uri("/extract")
739
- .header("content-type", format!("multipart/form-data; boundary={}", boundary))
740
- .body(Body::from(body_content))
741
- .unwrap(),
742
- )
743
- .await
744
- .unwrap();
745
-
746
- assert_eq!(response.status(), StatusCode::OK);
747
-
748
- let body = axum::body::to_bytes(response.into_body(), usize::MAX).await.unwrap();
749
- let results: Vec<serde_json::Value> = serde_json::from_slice(&body).unwrap();
750
-
751
- assert_eq!(results.len(), 1);
752
- assert_eq!(results[0]["mime_type"], "text/plain");
753
- }
754
-
755
- /// Test concurrent requests to extract endpoint.
756
- #[tokio::test]
757
- async fn test_concurrent_requests() {
758
- use tower::ServiceExt;
759
-
760
- let app = create_router(ExtractionConfig::default());
761
-
762
- let boundary = "----boundary";
763
- let file_content = "Concurrent test";
764
-
765
- let body_content = format!(
766
- "--{}\r\n\
767
- Content-Disposition: form-data; name=\"files\"; filename=\"test.txt\"\r\n\
768
- Content-Type: text/plain\r\n\
769
- \r\n\
770
- {}\r\n\
771
- --{}--\r\n",
772
- boundary, file_content, boundary
773
- );
774
-
775
- let mut handles = vec![];
776
-
777
- for _ in 0..5 {
778
- let app_clone = app.clone();
779
- let body_clone = body_content.clone();
780
-
781
- let handle = tokio::spawn(async move {
782
- app_clone
783
- .oneshot(
784
- Request::builder()
785
- .method("POST")
786
- .uri("/extract")
787
- .header("content-type", format!("multipart/form-data; boundary={}", boundary))
788
- .body(Body::from(body_clone))
789
- .unwrap(),
790
- )
791
- .await
792
- });
793
-
794
- handles.push(handle);
795
- }
796
-
797
- for handle in handles {
798
- let response = handle.await.unwrap().unwrap();
799
- assert_eq!(response.status(), StatusCode::OK);
800
- }
801
- }
802
-
803
- /// Test cache stats endpoint.
804
- #[tokio::test]
805
- async fn test_cache_stats_endpoint() {
806
- let app = create_router(ExtractionConfig::default());
807
-
808
- let response = app
809
- .oneshot(Request::builder().uri("/cache/stats").body(Body::empty()).unwrap())
810
- .await
811
- .unwrap();
812
-
813
- assert_eq!(response.status(), StatusCode::OK);
814
-
815
- let body = axum::body::to_bytes(response.into_body(), usize::MAX).await.unwrap();
816
- let stats: serde_json::Value = serde_json::from_slice(&body).unwrap();
817
-
818
- assert!(stats["directory"].is_string());
819
- assert!(stats["total_files"].is_number());
820
- assert!(stats["total_size_mb"].is_number());
821
- }
822
-
823
- /// Test cache clear endpoint.
824
- #[tokio::test]
825
- async fn test_cache_clear_endpoint() {
826
- let app = create_router(ExtractionConfig::default());
827
-
828
- let response = app
829
- .oneshot(
830
- Request::builder()
831
- .method("DELETE")
832
- .uri("/cache/clear")
833
- .body(Body::empty())
834
- .unwrap(),
835
- )
836
- .await
837
- .unwrap();
838
-
839
- assert_eq!(response.status(), StatusCode::OK);
840
-
841
- let body = axum::body::to_bytes(response.into_body(), usize::MAX).await.unwrap();
842
- let clear_result: serde_json::Value = serde_json::from_slice(&body).unwrap();
843
-
844
- assert!(clear_result["directory"].is_string());
845
- assert!(clear_result["removed_files"].is_number());
846
- assert!(clear_result["freed_mb"].is_number());
847
- }
848
-
849
- /// Test extract endpoint with mixed content types.
850
- #[tokio::test]
851
- async fn test_extract_mixed_content_types() {
852
- let app = create_router(ExtractionConfig::default());
853
-
854
- let boundary = "----boundary";
855
- let text_content = "Text file";
856
- let json_content = r#"{"test": "data"}"#;
857
-
858
- let body_content = format!(
859
- "--{}\r\n\
860
- Content-Disposition: form-data; name=\"files\"; filename=\"test.txt\"\r\n\
861
- Content-Type: text/plain\r\n\
862
- \r\n\
863
- {}\r\n\
864
- --{}\r\n\
865
- Content-Disposition: form-data; name=\"files\"; filename=\"test.json\"\r\n\
866
- Content-Type: application/json\r\n\
867
- \r\n\
868
- {}\r\n\
869
- --{}--\r\n",
870
- boundary, text_content, boundary, json_content, boundary
871
- );
872
-
873
- let response = app
874
- .oneshot(
875
- Request::builder()
876
- .method("POST")
877
- .uri("/extract")
878
- .header("content-type", format!("multipart/form-data; boundary={}", boundary))
879
- .body(Body::from(body_content))
880
- .unwrap(),
881
- )
882
- .await
883
- .unwrap();
884
-
885
- assert_eq!(response.status(), StatusCode::OK);
886
-
887
- let body = axum::body::to_bytes(response.into_body(), usize::MAX).await.unwrap();
888
- let results: Vec<serde_json::Value> = serde_json::from_slice(&body).unwrap();
889
-
890
- assert_eq!(results.len(), 2);
891
- assert_eq!(results[0]["mime_type"], "text/plain");
892
- assert_eq!(results[1]["mime_type"], "application/json");
893
- }
894
-
895
- /// Test extract endpoint with unknown field in multipart.
896
- #[tokio::test]
897
- async fn test_extract_unknown_multipart_field() {
898
- let app = create_router(ExtractionConfig::default());
899
-
900
- let boundary = "----boundary";
901
- let file_content = "Test content";
902
-
903
- let body_content = format!(
904
- "--{}\r\n\
905
- Content-Disposition: form-data; name=\"files\"; filename=\"test.txt\"\r\n\
906
- Content-Type: text/plain\r\n\
907
- \r\n\
908
- {}\r\n\
909
- --{}\r\n\
910
- Content-Disposition: form-data; name=\"unknown_field\"\r\n\
911
- \r\n\
912
- some value\r\n\
913
- --{}--\r\n",
914
- boundary, file_content, boundary, boundary
915
- );
916
-
917
- let response = app
918
- .oneshot(
919
- Request::builder()
920
- .method("POST")
921
- .uri("/extract")
922
- .header("content-type", format!("multipart/form-data; boundary={}", boundary))
923
- .body(Body::from(body_content))
924
- .unwrap(),
925
- )
926
- .await
927
- .unwrap();
928
-
929
- assert_eq!(response.status(), StatusCode::OK);
930
- }
931
-
932
- /// Test extract endpoint with default MIME type (application/octet-stream).
933
- #[tokio::test]
934
- async fn test_extract_default_mime_type() {
935
- let app = create_router(ExtractionConfig::default());
936
-
937
- let boundary = "----boundary";
938
- let file_content = "Test content";
939
-
940
- let body_content = format!(
941
- "--{}\r\n\
942
- Content-Disposition: form-data; name=\"files\"; filename=\"test.txt\"\r\n\
943
- \r\n\
944
- {}\r\n\
945
- --{}--\r\n",
946
- boundary, file_content, boundary
947
- );
948
-
949
- let response = app
950
- .oneshot(
951
- Request::builder()
952
- .method("POST")
953
- .uri("/extract")
954
- .header("content-type", format!("multipart/form-data; boundary={}", boundary))
955
- .body(Body::from(body_content))
956
- .unwrap(),
957
- )
958
- .await
959
- .unwrap();
960
-
961
- assert!(
962
- response.status() == StatusCode::OK
963
- || response.status() == StatusCode::UNPROCESSABLE_ENTITY
964
- || response.status() == StatusCode::INTERNAL_SERVER_ERROR
965
- );
966
- }
1
+ //! Integration tests for the API module.
2
+
3
+ #![cfg(feature = "api")]
4
+
5
+ use axum::{
6
+ body::Body,
7
+ http::{Request, StatusCode},
8
+ };
9
+ use serde_json::json;
10
+ use tower::ServiceExt;
11
+
12
+ use kreuzberg::{
13
+ ExtractionConfig,
14
+ api::{HealthResponse, InfoResponse, create_router},
15
+ };
16
+
17
+ /// Test the health check endpoint.
18
+ #[tokio::test]
19
+ async fn test_health_endpoint() {
20
+ let app = create_router(ExtractionConfig::default());
21
+
22
+ let response = app
23
+ .oneshot(Request::builder().uri("/health").body(Body::empty()).unwrap())
24
+ .await
25
+ .unwrap();
26
+
27
+ assert_eq!(response.status(), StatusCode::OK);
28
+
29
+ let body = axum::body::to_bytes(response.into_body(), usize::MAX).await.unwrap();
30
+ let health: HealthResponse = serde_json::from_slice(&body).unwrap();
31
+
32
+ assert_eq!(health.status, "healthy");
33
+ assert!(!health.version.is_empty());
34
+ }
35
+
36
+ /// Test the info endpoint.
37
+ #[tokio::test]
38
+ async fn test_info_endpoint() {
39
+ let app = create_router(ExtractionConfig::default());
40
+
41
+ let response = app
42
+ .oneshot(Request::builder().uri("/info").body(Body::empty()).unwrap())
43
+ .await
44
+ .unwrap();
45
+
46
+ assert_eq!(response.status(), StatusCode::OK);
47
+
48
+ let body = axum::body::to_bytes(response.into_body(), usize::MAX).await.unwrap();
49
+ let info: InfoResponse = serde_json::from_slice(&body).unwrap();
50
+
51
+ assert!(!info.version.is_empty());
52
+ assert!(info.rust_backend);
53
+ }
54
+
55
+ /// Test extract endpoint with no files returns 400.
56
+ #[tokio::test]
57
+ async fn test_extract_no_files() {
58
+ let app = create_router(ExtractionConfig::default());
59
+
60
+ let boundary = "----boundary";
61
+ let body_content = format!("--{}--\r\n", boundary);
62
+
63
+ let response = app
64
+ .oneshot(
65
+ Request::builder()
66
+ .method("POST")
67
+ .uri("/extract")
68
+ .header("content-type", format!("multipart/form-data; boundary={}", boundary))
69
+ .body(Body::from(body_content))
70
+ .unwrap(),
71
+ )
72
+ .await
73
+ .unwrap();
74
+
75
+ assert_eq!(response.status(), StatusCode::BAD_REQUEST);
76
+ }
77
+
78
+ /// Test extract endpoint with a simple text file.
79
+ #[tokio::test]
80
+ async fn test_extract_text_file() {
81
+ let app = create_router(ExtractionConfig::default());
82
+
83
+ let boundary = "----boundary";
84
+ let file_content = "Hello, world!";
85
+
86
+ let body_content = format!(
87
+ "--{}\r\n\
88
+ Content-Disposition: form-data; name=\"files\"; filename=\"test.txt\"\r\n\
89
+ Content-Type: text/plain\r\n\
90
+ \r\n\
91
+ {}\r\n\
92
+ --{}--\r\n",
93
+ boundary, file_content, boundary
94
+ );
95
+
96
+ let response = app
97
+ .oneshot(
98
+ Request::builder()
99
+ .method("POST")
100
+ .uri("/extract")
101
+ .header("content-type", format!("multipart/form-data; boundary={}", boundary))
102
+ .body(Body::from(body_content))
103
+ .unwrap(),
104
+ )
105
+ .await
106
+ .unwrap();
107
+
108
+ assert_eq!(response.status(), StatusCode::OK);
109
+
110
+ let body = axum::body::to_bytes(response.into_body(), usize::MAX).await.unwrap();
111
+ let results: Vec<serde_json::Value> = serde_json::from_slice(&body).unwrap();
112
+
113
+ assert_eq!(results.len(), 1);
114
+ assert_eq!(results[0]["mime_type"], "text/plain");
115
+ assert!(results[0]["content"].as_str().unwrap().contains("Hello, world!"));
116
+
117
+ assert!(
118
+ results[0]["chunks"].is_null(),
119
+ "Chunks should be null without chunking config"
120
+ );
121
+ assert!(
122
+ results[0]["detected_languages"].is_null(),
123
+ "Language detection not enabled"
124
+ );
125
+ assert!(results[0]["tables"].is_array(), "Tables field should be present");
126
+ assert!(results[0]["metadata"].is_object(), "Metadata field should be present");
127
+ }
128
+
129
+ /// Test extract endpoint with JSON config.
130
+ #[tokio::test]
131
+ async fn test_extract_with_config() {
132
+ let app = create_router(ExtractionConfig::default());
133
+
134
+ let boundary = "----boundary";
135
+ let file_content = "Hello, world!";
136
+ let config = json!({
137
+ "force_ocr": false
138
+ });
139
+
140
+ let body_content = format!(
141
+ "--{}\r\n\
142
+ Content-Disposition: form-data; name=\"files\"; filename=\"test.txt\"\r\n\
143
+ Content-Type: text/plain\r\n\
144
+ \r\n\
145
+ {}\r\n\
146
+ --{}\r\n\
147
+ Content-Disposition: form-data; name=\"config\"\r\n\
148
+ \r\n\
149
+ {}\r\n\
150
+ --{}--\r\n",
151
+ boundary, file_content, boundary, config, boundary
152
+ );
153
+
154
+ let response = app
155
+ .oneshot(
156
+ Request::builder()
157
+ .method("POST")
158
+ .uri("/extract")
159
+ .header("content-type", format!("multipart/form-data; boundary={}", boundary))
160
+ .body(Body::from(body_content))
161
+ .unwrap(),
162
+ )
163
+ .await
164
+ .unwrap();
165
+
166
+ assert_eq!(response.status(), StatusCode::OK);
167
+
168
+ let body = axum::body::to_bytes(response.into_body(), usize::MAX).await.unwrap();
169
+ let results: Vec<serde_json::Value> = serde_json::from_slice(&body).unwrap();
170
+
171
+ assert_eq!(results.len(), 1);
172
+ assert_eq!(results[0]["mime_type"], "text/plain");
173
+ assert!(results[0]["content"].as_str().unwrap().contains("Hello, world!"));
174
+
175
+ assert!(
176
+ results[0]["chunks"].is_null(),
177
+ "Chunks should be null without chunking config"
178
+ );
179
+ assert!(
180
+ results[0]["detected_languages"].is_null(),
181
+ "Language detection not enabled"
182
+ );
183
+ assert!(results[0]["tables"].is_array(), "Tables field should be present");
184
+ assert!(results[0]["metadata"].is_object(), "Metadata field should be present");
185
+ }
186
+
187
+ /// Test extract endpoint with invalid config returns 400.
188
+ #[tokio::test]
189
+ async fn test_extract_invalid_config() {
190
+ let app = create_router(ExtractionConfig::default());
191
+
192
+ let boundary = "----boundary";
193
+ let file_content = "Hello, world!";
194
+ let invalid_config = "not valid json";
195
+
196
+ let body_content = format!(
197
+ "--{}\r\n\
198
+ Content-Disposition: form-data; name=\"files\"; filename=\"test.txt\"\r\n\
199
+ Content-Type: text/plain\r\n\
200
+ \r\n\
201
+ {}\r\n\
202
+ --{}\r\n\
203
+ Content-Disposition: form-data; name=\"config\"\r\n\
204
+ \r\n\
205
+ {}\r\n\
206
+ --{}--\r\n",
207
+ boundary, file_content, boundary, invalid_config, boundary
208
+ );
209
+
210
+ let response = app
211
+ .oneshot(
212
+ Request::builder()
213
+ .method("POST")
214
+ .uri("/extract")
215
+ .header("content-type", format!("multipart/form-data; boundary={}", boundary))
216
+ .body(Body::from(body_content))
217
+ .unwrap(),
218
+ )
219
+ .await
220
+ .unwrap();
221
+
222
+ assert_eq!(response.status(), StatusCode::BAD_REQUEST);
223
+ }
224
+
225
+ /// Test extract endpoint with multiple files.
226
+ #[tokio::test]
227
+ async fn test_extract_multiple_files() {
228
+ let app = create_router(ExtractionConfig::default());
229
+
230
+ let boundary = "----boundary";
231
+ let file1_content = "First file content";
232
+ let file2_content = "Second file content";
233
+
234
+ let body_content = format!(
235
+ "--{}\r\n\
236
+ Content-Disposition: form-data; name=\"files\"; filename=\"test1.txt\"\r\n\
237
+ Content-Type: text/plain\r\n\
238
+ \r\n\
239
+ {}\r\n\
240
+ --{}\r\n\
241
+ Content-Disposition: form-data; name=\"files\"; filename=\"test2.txt\"\r\n\
242
+ Content-Type: text/plain\r\n\
243
+ \r\n\
244
+ {}\r\n\
245
+ --{}--\r\n",
246
+ boundary, file1_content, boundary, file2_content, boundary
247
+ );
248
+
249
+ let response = app
250
+ .oneshot(
251
+ Request::builder()
252
+ .method("POST")
253
+ .uri("/extract")
254
+ .header("content-type", format!("multipart/form-data; boundary={}", boundary))
255
+ .body(Body::from(body_content))
256
+ .unwrap(),
257
+ )
258
+ .await
259
+ .unwrap();
260
+
261
+ assert_eq!(response.status(), StatusCode::OK);
262
+
263
+ let body = axum::body::to_bytes(response.into_body(), usize::MAX).await.unwrap();
264
+ let results: Vec<serde_json::Value> = serde_json::from_slice(&body).unwrap();
265
+
266
+ assert_eq!(results.len(), 2);
267
+ assert!(results[0]["content"].as_str().unwrap().contains("First file"));
268
+ assert!(results[1]["content"].as_str().unwrap().contains("Second file"));
269
+
270
+ for result in &results {
271
+ assert!(
272
+ result["chunks"].is_null(),
273
+ "Chunks should be null without chunking config"
274
+ );
275
+ assert!(result["detected_languages"].is_null(), "Language detection not enabled");
276
+ assert!(result["tables"].is_array(), "Tables field should be present");
277
+ assert!(result["metadata"].is_object(), "Metadata field should be present");
278
+ assert_eq!(result["mime_type"], "text/plain");
279
+ }
280
+ }
281
+
282
+ /// Test extract endpoint with markdown content.
283
+ #[tokio::test]
284
+ async fn test_extract_markdown_file() {
285
+ let app = create_router(ExtractionConfig::default());
286
+
287
+ let boundary = "----boundary";
288
+ let file_content = "# Heading\n\nSome **bold** text.";
289
+
290
+ let body_content = format!(
291
+ "--{}\r\n\
292
+ Content-Disposition: form-data; name=\"files\"; filename=\"test.md\"\r\n\
293
+ Content-Type: text/markdown\r\n\
294
+ \r\n\
295
+ {}\r\n\
296
+ --{}--\r\n",
297
+ boundary, file_content, boundary
298
+ );
299
+
300
+ let response = app
301
+ .oneshot(
302
+ Request::builder()
303
+ .method("POST")
304
+ .uri("/extract")
305
+ .header("content-type", format!("multipart/form-data; boundary={}", boundary))
306
+ .body(Body::from(body_content))
307
+ .unwrap(),
308
+ )
309
+ .await
310
+ .unwrap();
311
+
312
+ assert_eq!(response.status(), StatusCode::OK);
313
+
314
+ let body = axum::body::to_bytes(response.into_body(), usize::MAX).await.unwrap();
315
+ let results: Vec<serde_json::Value> = serde_json::from_slice(&body).unwrap();
316
+
317
+ assert_eq!(results.len(), 1);
318
+ assert_eq!(results[0]["mime_type"], "text/markdown");
319
+ assert!(results[0]["content"].as_str().unwrap().contains("Heading"));
320
+ }
321
+
322
+ /// Test extract endpoint with JSON content.
323
+ #[tokio::test]
324
+ async fn test_extract_json_file() {
325
+ let app = create_router(ExtractionConfig::default());
326
+
327
+ let boundary = "----boundary";
328
+ let file_content = r#"{"key": "value", "number": 42}"#;
329
+
330
+ let body_content = format!(
331
+ "--{}\r\n\
332
+ Content-Disposition: form-data; name=\"files\"; filename=\"test.json\"\r\n\
333
+ Content-Type: application/json\r\n\
334
+ \r\n\
335
+ {}\r\n\
336
+ --{}--\r\n",
337
+ boundary, file_content, boundary
338
+ );
339
+
340
+ let response = app
341
+ .oneshot(
342
+ Request::builder()
343
+ .method("POST")
344
+ .uri("/extract")
345
+ .header("content-type", format!("multipart/form-data; boundary={}", boundary))
346
+ .body(Body::from(body_content))
347
+ .unwrap(),
348
+ )
349
+ .await
350
+ .unwrap();
351
+
352
+ assert_eq!(response.status(), StatusCode::OK);
353
+
354
+ let body = axum::body::to_bytes(response.into_body(), usize::MAX).await.unwrap();
355
+ let results: Vec<serde_json::Value> = serde_json::from_slice(&body).unwrap();
356
+
357
+ assert_eq!(results.len(), 1);
358
+ assert_eq!(results[0]["mime_type"], "application/json");
359
+ }
360
+
361
+ /// Test extract endpoint with XML content.
362
+ #[tokio::test]
363
+ #[cfg(feature = "xml")]
364
+ async fn test_extract_xml_file() {
365
+ let app = create_router(ExtractionConfig::default());
366
+
367
+ let boundary = "----boundary";
368
+ let file_content = r#"<?xml version="1.0"?><root><item>test</item></root>"#;
369
+
370
+ let body_content = format!(
371
+ "--{}\r\n\
372
+ Content-Disposition: form-data; name=\"files\"; filename=\"test.xml\"\r\n\
373
+ Content-Type: application/xml\r\n\
374
+ \r\n\
375
+ {}\r\n\
376
+ --{}--\r\n",
377
+ boundary, file_content, boundary
378
+ );
379
+
380
+ let response = app
381
+ .oneshot(
382
+ Request::builder()
383
+ .method("POST")
384
+ .uri("/extract")
385
+ .header("content-type", format!("multipart/form-data; boundary={}", boundary))
386
+ .body(Body::from(body_content))
387
+ .unwrap(),
388
+ )
389
+ .await
390
+ .unwrap();
391
+
392
+ assert_eq!(response.status(), StatusCode::OK);
393
+
394
+ let body = axum::body::to_bytes(response.into_body(), usize::MAX).await.unwrap();
395
+ let results: Vec<serde_json::Value> = serde_json::from_slice(&body).unwrap();
396
+
397
+ assert_eq!(results.len(), 1);
398
+ assert_eq!(results[0]["mime_type"], "application/xml");
399
+ assert!(results[0]["content"].as_str().unwrap().contains("test"));
400
+ }
401
+
402
+ /// Test extract endpoint with HTML content.
403
+ #[tokio::test]
404
+ #[cfg(feature = "html")]
405
+ async fn test_extract_html_file() {
406
+ let app = create_router(ExtractionConfig::default());
407
+
408
+ let boundary = "----boundary";
409
+ let file_content = r#"<html><body><h1>Title</h1><p>Content</p></body></html>"#;
410
+
411
+ let body_content = format!(
412
+ "--{}\r\n\
413
+ Content-Disposition: form-data; name=\"files\"; filename=\"test.html\"\r\n\
414
+ Content-Type: text/html\r\n\
415
+ \r\n\
416
+ {}\r\n\
417
+ --{}--\r\n",
418
+ boundary, file_content, boundary
419
+ );
420
+
421
+ let response = app
422
+ .oneshot(
423
+ Request::builder()
424
+ .method("POST")
425
+ .uri("/extract")
426
+ .header("content-type", format!("multipart/form-data; boundary={}", boundary))
427
+ .body(Body::from(body_content))
428
+ .unwrap(),
429
+ )
430
+ .await
431
+ .unwrap();
432
+
433
+ assert_eq!(response.status(), StatusCode::OK);
434
+
435
+ let body = axum::body::to_bytes(response.into_body(), usize::MAX).await.unwrap();
436
+ let results: Vec<serde_json::Value> = serde_json::from_slice(&body).unwrap();
437
+
438
+ assert_eq!(results.len(), 1);
439
+ assert_eq!(results[0]["mime_type"], "text/html");
440
+ assert!(results[0]["content"].as_str().unwrap().contains("Title"));
441
+ }
442
+
443
+ /// Test extract endpoint with missing Content-Type header.
444
+ #[tokio::test]
445
+ async fn test_extract_missing_content_type() {
446
+ let app = create_router(ExtractionConfig::default());
447
+
448
+ let response = app
449
+ .oneshot(
450
+ Request::builder()
451
+ .method("POST")
452
+ .uri("/extract")
453
+ .body(Body::from("some data"))
454
+ .unwrap(),
455
+ )
456
+ .await
457
+ .unwrap();
458
+
459
+ assert!(response.status() == StatusCode::BAD_REQUEST || response.status() == StatusCode::UNSUPPORTED_MEDIA_TYPE);
460
+ }
461
+
462
+ /// Test extract endpoint with empty file.
463
+ #[tokio::test]
464
+ async fn test_extract_empty_file() {
465
+ let app = create_router(ExtractionConfig::default());
466
+
467
+ let boundary = "----boundary";
468
+ let file_content = "";
469
+
470
+ let body_content = format!(
471
+ "--{}\r\n\
472
+ Content-Disposition: form-data; name=\"files\"; filename=\"empty.txt\"\r\n\
473
+ Content-Type: text/plain\r\n\
474
+ \r\n\
475
+ {}\r\n\
476
+ --{}--\r\n",
477
+ boundary, file_content, boundary
478
+ );
479
+
480
+ let response = app
481
+ .oneshot(
482
+ Request::builder()
483
+ .method("POST")
484
+ .uri("/extract")
485
+ .header("content-type", format!("multipart/form-data; boundary={}", boundary))
486
+ .body(Body::from(body_content))
487
+ .unwrap(),
488
+ )
489
+ .await
490
+ .unwrap();
491
+
492
+ assert_eq!(response.status(), StatusCode::OK);
493
+
494
+ let body = axum::body::to_bytes(response.into_body(), usize::MAX).await.unwrap();
495
+ let results: Vec<serde_json::Value> = serde_json::from_slice(&body).unwrap();
496
+
497
+ assert_eq!(results.len(), 1);
498
+ assert_eq!(results[0]["mime_type"], "text/plain");
499
+ }
500
+
501
+ /// Test extract endpoint with unsupported MIME type.
502
+ #[tokio::test]
503
+ async fn test_extract_unsupported_mime_type() {
504
+ let app = create_router(ExtractionConfig::default());
505
+
506
+ let boundary = "----boundary";
507
+ let file_content = "Binary data";
508
+
509
+ let body_content = format!(
510
+ "--{}\r\n\
511
+ Content-Disposition: form-data; name=\"files\"; filename=\"test.bin\"\r\n\
512
+ Content-Type: application/x-unknown-binary\r\n\
513
+ \r\n\
514
+ {}\r\n\
515
+ --{}--\r\n",
516
+ boundary, file_content, boundary
517
+ );
518
+
519
+ let response = app
520
+ .oneshot(
521
+ Request::builder()
522
+ .method("POST")
523
+ .uri("/extract")
524
+ .header("content-type", format!("multipart/form-data; boundary={}", boundary))
525
+ .body(Body::from(body_content))
526
+ .unwrap(),
527
+ )
528
+ .await
529
+ .unwrap();
530
+
531
+ assert!(
532
+ response.status() == StatusCode::UNPROCESSABLE_ENTITY || response.status() == StatusCode::INTERNAL_SERVER_ERROR
533
+ );
534
+ }
535
+
536
+ /// Test extract endpoint without filename in multipart field.
537
+ #[tokio::test]
538
+ async fn test_extract_without_filename() {
539
+ let app = create_router(ExtractionConfig::default());
540
+
541
+ let boundary = "----boundary";
542
+ let file_content = "Test content";
543
+
544
+ let body_content = format!(
545
+ "--{}\r\n\
546
+ Content-Disposition: form-data; name=\"files\"\r\n\
547
+ Content-Type: text/plain\r\n\
548
+ \r\n\
549
+ {}\r\n\
550
+ --{}--\r\n",
551
+ boundary, file_content, boundary
552
+ );
553
+
554
+ let response = app
555
+ .oneshot(
556
+ Request::builder()
557
+ .method("POST")
558
+ .uri("/extract")
559
+ .header("content-type", format!("multipart/form-data; boundary={}", boundary))
560
+ .body(Body::from(body_content))
561
+ .unwrap(),
562
+ )
563
+ .await
564
+ .unwrap();
565
+
566
+ assert_eq!(response.status(), StatusCode::OK);
567
+ }
568
+
569
+ /// Test extract endpoint with malformed multipart data.
570
+ #[tokio::test]
571
+ async fn test_extract_malformed_multipart() {
572
+ let app = create_router(ExtractionConfig::default());
573
+
574
+ let boundary = "----boundary";
575
+ let body_content = format!("--{}\r\nmalformed data\r\n", boundary);
576
+
577
+ let response = app
578
+ .oneshot(
579
+ Request::builder()
580
+ .method("POST")
581
+ .uri("/extract")
582
+ .header("content-type", format!("multipart/form-data; boundary={}", boundary))
583
+ .body(Body::from(body_content))
584
+ .unwrap(),
585
+ )
586
+ .await
587
+ .unwrap();
588
+
589
+ assert!(response.status().is_client_error() || response.status().is_server_error());
590
+ }
591
+
592
+ /// Test CORS headers are present.
593
+ #[tokio::test]
594
+ async fn test_cors_headers() {
595
+ let app = create_router(ExtractionConfig::default());
596
+
597
+ let response = app
598
+ .oneshot(Request::builder().uri("/health").body(Body::empty()).unwrap())
599
+ .await
600
+ .unwrap();
601
+
602
+ assert_eq!(response.status(), StatusCode::OK);
603
+
604
+ let headers = response.headers();
605
+ assert!(headers.contains_key("access-control-allow-origin") || headers.contains_key("Access-Control-Allow-Origin"));
606
+ }
607
+
608
+ /// Test OPTIONS preflight request for CORS.
609
+ #[tokio::test]
610
+ async fn test_cors_preflight() {
611
+ let app = create_router(ExtractionConfig::default());
612
+
613
+ let response = app
614
+ .oneshot(
615
+ Request::builder()
616
+ .method("OPTIONS")
617
+ .uri("/extract")
618
+ .header("origin", "http://example.com")
619
+ .header("access-control-request-method", "POST")
620
+ .body(Body::empty())
621
+ .unwrap(),
622
+ )
623
+ .await
624
+ .unwrap();
625
+
626
+ assert!(response.status().is_success() || response.status() == StatusCode::NO_CONTENT);
627
+ }
628
+
629
+ /// Test error response format for validation errors.
630
+ #[tokio::test]
631
+ async fn test_error_response_format_validation() {
632
+ let app = create_router(ExtractionConfig::default());
633
+
634
+ let boundary = "----boundary";
635
+ let body_content = format!("--{}--\r\n", boundary);
636
+
637
+ let response = app
638
+ .oneshot(
639
+ Request::builder()
640
+ .method("POST")
641
+ .uri("/extract")
642
+ .header("content-type", format!("multipart/form-data; boundary={}", boundary))
643
+ .body(Body::from(body_content))
644
+ .unwrap(),
645
+ )
646
+ .await
647
+ .unwrap();
648
+
649
+ assert_eq!(response.status(), StatusCode::BAD_REQUEST);
650
+
651
+ let body = axum::body::to_bytes(response.into_body(), usize::MAX).await.unwrap();
652
+ let error: serde_json::Value = serde_json::from_slice(&body).unwrap();
653
+
654
+ assert!(error["error_type"].is_string());
655
+ assert!(error["message"].is_string());
656
+ assert_eq!(error["status_code"], 400);
657
+ assert_eq!(error["error_type"], "ValidationError");
658
+ }
659
+
660
+ /// Test error response format for parsing errors.
661
+ #[tokio::test]
662
+ async fn test_error_response_format_parsing() {
663
+ let app = create_router(ExtractionConfig::default());
664
+
665
+ let boundary = "----boundary";
666
+ let invalid_config = "not valid json";
667
+
668
+ let body_content = format!(
669
+ "--{}\r\n\
670
+ Content-Disposition: form-data; name=\"files\"; filename=\"test.txt\"\r\n\
671
+ Content-Type: text/plain\r\n\
672
+ \r\n\
673
+ content\r\n\
674
+ --{}\r\n\
675
+ Content-Disposition: form-data; name=\"config\"\r\n\
676
+ \r\n\
677
+ {}\r\n\
678
+ --{}--\r\n",
679
+ boundary, boundary, invalid_config, boundary
680
+ );
681
+
682
+ let response = app
683
+ .oneshot(
684
+ Request::builder()
685
+ .method("POST")
686
+ .uri("/extract")
687
+ .header("content-type", format!("multipart/form-data; boundary={}", boundary))
688
+ .body(Body::from(body_content))
689
+ .unwrap(),
690
+ )
691
+ .await
692
+ .unwrap();
693
+
694
+ assert_eq!(response.status(), StatusCode::BAD_REQUEST);
695
+
696
+ let body = axum::body::to_bytes(response.into_body(), usize::MAX).await.unwrap();
697
+ let error: serde_json::Value = serde_json::from_slice(&body).unwrap();
698
+
699
+ assert_eq!(error["error_type"], "ValidationError");
700
+ assert!(error["message"].as_str().unwrap().contains("configuration"));
701
+ }
702
+
703
+ /// Test 404 error for non-existent endpoint.
704
+ #[tokio::test]
705
+ async fn test_not_found_endpoint() {
706
+ let app = create_router(ExtractionConfig::default());
707
+
708
+ let response = app
709
+ .oneshot(Request::builder().uri("/nonexistent").body(Body::empty()).unwrap())
710
+ .await
711
+ .unwrap();
712
+
713
+ assert_eq!(response.status(), StatusCode::NOT_FOUND);
714
+ }
715
+
716
+ /// Test extract endpoint with very large text content.
717
+ #[tokio::test]
718
+ async fn test_extract_large_file() {
719
+ let app = create_router(ExtractionConfig::default());
720
+
721
+ let boundary = "----boundary";
722
+ let large_content = "A".repeat(1024 * 1024);
723
+
724
+ let body_content = format!(
725
+ "--{}\r\n\
726
+ Content-Disposition: form-data; name=\"files\"; filename=\"large.txt\"\r\n\
727
+ Content-Type: text/plain\r\n\
728
+ \r\n\
729
+ {}\r\n\
730
+ --{}--\r\n",
731
+ boundary, large_content, boundary
732
+ );
733
+
734
+ let response = app
735
+ .oneshot(
736
+ Request::builder()
737
+ .method("POST")
738
+ .uri("/extract")
739
+ .header("content-type", format!("multipart/form-data; boundary={}", boundary))
740
+ .body(Body::from(body_content))
741
+ .unwrap(),
742
+ )
743
+ .await
744
+ .unwrap();
745
+
746
+ assert_eq!(response.status(), StatusCode::OK);
747
+
748
+ let body = axum::body::to_bytes(response.into_body(), usize::MAX).await.unwrap();
749
+ let results: Vec<serde_json::Value> = serde_json::from_slice(&body).unwrap();
750
+
751
+ assert_eq!(results.len(), 1);
752
+ assert_eq!(results[0]["mime_type"], "text/plain");
753
+ }
754
+
755
+ /// Test concurrent requests to extract endpoint.
756
+ #[tokio::test]
757
+ async fn test_concurrent_requests() {
758
+ use tower::ServiceExt;
759
+
760
+ let app = create_router(ExtractionConfig::default());
761
+
762
+ let boundary = "----boundary";
763
+ let file_content = "Concurrent test";
764
+
765
+ let body_content = format!(
766
+ "--{}\r\n\
767
+ Content-Disposition: form-data; name=\"files\"; filename=\"test.txt\"\r\n\
768
+ Content-Type: text/plain\r\n\
769
+ \r\n\
770
+ {}\r\n\
771
+ --{}--\r\n",
772
+ boundary, file_content, boundary
773
+ );
774
+
775
+ let mut handles = vec![];
776
+
777
+ for _ in 0..5 {
778
+ let app_clone = app.clone();
779
+ let body_clone = body_content.clone();
780
+
781
+ let handle = tokio::spawn(async move {
782
+ app_clone
783
+ .oneshot(
784
+ Request::builder()
785
+ .method("POST")
786
+ .uri("/extract")
787
+ .header("content-type", format!("multipart/form-data; boundary={}", boundary))
788
+ .body(Body::from(body_clone))
789
+ .unwrap(),
790
+ )
791
+ .await
792
+ });
793
+
794
+ handles.push(handle);
795
+ }
796
+
797
+ for handle in handles {
798
+ let response = handle.await.unwrap().unwrap();
799
+ assert_eq!(response.status(), StatusCode::OK);
800
+ }
801
+ }
802
+
803
+ /// Test cache stats endpoint.
804
+ #[tokio::test]
805
+ async fn test_cache_stats_endpoint() {
806
+ let app = create_router(ExtractionConfig::default());
807
+
808
+ let response = app
809
+ .oneshot(Request::builder().uri("/cache/stats").body(Body::empty()).unwrap())
810
+ .await
811
+ .unwrap();
812
+
813
+ assert_eq!(response.status(), StatusCode::OK);
814
+
815
+ let body = axum::body::to_bytes(response.into_body(), usize::MAX).await.unwrap();
816
+ let stats: serde_json::Value = serde_json::from_slice(&body).unwrap();
817
+
818
+ assert!(stats["directory"].is_string());
819
+ assert!(stats["total_files"].is_number());
820
+ assert!(stats["total_size_mb"].is_number());
821
+ }
822
+
823
+ /// Test cache clear endpoint.
824
+ #[tokio::test]
825
+ async fn test_cache_clear_endpoint() {
826
+ let app = create_router(ExtractionConfig::default());
827
+
828
+ let response = app
829
+ .oneshot(
830
+ Request::builder()
831
+ .method("DELETE")
832
+ .uri("/cache/clear")
833
+ .body(Body::empty())
834
+ .unwrap(),
835
+ )
836
+ .await
837
+ .unwrap();
838
+
839
+ assert_eq!(response.status(), StatusCode::OK);
840
+
841
+ let body = axum::body::to_bytes(response.into_body(), usize::MAX).await.unwrap();
842
+ let clear_result: serde_json::Value = serde_json::from_slice(&body).unwrap();
843
+
844
+ assert!(clear_result["directory"].is_string());
845
+ assert!(clear_result["removed_files"].is_number());
846
+ assert!(clear_result["freed_mb"].is_number());
847
+ }
848
+
849
+ /// Test extract endpoint with mixed content types.
850
+ #[tokio::test]
851
+ async fn test_extract_mixed_content_types() {
852
+ let app = create_router(ExtractionConfig::default());
853
+
854
+ let boundary = "----boundary";
855
+ let text_content = "Text file";
856
+ let json_content = r#"{"test": "data"}"#;
857
+
858
+ let body_content = format!(
859
+ "--{}\r\n\
860
+ Content-Disposition: form-data; name=\"files\"; filename=\"test.txt\"\r\n\
861
+ Content-Type: text/plain\r\n\
862
+ \r\n\
863
+ {}\r\n\
864
+ --{}\r\n\
865
+ Content-Disposition: form-data; name=\"files\"; filename=\"test.json\"\r\n\
866
+ Content-Type: application/json\r\n\
867
+ \r\n\
868
+ {}\r\n\
869
+ --{}--\r\n",
870
+ boundary, text_content, boundary, json_content, boundary
871
+ );
872
+
873
+ let response = app
874
+ .oneshot(
875
+ Request::builder()
876
+ .method("POST")
877
+ .uri("/extract")
878
+ .header("content-type", format!("multipart/form-data; boundary={}", boundary))
879
+ .body(Body::from(body_content))
880
+ .unwrap(),
881
+ )
882
+ .await
883
+ .unwrap();
884
+
885
+ assert_eq!(response.status(), StatusCode::OK);
886
+
887
+ let body = axum::body::to_bytes(response.into_body(), usize::MAX).await.unwrap();
888
+ let results: Vec<serde_json::Value> = serde_json::from_slice(&body).unwrap();
889
+
890
+ assert_eq!(results.len(), 2);
891
+ assert_eq!(results[0]["mime_type"], "text/plain");
892
+ assert_eq!(results[1]["mime_type"], "application/json");
893
+ }
894
+
895
+ /// Test extract endpoint with unknown field in multipart.
896
+ #[tokio::test]
897
+ async fn test_extract_unknown_multipart_field() {
898
+ let app = create_router(ExtractionConfig::default());
899
+
900
+ let boundary = "----boundary";
901
+ let file_content = "Test content";
902
+
903
+ let body_content = format!(
904
+ "--{}\r\n\
905
+ Content-Disposition: form-data; name=\"files\"; filename=\"test.txt\"\r\n\
906
+ Content-Type: text/plain\r\n\
907
+ \r\n\
908
+ {}\r\n\
909
+ --{}\r\n\
910
+ Content-Disposition: form-data; name=\"unknown_field\"\r\n\
911
+ \r\n\
912
+ some value\r\n\
913
+ --{}--\r\n",
914
+ boundary, file_content, boundary, boundary
915
+ );
916
+
917
+ let response = app
918
+ .oneshot(
919
+ Request::builder()
920
+ .method("POST")
921
+ .uri("/extract")
922
+ .header("content-type", format!("multipart/form-data; boundary={}", boundary))
923
+ .body(Body::from(body_content))
924
+ .unwrap(),
925
+ )
926
+ .await
927
+ .unwrap();
928
+
929
+ assert_eq!(response.status(), StatusCode::OK);
930
+ }
931
+
932
+ /// Test extract endpoint with default MIME type (application/octet-stream).
933
+ #[tokio::test]
934
+ async fn test_extract_default_mime_type() {
935
+ let app = create_router(ExtractionConfig::default());
936
+
937
+ let boundary = "----boundary";
938
+ let file_content = "Test content";
939
+
940
+ let body_content = format!(
941
+ "--{}\r\n\
942
+ Content-Disposition: form-data; name=\"files\"; filename=\"test.txt\"\r\n\
943
+ \r\n\
944
+ {}\r\n\
945
+ --{}--\r\n",
946
+ boundary, file_content, boundary
947
+ );
948
+
949
+ let response = app
950
+ .oneshot(
951
+ Request::builder()
952
+ .method("POST")
953
+ .uri("/extract")
954
+ .header("content-type", format!("multipart/form-data; boundary={}", boundary))
955
+ .body(Body::from(body_content))
956
+ .unwrap(),
957
+ )
958
+ .await
959
+ .unwrap();
960
+
961
+ assert!(
962
+ response.status() == StatusCode::OK
963
+ || response.status() == StatusCode::UNPROCESSABLE_ENTITY
964
+ || response.status() == StatusCode::INTERNAL_SERVER_ERROR
965
+ );
966
+ }
967
+
968
+ /// Test size limits configuration with custom limits.
969
+ #[tokio::test]
970
+ async fn test_size_limits_custom_limits() {
971
+ use kreuzberg::api::{ApiSizeLimits, create_router_with_limits};
972
+
973
+ let config = ExtractionConfig::default();
974
+ let limits = ApiSizeLimits::from_mb(50, 50);
975
+ let app = create_router_with_limits(config, limits);
976
+
977
+ assert_eq!(limits.max_request_body_bytes, 50 * 1024 * 1024);
978
+ assert_eq!(limits.max_multipart_field_bytes, 50 * 1024 * 1024);
979
+
980
+ let boundary = "----boundary";
981
+ let file_content = "Test";
982
+
983
+ let body_content = format!(
984
+ "--{}\r\n\
985
+ Content-Disposition: form-data; name=\"files\"; filename=\"test.txt\"\r\n\
986
+ Content-Type: text/plain\r\n\
987
+ \r\n\
988
+ {}\r\n\
989
+ --{}--\r\n",
990
+ boundary, file_content, boundary
991
+ );
992
+
993
+ let response = app
994
+ .oneshot(
995
+ Request::builder()
996
+ .method("POST")
997
+ .uri("/extract")
998
+ .header("content-type", format!("multipart/form-data; boundary={}", boundary))
999
+ .body(Body::from(body_content))
1000
+ .unwrap(),
1001
+ )
1002
+ .await
1003
+ .unwrap();
1004
+
1005
+ assert_eq!(response.status(), StatusCode::OK);
1006
+ }
1007
+
1008
+ /// Test size limits with asymmetric limits (different request vs field sizes).
1009
+ #[tokio::test]
1010
+ async fn test_size_limits_asymmetric() {
1011
+ use kreuzberg::api::{ApiSizeLimits, create_router_with_limits};
1012
+
1013
+ let config = ExtractionConfig::default();
1014
+ let limits = ApiSizeLimits::new(100 * 1024 * 1024, 50 * 1024 * 1024);
1015
+ let _app = create_router_with_limits(config, limits);
1016
+
1017
+ assert_eq!(limits.max_request_body_bytes, 100 * 1024 * 1024);
1018
+ assert_eq!(limits.max_multipart_field_bytes, 50 * 1024 * 1024);
1019
+ }
1020
+
1021
+ /// Test default size limits are 100 MB.
1022
+ #[test]
1023
+ fn test_default_size_limits_100mb() {
1024
+ use kreuzberg::api::ApiSizeLimits;
1025
+
1026
+ let limits = ApiSizeLimits::default();
1027
+
1028
+ assert_eq!(limits.max_request_body_bytes, 100 * 1024 * 1024);
1029
+ assert_eq!(limits.max_multipart_field_bytes, 100 * 1024 * 1024);
1030
+ }
1031
+
1032
+ /// Test ApiSizeLimits from_mb convenience method.
1033
+ #[test]
1034
+ fn test_api_size_limits_from_mb() {
1035
+ use kreuzberg::api::ApiSizeLimits;
1036
+
1037
+ let limits = ApiSizeLimits::from_mb(100, 50);
1038
+ assert_eq!(limits.max_request_body_bytes, 100 * 1024 * 1024);
1039
+ assert_eq!(limits.max_multipart_field_bytes, 50 * 1024 * 1024);
1040
+ }
1041
+
1042
+ /// Test ApiSizeLimits new method.
1043
+ #[test]
1044
+ fn test_api_size_limits_new() {
1045
+ use kreuzberg::api::ApiSizeLimits;
1046
+
1047
+ let limits = ApiSizeLimits::new(1_000_000, 500_000);
1048
+ assert_eq!(limits.max_request_body_bytes, 1_000_000);
1049
+ assert_eq!(limits.max_multipart_field_bytes, 500_000);
1050
+ }
1051
+
1052
+ /// Test extracting a file larger than 2MB (issue #248).
1053
+ ///
1054
+ /// This test verifies that the API can handle files larger than Axum's old
1055
+ /// default multipart field limit of 2MB. The issue reported files >2MB being
1056
+ /// rejected with HTTP 400, which was due to Axum's default `DefaultBodyLimit`.
1057
+ ///
1058
+ /// With the fix, we now explicitly set `DefaultBodyLimit::max()` to match our
1059
+ /// configured size limits (default 10 GB), allowing large file uploads.
1060
+ #[tokio::test]
1061
+ async fn test_extract_file_larger_than_2mb() {
1062
+ let app = create_router(ExtractionConfig::default());
1063
+
1064
+ let boundary = "----boundary";
1065
+ let file_content = "A".repeat(3 * 1024 * 1024);
1066
+
1067
+ let body_content = format!(
1068
+ "--{}\r\n\
1069
+ Content-Disposition: form-data; name=\"files\"; filename=\"large.txt\"\r\n\
1070
+ Content-Type: text/plain\r\n\
1071
+ \r\n\
1072
+ {}\r\n\
1073
+ --{}--\r\n",
1074
+ boundary, file_content, boundary
1075
+ );
1076
+
1077
+ let response = app
1078
+ .oneshot(
1079
+ Request::builder()
1080
+ .method("POST")
1081
+ .uri("/extract")
1082
+ .header("content-type", format!("multipart/form-data; boundary={}", boundary))
1083
+ .body(Body::from(body_content))
1084
+ .unwrap(),
1085
+ )
1086
+ .await
1087
+ .unwrap();
1088
+
1089
+ assert_eq!(
1090
+ response.status(),
1091
+ StatusCode::OK,
1092
+ "3MB file should be accepted. If this fails with 400 or 413, the size limit fix is not working correctly."
1093
+ );
1094
+
1095
+ let body = axum::body::to_bytes(response.into_body(), usize::MAX).await.unwrap();
1096
+ let results: Vec<serde_json::Value> = serde_json::from_slice(&body).unwrap();
1097
+
1098
+ assert_eq!(results.len(), 1);
1099
+ assert_eq!(results[0]["mime_type"], "text/plain");
1100
+ assert!(results[0]["content"].as_str().unwrap().contains("A"));
1101
+ }
1102
+
1103
+ /// Test extracting a 2MB file (just above the old Axum limit).
1104
+ ///
1105
+ /// This tests the boundary case at exactly 2MB, which was the old Axum default limit.
1106
+ /// Files at this size should now be accepted with the DefaultBodyLimit::max() fix.
1107
+ #[tokio::test]
1108
+ async fn test_extract_2mb_file() {
1109
+ let app = create_router(ExtractionConfig::default());
1110
+
1111
+ let boundary = "----boundary";
1112
+ let file_content = "X".repeat(2 * 1024 * 1024);
1113
+
1114
+ let body_content = format!(
1115
+ "--{}\r\n\
1116
+ Content-Disposition: form-data; name=\"files\"; filename=\"boundary.txt\"\r\n\
1117
+ Content-Type: text/plain\r\n\
1118
+ \r\n\
1119
+ {}\r\n\
1120
+ --{}--\r\n",
1121
+ boundary, file_content, boundary
1122
+ );
1123
+
1124
+ let response = app
1125
+ .oneshot(
1126
+ Request::builder()
1127
+ .method("POST")
1128
+ .uri("/extract")
1129
+ .header("content-type", format!("multipart/form-data; boundary={}", boundary))
1130
+ .body(Body::from(body_content))
1131
+ .unwrap(),
1132
+ )
1133
+ .await
1134
+ .unwrap();
1135
+
1136
+ assert_eq!(
1137
+ response.status(),
1138
+ StatusCode::OK,
1139
+ "2MB file should be accepted (boundary case)"
1140
+ );
1141
+
1142
+ let body = axum::body::to_bytes(response.into_body(), usize::MAX).await.unwrap();
1143
+ let results: Vec<serde_json::Value> = serde_json::from_slice(&body).unwrap();
1144
+
1145
+ assert_eq!(results.len(), 1);
1146
+ assert_eq!(results[0]["mime_type"], "text/plain");
1147
+ assert!(results[0]["content"].as_str().unwrap().contains("X"));
1148
+ }
1149
+
1150
+ /// Test extracting a 5MB file.
1151
+ ///
1152
+ /// Verifies that files significantly larger than the old 2MB limit work correctly.
1153
+ #[tokio::test]
1154
+ async fn test_extract_5mb_file() {
1155
+ let app = create_router(ExtractionConfig::default());
1156
+
1157
+ let boundary = "----boundary";
1158
+ let file_content = "B".repeat(5 * 1024 * 1024);
1159
+
1160
+ let body_content = format!(
1161
+ "--{}\r\n\
1162
+ Content-Disposition: form-data; name=\"files\"; filename=\"medium.txt\"\r\n\
1163
+ Content-Type: text/plain\r\n\
1164
+ \r\n\
1165
+ {}\r\n\
1166
+ --{}--\r\n",
1167
+ boundary, file_content, boundary
1168
+ );
1169
+
1170
+ let response = app
1171
+ .oneshot(
1172
+ Request::builder()
1173
+ .method("POST")
1174
+ .uri("/extract")
1175
+ .header("content-type", format!("multipart/form-data; boundary={}", boundary))
1176
+ .body(Body::from(body_content))
1177
+ .unwrap(),
1178
+ )
1179
+ .await
1180
+ .unwrap();
1181
+
1182
+ assert_eq!(response.status(), StatusCode::OK, "5MB file should be accepted");
1183
+
1184
+ let body = axum::body::to_bytes(response.into_body(), usize::MAX).await.unwrap();
1185
+ let results: Vec<serde_json::Value> = serde_json::from_slice(&body).unwrap();
1186
+
1187
+ assert_eq!(results.len(), 1);
1188
+ assert_eq!(results[0]["mime_type"], "text/plain");
1189
+ assert!(results[0]["content"].as_str().unwrap().contains("B"));
1190
+ }
1191
+
1192
+ /// Test extracting a 10MB file.
1193
+ ///
1194
+ /// Verifies that moderately large files (10MB) are handled correctly.
1195
+ #[tokio::test]
1196
+ async fn test_extract_10mb_file() {
1197
+ let app = create_router(ExtractionConfig::default());
1198
+
1199
+ let boundary = "----boundary";
1200
+ let file_content = "C".repeat(10 * 1024 * 1024);
1201
+
1202
+ let body_content = format!(
1203
+ "--{}\r\n\
1204
+ Content-Disposition: form-data; name=\"files\"; filename=\"large.txt\"\r\n\
1205
+ Content-Type: text/plain\r\n\
1206
+ \r\n\
1207
+ {}\r\n\
1208
+ --{}--\r\n",
1209
+ boundary, file_content, boundary
1210
+ );
1211
+
1212
+ let response = app
1213
+ .oneshot(
1214
+ Request::builder()
1215
+ .method("POST")
1216
+ .uri("/extract")
1217
+ .header("content-type", format!("multipart/form-data; boundary={}", boundary))
1218
+ .body(Body::from(body_content))
1219
+ .unwrap(),
1220
+ )
1221
+ .await
1222
+ .unwrap();
1223
+
1224
+ assert_eq!(response.status(), StatusCode::OK, "10MB file should be accepted");
1225
+
1226
+ let body = axum::body::to_bytes(response.into_body(), usize::MAX).await.unwrap();
1227
+ let results: Vec<serde_json::Value> = serde_json::from_slice(&body).unwrap();
1228
+
1229
+ assert_eq!(results.len(), 1);
1230
+ assert_eq!(results[0]["mime_type"], "text/plain");
1231
+ assert!(results[0]["content"].as_str().unwrap().contains("C"));
1232
+ }
1233
+
1234
+ /// Test extracting a 50MB file (half the default limit).
1235
+ ///
1236
+ /// Verifies that very large files (50MB) are handled correctly,
1237
+ /// well within the 100MB default limit.
1238
+ #[tokio::test]
1239
+ async fn test_extract_50mb_file() {
1240
+ let app = create_router(ExtractionConfig::default());
1241
+
1242
+ let boundary = "----boundary";
1243
+ let file_content = "D".repeat(50 * 1024 * 1024);
1244
+
1245
+ let body_content = format!(
1246
+ "--{}\r\n\
1247
+ Content-Disposition: form-data; name=\"files\"; filename=\"very_large.txt\"\r\n\
1248
+ Content-Type: text/plain\r\n\
1249
+ \r\n\
1250
+ {}\r\n\
1251
+ --{}--\r\n",
1252
+ boundary, file_content, boundary
1253
+ );
1254
+
1255
+ let response = app
1256
+ .oneshot(
1257
+ Request::builder()
1258
+ .method("POST")
1259
+ .uri("/extract")
1260
+ .header("content-type", format!("multipart/form-data; boundary={}", boundary))
1261
+ .body(Body::from(body_content))
1262
+ .unwrap(),
1263
+ )
1264
+ .await
1265
+ .unwrap();
1266
+
1267
+ assert_eq!(response.status(), StatusCode::OK, "50MB file should be accepted");
1268
+
1269
+ let body = axum::body::to_bytes(response.into_body(), usize::MAX).await.unwrap();
1270
+ let results: Vec<serde_json::Value> = serde_json::from_slice(&body).unwrap();
1271
+
1272
+ assert_eq!(results.len(), 1);
1273
+ assert_eq!(results[0]["mime_type"], "text/plain");
1274
+ assert!(results[0]["content"].as_str().unwrap().contains("D"));
1275
+ }
1276
+
1277
+ /// Test extracting a 90MB file (near the 100MB default limit).
1278
+ ///
1279
+ /// Verifies that very large files close to the default limit (90MB out of 100MB)
1280
+ /// are handled correctly. This tests the upper boundary of the default configuration.
1281
+ #[tokio::test]
1282
+ async fn test_extract_90mb_file() {
1283
+ let app = create_router(ExtractionConfig::default());
1284
+
1285
+ let boundary = "----boundary";
1286
+ let file_content = "E".repeat(90 * 1024 * 1024);
1287
+
1288
+ let body_content = format!(
1289
+ "--{}\r\n\
1290
+ Content-Disposition: form-data; name=\"files\"; filename=\"huge.txt\"\r\n\
1291
+ Content-Type: text/plain\r\n\
1292
+ \r\n\
1293
+ {}\r\n\
1294
+ --{}--\r\n",
1295
+ boundary, file_content, boundary
1296
+ );
1297
+
1298
+ let response = app
1299
+ .oneshot(
1300
+ Request::builder()
1301
+ .method("POST")
1302
+ .uri("/extract")
1303
+ .header("content-type", format!("multipart/form-data; boundary={}", boundary))
1304
+ .body(Body::from(body_content))
1305
+ .unwrap(),
1306
+ )
1307
+ .await
1308
+ .unwrap();
1309
+
1310
+ assert_eq!(
1311
+ response.status(),
1312
+ StatusCode::OK,
1313
+ "90MB file should be accepted (within default 100MB limit)"
1314
+ );
1315
+
1316
+ let body = axum::body::to_bytes(response.into_body(), usize::MAX).await.unwrap();
1317
+ let results: Vec<serde_json::Value> = serde_json::from_slice(&body).unwrap();
1318
+
1319
+ assert_eq!(results.len(), 1);
1320
+ assert_eq!(results[0]["mime_type"], "text/plain");
1321
+ assert!(results[0]["content"].as_str().unwrap().contains("E"));
1322
+ }
1323
+
1324
+ /// Test extracting a file over the 100MB default limit (HTTP 400/413).
1325
+ ///
1326
+ /// Verifies that files exceeding the 100MB default limit are rejected
1327
+ /// with a 4xx error (typically HTTP 400 from tower-http RequestBodyLimitLayer or 413)
1328
+ /// rather than silently failing or accepting the request.
1329
+ #[tokio::test]
1330
+ async fn test_extract_file_over_default_limit() {
1331
+ let app = create_router(ExtractionConfig::default());
1332
+
1333
+ let boundary = "----boundary";
1334
+ let file_content = "F".repeat(101 * 1024 * 1024);
1335
+
1336
+ let body_content = format!(
1337
+ "--{}\r\n\
1338
+ Content-Disposition: form-data; name=\"files\"; filename=\"over_limit.txt\"\r\n\
1339
+ Content-Type: text/plain\r\n\
1340
+ \r\n\
1341
+ {}\r\n\
1342
+ --{}--\r\n",
1343
+ boundary, file_content, boundary
1344
+ );
1345
+
1346
+ let response = app
1347
+ .oneshot(
1348
+ Request::builder()
1349
+ .method("POST")
1350
+ .uri("/extract")
1351
+ .header("content-type", format!("multipart/form-data; boundary={}", boundary))
1352
+ .body(Body::from(body_content))
1353
+ .unwrap(),
1354
+ )
1355
+ .await
1356
+ .unwrap();
1357
+
1358
+ assert!(
1359
+ response.status() == StatusCode::BAD_REQUEST || response.status() == StatusCode::PAYLOAD_TOO_LARGE,
1360
+ "101MB file should be rejected with HTTP 400 or 413 (over 100MB default limit), got {}",
1361
+ response.status()
1362
+ );
1363
+ }
1364
+
1365
+ /// Test extracting multiple large files within limit.
1366
+ ///
1367
+ /// Verifies that multiple large files can be uploaded together as long as
1368
+ /// the total size is within the default 100MB limit.
1369
+ #[tokio::test]
1370
+ async fn test_extract_multiple_large_files_within_limit() {
1371
+ let app = create_router(ExtractionConfig::default());
1372
+
1373
+ let boundary = "----boundary";
1374
+ let file1_content = "G".repeat(25 * 1024 * 1024);
1375
+ let file2_content = "H".repeat(25 * 1024 * 1024);
1376
+ let file3_content = "I".repeat(25 * 1024 * 1024);
1377
+
1378
+ let body_content = format!(
1379
+ "--{}\r\n\
1380
+ Content-Disposition: form-data; name=\"files\"; filename=\"file1.txt\"\r\n\
1381
+ Content-Type: text/plain\r\n\
1382
+ \r\n\
1383
+ {}\r\n\
1384
+ --{}\r\n\
1385
+ Content-Disposition: form-data; name=\"files\"; filename=\"file2.txt\"\r\n\
1386
+ Content-Type: text/plain\r\n\
1387
+ \r\n\
1388
+ {}\r\n\
1389
+ --{}\r\n\
1390
+ Content-Disposition: form-data; name=\"files\"; filename=\"file3.txt\"\r\n\
1391
+ Content-Type: text/plain\r\n\
1392
+ \r\n\
1393
+ {}\r\n\
1394
+ --{}--\r\n",
1395
+ boundary, file1_content, boundary, file2_content, boundary, file3_content, boundary
1396
+ );
1397
+
1398
+ let response = app
1399
+ .oneshot(
1400
+ Request::builder()
1401
+ .method("POST")
1402
+ .uri("/extract")
1403
+ .header("content-type", format!("multipart/form-data; boundary={}", boundary))
1404
+ .body(Body::from(body_content))
1405
+ .unwrap(),
1406
+ )
1407
+ .await
1408
+ .unwrap();
1409
+
1410
+ assert_eq!(
1411
+ response.status(),
1412
+ StatusCode::OK,
1413
+ "Multiple files totaling 75MB should be accepted"
1414
+ );
1415
+
1416
+ let body = axum::body::to_bytes(response.into_body(), usize::MAX).await.unwrap();
1417
+ let results: Vec<serde_json::Value> = serde_json::from_slice(&body).unwrap();
1418
+
1419
+ assert_eq!(results.len(), 3, "Should have 3 results");
1420
+ for result in &results {
1421
+ assert_eq!(result["mime_type"], "text/plain");
1422
+ }
1423
+ assert!(results[0]["content"].as_str().unwrap().contains("G"));
1424
+ assert!(results[1]["content"].as_str().unwrap().contains("H"));
1425
+ assert!(results[2]["content"].as_str().unwrap().contains("I"));
1426
+ }
1427
+
1428
+ /// Test extracting multiple large files exceeding limit (HTTP 400/413).
1429
+ ///
1430
+ /// Verifies that when multiple files together exceed the 100MB default limit,
1431
+ /// the request is rejected with a 4xx error (typically HTTP 400 or 413).
1432
+ #[tokio::test]
1433
+ async fn test_extract_multiple_large_files_exceeding_limit() {
1434
+ let app = create_router(ExtractionConfig::default());
1435
+
1436
+ let boundary = "----boundary";
1437
+ let file1_content = "J".repeat(50 * 1024 * 1024);
1438
+ let file2_content = "K".repeat(55 * 1024 * 1024);
1439
+
1440
+ let body_content = format!(
1441
+ "--{}\r\n\
1442
+ Content-Disposition: form-data; name=\"files\"; filename=\"file1.txt\"\r\n\
1443
+ Content-Type: text/plain\r\n\
1444
+ \r\n\
1445
+ {}\r\n\
1446
+ --{}\r\n\
1447
+ Content-Disposition: form-data; name=\"files\"; filename=\"file2.txt\"\r\n\
1448
+ Content-Type: text/plain\r\n\
1449
+ \r\n\
1450
+ {}\r\n\
1451
+ --{}--\r\n",
1452
+ boundary, file1_content, boundary, file2_content, boundary
1453
+ );
1454
+
1455
+ let response = app
1456
+ .oneshot(
1457
+ Request::builder()
1458
+ .method("POST")
1459
+ .uri("/extract")
1460
+ .header("content-type", format!("multipart/form-data; boundary={}", boundary))
1461
+ .body(Body::from(body_content))
1462
+ .unwrap(),
1463
+ )
1464
+ .await
1465
+ .unwrap();
1466
+
1467
+ assert!(
1468
+ response.status() == StatusCode::BAD_REQUEST || response.status() == StatusCode::PAYLOAD_TOO_LARGE,
1469
+ "Multiple files totaling 105MB should be rejected with HTTP 400 or 413, got {}",
1470
+ response.status()
1471
+ );
1472
+ }