返回 CodeWhale
tests.rs
根目录 / crates / tui / src / tools / file / tests.rs
1 use super::*;
2 use std::time::Duration;
3
4 #[tokio::test]
5 async fn missing_pdf_path_precedes_unavailable_helper() {
6 let temporary = tempfile::tempdir().expect("tempdir");
7 let input = temporary.path().join("missing.pdf");
8 let missing = temporary.path().join("definitely-not-pdftotext");
9 let error = read_pdf_if_detected(
10 &input,
11 None,
12 super::super::pdf::PdfTextCommand::test(missing.as_os_str(), Duration::from_secs(1), None),
13 )
14 .await
15 .expect_err("missing path must fail before the missing helper is launched");
16
17 match error {
18 ToolError::ExecutionFailed { message } => {
19 assert!(message.contains("Failed to read"), "{message}");
20 assert!(message.contains("missing.pdf"), "{message}");
21 }
22 other => panic!("expected ordinary read failure, got {other:?}"),
23 }
24 }
25
26 #[tokio::test]
27 async fn read_file_missing_pdftotext_is_a_failed_typed_outcome() {
28 let temporary = tempfile::tempdir().expect("tempdir");
29 let missing = temporary.path().join("definitely-not-pdftotext");
30 let input = temporary.path().join("input.pdf");
31 std::fs::write(&input, b"%PDF-1.7\n%%EOF").expect("fixture");
32
33 let error = read_pdf_with_command(
34 &input,
35 None,
36 super::super::pdf::PdfTextCommand::test(missing.as_os_str(), Duration::from_secs(1), None),
37 )
38 .await
39 .expect_err("missing helper must fail the tool call");
40 let payload = match &error {
41 ToolError::NotAvailable { message } => {
42 serde_json::from_str::<Value>(message).expect("structured unavailable payload")
43 }
44 other => panic!("unexpected error: {other:?}"),
45 };
46 assert_eq!(payload["type"], "binary_unavailable");
47 assert_eq!(
48 crate::tools::spec::ToolExecutionOutcome::from_legacy(Err(error)).status,
49 crate::tools::spec::ToolTerminalStatus::Failed
50 );
51 }
52
52 lines RUST