Skip to content

SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.

Settings profiles: export and import stay inside an agent's folders (#11362) (#11390)

thocsmithee3cc32525bc
diff --git a/crates/ui-egui/src/control.rs b/crates/ui-egui/src/control.rs
index 97ce6175ec..3b57df38b6 100644
--- a/crates/ui-egui/src/control.rs
+++ b/crates/ui-egui/src/control.rs
@@ -2635,12 +2635,23 @@ mod tests {
assert_eq!(call("ui.render", json!({"path": at(&root, "a.png"), "width": 32, "height": 32}), true)["ok"], true);
}
assert_eq!(call("ui.screenshot", json!({"path": at(&root, "b.png")}), true)["ok"], true);
+ // Settings profiles are read and written by the app, not the engine, and stay inside too (#11362).
+ let profile = |id: &str, params: Value| json!({"command": id, "params": params});
+ let poc = json!({"format": "solidcraft-profile/1", "name": "scope-poc"});
+ assert_eq!(call("engine.execute", profile("settings.profile.import", json!({"profile": poc})), true)["ok"], true);
+ let inside = json!({"name": "scope-poc", "path": at(&root, "p.json")});
+ assert_eq!(call("engine.execute", profile("settings.profile.export", inside), true)["ok"], true);
+ assert_eq!(call("engine.execute", profile("settings.profile.import", json!({"path": at(&root, "p.json")})), true)["ok"], true);
+ std::fs::write(at(&base, "p.json"), poc.to_string()).unwrap();
for (method, params) in [
("engine.execute", export(at(&out, "a.step"))),
("engine.execute", export(at(&root, "../out/a.step"))),
("engine.script", json!({"commands": [{"command": "file.export", "params": {"path": at(&out, "a.step")}}]})),
("ui.render", json!({"path": at(&out, "a.png"), "width": 32, "height": 32})),
("ui.screenshot", json!({"path": at(&out, "b.png")})),
+ ("engine.execute", profile("settings.profile.export", json!({"name": "scope-poc", "path": at(&out, "p.json")}))),
+ ("engine.execute", profile("settings.profile.import", json!({"path": at(&base, "p.json")}))),
+ ("engine.execute", profile("settings.profile.import", json!({"path": at(&out, "missing.json")}))),
] {
let v = call(method, params, true);
assert!(v["ok"] == false && v.to_string().contains("outside the folders this agent may use"), "{method}: {v}");
diff --git a/crates/ui-egui/src/settings_profiles.rs b/crates/ui-egui/src/settings_profiles.rs
index 368c80f48d..2ae1b43057 100644
--- a/crates/ui-egui/src/settings_profiles.rs
+++ b/crates/ui-egui/src/settings_profiles.rs
@@ -15,6 +15,7 @@
//! parameters, and [`command`] does the rest after `SolveApp::run`.
use serde_json::{Map, Value, json};
+use solidcraft_engine::io::vfs;
use solidcraft_engine::{MAX_PROFILE_NAME, profile_name};
use crate::ui_kit::BackingTooltipExt as _;
@@ -418,13 +419,14 @@ fn apply(app: &mut SolveApp, doc: &Value) -> Vec<String> {
skipped
}
-/// A profile file read and checked, refusing one too large to be a profile.
+/// A profile file read and checked, refusing one too large to be a profile. Read through `vfs`, so
+/// an MCP agent's folders apply as they do to the engine's files (#11362).
fn read_file(path: &str) -> Result<Value, String> {
- let size = std::fs::metadata(path).map_err(|e| format!("{path}: {e}"))?.len();
+ let size = vfs::len(path).map_err(|e| format!("{path}: {e}"))?;
if size > MAX_FILE_BYTES {
return Err(format!("{path}: a settings profile file is at most {} MiB", MAX_FILE_BYTES / 1024 / 1024));
}
- let text = std::fs::read_to_string(path).map_err(|e| format!("{path}: {e}"))?;
+ let text = vfs::read_to_string(path, MAX_FILE_BYTES as usize).map_err(|e| format!("{path}: {e}"))?;
serde_json::from_str(&text).map_err(|e| format!("{path}: not a settings profile: {e}"))
}
@@ -494,7 +496,7 @@ pub fn command(app: &mut SolveApp, id: &str, v: &Value) -> Result<Value, String>
let doc = app.settings_profiles.get(name)?.clone();
if let Some(path) = v.get("path").and_then(Value::as_str) {
let text = serde_json::to_string_pretty(&doc).map_err(|e| e.to_string())?;
- std::fs::write(path, text).map_err(|e| format!("{path}: {e}"))?;
+ vfs::write(path, text.as_bytes()).map_err(|e| format!("{path}: {e}"))?;
return Ok(json!({ "profile": doc, "path": path }));
}
Ok(json!({ "profile": doc }))