mirror of
https://github.com/storytold/designcraft.git
synced 2026-10-24 18:26:50 -06:00
- engine::script: parse scripts (lines, JSON lines, JSON arrays), resolve "$N.path" /
"${N.path}" references to earlier results, run with a failure report (+ tests)
- CLI: script [FILE|-] (headless or --connect to the running app; --save/--export,
--keep-going), app COMMAND [JSON] / --method, describe ID, commands FILTER, $N references in
run --cmd (+ integration tests)
- MCP batch: references and a script-text alternative (+ test)
- docs/agents.md; docs/parity.md scored over 275 catalogue features with cargo xtask parity;
ROADMAP: parity ~63% breadth / ~55% overall, ~600 agent-hours remaining
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
69 lines
2.7 KiB
Rust
69 lines
2.7 KiB
Rust
//! The agent-facing command line: scripts with references, describe, filtered command lists.
|
|
|
|
use std::io::Write;
|
|
use std::process::{Command, Stdio};
|
|
|
|
fn cli() -> Command {
|
|
Command::new(env!("CARGO_BIN_EXE_designcraft-cli"))
|
|
}
|
|
|
|
#[test]
|
|
fn script_from_stdin_with_references_saves_and_exports() {
|
|
let dir = std::env::temp_dir().join(format!("dc-cli-{}", std::process::id()));
|
|
std::fs::create_dir_all(&dir).unwrap();
|
|
let (doc, png) = (dir.join("a.designcraft"), dir.join("a.png"));
|
|
let mut child = cli()
|
|
.args(["script", "-", "--save", doc.to_str().unwrap(), "--export", png.to_str().unwrap()])
|
|
.stdin(Stdio::piped())
|
|
.stdout(Stdio::piped())
|
|
.spawn()
|
|
.unwrap();
|
|
child
|
|
.stdin
|
|
.take()
|
|
.unwrap()
|
|
.write_all(
|
|
b"# comment\nframe.create {\"rect\": [72, 72, 300, 200], \"content\": \"text\", \"text\": \"Hi\"}\nstory.get {\"story\": \"$0.story\"}\n",
|
|
)
|
|
.unwrap();
|
|
let out = child.wait_with_output().unwrap();
|
|
assert!(out.status.success(), "{}", String::from_utf8_lossy(&out.stderr));
|
|
let v: serde_json::Value = serde_json::from_slice(&out.stdout).unwrap();
|
|
assert_eq!(v["completed"], 2);
|
|
assert_eq!(v["results"][1]["text"], "Hi");
|
|
assert!(doc.exists() && png.exists());
|
|
let _ = std::fs::remove_dir_all(&dir);
|
|
}
|
|
|
|
#[test]
|
|
fn failing_script_exits_nonzero_with_the_step() {
|
|
let mut child = cli().args(["script", "-"]).stdin(Stdio::piped()).stdout(Stdio::piped()).stderr(Stdio::piped()).spawn().unwrap();
|
|
child.stdin.take().unwrap().write_all(b"document.inspect\nno.such.command\n").unwrap();
|
|
let out = child.wait_with_output().unwrap();
|
|
assert!(!out.status.success());
|
|
let v: serde_json::Value = serde_json::from_slice(&out.stdout).unwrap();
|
|
assert_eq!(v["failedIndex"], 1);
|
|
}
|
|
|
|
#[test]
|
|
fn run_cmd_references_and_describe() {
|
|
let out = cli()
|
|
.args([
|
|
"run",
|
|
"--cmd",
|
|
r#"frame.create={"rect":[72,72,300,200],"content":"text","text":"Hello"}"#,
|
|
"--cmd",
|
|
r#"story.get={"story":"$0.story"}"#,
|
|
])
|
|
.output()
|
|
.unwrap();
|
|
assert!(out.status.success(), "{}", String::from_utf8_lossy(&out.stderr));
|
|
assert!(String::from_utf8_lossy(&out.stdout).contains("\"text\":\"Hello\""));
|
|
let out = cli().args(["describe", "footnote.insert"]).output().unwrap();
|
|
let v: serde_json::Value = serde_json::from_slice(&out.stdout).unwrap();
|
|
assert_eq!(v["label"], "Insert Footnote");
|
|
let out = cli().args(["commands", "footnote."]).output().unwrap();
|
|
let v: serde_json::Value = serde_json::from_slice(&out.stdout).unwrap();
|
|
assert!(v.as_array().unwrap().iter().all(|c| c.to_string().contains("footnote")));
|
|
}
|