use assert_cmd::prelude::*;
use predicates::prelude::*;
use std::process::Command;
use tokio::fs;
mod common;
mod fixtures;
use common::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()).unwrap();
let manifest_content = format!(
r#"
[sources]
official = "{}"
[agents]
agent1 = {{ source = "official", path = "agents/test-agent-1.md", version = "v1.0.0" }}
agent2 = {{ source = "official", path = "agents/test-agent-2.md", version = "v1.0.0" }}
agent3 = {{ source = "official", path = "agents/test-agent-3.md", version = "v1.0.0" }}
"#,
source_url
);
project.write_manifest(&manifest_content).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/test-agent-1.md").exists());
assert!(project.project_path().join(".claude/agents/test-agent-2.md").exists());
assert!(project.project_path().join(".claude/agents/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()).unwrap();
let manifest_content = format!(
r#"
[sources]
official = "{}"
[agents]
agent = {{ source = "official", path = "agents/test-agent.md", version = "v1.0.0" }}
"#,
source_url
);
project.write_manifest(&manifest_content).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/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()).unwrap();
let manifest_content = format!(
r#"
[sources]
official = "{}"
[agents]
agent = {{ source = "official", path = "agents/test-agent.md", version = "v1.0.0" }}
"#,
source_url
);
project.write_manifest(&manifest_content).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::cargo_bin("agpm").unwrap();
cmd.arg("install")
.arg("--help")
.assert()
.success()
.stdout(predicate::str::contains("--max-parallel"));
}