From fcfd65d0d45328922b4a4a2a19bb73871a2d2338 Mon Sep 17 00:00:00 2001 From: ViktorBystrov72 Date: Sat, 28 Nov 2026 12:48:21 +0500 Subject: [PATCH 1/2] Open linked SBS source under a .mcraft filename (#310) Co-authored-by: ViktorBystrov72 <18964918+ViktorBystrov72@users.noreply.github.com> --- crates/automation/src/headless.test.rs | 22 ++++++++++++++++++++++ crates/engine/src/file_cmds.rs | 3 ++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/crates/automation/src/headless.test.rs b/crates/automation/src/headless.test.rs index fbcde85c..5d02bc29 100644 --- a/crates/automation/src/headless.test.rs +++ b/crates/automation/src/headless.test.rs @@ -3,6 +3,28 @@ mod end_merge_tests { use crate::headless::{Filesystem, Headless, RenderOptions}; use serde_json::json; + #[test] + fn linked_material_source_opens_as_sbs_with_a_mcraft_name() { + use materialcraft_engine::{Session, core::Package, file_cmds}; + + let dir = tempfile::tempdir().unwrap(); + let mut source = Headless::new(Session::new(Package::new("Linked source")), Filesystem::TrustedLocal); + source.command_run("file.new", json!({"template": "empty"})).unwrap(); + source.command_run("graph.node.add", json!({"def": "uniform"})).unwrap(); + let xml = file_cmds::save_bytes(&source.session).unwrap(); + let archive = file_cmds::save_files_at(&source.session, "archive.mcraft").unwrap().zip().unwrap(); + + for (name, bytes) in [("source.sbs", &xml), ("source.mcraft", &xml), ("archive.mcraft", &archive)] { + let path = dir.path().join(name); + std::fs::write(&path, bytes).unwrap(); + let mut opened = Headless::new(Headless::default_session(), Filesystem::TrustedLocal); + opened.load(path.to_str().unwrap()).unwrap_or_else(|error| panic!("{name}: {error}")); + let graph = opened.session.graph().unwrap(); + assert_eq!(graph.nodes.len(), 1, "{name}"); + assert_eq!(graph.nodes[0].def, "uniform", "{name}"); + } + } + #[cfg(unix)] #[test] fn trusted_reads_are_bounded_and_regular_files_only() { diff --git a/crates/engine/src/file_cmds.rs b/crates/engine/src/file_cmds.rs index 32a543c3..d1fab72c 100644 --- a/crates/engine/src/file_cmds.rs +++ b/crates/engine/src/file_cmds.rs @@ -225,7 +225,8 @@ fn open_resolved( } pub(crate) fn read_package_bytes(bytes: &[u8], name: &str, linked: &dyn Fn(&str) -> Option>) -> Result { - if materialcraft_formats::project::is_archive(bytes) || is_mcraft(name) { + // Linked-material cooks can pass SBS XML under a .mcraft name. + if materialcraft_formats::project::is_archive(bytes) { return Ok(materialcraft_formats::project::read(bytes, name)?); } From 7a20298e43b82e081d07568a88a862bad5b73e27 Mon Sep 17 00:00:00 2001 From: NetterSilver <133535268+Silvertree2010@users.noreply.github.com> Date: Sat, 28 Nov 2026 08:48:31 +0100 Subject: [PATCH 2/2] Accept whole-number floats for Int2/Int3/Int4 in coerce_json (#227) Found while testing crates/core/src/value.rs:192 (parse_integers, used by the Int2/Int3/Int4 arms of coerce_json) Co-authored-by: Claude Haiku 5.5 --- crates/core/src/value.rs | 26 +++++++++++++++----------- crates/core/src/value_tests.rs | 8 ++++++++ 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/crates/core/src/value.rs b/crates/core/src/value.rs index 5fb0b821..e3607dc7 100644 --- a/crates/core/src/value.rs +++ b/crates/core/src/value.rs @@ -133,16 +133,7 @@ impl Value { Value::Float4([a[0], a[1], a[2], a[3]]) } Value::Color(_) => Value::Color(parse_color(j)?), - Value::Int(_) => Value::Int(match j.as_i64() { - Some(value) => i32::try_from(value).ok()?, - None => { - let value = j.as_f64()?.round(); - if !value.is_finite() || value < i32::MIN as f64 || value > i32::MAX as f64 { - return None; - } - value as i32 - } - }), + Value::Int(_) => Value::Int(parse_integer(j)?), Value::Int2(_) => Value::Int2(parse_integers(j)?), Value::Int3(_) => Value::Int3(parse_integers(j)?), Value::Int4(_) => Value::Int4(parse_integers(j)?), @@ -175,8 +166,21 @@ fn parse_integers(value: &serde_json::Value) -> Option<[i32; let mut result = [0; COUNT]; for (target, component) in result.iter_mut().zip(components) { - *target = i32::try_from(component.as_i64()?).ok()?; + *target = parse_integer(component)?; } Some(result) } + +fn parse_integer(value: &serde_json::Value) -> Option { + match value.as_i64() { + Some(value) => i32::try_from(value).ok(), + None => { + let value = value.as_f64()?.round(); + if !value.is_finite() || value < i32::MIN as f64 || value > i32::MAX as f64 { + return None; + } + Some(value as i32) + } + } +} diff --git a/crates/core/src/value_tests.rs b/crates/core/src/value_tests.rs index b3337cd8..0e655809 100644 --- a/crates/core/src/value_tests.rs +++ b/crates/core/src/value_tests.rs @@ -28,6 +28,14 @@ fn coerce_from_json() { assert_eq!(Value::Int(0).coerce_json(&serde_json::json!({"t": "text", "v": "x"})), None); } +#[test] +fn coerce_json_int_vectors_accept_floats() { + assert_eq!(Value::Int2([0; 2]).coerce_json(&serde_json::json!([3.0, 4.0])), Some(Value::Int2([3, 4]))); + assert_eq!(Value::Int3([0; 3]).coerce_json(&serde_json::json!([1.0, 2, 8.6])), Some(Value::Int3([1, 2, 9]))); + assert_eq!(Value::Int4([0; 4]).coerce_json(&serde_json::json!([1.0, 2.0, 3.0, 4.0])), Some(Value::Int4([1, 2, 3, 4]))); + assert_eq!(Value::Int2([0; 2]).coerce_json(&serde_json::json!([1e20, 1.0])), None); +} + #[test] fn gradient_interpolates() { let g = Gradient::default();