Skip to content
Open
Show file tree
Hide file tree
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
15 changes: 15 additions & 0 deletions patch.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
--- rust/crates/tools/src/pdf_extract.rs
+++ rust/crates/tools/src/pdf_extract.rs
@@ -404,4 +404,12 @@
// cleanup
let _ = std::fs::remove_dir_all(&dir);
}
+
+ #[test]
+ fn extract_text_returns_error_for_nonexistent_file() {
+ let path = Path::new("/this/path/does/not/exist.pdf");
+ let result = extract_text(path);
+ assert!(result.is_err());
+ assert!(result.unwrap_err().starts_with("failed to read PDF:"));
+ }
}
Comment on lines +1 to +15

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.

patch.diff looks like a generated patch artifact and is not referenced by the build/tests. Committing it adds noise and can confuse future changes; please remove it from the PR (or place it under a docs/fixtures location if it’s intentionally needed, with a reference).

Suggested change
--- rust/crates/tools/src/pdf_extract.rs
+++ rust/crates/tools/src/pdf_extract.rs
@@ -404,4 +404,12 @@
// cleanup
let _ = std::fs::remove_dir_all(&dir);
}
+
+ #[test]
+ fn extract_text_returns_error_for_nonexistent_file() {
+ let path = Path::new("/this/path/does/not/exist.pdf");
+ let result = extract_text(path);
+ assert!(result.is_err());
+ assert!(result.unwrap_err().starts_with("failed to read PDF:"));
+ }
}

Copilot uses AI. Check for mistakes.
8 changes: 8 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,12 @@ mod tests {
// cleanup
let _ = std::fs::remove_dir_all(&dir);
}

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Make nonexistent-path test independent of host filesystem

This test assumes /this/path/does/not/exist.pdf is always absent, but if that path exists in any runner image or local environment, extract_text can return Ok(_) and the assertion will fail despite correct behavior. That makes the test environment-dependent and potentially flaky; use a temp-directory path that is guaranteed not to exist for the duration of the test instead of a fixed absolute path.

Useful? React with πŸ‘Β / πŸ‘Ž.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

@copilot, make changes based on the above suggestion.

let result = extract_text(path);
Comment on lines +551 to +552

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.

extract_text_returns_error_for_nonexistent_file uses a hard-coded absolute path (/this/path/does/not/exist.pdf). This can make the test flaky if that path exists in some environments. Prefer constructing a guaranteed-missing path under std::env::temp_dir() (e.g., add a unique/random component) and asserting on that instead.

Suggested change
let path = Path::new("/this/path/does/not/exist.pdf");
let result = extract_text(path);
let unique = format!(
"clawd-pdf-extract-missing-{}-{}.pdf",
std::process::id(),
std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.unwrap()
.as_nanos()
);
let path = std::env::temp_dir().join(unique);
let _ = std::fs::remove_file(&path);
let result = extract_text(path.as_path());

Copilot uses AI. Check for mistakes.
assert!(result.is_err());
assert!(result.unwrap_err().starts_with("failed to read PDF:"));
}
}
Loading
Loading