use anyhow::Result;
mod common;
use common::{DirAssert, FileAssert, TestProject};
#[test]
fn test_using_test_project_helper() -> Result<()> {
ccpm::test_utils::init_test_logging(None);
let project = TestProject::new()?;
project.write_manifest(
r#"
[sources]
example = "https://github.com/example/repo.git"
[agents]
test-agent = { source = "example", path = "agents/test.md", version = "v1.0.0" }
"#,
)?;
project.create_local_resource("agents/local-agent.md", "# Local Agent\n\nTest content")?;
DirAssert::exists(project.project_path());
DirAssert::exists(project.cache_path());
DirAssert::exists(project.sources_path());
FileAssert::exists(project.project_path().join("ccpm.toml"));
FileAssert::contains(project.project_path().join("ccpm.toml"), "test-agent");
FileAssert::exists(project.project_path().join("agents/local-agent.md"));
FileAssert::contains(
project.project_path().join("agents/local-agent.md"),
"# Local Agent",
);
let output = project.run_ccpm(&["validate"])?;
output.assert_success();
output.assert_stdout_contains("Valid ccpm.toml");
Ok(())
}
#[test]
fn test_using_test_source_repo_helper() -> Result<()> {
ccpm::test_utils::init_test_logging(None);
let project = TestProject::new()?;
let source_repo = project.create_source_repo("test-source")?;
source_repo.create_standard_resources()?;
source_repo.commit_all("Initial commit")?;
source_repo.tag_version("v1.0.0")?;
source_repo.add_resource("agents", "custom", "# Custom Agent\nSpecial content")?;
source_repo.commit_all("Add custom agent")?;
source_repo.tag_version("v1.1.0")?;
let repo_url = source_repo.bare_file_url(project.sources_path())?;
let manifest_content = format!(
r#"
[sources]
test = "{}"
[agents]
standard = {{ source = "test", path = "agents/test-agent.md", version = "v1.0.0" }}
custom = {{ source = "test", path = "agents/custom.md", version = "v1.1.0" }}
"#,
repo_url
);
project.write_manifest(&manifest_content)?;
let output = project.run_ccpm(&["install"])?;
output.assert_success();
let agents_dir = project.project_path().join(".claude/agents");
DirAssert::exists(&agents_dir);
DirAssert::contains_file(&agents_dir, "standard.md");
DirAssert::contains_file(&agents_dir, "custom.md");
FileAssert::exists(project.project_path().join("ccpm.lock"));
Ok(())
}
#[test]
fn test_assertion_helpers() -> Result<()> {
ccpm::test_utils::init_test_logging(None);
let project = TestProject::new()?;
let test_file = project.project_path().join("test.txt");
std::fs::write(&test_file, "Hello, World!")?;
let test_dir = project.project_path().join("test-dir");
std::fs::create_dir(&test_dir)?;
std::fs::write(test_dir.join("nested.txt"), "Nested content")?;
FileAssert::exists(&test_file);
FileAssert::contains(&test_file, "Hello");
FileAssert::equals(&test_file, "Hello, World!");
DirAssert::exists(&test_dir);
DirAssert::contains_file(&test_dir, "nested.txt");
FileAssert::not_exists(project.project_path().join("nonexistent.txt"));
let empty_dir = project.project_path().join("empty");
std::fs::create_dir(&empty_dir)?;
DirAssert::is_empty(&empty_dir);
Ok(())
}