2026-10-13 15:06:40 +02:00
//! 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 #"<w:document xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"><w:body><w:p><w:r><w:t>Cancel with sixty days written notice.</w:t></w:r></w:p></w:body></w:document>"# ). unwrap ();
let input = document . finish (). unwrap (). into_inner ();
let request = RequestHeader ::from_bytes ( DocumentFormat ::Docx , & input ). unwrap ();
let expected_hash = request . input_sha256 . clone ();
2026-10-23 09:49:17 +02:00
// Exercise short-lived native worker exit/task-inspection races too.
for _ in 0 .. 10 {
let response = run (
& config (),
request . clone (),
input . clone (),
& 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 );
}
2026-10-13 15:06:40 +02:00
}
#[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 )
));
}