use assert_cmd::Command;
use std::path::Path;
fn aristo_in(repo: &Path) -> Command {
let mut cmd = Command::cargo_bin("aristo").unwrap();
cmd.current_dir(repo);
cmd
}
fn make_fixture_workspace() -> tempfile::TempDir {
let tmp = tempfile::tempdir().unwrap();
let repo = tmp.path();
std::fs::create_dir_all(repo.join(".aristo")).unwrap();
std::fs::write(
repo.join("aristo.toml"),
"[project]\ncrate_root = \"src/lib.rs\"\n",
)
.unwrap();
std::fs::write(
repo.join(".aristo/index.toml"),
r#"[__meta__]
schema_version = 1
[demo_intent]
kind = "intent"
text = "demo"
verify = "neural"
status = "unknown"
text_hash = "sha256:0000000000000000000000000000000000000000000000000000000000000000"
body_hash = "sha256:0000000000000000000000000000000000000000000000000000000000000000"
file = "src/lib.rs"
site = "fn demo (line 1)"
covered_region = "function"
"#,
)
.unwrap();
tmp
}
fn dot_on_path() -> bool {
std::process::Command::new("dot")
.arg("-V")
.stderr(std::process::Stdio::null())
.output()
.map(|o| o.status.success())
.unwrap_or(false)
}
#[test]
fn svg_renders_valid_xml_when_dot_is_on_path() {
if !dot_on_path() {
eprintln!("skipping: `dot` not on PATH (install graphviz to exercise this test)");
return;
}
let tmp = make_fixture_workspace();
let repo = tmp.path();
let out_path = repo.join("out.svg");
aristo_in(repo)
.args(["graph", "--format=svg", "--include-orphans", "--out"])
.arg(&out_path)
.assert()
.success();
let svg = std::fs::read_to_string(&out_path).unwrap();
assert!(
svg.starts_with("<?xml") || svg.contains("<svg "),
"expected SVG content, got: {svg:.200}..."
);
assert!(svg.contains("demo_intent"), "node id should be in the SVG");
}
#[test]
fn svg_with_no_dot_on_path_errors_with_install_hints_and_alternatives() {
let tmp = make_fixture_workspace();
let repo = tmp.path();
let empty_path_dir = tmp.path().join("__no_dot_path__");
std::fs::create_dir(&empty_path_dir).unwrap();
let assert = Command::cargo_bin("aristo")
.unwrap()
.current_dir(repo)
.env("PATH", &empty_path_dir)
.args(["graph", "--format=svg", "--out=out.svg"])
.assert()
.failure()
.code(2);
let stderr_assertion = assert
.stderr(predicates::str::contains(
"SVG output requires Graphviz `dot`, which was not found on PATH",
))
.stderr(predicates::str::contains("brew install graphviz"))
.stderr(predicates::str::contains("apt install graphviz"))
.stderr(predicates::str::contains("https://graphviz.org/download/"))
.stderr(predicates::str::contains("--format=dot"))
.stderr(predicates::str::contains("--format=mermaid"));
let _ = stderr_assertion;
assert!(!repo.join("out.svg").exists());
}