Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions rust/crates/tools/src/pdf_extract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -545,4 +545,18 @@ mod tests {
// cleanup
let _ = std::fs::remove_dir_all(&dir);
}

#[test]
fn extract_text_returns_error_for_missing_file() {
// given
let path = Path::new("/path/that/does/not/exist.pdf");

// when
let result = extract_text(path);
Comment on lines +552 to +555

Copilot AI Apr 24, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test hard-codes an absolute Unix-style path ("/path/that/does/not/exist.pdf"), which can be non-portable and potentially flaky (e.g., different path semantics on Windows, or the path unexpectedly existing in some environments). Prefer constructing a definitely-nonexistent path under std::env::temp_dir() (and ensure the file does not exist) so the failure mode is consistent across platforms.

Suggested change
let path = Path::new("/path/that/does/not/exist.pdf");
// when
let result = extract_text(path);
let path = std::env::temp_dir().join(format!(
"clawd-missing-{}-{}.pdf",
std::process::id(),
"extract-text-test"
));
let _ = std::fs::remove_file(&path);
// when
let result = extract_text(&path);

Copilot uses AI. Check for mistakes.

// then
assert!(result.is_err());
let err = result.unwrap_err();
assert!(err.starts_with("failed to read PDF:"));
}
}
Loading