#![allow(dead_code)]
use assert_cmd::Command;
use std::path::{Path, PathBuf};
const AMBIENT_ENV: &[&str] = &[
"SUNO_DEFAULT_MODEL",
"SUNO_POLL_INTERVAL_SECS",
"SUNO_POLL_TIMEOUT_SECS",
"SUNO_OUTPUT_DIR",
"SUNO_INSTALL_SOURCE",
"SUNO_CHROME_PATH",
"SUNO_CONFIG_DIR",
"SUNO_DATA_DIR",
"SUNO_LIVE_TESTS",
];
pub fn suno() -> Command {
let mut cmd = Command::cargo_bin("suno").unwrap();
for key in AMBIENT_ENV {
cmd.env_remove(key);
}
cmd
}
pub fn suno_in(home: &Path) -> Command {
let mut cmd = suno();
cmd.env("SUNO_CONFIG_DIR", home.join("config"))
.env("SUNO_DATA_DIR", home.join("data"))
.env("HOME", home)
.env("XDG_CONFIG_HOME", home.join(".config"))
.env("XDG_DATA_HOME", home.join(".local/share"))
.env("XDG_CACHE_HOME", home.join(".cache"));
cmd
}
pub fn config_path_in(home: &Path) -> PathBuf {
let out = suno_in(home)
.args(["config", "path", "--json"])
.output()
.unwrap();
assert!(out.status.success());
let json: serde_json::Value =
serde_json::from_slice(&out.stdout).expect("config path should be JSON");
PathBuf::from(json["data"]["path"].as_str().unwrap())
}
pub fn write_config_in(home: &Path, contents: &str) -> PathBuf {
let path = config_path_in(home);
std::fs::create_dir_all(path.parent().unwrap()).unwrap();
std::fs::write(&path, contents).unwrap();
path
}
pub fn agent_info() -> serde_json::Value {
let out = suno().arg("agent-info").output().unwrap();
assert!(out.status.success());
serde_json::from_slice(&out.stdout).expect("agent-info must be valid JSON")
}
pub fn vendored_schema(name: &str) -> serde_json::Value {
let path = Path::new(env!("CARGO_MANIFEST_DIR"))
.join("conformance/schemas")
.join(name);
serde_json::from_str(&std::fs::read_to_string(&path).unwrap())
.unwrap_or_else(|e| panic!("{} is not valid JSON: {e}", path.display()))
}
pub fn skip_live() -> bool {
if std::env::var("SUNO_LIVE_TESTS").as_deref() == Ok("1") {
false
} else {
eprintln!("skipped: set SUNO_LIVE_TESTS=1 to run network-touching tests");
true
}
}