Merge pull request #274 from storytold/fix/issue-258

Fix #258: the save_file tool says what it saves
This commit is contained in:
BFlat 2026-10-07 12:13:39 +07:00 committed by GitHub
commit b743d08f11
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 23 additions and 3 deletions

View File

@ -303,6 +303,17 @@ fn inspect_document_reports_the_paint_of_type() {
assert_eq!((t["fill"].as_str(), t["stroke"].as_str(), t["strokeWidth"].as_f64()), (Some("#0000ff"), Some("#00ff00"), Some(3.0)), "{t}"); assert_eq!((t["fill"].as_str(), t["stroke"].as_str(), t["strokeWidth"].as_f64()), (Some("#0000ff"), Some("#00ff00"), Some(3.0)), "{t}");
} }
/// save_file says it saves in the document's own format or the one the path's extension picks.
#[test]
fn save_file_describes_the_formats_it_writes() {
let tools = tool_definitions();
let d = tools.iter().find(|t| t["name"] == "save_file").and_then(|t| t["description"].as_str()).unwrap();
for ext in [".vectorcraft", ".vctemplate", ".pdf", ".svg", ".svgz", ".ai"] {
assert!(d.contains(ext), "{ext}: {d}");
}
assert!(d.contains("its own format"), "{d}");
}
#[test] #[test]
fn errors_are_tool_results_not_crashes() { fn errors_are_tool_results_not_crashes() {
let mut s = server(); let mut s = server();

View File

@ -2,7 +2,7 @@
//! [`Backend`]. //! [`Backend`].
use serde_json::{Map, Value, json}; use serde_json::{Map, Value, json};
use vectorcraft_engine::cmd::fileio::{ARTBOARD_PARAMS, FORMATS, OPEN_EXTS}; use vectorcraft_engine::cmd::fileio::{ARTBOARD_PARAMS, FORMATS, OPEN_EXTS, SAVE_FORMATS, format};
use crate::backend::Backend; use crate::backend::Backend;
@ -57,6 +57,12 @@ fn obj(props: Value, required: &[&str]) -> Value {
} }
o o
} }
/// The extension of each format Save writes, in [`SAVE_FORMATS`] order.
fn save_extensions() -> Vec<&'static str> {
SAVE_FORMATS.iter().filter_map(|id| format(id)?.extensions.first().copied()).collect()
}
fn tool(name: &str, title: &str, desc: &str, schema: Value, read_only: bool) -> Value { fn tool(name: &str, title: &str, desc: &str, schema: Value, read_only: bool) -> Value {
json!({ json!({
"name": name, "name": name,
@ -259,8 +265,11 @@ pub fn tool_definitions() -> Vec<Value> {
tool( tool(
"save_file", "save_file",
"Save file", "Save file",
"Save the active document in the native .vectorcraft format.", &format!(
obj(json!({"path": string("Destination (default: the document's current path)")}), &[]), "Save the active document with the engine's document.save: by default to its own file in its own format (native .vectorcraft unless it was opened from or saved as SVG, PDF or a restorable .ai). With `path`, the extension picks the format: .{}. Other formats are exports (see export). The reply's `format` says what was written and `warnings` what that format loses.",
save_extensions().join(", .")
),
obj(json!({"path": string("Destination; its extension picks the format (default: the document's own file)")}), &[]),
false, false,
), ),
tool( tool(