SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.
Agents and scripts: Render Settings and Save Render Settings describe their exact parameters and reply (#12783) (#12784)
austin62jake2c6230eafc29
diff --git a/crates/engine/src/cmd/render.rs b/crates/engine/src/cmd/render.rsindex f0b0d4e02f..15a4cf12ac 100644--- a/crates/engine/src/cmd/render.rs+++ b/crates/engine/src/cmd/render.rs@@ -9,6 +9,7 @@ use solidcraft_doc::render_settings::{RenderSettings, RenderSetup};use super::CommandSpec;use crate::params::bad;use crate::schema::render_camera::{CameraApplied, CameraFitted, CameraInfo, CameraSet, RenderCamera};+use crate::schema::render_settings::{RenderSettingsGot, RenderSettingsInfo, RenderSettingsSaved, SETUP_FIELDS, SetupFields, set_message};use crate::{Result, Session};mod clear_coat;@@ -222,9 +223,13 @@ CommandSpec::new("render.backends", "Render Backends", backends).icon("list").noundo().doc_only().params("No parameters. Returns {schema_version: 1, default_backend: builtin, backends: [{id, label, availability, executors: [{id, availability, profiles, limits, scratch}]}]}. Metadata only; does not start rendering or probe a GPU. See docs/render-backends.md"),-CommandSpec::new("render.settings.get", "Render Settings", get_settings).icon("settings").noundo().doc_only()+CommandSpec::new("render.settings.get", "Render Settings", crate::checked!("render.settings.get", get_settings)).icon("settings").noundo().doc_only()+ .contract(&crate::schema::TypedContract::<crate::schema::render_settings::GetParams>::new())+ .output(crate::schema::output_schema_for::<RenderSettingsGot>).params("name?: saved setup. Without name returns {setups, defaults}; with name returns {name, setup}. Does not evaluate the model or apply a camera. See docs/render-settings.md"),-CommandSpec::new("render.settings.set", "Save Render Settings", set_settings).icon("settings").doc_only()+CommandSpec::new("render.settings.set", "Save Render Settings", crate::checked!("render.settings.set", set_settings)).icon("settings").doc_only()+ .contract(&crate::schema::TypedContract::<crate::schema::render_settings::SetParams>::new())+ .output(crate::schema::output_schema_for::<RenderSettingsSaved>).params("name: setup name, set: object of fields to replace (backend, mode, camera, width, height, format, exposure_ev, environment_rotation, environment_intensity, background, job, surfaces, optics, coats, stage). job?: typed active raster/cpu_raytrace/gpu_path configuration with optional validated embedded HDR reference; omitted preserves, null clears, object replaces the complete job. Creates from defaults and saves without a host, validates atomically, one undo step; identical edits are no-ops. See docs/render-settings.md"),CommandSpec::new("render.scene", "Inspect Render Scene", scene).noundo().at("RENDER", "SCENE").icon("render_scene").params("No parameters. Authoritative product-scene metadata, without modelling overlays or mesh payloads. Explicitly settles stale geometry; does not render an image. See docs/render-workspace.md"),@@ -329,13 +334,25 @@ struct GetSettings {fn get_settings(s: &mut Session, params: &Value) -> Result<Value> {let cmd = "render.settings.get";let request: GetSettings = serde_json::from_value(params.clone()).map_err(|e| bad(cmd, e.to_string()))?;- match request.name {- None => Ok(json!({"setups": s.doc.render.setups, "defaults": RenderSetup::default()})),+ let info = match request.name {+ None => {+ let setups = s.doc.render.setups.iter().map(|(name, setup)| Ok((name.clone(), setup_fields(cmd, setup)?))).collect::<Result<_>>()?;+ RenderSettingsInfo::All { setups, defaults: setup_fields(cmd, &RenderSetup::default())? }+ }Some(name) => {RenderSettings::validate_name(&name).map_err(|e| bad(cmd, e.to_string()))?;let setup = s.doc.render.setups.get(&name).ok_or_else(|| bad(cmd, "no saved render setup with that name"))?;- Ok(json!({"name": name, "setup": setup}))+ RenderSettingsInfo::One { setup: setup_fields(cmd, setup)?, name }}+ };+ typed_reply(cmd, RenderSettingsGot { info, param_warnings: Vec::new() })+}++/// A render setup's fields, as it saves them, for a reply.+fn setup_fields(cmd: &str, setup: &RenderSetup) -> Result<SetupFields> {+ match serde_json::to_value(setup).map_err(|e| bad(cmd, e.to_string()))? {+ Value::Object(fields) => Ok(fields),+ _ => Err(bad(cmd, "invalid render setup")),}}@@ -350,23 +367,23 @@ fn set_settings(s: &mut Session, params: &Value) -> Result<Value> {let cmd = "render.settings.set";let request: SetSettings = serde_json::from_value(params.clone()).map_err(|e| bad(cmd, e.to_string()))?;let setup = patched_settings(s, &request.name, &request.set, cmd)?;- let reply = json!({"name": request.name, "setup": setup});+ let reply = RenderSettingsSaved { name: request.name.clone(), setup: setup_fields(cmd, &setup)?, param_warnings: Vec::new() };if s.doc.render.setups.get(&request.name) == Some(&setup) {- return Ok(reply);+ return typed_reply(cmd, reply);}let mut settings = (*s.doc.render).clone();settings.setups.insert(request.name, setup);settings.validate().map_err(|e| bad(cmd, e.to_string()))?;s.doc_mut().render = Arc::new(settings);- Ok(reply)+ typed_reply(cmd, reply)}fn patched_settings(s: &Session, name: &str, set: &Value, cmd: &str) -> Result<RenderSetup> {RenderSettings::validate_name(name).map_err(|e| bad(cmd, e.to_string()))?;- // A full RenderSetup has 15 known fields, including maps, optics, coats and- // stage. Bound the patch by that schema; decoding below still rejects any+ // A RenderSetup has `SETUP_FIELDS`, including surfaces, optics, coats and stage; the published+ // schemas list the same fields. Bound the patch by them; decoding below still rejects any// unknown field instead of silently dropping saved intent.- let patch = set.as_object().filter(|p| p.len() <= 15).ok_or_else(|| bad(cmd, "`set` must be an object with at most 15 fields"))?;+ let patch = set.as_object().filter(|p| p.len() <= SETUP_FIELDS.len()).ok_or_else(|| bad(cmd, set_message()))?;let current = s.doc.render.setups.get(name).cloned().unwrap_or_default();let mut value = serde_json::to_value(¤t).map_err(|e| bad(cmd, e.to_string()))?;let object = value.as_object_mut().ok_or_else(|| bad(cmd, "invalid render setup"))?;diff --git a/crates/engine/src/schema/mod.rs b/crates/engine/src/schema/mod.rsindex d0ece2c299..a88a695989 100644--- a/crates/engine/src/schema/mod.rs+++ b/crates/engine/src/schema/mod.rs@@ -94,6 +94,7 @@ pub mod render_hdr;pub mod render_library;pub mod render_lights;pub mod render_presets;+pub mod render_settings;pub mod render_shots;pub mod render_stage;pub mod render_surface_resources;diff --git a/crates/engine/src/schema/render_camera.rs b/crates/engine/src/schema/render_camera.rsindex bd6eb7cc51..67ef8809cb 100644--- a/crates/engine/src/schema/render_camera.rs+++ b/crates/engine/src/schema/render_camera.rs@@ -191,7 +191,7 @@ pub struct ApplyParams {/// A setup's name as `render.settings.apply` reads it: `null` is left out, other text than a/// string gets serde's message, and a string must be a valid setup name.-fn setup_name<'de, D: Deserializer<'de>>(d: D) -> Result<Option<String>, D::Error> {+pub(super) fn setup_name<'de, D: Deserializer<'de>>(d: D) -> Result<Option<String>, D::Error> {let Some(name) = Option::<String>::deserialize(Value::deserialize(d)?).map_err(|e| D::Error::custom(whole(e)))? else {return Ok(None);};@@ -202,7 +202,7 @@ fn setup_name<'de, D: Deserializer<'de>>(d: D) -> Result<Option<String>, D::Erro/// The pattern says "not blank"; trimmed, at most 128 bytes and free of control characters,/// which JSON Schema can't count or class portably, are in the field's description and/// checked by [`setup_name`].-fn setup_name_schema(_: &mut SchemaGenerator) -> Schema {+pub(super) fn setup_name_schema(_: &mut SchemaGenerator) -> Schema {json_schema!({"type": "string","minLength": 1,diff --git a/crates/engine/src/schema/render_hdr.rs b/crates/engine/src/schema/render_hdr.rsindex f35885ad5f..413088393f 100644--- a/crates/engine/src/schema/render_hdr.rs+++ b/crates/engine/src/schema/render_hdr.rs@@ -11,6 +11,8 @@ use serde::{Deserialize, Serialize};use serde_json::Value;use solidcraft_doc::render_resources::HdrId;+use super::render_settings::{SETUP_FIELDS, setup_patch_schema};+fn one() -> f64 {1.0}@@ -24,42 +26,14 @@ fn digest_schema(_: &mut SchemaGenerator) -> Schema {})}-/// The fields of a render setup, as `render.settings.get` gives them. A `set` patch may give up-/// to 13 of them; `patched_settings` reads the patched setup as a `RenderSetup`, which refuses any-/// other key.-const SETUP_FIELDS: &[&str] = &[- "backend",- "mode",- "camera",- "width",- "height",- "format",- "exposure_ev",- "environment_rotation",- "environment_intensity",- "background",- "job",- "surfaces",- "optics",- "stage",-];--/// Each setup field, without its own schema: `patched_settings` checks the values.-fn setup_properties() -> serde_json::Map<String, Value> {- SETUP_FIELDS.iter().map(|field| (field.to_string(), Value::Object(serde_json::Map::new()))).collect()-}-/// `set`: changes to the setup, as `render.settings.set` takes them. `patched_settings` in-/// `cmd/render.rs` refuses anything but an object of at most 13 setup fields, with its own-/// message.+/// `cmd/render.rs` refuses anything but an object of at most [`SETUP_FIELDS`] setup fields, with+/// its own message; the list is shared with Save Render Settings' schema, so the two can't drift.fn set_schema(_: &mut SchemaGenerator) -> Schema {- json_schema!({- "description": "Changes to the setup the HDR is saved into, as `render.settings.set` takes them: at most 13 of the setup's fields. The setup they make (a saved one keeps the fields left out) must have a `job` with method `cpu_raytrace` or `gpu_path`, without an `hdr` or an `environment`.",- "type": "object",- "properties": setup_properties(),- "additionalProperties": false,- "maxProperties": 13- })+ setup_patch_schema(&format!(+ "Changes to the setup the HDR is saved into, as `render.settings.set` takes them: at most {} of the setup's fields. The setup they make (a saved one keeps the fields left out) must have a `job` with method `cpu_raytrace` or `gpu_path`, without an `hdr` or an `environment`.",+ SETUP_FIELDS.len()+ ))}/// Read an HDR file and check it: its size in pixels, its byte count, its SHA-256 and the colourdiff --git a/crates/engine/src/schema/render_hdr_tests.rs b/crates/engine/src/schema/render_hdr_tests.rsindex 87d4402ab5..b7ac557818 100644--- a/crates/engine/src/schema/render_hdr_tests.rs+++ b/crates/engine/src/schema/render_hdr_tests.rs@@ -120,17 +120,24 @@ fn hdr_commands_reply_with_their_schemas() {/// `set` names the render setup's fields: `patched_settings` reads the patched setup as a/// `RenderSetup`, which refuses any other key, so the schema refuses a misspelt one too (and-/// more than 13 at once).+/// more than `SETUP_FIELDS` at once). `coats` is one of them (#12783).#[test]fn the_set_schema_names_the_setup_fields() {let root = input_schema_for::<HdrCaptureParams>();let root = root.as_value();let set = &root["properties"]["set"];- for (patch, takes) in- [(json!({}), true), (json!({"width": 640, "height": 480, "job": {"method": "gpu_path"}}), true), (json!({"widht": 640}), false)]- {+ for (patch, takes) in [+ (json!({}), true),+ (json!({"width": 640, "height": 480, "job": {"method": "gpu_path"}}), true),+ (json!({"coats": {}}), true),+ (json!({"widht": 640}), false),+ ] {assert_eq!(conforms(root, set, &patch), takes, "{patch}");}// `conforms` doesn't read `maxProperties`, so the limit is pinned here.- assert_eq!((set["maxProperties"].as_u64(), set["properties"].as_object().map(|p| p.len())), (Some(13), Some(super::SETUP_FIELDS.len())), "{set}");+ assert_eq!(+ (set["maxProperties"].as_u64(), set["properties"].as_object().map(|p| p.len())),+ (Some(crate::schema::render_settings::SETUP_FIELDS.len() as u64), Some(crate::schema::render_settings::SETUP_FIELDS.len())),+ "{set}"+ );}diff --git a/crates/engine/src/schema/render_settings.rs b/crates/engine/src/schema/render_settings.rsnew file mode 100644index 0000000000..4b4c03e72c--- /dev/null+++ b/crates/engine/src/schema/render_settings.rs@@ -0,0 +1,154 @@+//! Contracts and reply types for Render Settings and Save Render Settings in `cmd/render.rs`+//! (#12783), and the render setup fields a `set` patch may change, which Save Render Settings+//! with HDR (`schema/render_hdr.rs`) shares.+//!+//! The handlers read their parameters with serde, so each key here reads as the handler reads+//! it, with serde's message (`invalid type: …`) or the setup name rules'. Whether a setup exists,+//! and whether the patched setup is valid, stay the handlers' to check.++use std::collections::BTreeMap;++use schemars::{JsonSchema, Schema, SchemaGenerator, json_schema};+use serde::de::Error as _;+use serde::{Deserialize, Deserializer, Serialize};+use serde_json::{Map, Value};+use solidcraft_doc::render_settings::RenderSettings;++use super::check::whole;+use super::render_camera::{setup_name, setup_name_schema};++/// The fields of a render setup (`solidcraft_doc::render_settings::RenderSetup`), as the render+/// settings commands give and take them. `cmd/render.rs`'s `patched_settings` takes a patch of at+/// most this many fields, so the published schemas and the handlers share one list and one bound;+/// a test checks the list against `RenderSetup`'s own fields.+pub(crate) const SETUP_FIELDS: &[&str] = &[+ "backend",+ "mode",+ "camera",+ "width",+ "height",+ "format",+ "exposure_ev",+ "environment_rotation",+ "environment_intensity",+ "background",+ "job",+ "surfaces",+ "optics",+ "coats",+ "stage",+];++/// `patched_settings`' message for a `set` that isn't an object of at most [`SETUP_FIELDS`] keys.+pub(crate) fn set_message() -> String {+ format!("`set` must be an object with at most {} fields", SETUP_FIELDS.len())+}++/// The schema of a `set` patch: an object of setup fields, each without its own schema+/// (`patched_settings` reads the patched setup as a `RenderSetup`, which checks the values and+/// refuses any other key).+pub(super) fn setup_patch_schema(description: &str) -> Schema {+ let properties: Map<String, Value> = SETUP_FIELDS.iter().map(|field| (field.to_string(), Value::Object(Map::new()))).collect();+ json_schema!({+ "description": description,+ "type": "object",+ "properties": properties,+ "additionalProperties": false,+ "maxProperties": SETUP_FIELDS.len()+ })+}++/// Give every saved render setup and the defaults a new one starts from, or one setup by name.+/// Nothing is changed.+#[derive(Debug, Deserialize, JsonSchema)]+#[schemars(deny_unknown_fields)]+pub struct GetParams {+ /// The saved setup, by name: trimmed, at most 128 bytes, with no control characters. Left out+ /// or `null`: every setup and the defaults.+ #[serde(default, deserialize_with = "setup_name")]+ #[schemars(schema_with = "optional_setup_name_schema")]+ pub name: Option<String>,+}++fn optional_setup_name_schema(generator: &mut SchemaGenerator) -> Schema {+ json_schema!({"anyOf": [setup_name_schema(generator), {"type": "null"}]})+}++/// Change a render setup's fields, or make a new setup from the defaults with them; the fields+/// left out keep their values. One undo step, none when nothing changes.+#[derive(Debug, Deserialize, JsonSchema)]+#[schemars(deny_unknown_fields)]+pub struct SetParams {+ // Both keys are required, so the check refuses a call without one ("`name` is required")+ // before the handler runs, as for the other required keys. The handler's own words for it are+ // serde's ("missing field `name`").+ /// The setup, by name: trimmed, at most 128 bytes, with no control characters.+ #[serde(deserialize_with = "saved_name")]+ #[schemars(schema_with = "setup_name_schema")]+ pub name: String,+ #[serde(deserialize_with = "setup_patch")]+ #[schemars(schema_with = "set_schema")]+ pub set: Value,+}++/// Save Render Settings' `name`: text, as the handler's serde struct reads it (its message for+/// anything else, `null` included), and a valid setup name.+fn saved_name<'de, D: Deserializer<'de>>(d: D) -> Result<String, D::Error> {+ let name = String::deserialize(Value::deserialize(d)?).map_err(|e| D::Error::custom(whole(e)))?;+ RenderSettings::validate_name(&name).map_err(|e| D::Error::custom(whole(e)))?;+ Ok(name)+}++/// `set`: an object of at most [`SETUP_FIELDS`] keys, with `patched_settings`' message for+/// anything else, `null` included. Which keys and values a setup takes stays the handler's to+/// check, with serde's messages.+fn setup_patch<'de, D: Deserializer<'de>>(d: D) -> Result<Value, D::Error> {+ match Value::deserialize(d)? {+ Value::Object(patch) if patch.len() <= SETUP_FIELDS.len() => Ok(Value::Object(patch)),+ _ => Err(D::Error::custom(whole(set_message()))),+ }+}++fn set_schema(_: &mut SchemaGenerator) -> Schema {+ setup_patch_schema(&format!(+ "The fields to change: at most {} of the setup's fields, as `render.settings.get` gives them. `job`: `null` clears it, an object replaces it whole.",+ SETUP_FIELDS.len()+ ))+}++/// A render setup's fields, as `RenderSetup` saves them.+pub type SetupFields = Map<String, Value>;++/// The saved setups, or one of them.+#[derive(Debug, Serialize, JsonSchema)]+#[serde(untagged)]+pub enum RenderSettingsInfo {+ /// Without `name`: every saved setup, by name, and the defaults a new setup starts from.+ All { setups: BTreeMap<String, SetupFields>, defaults: SetupFields },+ /// With `name`: that setup.+ One { name: String, setup: SetupFields },+}++/// What `render.settings.get` returns.+#[derive(Debug, Serialize, JsonSchema)]+pub struct RenderSettingsGot {+ #[serde(flatten)]+ pub info: RenderSettingsInfo,+ /// In the warn parameter-check mode: what the call's parameters got wrong.+ #[serde(default, skip_serializing_if = "Vec::is_empty")]+ pub param_warnings: Vec<String>,+}++/// What `render.settings.set` returns: the setup as saved.+#[derive(Debug, Serialize, JsonSchema)]+pub struct RenderSettingsSaved {+ pub name: String,+ pub setup: SetupFields,+ /// In the warn parameter-check mode: what the call's parameters got wrong.+ #[serde(default, skip_serializing_if = "Vec::is_empty")]+ pub param_warnings: Vec<String>,+}++#[cfg(test)]+#[path = "render_settings_tests.rs"]+mod tests;diff --git a/crates/engine/src/schema/render_settings_tests.rs b/crates/engine/src/schema/render_settings_tests.rsnew file mode 100644index 0000000000..04bb30a7fa--- /dev/null+++ b/crates/engine/src/schema/render_settings_tests.rs@@ -0,0 +1,131 @@+use serde_json::{Value, json};+use solidcraft_doc::render_settings::RenderSetup;++use super::{GetParams, RenderSettingsGot, RenderSettingsSaved, SETUP_FIELDS, SetParams};+use crate::Session;+use crate::schema::tests::{assert_keys, assert_strict_keeps_todays_errors, conforms};+use crate::schema::{ParamCheck, input_schema_for, output_schema_for};++/// A design with one saved render setup, `Studio`, 800 × 600.+fn studio(level: ParamCheck) -> Session {+ let mut s = Session::default();+ s.execute("render.settings.set", &json!({"name": "Studio", "set": {"width": 800, "height": 600}})).unwrap_or_else(|e| panic!("{e}"));+ s.param_check = level;+ s+}++#[test]+fn schemas_and_the_key_check_agree() {+ assert_keys(input_schema_for::<GetParams>(), &["name"]);+ assert_keys(input_schema_for::<SetParams>(), &["name", "set"]);+}++/// #12783: `SETUP_FIELDS` is `RenderSetup`'s own list of fields, which serde gives in its message+/// for a field it doesn't know. The schemas and `patched_settings`' bound both come from it.+#[test]+fn the_setup_fields_are_render_setups_fields() {+ let error = serde_json::from_value::<RenderSetup>(json!({"not_a_setup_field": 1})).err().map(|e| e.to_string()).unwrap_or_default();+ let expected = error.split_once("expected").map(|(_, list)| list).unwrap_or_default();+ let fields: Vec<&str> = expected.split('`').skip(1).step_by(2).collect();+ assert_eq!(fields, SETUP_FIELDS, "{error}");+}++/// #12783: calls that fail today get the same message in strict: serde's for a name or patch of+/// the wrong type, the setup name rules', `patched_settings`' and a missing setup. (A key left out+/// is in `a_key_left_out_is_refused_by_the_check`.)+#[test]+fn strict_keeps_todays_errors() {+ let too_many: serde_json::Map<String, Value> = (0..16).map(|i| (format!("field{i}"), json!(1))).collect();+ assert_strict_keeps_todays_errors(&[+ ("render.settings.get", json!({"name": 5})),+ ("render.settings.get", json!({"name": ""})),+ ("render.settings.get", json!({"name": " Studio"})),+ ("render.settings.get", json!({"name": "Nope"})),+ ("render.settings.set", json!({"name": null, "set": {}})),+ ("render.settings.set", json!({"name": 5, "set": {}})),+ ("render.settings.set", json!({"name": "", "set": {}})),+ ("render.settings.set", json!({"name": "Studio", "set": null})),+ ("render.settings.set", json!({"name": "Studio", "set": []})),+ ("render.settings.set", json!({"name": "Studio", "set": too_many})),+ ("render.settings.set", json!({"name": "Studio", "set": {"widht": 800}})),+ ("render.settings.set", json!({"name": "Studio", "set": {"width": "wide"}})),+ ("render.settings.set", json!({"name": "Studio", "set": {"width": 0}})),+ ]);+}++/// #12783: Save Render Settings without `name` or `set` is refused by the check itself, before+/// the handler runs: in strict with the check's "is required", where the handler says serde's+/// "missing field". The first key left out, in the struct's order, is the one named either way.+#[test]+fn a_key_left_out_is_refused_by_the_check() {+ for (p, key) in [(json!({}), "name"), (json!({"set": {}}), "name"), (json!({"name": "Studio"}), "set")] {+ let messages: Vec<String> = crate::schema::issues("render.settings.set", &p).into_iter().map(|i| i.message).collect();+ assert_eq!(messages, [format!("`{key}` is required")], "{p}");+ let error = |level: ParamCheck| studio(level).execute("render.settings.set", &p).err().map(|e| e.to_string()).unwrap_or_default();+ assert!(error(ParamCheck::Off).ends_with(&format!("missing field `{key}`")), "{p}: {}", error(ParamCheck::Off));+ assert!(error(ParamCheck::Strict).ends_with(&format!("`{key}` is required")), "{p}: {}", error(ParamCheck::Strict));+ }+}++/// #12783: the schemas take what the handlers take. Each call is checked against both the schema+/// and the handler on the design with `Studio`, with the check off, so the two can't drift apart.+#[test]+fn the_schemas_take_what_the_handlers_take() {+ let get = input_schema_for::<GetParams>();+ let set = input_schema_for::<SetParams>();+ for (id, schema, p) in [+ ("render.settings.get", &get, json!({})),+ ("render.settings.get", &get, json!({"name": null})),+ ("render.settings.get", &get, json!({"name": "Studio"})),+ ("render.settings.get", &get, json!({"name": 5})),+ ("render.settings.get", &get, json!({"name": ""})),+ ("render.settings.set", &set, json!({"name": "Studio", "set": {"width": 1024}})),+ ("render.settings.set", &set, json!({"name": "Draft", "set": {}})),+ ("render.settings.set", &set, json!({"name": "Studio", "set": {"exposure_ev": 0.5, "job": null}})),+ ("render.settings.set", &set, json!({"name": "Studio", "set": {"widht": 1024}})),+ ("render.settings.set", &set, json!({"name": "Studio", "set": []})),+ ("render.settings.set", &set, json!({"name": "Studio"})),+ ] {+ let takes = studio(ParamCheck::Off).execute(id, &p).is_ok();+ assert_eq!(conforms(schema.as_value(), schema.as_value(), &p), takes, "{id} {p}");+ }+}++/// #12783: both commands reply as their output schemas say, in Warn without warnings, and the+/// replies are the JSON the handlers gave before: every setup with the defaults, one setup by+/// name, and a setup changed and saved again unchanged. Unknown keys fail in every mode, as the+/// handlers' serde structs refuse them; strict refuses them in the check's own words.+#[test]+fn render_settings_reply_with_their_schemas() {+ let got = output_schema_for::<RenderSettingsGot>();+ let got = got.as_value();+ let saved = output_schema_for::<RenderSettingsSaved>();+ let saved = saved.as_value();+ let mut s = studio(ParamCheck::Warn);+ let mut run = |id: &str, p: Value, schema: &Value| {+ let r = s.execute(id, &p).unwrap_or_else(|e| panic!("{id} {p}: {e}"));+ assert!(conforms(schema, schema, &r), "{r} doesn't match {schema}");+ assert!(r.get("param_warnings").is_none(), "{r}");+ r+ };+ let all = run("render.settings.get", json!({}), got);+ let one = run("render.settings.get", json!({"name": "Studio"}), got);+ let changed = run("render.settings.set", json!({"name": "Studio", "set": {"width": 1024}}), saved);+ let unchanged = run("render.settings.set", json!({"name": "Studio", "set": {"width": 1024}}), saved);+ assert_eq!(changed, unchanged, "saved again unchanged");+ assert_eq!(changed["setup"]["width"], 1024, "{changed}");+ let setups = s.doc.render.setups.clone();+ let studio_before = {+ let mut setup = setups.get("Studio").cloned().unwrap_or_default();+ setup.width = 800;+ setup+ };+ assert_eq!(all, json!({"setups": {"Studio": studio_before}, "defaults": RenderSetup::default()}));+ assert_eq!(one, json!({"name": "Studio", "setup": studio_before}));+ assert_eq!(changed, json!({"name": "Studio", "setup": setups.get("Studio")}));+ for level in [ParamCheck::Off, ParamCheck::Warn, ParamCheck::Strict] {+ s.param_check = level;+ let error = s.execute("render.settings.get", &json!({"nmae": "Studio"})).err().map(|e| e.to_string()).unwrap_or_default();+ assert!(error.contains("nmae"), "{level:?}: {error}");+ }+}diff --git a/crates/engine/src/schema/unconverted.txt b/crates/engine/src/schema/unconverted.txtindex 20d596f341..f7a166d217 100644--- a/crates/engine/src/schema/unconverted.txt+++ b/crates/engine/src/schema/unconverted.txt@@ -87,8 +87,6 @@ render.preflightrender.result.pinrender.result.regraderender.scene-render.settings.get-render.settings.setrender.startrender.statusselect.clear