use assert_cmd::prelude::*;
use predicates::prelude::*;
use std::fs;
use std::process::Command;
mod common;
mod fixtures;
use common::TestProject;
#[test]
fn test_max_parallel_flag_values() {
let project = TestProject::new().unwrap();
let official_repo = project.create_source_repo("official").unwrap();
official_repo
.add_resource("agents", "test-agent-1", "# Test Agent 1\n\nA test agent")
.unwrap();
official_repo
.add_resource("agents", "test-agent-2", "# Test Agent 2\n\nA test agent")
.unwrap();
official_repo
.add_resource("agents", "test-agent-3", "# Test Agent 3\n\nA test agent")
.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).unwrap();
for max_parallel in [1, 2, 4, 8] {
let output = project
.run_ccpm(&["install", "--max-parallel", &max_parallel.to_string()])
.unwrap();
assert!(output.success);
assert!(output.stdout.contains("Installing") || output.stdout.contains("Installed"));
assert!(
project
.project_path()
.join(".claude/agents/agent1.md")
.exists()
);
assert!(
project
.project_path()
.join(".claude/agents/agent2.md")
.exists()
);
assert!(
project
.project_path()
.join(".claude/agents/agent3.md")
.exists()
);
let _ = fs::remove_dir_all(project.project_path().join(".claude"));
}
}
#[test]
fn test_max_parallel_invalid_values() {
let project = TestProject::new().unwrap();
let output = project
.run_ccpm(&["install", "--max-parallel", "0"])
.unwrap();
assert!(!output.success);
let output = project
.run_ccpm(&["install", "--max-parallel", "-1"])
.unwrap();
assert!(!output.success);
let output = project
.run_ccpm(&["install", "--max-parallel", "abc"])
.unwrap();
assert!(!output.success);
}
#[test]
fn test_default_parallelism() {
let project = TestProject::new().unwrap();
let official_repo = project.create_source_repo("official").unwrap();
official_repo
.add_resource("agents", "test-agent", "# Test Agent\n\nA test agent")
.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).unwrap();
let output = project.run_ccpm(&["install"]).unwrap();
assert!(output.success);
assert!(output.stdout.contains("Installing") || output.stdout.contains("Installed"));
assert!(
project
.project_path()
.join(".claude/agents/agent.md")
.exists()
);
}
#[test]
fn test_max_parallel_install_only() {
let project = TestProject::new().unwrap();
let official_repo = project.create_source_repo("official").unwrap();
official_repo
.add_resource("agents", "test-agent", "# Test Agent\n\nA test agent")
.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).unwrap();
let output = project
.run_ccpm(&["install", "--max-parallel", "2"])
.unwrap();
assert!(output.success);
let output = project.run_ccpm(&["update"]).unwrap();
assert!(output.success);
}
#[test]
fn test_max_parallel_help_coverage() {
let mut cmd = Command::cargo_bin("ccpm").unwrap();
cmd.arg("install")
.arg("--help")
.assert()
.success()
.stdout(predicate::str::contains("--max-parallel"));
}