Skip to content

PdfCraft: An open-source PDF reader and editor written by scratch in pure Rust

test(cli): reject unknown MCP options (#1342)

Masterf81e23bd4ec3
diff --git a/apps/pdfcraft-cli/tests/mcp_compact.rs b/apps/pdfcraft-cli/tests/mcp_compact.rs
index 486920680..a3864d46e 100644
--- a/apps/pdfcraft-cli/tests/mcp_compact.rs
+++ b/apps/pdfcraft-cli/tests/mcp_compact.rs
@@ -37,6 +37,18 @@ fn listed_tools(flags: &[&str]) -> Vec<String> {
reply["result"]["tools"].as_array().unwrap().iter().map(|t| t["name"].as_str().unwrap().to_string()).collect()
}
+#[test]
+fn mcp_rejects_unknown_options_before_starting_the_server() {
+ for option in ["--totally-bogus-flag", "--rot", "--root=."] {
+ let out = Command::new(env!("CARGO_BIN_EXE_pdfcraft-cli")).args(["mcp", option]).output().expect("run CLI");
+
+ let stderr = String::from_utf8_lossy(&out.stderr);
+ assert!(!out.status.success(), "mcp {option} unexpectedly succeeded");
+ assert!(stderr.contains("unknown option") && stderr.contains(option), "mcp {option}: {stderr}");
+ assert!(!stderr.contains("MCP server on stdio"), "server started despite invalid option: {stderr}");
+ }
+}
+
#[test]
fn compact_flag_shortens_the_tool_list() {
let full = listed_tools(&[]);
diff --git a/crates/ui-egui/tests/viewer.rs b/crates/ui-egui/tests/viewer.rs
index 033c31482..4f0c6dbd7 100644
--- a/crates/ui-egui/tests/viewer.rs
+++ b/crates/ui-egui/tests/viewer.rs
@@ -39,7 +39,8 @@ fn harness() -> Harness<'static, PdfCraftApp> {
app.open_bytes("b.pdf", None, fixture(2)).unwrap();
app
});
- for _ in 0..40 {
+ // Background rendering and text extraction can take seconds on a loaded CI runner (FreeBSD VM).
+ for _ in 0..3000 {
h.run_steps(2);
if !h.state().render_pending() {
break;
@@ -91,7 +92,8 @@ fn view_history_select_all_and_find_options() {
assert!(h.state_mut().views[0].view_history(true));
assert_eq!(h.state().views[0].current, 3, "next view");
// Select all on the current page (once its text is known).
- for _ in 0..40 {
+ // Background rendering and text extraction can take seconds on a loaded CI runner (FreeBSD VM).
+ for _ in 0..3000 {
h.run_steps(2);
if h.state_mut().views[0].select_all() {
break;
@@ -476,7 +478,8 @@ fn advanced_search_lists_results_with_context() {
h.run_steps(2);
h.get_by_label("What word or phrase would you like to search for?");
h.state_mut().views[i].find.as_mut().unwrap().query = "pages".into();
- for _ in 0..40 {
+ // Background rendering and text extraction can take seconds on a loaded CI runner (FreeBSD VM).
+ for _ in 0..3000 {
h.run_steps(2);
if h.state().views[i].find.as_ref().is_some_and(|f| f.matches.len() == 2) {
break;