From fcfd65d0d45328922b4a4a2a19bb73871a2d2338 Mon Sep 17 00:00:00 2001 From: ViktorBystrov72 Date: Sat, 28 Nov 2026 12:48:21 +0500 Subject: [PATCH] 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)?); }