47 lines
1.7 KiB
Rust
47 lines
1.7 KiB
Rust
//! init + context detection.
|
|
|
|
mod common;
|
|
|
|
use agent_manager::commands::init_cmd;
|
|
use agent_manager::context;
|
|
|
|
#[test]
|
|
fn context_detects_stack_from_markers() {
|
|
let dir = tempfile::tempdir().unwrap();
|
|
std::fs::write(dir.path().join("Cargo.toml"), "[package]").unwrap();
|
|
std::fs::write(dir.path().join("package.json"), "{}").unwrap();
|
|
let stack = context::detect_stack(dir.path());
|
|
assert_eq!(stack, vec!["node".to_string(), "rust".to_string()]);
|
|
assert_eq!(context::recommended_agents(&stack), vec!["smelt", "claude-code"]);
|
|
}
|
|
|
|
#[test]
|
|
fn generate_writes_valid_config_and_refuses_overwrite() {
|
|
let dir = tempfile::tempdir().unwrap();
|
|
std::fs::write(dir.path().join("Cargo.toml"), "[package]").unwrap();
|
|
let path = init_cmd::generate(dir.path(), false).unwrap();
|
|
assert!(path.ends_with("agent-manager.yaml"));
|
|
let text = std::fs::read_to_string(&path).unwrap();
|
|
assert!(text.contains(r#"version: "1.0""#), "config valide: {text}");
|
|
assert!(text.contains("smelt"), "agent recommande pour rust: {text}");
|
|
// Un second appel sans --force échoue.
|
|
assert!(init_cmd::generate(dir.path(), false).is_err());
|
|
// Avec --force, il écrase.
|
|
assert!(init_cmd::generate(dir.path(), true).is_ok());
|
|
}
|
|
|
|
#[test]
|
|
fn generate_uses_default_for_empty_dir() {
|
|
let dir = tempfile::tempdir().unwrap();
|
|
let path = init_cmd::generate(dir.path(), false).unwrap();
|
|
let text = std::fs::read_to_string(&path).unwrap();
|
|
assert!(text.contains("claude-code"), "default agent: {text}");
|
|
}
|
|
|
|
#[test]
|
|
fn command_runs_dry() {
|
|
let app = common::test_app("initdry", &["init", "--dry-run"]);
|
|
let code = init_cmd::run(&app, false).unwrap();
|
|
assert_eq!(code, 0);
|
|
}
|