//! Exercise the real helper through the shared engine's process owner. use searchi_core::{ extraction_process::{run, ProcessConfig, ProcessError}, extraction_protocol::{DocumentFormat, ExtractionOutcome, RequestHeader}, }; use std::{ io::{Cursor, Write}, path::PathBuf, sync::atomic::AtomicBool, time::Duration, }; fn config() -> ProcessConfig { ProcessConfig { executable: PathBuf::from(env!("CARGO_BIN_EXE_searchi-extract-worker")), timeout: Duration::from_secs(10), } } #[test] fn actual_parent_and_worker_return_original_docx_passage_and_digest() { let mut document = zip::ZipWriter::new(Cursor::new(Vec::new())); document .start_file( "word/document.xml", zip::write::SimpleFileOptions::default(), ) .unwrap(); document.write_all(br#"Cancel with sixty days written notice."#).unwrap(); let input = document.finish().unwrap().into_inner(); let request = RequestHeader::from_bytes(DocumentFormat::Docx, &input).unwrap(); let expected_hash = request.input_sha256.clone(); let response = run(&config(), request, input, &AtomicBool::new(false)).unwrap(); assert_eq!(response.input_sha256, expected_hash); let ExtractionOutcome::Extracted { passages } = response.outcome else { panic!("Valid document rejected"); }; assert_eq!(passages.len(), 1); assert_eq!(passages[0].text, "Cancel with sixty days written notice."); assert_eq!(passages[0].source.kind, "paragraph"); assert_eq!(passages[0].source.number, 1); } #[test] fn parser_rejection_and_cancellation_remain_distinct() { let input = b"invalid PDF".to_vec(); let request = RequestHeader::from_bytes(DocumentFormat::Pdf, &input).unwrap(); let response = run( &config(), request.clone(), input.clone(), &AtomicBool::new(false), ) .unwrap(); assert!(matches!( response.outcome, ExtractionOutcome::Rejected { .. } )); assert!(matches!( run(&config(), request, input, &AtomicBool::new(true)), Err(ProcessError::Cancelled) )); }