kreuzberg 4.0.0.pre.rc.6
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.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/.rspec +3 -0
- data/.rubocop.yaml +1 -0
- data/.rubocop.yml +538 -0
- data/Gemfile +8 -0
- data/Gemfile.lock +157 -0
- data/README.md +426 -0
- data/Rakefile +25 -0
- data/Steepfile +47 -0
- data/examples/async_patterns.rb +341 -0
- data/ext/kreuzberg_rb/extconf.rb +45 -0
- data/ext/kreuzberg_rb/native/Cargo.lock +6535 -0
- data/ext/kreuzberg_rb/native/Cargo.toml +44 -0
- data/ext/kreuzberg_rb/native/README.md +425 -0
- data/ext/kreuzberg_rb/native/build.rs +15 -0
- data/ext/kreuzberg_rb/native/include/ieeefp.h +11 -0
- data/ext/kreuzberg_rb/native/include/msvc_compat/strings.h +14 -0
- data/ext/kreuzberg_rb/native/include/strings.h +20 -0
- data/ext/kreuzberg_rb/native/include/unistd.h +47 -0
- data/ext/kreuzberg_rb/native/src/lib.rs +2998 -0
- data/extconf.rb +28 -0
- data/kreuzberg.gemspec +148 -0
- data/lib/kreuzberg/api_proxy.rb +142 -0
- data/lib/kreuzberg/cache_api.rb +46 -0
- data/lib/kreuzberg/cli.rb +55 -0
- data/lib/kreuzberg/cli_proxy.rb +127 -0
- data/lib/kreuzberg/config.rb +691 -0
- data/lib/kreuzberg/error_context.rb +32 -0
- data/lib/kreuzberg/errors.rb +118 -0
- data/lib/kreuzberg/extraction_api.rb +85 -0
- data/lib/kreuzberg/mcp_proxy.rb +186 -0
- data/lib/kreuzberg/ocr_backend_protocol.rb +113 -0
- data/lib/kreuzberg/post_processor_protocol.rb +86 -0
- data/lib/kreuzberg/result.rb +216 -0
- data/lib/kreuzberg/setup_lib_path.rb +80 -0
- data/lib/kreuzberg/validator_protocol.rb +89 -0
- data/lib/kreuzberg/version.rb +5 -0
- data/lib/kreuzberg.rb +103 -0
- data/sig/kreuzberg/internal.rbs +184 -0
- data/sig/kreuzberg.rbs +520 -0
- data/spec/binding/cache_spec.rb +227 -0
- data/spec/binding/cli_proxy_spec.rb +85 -0
- data/spec/binding/cli_spec.rb +55 -0
- data/spec/binding/config_spec.rb +345 -0
- data/spec/binding/config_validation_spec.rb +283 -0
- data/spec/binding/error_handling_spec.rb +213 -0
- data/spec/binding/errors_spec.rb +66 -0
- data/spec/binding/plugins/ocr_backend_spec.rb +307 -0
- data/spec/binding/plugins/postprocessor_spec.rb +269 -0
- data/spec/binding/plugins/validator_spec.rb +274 -0
- data/spec/fixtures/config.toml +39 -0
- data/spec/fixtures/config.yaml +41 -0
- data/spec/fixtures/invalid_config.toml +4 -0
- data/spec/smoke/package_spec.rb +178 -0
- data/spec/spec_helper.rb +42 -0
- data/vendor/kreuzberg/Cargo.toml +204 -0
- data/vendor/kreuzberg/README.md +175 -0
- data/vendor/kreuzberg/benches/otel_overhead.rs +48 -0
- data/vendor/kreuzberg/build.rs +474 -0
- data/vendor/kreuzberg/src/api/error.rs +81 -0
- data/vendor/kreuzberg/src/api/handlers.rs +199 -0
- data/vendor/kreuzberg/src/api/mod.rs +79 -0
- data/vendor/kreuzberg/src/api/server.rs +353 -0
- data/vendor/kreuzberg/src/api/types.rs +170 -0
- data/vendor/kreuzberg/src/cache/mod.rs +1167 -0
- data/vendor/kreuzberg/src/chunking/mod.rs +677 -0
- data/vendor/kreuzberg/src/core/batch_mode.rs +95 -0
- data/vendor/kreuzberg/src/core/config.rs +1032 -0
- data/vendor/kreuzberg/src/core/extractor.rs +1024 -0
- data/vendor/kreuzberg/src/core/io.rs +329 -0
- data/vendor/kreuzberg/src/core/mime.rs +605 -0
- data/vendor/kreuzberg/src/core/mod.rs +45 -0
- data/vendor/kreuzberg/src/core/pipeline.rs +984 -0
- data/vendor/kreuzberg/src/embeddings.rs +432 -0
- data/vendor/kreuzberg/src/error.rs +431 -0
- data/vendor/kreuzberg/src/extraction/archive.rs +954 -0
- data/vendor/kreuzberg/src/extraction/docx.rs +40 -0
- data/vendor/kreuzberg/src/extraction/email.rs +854 -0
- data/vendor/kreuzberg/src/extraction/excel.rs +688 -0
- data/vendor/kreuzberg/src/extraction/html.rs +553 -0
- data/vendor/kreuzberg/src/extraction/image.rs +368 -0
- data/vendor/kreuzberg/src/extraction/libreoffice.rs +563 -0
- data/vendor/kreuzberg/src/extraction/markdown.rs +213 -0
- data/vendor/kreuzberg/src/extraction/mod.rs +81 -0
- data/vendor/kreuzberg/src/extraction/office_metadata/app_properties.rs +398 -0
- data/vendor/kreuzberg/src/extraction/office_metadata/core_properties.rs +247 -0
- data/vendor/kreuzberg/src/extraction/office_metadata/custom_properties.rs +240 -0
- data/vendor/kreuzberg/src/extraction/office_metadata/mod.rs +130 -0
- data/vendor/kreuzberg/src/extraction/office_metadata/odt_properties.rs +287 -0
- data/vendor/kreuzberg/src/extraction/pptx.rs +3000 -0
- data/vendor/kreuzberg/src/extraction/structured.rs +490 -0
- data/vendor/kreuzberg/src/extraction/table.rs +328 -0
- data/vendor/kreuzberg/src/extraction/text.rs +269 -0
- data/vendor/kreuzberg/src/extraction/xml.rs +333 -0
- data/vendor/kreuzberg/src/extractors/archive.rs +446 -0
- data/vendor/kreuzberg/src/extractors/bibtex.rs +469 -0
- data/vendor/kreuzberg/src/extractors/docbook.rs +502 -0
- data/vendor/kreuzberg/src/extractors/docx.rs +367 -0
- data/vendor/kreuzberg/src/extractors/email.rs +143 -0
- data/vendor/kreuzberg/src/extractors/epub.rs +707 -0
- data/vendor/kreuzberg/src/extractors/excel.rs +343 -0
- data/vendor/kreuzberg/src/extractors/fictionbook.rs +491 -0
- data/vendor/kreuzberg/src/extractors/fictionbook.rs.backup2 +738 -0
- data/vendor/kreuzberg/src/extractors/html.rs +393 -0
- data/vendor/kreuzberg/src/extractors/image.rs +198 -0
- data/vendor/kreuzberg/src/extractors/jats.rs +1051 -0
- data/vendor/kreuzberg/src/extractors/jupyter.rs +367 -0
- data/vendor/kreuzberg/src/extractors/latex.rs +652 -0
- data/vendor/kreuzberg/src/extractors/markdown.rs +700 -0
- data/vendor/kreuzberg/src/extractors/mod.rs +365 -0
- data/vendor/kreuzberg/src/extractors/odt.rs +628 -0
- data/vendor/kreuzberg/src/extractors/opml.rs +634 -0
- data/vendor/kreuzberg/src/extractors/orgmode.rs +528 -0
- data/vendor/kreuzberg/src/extractors/pdf.rs +493 -0
- data/vendor/kreuzberg/src/extractors/pptx.rs +248 -0
- data/vendor/kreuzberg/src/extractors/rst.rs +576 -0
- data/vendor/kreuzberg/src/extractors/rtf.rs +810 -0
- data/vendor/kreuzberg/src/extractors/security.rs +484 -0
- data/vendor/kreuzberg/src/extractors/security_tests.rs +367 -0
- data/vendor/kreuzberg/src/extractors/structured.rs +140 -0
- data/vendor/kreuzberg/src/extractors/text.rs +260 -0
- data/vendor/kreuzberg/src/extractors/typst.rs +650 -0
- data/vendor/kreuzberg/src/extractors/xml.rs +135 -0
- data/vendor/kreuzberg/src/image/dpi.rs +164 -0
- data/vendor/kreuzberg/src/image/mod.rs +6 -0
- data/vendor/kreuzberg/src/image/preprocessing.rs +417 -0
- data/vendor/kreuzberg/src/image/resize.rs +89 -0
- data/vendor/kreuzberg/src/keywords/config.rs +154 -0
- data/vendor/kreuzberg/src/keywords/mod.rs +237 -0
- data/vendor/kreuzberg/src/keywords/processor.rs +267 -0
- data/vendor/kreuzberg/src/keywords/rake.rs +293 -0
- data/vendor/kreuzberg/src/keywords/types.rs +68 -0
- data/vendor/kreuzberg/src/keywords/yake.rs +163 -0
- data/vendor/kreuzberg/src/language_detection/mod.rs +942 -0
- data/vendor/kreuzberg/src/lib.rs +105 -0
- data/vendor/kreuzberg/src/mcp/mod.rs +32 -0
- data/vendor/kreuzberg/src/mcp/server.rs +1968 -0
- data/vendor/kreuzberg/src/ocr/cache.rs +469 -0
- data/vendor/kreuzberg/src/ocr/error.rs +37 -0
- data/vendor/kreuzberg/src/ocr/hocr.rs +216 -0
- data/vendor/kreuzberg/src/ocr/mod.rs +58 -0
- data/vendor/kreuzberg/src/ocr/processor.rs +863 -0
- data/vendor/kreuzberg/src/ocr/table/mod.rs +4 -0
- data/vendor/kreuzberg/src/ocr/table/tsv_parser.rs +144 -0
- data/vendor/kreuzberg/src/ocr/tesseract_backend.rs +450 -0
- data/vendor/kreuzberg/src/ocr/types.rs +393 -0
- data/vendor/kreuzberg/src/ocr/utils.rs +47 -0
- data/vendor/kreuzberg/src/ocr/validation.rs +206 -0
- data/vendor/kreuzberg/src/panic_context.rs +154 -0
- data/vendor/kreuzberg/src/pdf/error.rs +122 -0
- data/vendor/kreuzberg/src/pdf/images.rs +139 -0
- data/vendor/kreuzberg/src/pdf/metadata.rs +346 -0
- data/vendor/kreuzberg/src/pdf/mod.rs +50 -0
- data/vendor/kreuzberg/src/pdf/rendering.rs +369 -0
- data/vendor/kreuzberg/src/pdf/table.rs +393 -0
- data/vendor/kreuzberg/src/pdf/text.rs +158 -0
- data/vendor/kreuzberg/src/plugins/extractor.rs +1013 -0
- data/vendor/kreuzberg/src/plugins/mod.rs +209 -0
- data/vendor/kreuzberg/src/plugins/ocr.rs +620 -0
- data/vendor/kreuzberg/src/plugins/processor.rs +642 -0
- data/vendor/kreuzberg/src/plugins/registry.rs +1337 -0
- data/vendor/kreuzberg/src/plugins/traits.rs +258 -0
- data/vendor/kreuzberg/src/plugins/validator.rs +956 -0
- data/vendor/kreuzberg/src/stopwords/mod.rs +1470 -0
- data/vendor/kreuzberg/src/text/mod.rs +19 -0
- data/vendor/kreuzberg/src/text/quality.rs +697 -0
- data/vendor/kreuzberg/src/text/string_utils.rs +217 -0
- data/vendor/kreuzberg/src/text/token_reduction/cjk_utils.rs +164 -0
- data/vendor/kreuzberg/src/text/token_reduction/config.rs +100 -0
- data/vendor/kreuzberg/src/text/token_reduction/core.rs +796 -0
- data/vendor/kreuzberg/src/text/token_reduction/filters.rs +902 -0
- data/vendor/kreuzberg/src/text/token_reduction/mod.rs +160 -0
- data/vendor/kreuzberg/src/text/token_reduction/semantic.rs +619 -0
- data/vendor/kreuzberg/src/text/token_reduction/simd_text.rs +147 -0
- data/vendor/kreuzberg/src/types.rs +903 -0
- data/vendor/kreuzberg/src/utils/mod.rs +17 -0
- data/vendor/kreuzberg/src/utils/quality.rs +959 -0
- data/vendor/kreuzberg/src/utils/string_utils.rs +381 -0
- data/vendor/kreuzberg/stopwords/af_stopwords.json +53 -0
- data/vendor/kreuzberg/stopwords/ar_stopwords.json +482 -0
- data/vendor/kreuzberg/stopwords/bg_stopwords.json +261 -0
- data/vendor/kreuzberg/stopwords/bn_stopwords.json +400 -0
- data/vendor/kreuzberg/stopwords/br_stopwords.json +1205 -0
- data/vendor/kreuzberg/stopwords/ca_stopwords.json +280 -0
- data/vendor/kreuzberg/stopwords/cs_stopwords.json +425 -0
- data/vendor/kreuzberg/stopwords/da_stopwords.json +172 -0
- data/vendor/kreuzberg/stopwords/de_stopwords.json +622 -0
- data/vendor/kreuzberg/stopwords/el_stopwords.json +849 -0
- data/vendor/kreuzberg/stopwords/en_stopwords.json +1300 -0
- data/vendor/kreuzberg/stopwords/eo_stopwords.json +175 -0
- data/vendor/kreuzberg/stopwords/es_stopwords.json +734 -0
- data/vendor/kreuzberg/stopwords/et_stopwords.json +37 -0
- data/vendor/kreuzberg/stopwords/eu_stopwords.json +100 -0
- data/vendor/kreuzberg/stopwords/fa_stopwords.json +801 -0
- data/vendor/kreuzberg/stopwords/fi_stopwords.json +849 -0
- data/vendor/kreuzberg/stopwords/fr_stopwords.json +693 -0
- data/vendor/kreuzberg/stopwords/ga_stopwords.json +111 -0
- data/vendor/kreuzberg/stopwords/gl_stopwords.json +162 -0
- data/vendor/kreuzberg/stopwords/gu_stopwords.json +226 -0
- data/vendor/kreuzberg/stopwords/ha_stopwords.json +41 -0
- data/vendor/kreuzberg/stopwords/he_stopwords.json +196 -0
- data/vendor/kreuzberg/stopwords/hi_stopwords.json +227 -0
- data/vendor/kreuzberg/stopwords/hr_stopwords.json +181 -0
- data/vendor/kreuzberg/stopwords/hu_stopwords.json +791 -0
- data/vendor/kreuzberg/stopwords/hy_stopwords.json +47 -0
- data/vendor/kreuzberg/stopwords/id_stopwords.json +760 -0
- data/vendor/kreuzberg/stopwords/it_stopwords.json +634 -0
- data/vendor/kreuzberg/stopwords/ja_stopwords.json +136 -0
- data/vendor/kreuzberg/stopwords/kn_stopwords.json +84 -0
- data/vendor/kreuzberg/stopwords/ko_stopwords.json +681 -0
- data/vendor/kreuzberg/stopwords/ku_stopwords.json +64 -0
- data/vendor/kreuzberg/stopwords/la_stopwords.json +51 -0
- data/vendor/kreuzberg/stopwords/lt_stopwords.json +476 -0
- data/vendor/kreuzberg/stopwords/lv_stopwords.json +163 -0
- data/vendor/kreuzberg/stopwords/ml_stopwords.json +1 -0
- data/vendor/kreuzberg/stopwords/mr_stopwords.json +101 -0
- data/vendor/kreuzberg/stopwords/ms_stopwords.json +477 -0
- data/vendor/kreuzberg/stopwords/ne_stopwords.json +490 -0
- data/vendor/kreuzberg/stopwords/nl_stopwords.json +415 -0
- data/vendor/kreuzberg/stopwords/no_stopwords.json +223 -0
- data/vendor/kreuzberg/stopwords/pl_stopwords.json +331 -0
- data/vendor/kreuzberg/stopwords/pt_stopwords.json +562 -0
- data/vendor/kreuzberg/stopwords/ro_stopwords.json +436 -0
- data/vendor/kreuzberg/stopwords/ru_stopwords.json +561 -0
- data/vendor/kreuzberg/stopwords/si_stopwords.json +193 -0
- data/vendor/kreuzberg/stopwords/sk_stopwords.json +420 -0
- data/vendor/kreuzberg/stopwords/sl_stopwords.json +448 -0
- data/vendor/kreuzberg/stopwords/so_stopwords.json +32 -0
- data/vendor/kreuzberg/stopwords/st_stopwords.json +33 -0
- data/vendor/kreuzberg/stopwords/sv_stopwords.json +420 -0
- data/vendor/kreuzberg/stopwords/sw_stopwords.json +76 -0
- data/vendor/kreuzberg/stopwords/ta_stopwords.json +129 -0
- data/vendor/kreuzberg/stopwords/te_stopwords.json +54 -0
- data/vendor/kreuzberg/stopwords/th_stopwords.json +118 -0
- data/vendor/kreuzberg/stopwords/tl_stopwords.json +149 -0
- data/vendor/kreuzberg/stopwords/tr_stopwords.json +506 -0
- data/vendor/kreuzberg/stopwords/uk_stopwords.json +75 -0
- data/vendor/kreuzberg/stopwords/ur_stopwords.json +519 -0
- data/vendor/kreuzberg/stopwords/vi_stopwords.json +647 -0
- data/vendor/kreuzberg/stopwords/yo_stopwords.json +62 -0
- data/vendor/kreuzberg/stopwords/zh_stopwords.json +796 -0
- data/vendor/kreuzberg/stopwords/zu_stopwords.json +31 -0
- data/vendor/kreuzberg/tests/api_extract_multipart.rs +52 -0
- data/vendor/kreuzberg/tests/api_tests.rs +966 -0
- data/vendor/kreuzberg/tests/archive_integration.rs +543 -0
- data/vendor/kreuzberg/tests/batch_orchestration.rs +556 -0
- data/vendor/kreuzberg/tests/batch_processing.rs +316 -0
- data/vendor/kreuzberg/tests/bibtex_parity_test.rs +421 -0
- data/vendor/kreuzberg/tests/concurrency_stress.rs +525 -0
- data/vendor/kreuzberg/tests/config_features.rs +598 -0
- data/vendor/kreuzberg/tests/config_loading_tests.rs +415 -0
- data/vendor/kreuzberg/tests/core_integration.rs +510 -0
- data/vendor/kreuzberg/tests/csv_integration.rs +414 -0
- data/vendor/kreuzberg/tests/docbook_extractor_tests.rs +498 -0
- data/vendor/kreuzberg/tests/docx_metadata_extraction_test.rs +122 -0
- data/vendor/kreuzberg/tests/docx_vs_pandoc_comparison.rs +370 -0
- data/vendor/kreuzberg/tests/email_integration.rs +325 -0
- data/vendor/kreuzberg/tests/epub_native_extractor_tests.rs +275 -0
- data/vendor/kreuzberg/tests/error_handling.rs +393 -0
- data/vendor/kreuzberg/tests/fictionbook_extractor_tests.rs +228 -0
- data/vendor/kreuzberg/tests/format_integration.rs +159 -0
- data/vendor/kreuzberg/tests/helpers/mod.rs +142 -0
- data/vendor/kreuzberg/tests/html_table_test.rs +551 -0
- data/vendor/kreuzberg/tests/image_integration.rs +253 -0
- data/vendor/kreuzberg/tests/instrumentation_test.rs +139 -0
- data/vendor/kreuzberg/tests/jats_extractor_tests.rs +639 -0
- data/vendor/kreuzberg/tests/jupyter_extractor_tests.rs +704 -0
- data/vendor/kreuzberg/tests/keywords_integration.rs +479 -0
- data/vendor/kreuzberg/tests/keywords_quality.rs +509 -0
- data/vendor/kreuzberg/tests/latex_extractor_tests.rs +496 -0
- data/vendor/kreuzberg/tests/markdown_extractor_tests.rs +490 -0
- data/vendor/kreuzberg/tests/mime_detection.rs +428 -0
- data/vendor/kreuzberg/tests/ocr_configuration.rs +510 -0
- data/vendor/kreuzberg/tests/ocr_errors.rs +676 -0
- data/vendor/kreuzberg/tests/ocr_quality.rs +627 -0
- data/vendor/kreuzberg/tests/ocr_stress.rs +469 -0
- data/vendor/kreuzberg/tests/odt_extractor_tests.rs +695 -0
- data/vendor/kreuzberg/tests/opml_extractor_tests.rs +616 -0
- data/vendor/kreuzberg/tests/orgmode_extractor_tests.rs +822 -0
- data/vendor/kreuzberg/tests/pdf_integration.rs +43 -0
- data/vendor/kreuzberg/tests/pipeline_integration.rs +1411 -0
- data/vendor/kreuzberg/tests/plugin_ocr_backend_test.rs +771 -0
- data/vendor/kreuzberg/tests/plugin_postprocessor_test.rs +560 -0
- data/vendor/kreuzberg/tests/plugin_system.rs +921 -0
- data/vendor/kreuzberg/tests/plugin_validator_test.rs +783 -0
- data/vendor/kreuzberg/tests/registry_integration_tests.rs +586 -0
- data/vendor/kreuzberg/tests/rst_extractor_tests.rs +692 -0
- data/vendor/kreuzberg/tests/rtf_extractor_tests.rs +776 -0
- data/vendor/kreuzberg/tests/security_validation.rs +415 -0
- data/vendor/kreuzberg/tests/stopwords_integration_test.rs +888 -0
- data/vendor/kreuzberg/tests/test_fastembed.rs +609 -0
- data/vendor/kreuzberg/tests/typst_behavioral_tests.rs +1259 -0
- data/vendor/kreuzberg/tests/typst_extractor_tests.rs +647 -0
- data/vendor/kreuzberg/tests/xlsx_metadata_extraction_test.rs +87 -0
- data/vendor/rb-sys/.cargo-ok +1 -0
- data/vendor/rb-sys/.cargo_vcs_info.json +6 -0
- data/vendor/rb-sys/Cargo.lock +393 -0
- data/vendor/rb-sys/Cargo.toml +70 -0
- data/vendor/rb-sys/Cargo.toml.orig +57 -0
- data/vendor/rb-sys/LICENSE-APACHE +190 -0
- data/vendor/rb-sys/LICENSE-MIT +21 -0
- data/vendor/rb-sys/bin/release.sh +21 -0
- data/vendor/rb-sys/build/features.rs +108 -0
- data/vendor/rb-sys/build/main.rs +246 -0
- data/vendor/rb-sys/build/stable_api_config.rs +153 -0
- data/vendor/rb-sys/build/version.rs +48 -0
- data/vendor/rb-sys/readme.md +36 -0
- data/vendor/rb-sys/src/bindings.rs +21 -0
- data/vendor/rb-sys/src/hidden.rs +11 -0
- data/vendor/rb-sys/src/lib.rs +34 -0
- data/vendor/rb-sys/src/macros.rs +371 -0
- data/vendor/rb-sys/src/memory.rs +53 -0
- data/vendor/rb-sys/src/ruby_abi_version.rs +38 -0
- data/vendor/rb-sys/src/special_consts.rs +31 -0
- data/vendor/rb-sys/src/stable_api/compiled.c +179 -0
- data/vendor/rb-sys/src/stable_api/compiled.rs +257 -0
- data/vendor/rb-sys/src/stable_api/ruby_2_6.rs +316 -0
- data/vendor/rb-sys/src/stable_api/ruby_2_7.rs +316 -0
- data/vendor/rb-sys/src/stable_api/ruby_3_0.rs +324 -0
- data/vendor/rb-sys/src/stable_api/ruby_3_1.rs +317 -0
- data/vendor/rb-sys/src/stable_api/ruby_3_2.rs +315 -0
- data/vendor/rb-sys/src/stable_api/ruby_3_3.rs +326 -0
- data/vendor/rb-sys/src/stable_api/ruby_3_4.rs +327 -0
- data/vendor/rb-sys/src/stable_api.rs +261 -0
- data/vendor/rb-sys/src/symbol.rs +31 -0
- data/vendor/rb-sys/src/tracking_allocator.rs +332 -0
- data/vendor/rb-sys/src/utils.rs +89 -0
- data/vendor/rb-sys/src/value_type.rs +7 -0
- metadata +536 -0
|
@@ -0,0 +1,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
|
+
}
|