mirror of
https://github.com/storytold/deckcraft.git
synced 2026-10-29 13:06:56 -06:00
Merge PR #95 from mikl0s: Export: an unknown format is an error instead of a deckcraft file
This commit is contained in:
@@ -353,11 +353,12 @@ fn export(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
write_file(&path, &bytes)?;
|
||||
Ok(json!({"path": path, "bytes": bytes.len()}))
|
||||
}
|
||||
other => {
|
||||
let bytes = save_bytes(&st.doc, other)?;
|
||||
"pptx" | "potx" | "ppsx" | "deckcraft" | "outline" | "txt" => {
|
||||
let bytes = save_bytes(&st.doc, &format)?;
|
||||
write_file(&path, &bytes)?;
|
||||
Ok(json!({"path": path, "bytes": bytes.len()}))
|
||||
}
|
||||
other => Err(bad("file.export", format!("unknown format `{other}`"))),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -117,3 +117,15 @@ fn export_tool_lists_pdf_and_its_options() {
|
||||
}
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn export_rejects_unknown_format() {
|
||||
let mut s = Server::new(Box::new(Headless::new()));
|
||||
tool(&mut s, "new_presentation", json!({"theme": "Harbor"}));
|
||||
let path = std::env::temp_dir().join(format!("deckcraft-mcp-unknown-format-{}.docx", std::process::id()));
|
||||
let _ = std::fs::remove_file(&path);
|
||||
let r = call(&mut s, 1, "tools/call", json!({"name": "export", "arguments": {"path": path.to_str().unwrap(), "format": "docx"}}));
|
||||
assert_eq!(r["result"]["isError"], true, "{r}");
|
||||
assert!(r["result"]["content"][0]["text"].as_str().unwrap().contains("docx"), "{r}");
|
||||
assert!(!path.exists(), "nothing may be written for an unknown format");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user