use assert_cmd::prelude::*;
use predicates::prelude::*;
use std::process::Command;
use tokio::fs;
use crate::common::{ManifestBuilder, TestProject};
#[tokio::test]
async fn test_max_parallel_flag_values() {
let project = TestProject::new().await.unwrap();
let official_repo = project.create_source_repo("official").await.unwrap();
official_repo
.add_resource("agents", "test-agent-1", "# Test Agent 1\n\nA test agent")
.await
.unwrap();
official_repo
.add_resource("agents", "test-agent-2", "# Test Agent 2\n\nA test agent")
.await
.unwrap();
official_repo
.add_resource("agents", "test-agent-3", "# Test Agent 3\n\nA test agent")
.await
.unwrap();
official_repo.commit_all("Initial commit").unwrap();
official_repo.tag_version("v1.0.0").unwrap();
let source_url = official_repo.bare_file_url(project.sources_path()).await.unwrap();
let manifest = ManifestBuilder::new()
.add_source("official", &source_url)
.add_standard_agent("agent1", "official", "agents/test-agent-1.md")
.add_standard_agent("agent2", "official", "agents/test-agent-2.md")
.add_standard_agent("agent3", "official", "agents/test-agent-3.md")
.build();
project.write_manifest(&manifest).await.unwrap();
for max_parallel in [1, 2, 4, 8] {
let output =
project.run_agpm(&["install", "--max-parallel", &max_parallel.to_string()]).unwrap();
assert!(
output.success,
"Install failed with max_parallel={}: {}",
max_parallel, output.stderr
);
assert!(project.project_path().join(".claude/agents/agpm/test-agent-1.md").exists());
assert!(project.project_path().join(".claude/agents/agpm/test-agent-2.md").exists());
assert!(project.project_path().join(".claude/agents/agpm/test-agent-3.md").exists());
let _ = fs::remove_dir_all(project.project_path().join(".claude")).await;
}
}
#[tokio::test]
async fn test_max_parallel_invalid_values() {
let project = TestProject::new().await.unwrap();
let output = project.run_agpm(&["install", "--max-parallel", "0"]).unwrap();
assert!(!output.success);
let output = project.run_agpm(&["install", "--max-parallel", "-1"]).unwrap();
assert!(!output.success);
let output = project.run_agpm(&["install", "--max-parallel", "abc"]).unwrap();
assert!(!output.success);
}
#[tokio::test]
async fn test_default_parallelism() {
let project = TestProject::new().await.unwrap();
let official_repo = project.create_source_repo("official").await.unwrap();
official_repo
.add_resource("agents", "test-agent", "# Test Agent\n\nA test agent")
.await
.unwrap();
official_repo.commit_all("Initial commit").unwrap();
official_repo.tag_version("v1.0.0").unwrap();
let source_url = official_repo.bare_file_url(project.sources_path()).await.unwrap();
let manifest = ManifestBuilder::new()
.add_source("official", &source_url)
.add_standard_agent("agent", "official", "agents/test-agent.md")
.build();
project.write_manifest(&manifest).await.unwrap();
let output = project.run_agpm(&["install"]).unwrap();
assert!(output.success);
assert!(output.stdout.contains("Installing") || output.stdout.contains("Installed"));
assert!(project.project_path().join(".claude/agents/agpm/test-agent.md").exists());
}
#[tokio::test]
async fn test_max_parallel_install_only() {
let project = TestProject::new().await.unwrap();
let official_repo = project.create_source_repo("official").await.unwrap();
official_repo
.add_resource("agents", "test-agent", "# Test Agent\n\nA test agent")
.await
.unwrap();
official_repo.commit_all("Initial commit").unwrap();
official_repo.tag_version("v1.0.0").unwrap();
let source_url = official_repo.bare_file_url(project.sources_path()).await.unwrap();
let manifest = ManifestBuilder::new()
.add_source("official", &source_url)
.add_standard_agent("agent", "official", "agents/test-agent.md")
.build();
project.write_manifest(&manifest).await.unwrap();
let output = project.run_agpm(&["install", "--max-parallel", "2"]).unwrap();
assert!(output.success);
let output = project.run_agpm(&["update"]).unwrap();
assert!(output.success);
}
#[tokio::test]
async fn test_max_parallel_help_coverage() {
let mut cmd = Command::new(env!("CARGO_BIN_EXE_agpm"));
cmd.arg("install")
.arg("--help")
.assert()
.success()
.stdout(predicate::str::contains("--max-parallel"));
}