- CLI Rust (am) : list/install/uninstall/update/start/stop/restart/run/status/search/info/config/doctor/completion/export/import/self-update + shell interactif (Tab, historique) - 9 methodes d'installation (npm, pip, uv, cargo, go, bun, curl, binary, git) - catalogue de 72 agents, dependances, processus, securite (dry-run, checksums) - sondes de version paralleles + cache (am list ~25 ms a chaud) - installateurs one-liner : install.sh, install.ps1
72 lines
2.3 KiB
Rust
72 lines
2.3 KiB
Rust
//! Shared helpers for integration tests: build an isolated App whose data,
|
|
//! state, logs and config all live inside one temporary directory.
|
|
|
|
#![allow(dead_code)]
|
|
|
|
use agent_manager::app::{App, Paths};
|
|
use agent_manager::cli::Cli;
|
|
use agent_manager::output::Logger;
|
|
use agent_manager::state::StateStore;
|
|
use clap::Parser;
|
|
use std::path::PathBuf;
|
|
use std::sync::atomic::{AtomicU32, Ordering};
|
|
|
|
static COUNTER: AtomicU32 = AtomicU32::new(0);
|
|
|
|
fn fresh_dir(tag: &str) -> PathBuf {
|
|
let id = COUNTER.fetch_add(1, Ordering::SeqCst);
|
|
let dir = std::env::temp_dir().join(format!("am-test-{tag}-{}-{id}", std::process::id()));
|
|
std::fs::create_dir_all(&dir).unwrap();
|
|
dir
|
|
}
|
|
|
|
/// Build an App from CLI args, isolated in a fresh temporary directory.
|
|
/// A minimal config file is passed via --config so no user config leaks in.
|
|
pub fn test_app(tag: &str, args: &[&str]) -> App {
|
|
let dir = fresh_dir(tag);
|
|
let cfg = dir.join("config.yaml");
|
|
std::fs::write(
|
|
&cfg,
|
|
"version: \"1.0\"\nsettings:\n auto_install_deps: false\n confirm_before_run: false\nagents: []\n",
|
|
)
|
|
.unwrap();
|
|
let mut full = vec!["am".to_string(), "--config".to_string(), cfg.display().to_string()];
|
|
full.extend(args.iter().map(|s| s.to_string()));
|
|
let cli = Cli::parse_from(full);
|
|
let mut app = App::from_cli(cli).expect("app should build");
|
|
isolate(&mut app, &dir);
|
|
app
|
|
}
|
|
|
|
/// Point every runtime path (data, state, logs) inside dir.
|
|
pub fn isolate(app: &mut App, dir: &PathBuf) {
|
|
app.paths = Paths {
|
|
install_dir: dir.join("agents"),
|
|
bin_dir: dir.join("agents").join("bin"),
|
|
log_dir: dir.join("logs"),
|
|
state_file: dir.join("state.json"),
|
|
probe_cache_file: dir.join("probe-cache.json"),
|
|
config_dir: Some(dir.join("config")),
|
|
};
|
|
app.state = StateStore::new(app.paths.state_file.clone());
|
|
app.log = Logger::new(
|
|
app.paths.log_dir.clone(),
|
|
app.cli.verbose,
|
|
app.cli.quiet,
|
|
app.cli.no_color,
|
|
);
|
|
}
|
|
|
|
/// A minimal valid config file with one agent, written into dir.
|
|
pub fn write_config(dir: &PathBuf, body: &str) -> PathBuf {
|
|
let cfg = dir.join("config.yaml");
|
|
std::fs::write(
|
|
&cfg,
|
|
format!(
|
|
"version: \"1.0\"\nsettings:\n auto_install_deps: false\n confirm_before_run: false\n{body}\n"
|
|
),
|
|
)
|
|
.unwrap();
|
|
cfg
|
|
}
|