use std::path::Path;
use std::process::Command;
pub(crate) fn aid_cmd_in(aid_home: &Path) -> Command {
aid_cmd_with_cwd(aid_home, aid_home)
}
pub(crate) fn aid_cmd_with_cwd(aid_home: &Path, cwd: &Path) -> Command {
let mut cmd = Command::new(env!("CARGO_BIN_EXE_aid"));
cmd.env("AID_HOME", aid_home);
cmd.env("AID_NO_DETACH", "1");
for var in [
"AID_GROUP",
"AID_TASK_ID",
"AID_TASK_DEPTH",
"AID_TASK_NAME",
"AID_ITERATION",
"AID_PARENT_TASK_ID",
"AID_CASCADE",
] {
cmd.env_remove(var);
}
cmd.current_dir(cwd);
cmd
}
#[allow(dead_code)]
pub fn seed_codex_leaderboard(home: &Path) {
let scores = include_str!("../fixtures/leaderboard/e2e-codex-scores.json");
let prices = include_str!("../fixtures/leaderboard/e2e-codex-prices.json");
for (file, body) in [("scores.json", scores), ("prices.json", prices)] {
let mut feed: serde_json::Value = serde_json::from_str(body).expect("leaderboard fixture");
feed["built_at"] = serde_json::Value::String(chrono::Utc::now().to_rfc3339());
std::fs::write(home.join(file), feed.to_string()).expect("leaderboard cache");
}
}
#[allow(dead_code)]
pub fn write_executable(path: &Path, content: &str) {
let parent = path.parent().unwrap_or_else(|| Path::new("."));
let parent = if parent.as_os_str().is_empty() {
Path::new(".")
} else {
parent
};
if !parent.exists() {
std::fs::create_dir_all(parent).expect("create parent directory for executable");
}
let mut temp = tempfile::Builder::new()
.prefix(".tmp-exec-")
.tempfile_in(parent)
.expect("create sibling temp file");
use std::io::Write;
temp.write_all(content.as_bytes()).expect("write executable content");
temp.flush().expect("flush executable content");
let status = Command::new("install")
.args(["-m", "755"])
.arg(temp.path())
.arg(path)
.status()
.expect("run install");
assert!(status.success(), "install -m 755 failed with status {status}");
let _ = temp.close();
}