A 1.2 MB pure-Rust rewrite of headless Blender built for AI agents — 3D B-rep modeling engine, CLI, and MCP server
use std::io::Write;
use std::process::{Command, Stdio};
fn run_forma(args: &[&str], stdin_data: &str) -> (i32, String, String) {
let bin = env!("CARGO_BIN_EXE_forma");
let mut child = Command::new(bin)
.args(args)
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.stderr(Stdio::piped())
.spawn()
.expect("spawn forma binary");
child
.stdin
.as_mut()
.expect("stdin piped")
.write_all(stdin_data.as_bytes())
.expect("write stdin to forma");
let out = child.wait_with_output().expect("wait for forma process");
let code = out.status.code().unwrap_or(-1);
(
code,
String::from_utf8_lossy(&out.stdout).into_owned(),
String::from_utf8_lossy(&out.stderr).into_owned(),
)
}
#[test]
fn issue_84_strict_invariant_failure_exits_with_code_3() {
// 1. Self-intersecting torus in --strict mode exits 3
let (code, _, stderr) = run_forma(&["eval", "--strict", "-"], "a = torus(0.5, 1)\n");
assert_eq!(code, 3, "expected exit code 3 for strict self-intersection, stderr={stderr}");
assert!(stderr.contains("invariant violation"), "stderr={stderr}");
// 2. Overlapping multi-shell array in --strict mode exits 3
let (code2, _, stderr2) = run_forma(
&["eval", "--strict", "-"],
"a = box(1, 1, 1) | array(2, step=(0.5, 0, 0), union=false)\n",
);
assert_eq!(code2, 3, "expected exit code 3 for overlapping shells, stderr={stderr2}");
// 3. JSON mode still exits 3 on strict invariant failure
let (code3, stdout3, _) = run_forma(&["eval", "--strict", "--json", "-"], "a = torus(0.5, 1)\n");
assert_eq!(code3, 3, "expected exit code 3 in --json mode, stdout={stdout3}");
assert!(stdout3.contains("\"ok\":false"), "stdout={stdout3}");
// 4. Syntax/script error still exits 1
let (code_syn, _, _) = run_forma(&["eval", "--strict", "-"], "a = box(1,\n");
assert_eq!(code_syn, 1, "syntax error must still exit 1");
// 5. Unknown flag still exits 2
let (code_flag, _, _) = run_forma(&["eval", "--bogus-flag"], "a = box(1,1,1)\n");
assert_eq!(code_flag, 2, "unknown flag must still exit 2");
// 6. Valid solid exits 0
let (code_ok, stdout_ok, _) = run_forma(&["eval", "--strict", "-"], "a = box(1,1,1)\n");
assert_eq!(code_ok, 0);
assert!(stdout_ok.contains("WT=ok"));
}