use predicates::prelude::*;
use std::env;
use tokio::fs;
use crate::common::{ManifestBuilder, TestProject};
use crate::fixtures::ManifestFixture;
#[tokio::test]
async fn test_list_installed_resources() {
let project = TestProject::new().await.unwrap();
let manifest_content = ManifestFixture::basic().content;
project.write_manifest(&manifest_content).await.unwrap();
let lockfile_content = r#"# Auto-generated lockfile - DO NOT EDIT
version = 1
[[sources]]
name = "official"
url = "https://github.com/example-org/agpm-official.git"
commit = "abc123456789abcdef123456789abcdef12345678"
fetched_at = "2024-01-01T00:00:00Z"
[[sources]]
name = "community"
url = "https://github.com/example-org/agpm-community.git"
commit = "def456789abcdef123456789abcdef123456789ab"
fetched_at = "2024-01-01T00:00:00Z"
[[agents]]
name = "my-agent"
source = "official"
path = "agents/my-agent.md"
version = "v1.0.0"
resolved_commit = "abc123456789abcdef123456789abcdef12345678"
checksum = "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
installed_at = "agents/my-agent.md"
[[agents]]
name = "helper"
source = "community"
path = "agents/helper.md"
version = "v1.0.0"
resolved_commit = "def456789abcdef123456789abcdef123456789ab"
checksum = "sha256:38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da"
installed_at = "agents/helper.md"
[[snippets]]
name = "utils"
source = "official"
path = "snippets/utils.md"
version = "v1.0.0"
resolved_commit = "abc123456789abcdef123456789abcdef12345678"
checksum = "sha256:74e6f7298a9c2d168935f58c6b6c5b5ea4c3df6a0b6b8d2e7b2a2b8c3d4e5f6a"
installed_at = "snippets/utils.md"
"#;
fs::write(project.project_path().join("agpm.lock"), lockfile_content).await.unwrap();
let output = project.run_agpm(&["list"]).unwrap();
output
.assert_success()
.assert_stdout_contains("my-agent")
.assert_stdout_contains("helper")
.assert_stdout_contains("utils");
}
#[tokio::test]
async fn test_list_no_lockfile() {
let project = TestProject::new().await.unwrap();
let manifest_content = ManifestFixture::basic().content;
project.write_manifest(&manifest_content).await.unwrap();
let output = project.run_agpm(&["list"]).unwrap();
output.assert_success();
assert!(
output.stdout.contains("No installed resources")
|| output.stdout.contains("agpm.lock not found"),
"Expected no resources message, got: {}",
output.stdout
);
}
#[tokio::test]
async fn test_list_without_project() {
let project = TestProject::new().await.unwrap();
let output = project.run_agpm(&["list"]).unwrap();
assert!(!output.success, "Expected command to fail but it succeeded");
assert!(
output.stderr.contains("agpm.toml not found"),
"Expected manifest not found error, got: {}",
output.stderr
);
}
#[tokio::test]
async fn test_list_table_format() {
let project = TestProject::new().await.unwrap();
let manifest_content = ManifestFixture::basic().content;
project.write_manifest(&manifest_content).await.unwrap();
let lockfile_content = r#"# Auto-generated lockfile - DO NOT EDIT
version = 1
[[agents]]
name = "my-agent"
source = "official"
path = "agents/my-agent.md"
version = "v1.0.0"
resolved_commit = "abc123456789abcdef123456789abcdef12345678"
checksum = "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
installed_at = "agents/my-agent.md"
"#;
fs::write(project.project_path().join("agpm.lock"), lockfile_content).await.unwrap();
let output = project.run_agpm(&["list", "--format", "table"]).unwrap();
output
.assert_success()
.assert_stdout_contains("Name")
.assert_stdout_contains("Version")
.assert_stdout_contains("Source")
.assert_stdout_contains("Type")
.assert_stdout_contains("my-agent");
}
#[tokio::test]
async fn test_list_json_format() {
let project = TestProject::new().await.unwrap();
let manifest_content = ManifestFixture::basic().content;
project.write_manifest(&manifest_content).await.unwrap();
let lockfile_content = r#"# Auto-generated lockfile - DO NOT EDIT
version = 1
[[agents]]
name = "my-agent"
source = "official"
path = "agents/my-agent.md"
version = "v1.0.0"
resolved_commit = "abc123456789abcdef123456789abcdef12345678"
checksum = "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
installed_at = "agents/my-agent.md"
"#;
fs::write(project.project_path().join("agpm.lock"), lockfile_content).await.unwrap();
let output = project.run_agpm(&["list", "--format", "json"]).unwrap();
assert!(output.success);
assert!(output.stdout.contains("{"));
assert!(output.stdout.contains("\"name\""));
assert!(output.stdout.contains("\"version\""));
assert!(output.stdout.contains("\"source\""));
assert!(output.stdout.contains("\"my-agent\""));
}
#[tokio::test]
async fn test_list_yaml_format() {
let project = TestProject::new().await.unwrap();
let manifest_content = ManifestFixture::basic().content;
project.write_manifest(&manifest_content).await.unwrap();
let lockfile_content = r#"# Auto-generated lockfile - DO NOT EDIT
version = 1
[[agents]]
name = "my-agent"
source = "official"
path = "agents/my-agent.md"
version = "v1.0.0"
resolved_commit = "abc123456789abcdef123456789abcdef12345678"
checksum = "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
installed_at = "agents/my-agent.md"
"#;
fs::write(project.project_path().join("agpm.lock"), lockfile_content).await.unwrap();
let output = project.run_agpm(&["list", "--format", "yaml"]).unwrap();
assert!(output.success);
assert!(output.stdout.contains("name:"));
assert!(output.stdout.contains("version:"));
assert!(output.stdout.contains("source:"));
assert!(output.stdout.contains("my-agent"));
}
#[tokio::test]
async fn test_list_compact_format() {
let project = TestProject::new().await.unwrap();
let manifest_content = ManifestFixture::basic().content;
project.write_manifest(&manifest_content).await.unwrap();
let lockfile_content = r#"# Auto-generated lockfile - DO NOT EDIT
version = 1
[[sources]]
name = "official"
url = "https://github.com/example-org/agpm-official.git"
commit = "abc123456789abcdef123456789abcdef12345678"
fetched_at = "2024-01-01T00:00:00Z"
[[sources]]
name = "community"
url = "https://github.com/example-org/agpm-community.git"
commit = "def456789abcdef123456789abcdef123456789ab"
fetched_at = "2024-01-01T00:00:00Z"
[[agents]]
name = "my-agent"
source = "official"
path = "agents/my-agent.md"
version = "v1.0.0"
resolved_commit = "abc123456789abcdef123456789abcdef12345678"
checksum = "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
installed_at = "agents/my-agent.md"
[[agents]]
name = "helper"
source = "community"
path = "agents/helper.md"
version = "v1.0.0"
resolved_commit = "def456789abcdef123456789abcdef123456789ab"
checksum = "sha256:38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da"
installed_at = "agents/helper.md"
[[snippets]]
name = "utils"
source = "official"
path = "snippets/utils.md"
version = "v1.0.0"
resolved_commit = "abc123456789abcdef123456789abcdef12345678"
checksum = "sha256:74e6f7298a9c2d168935f58c6b6c5b5ea4c3df6a0b6b8d2e7b2a2b8c3d4e5f6a"
installed_at = "snippets/utils.md"
"#;
fs::write(project.project_path().join("agpm.lock"), lockfile_content).await.unwrap();
let output = project.run_agpm(&["list", "--format", "compact"]).unwrap();
output
.assert_success()
.assert_stdout_contains("my-agent")
.assert_stdout_contains("v1.0.0")
.assert_stdout_contains("official");
}
#[tokio::test]
async fn test_list_agents_only() {
let project = TestProject::new().await.unwrap();
let manifest_content = ManifestFixture::basic().content;
project.write_manifest(&manifest_content).await.unwrap();
let lockfile_content = r#"# Auto-generated lockfile - DO NOT EDIT
version = 1
[[sources]]
name = "official"
url = "https://github.com/example-org/agpm-official.git"
commit = "abc123456789abcdef123456789abcdef12345678"
fetched_at = "2024-01-01T00:00:00Z"
[[sources]]
name = "community"
url = "https://github.com/example-org/agpm-community.git"
commit = "def456789abcdef123456789abcdef123456789ab"
fetched_at = "2024-01-01T00:00:00Z"
[[agents]]
name = "my-agent"
source = "official"
path = "agents/my-agent.md"
version = "v1.0.0"
resolved_commit = "abc123456789abcdef123456789abcdef12345678"
checksum = "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
installed_at = "agents/my-agent.md"
[[agents]]
name = "helper"
source = "community"
path = "agents/helper.md"
version = "v1.0.0"
resolved_commit = "def456789abcdef123456789abcdef123456789ab"
checksum = "sha256:38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da"
installed_at = "agents/helper.md"
[[snippets]]
name = "utils"
source = "official"
path = "snippets/utils.md"
version = "v1.0.0"
resolved_commit = "abc123456789abcdef123456789abcdef12345678"
checksum = "sha256:74e6f7298a9c2d168935f58c6b6c5b5ea4c3df6a0b6b8d2e7b2a2b8c3d4e5f6a"
installed_at = "snippets/utils.md"
"#;
fs::write(project.project_path().join("agpm.lock"), lockfile_content).await.unwrap();
let output = project.run_agpm(&["list", "--type", "agents"]).unwrap();
assert!(output.success);
assert!(output.stdout.contains("my-agent"));
assert!(output.stdout.contains("helper"));
assert!(!output.stdout.contains("utils")); }
#[tokio::test]
async fn test_list_snippets_only() {
let project = TestProject::new().await.unwrap();
let manifest_content = ManifestFixture::basic().content;
project.write_manifest(&manifest_content).await.unwrap();
let lockfile_content = r#"# Auto-generated lockfile - DO NOT EDIT
version = 1
[[sources]]
name = "official"
url = "https://github.com/example-org/agpm-official.git"
commit = "abc123456789abcdef123456789abcdef12345678"
fetched_at = "2024-01-01T00:00:00Z"
[[sources]]
name = "community"
url = "https://github.com/example-org/agpm-community.git"
commit = "def456789abcdef123456789abcdef123456789ab"
fetched_at = "2024-01-01T00:00:00Z"
[[agents]]
name = "my-agent"
source = "official"
path = "agents/my-agent.md"
version = "v1.0.0"
resolved_commit = "abc123456789abcdef123456789abcdef12345678"
checksum = "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
installed_at = "agents/my-agent.md"
[[agents]]
name = "helper"
source = "community"
path = "agents/helper.md"
version = "v1.0.0"
resolved_commit = "def456789abcdef123456789abcdef123456789ab"
checksum = "sha256:38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da"
installed_at = "agents/helper.md"
[[snippets]]
name = "utils"
source = "official"
path = "snippets/utils.md"
version = "v1.0.0"
resolved_commit = "abc123456789abcdef123456789abcdef12345678"
checksum = "sha256:74e6f7298a9c2d168935f58c6b6c5b5ea4c3df6a0b6b8d2e7b2a2b8c3d4e5f6a"
installed_at = "snippets/utils.md"
"#;
fs::write(project.project_path().join("agpm.lock"), lockfile_content).await.unwrap();
let output = project.run_agpm(&["list", "--type", "snippets"]).unwrap();
assert!(output.success);
assert!(output.stdout.contains("utils"));
assert!(!output.stdout.contains("my-agent")); assert!(!output.stdout.contains("helper")); }
#[tokio::test]
async fn test_list_filter_by_source() {
let project = TestProject::new().await.unwrap();
let manifest_content = ManifestFixture::basic().content;
project.write_manifest(&manifest_content).await.unwrap();
let lockfile_content = r#"# Auto-generated lockfile - DO NOT EDIT
version = 1
[[sources]]
name = "official"
url = "https://github.com/example-org/agpm-official.git"
commit = "abc123456789abcdef123456789abcdef12345678"
fetched_at = "2024-01-01T00:00:00Z"
[[sources]]
name = "community"
url = "https://github.com/example-org/agpm-community.git"
commit = "def456789abcdef123456789abcdef123456789ab"
fetched_at = "2024-01-01T00:00:00Z"
[[agents]]
name = "my-agent"
source = "official"
path = "agents/my-agent.md"
version = "v1.0.0"
resolved_commit = "abc123456789abcdef123456789abcdef12345678"
checksum = "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
installed_at = "agents/my-agent.md"
[[agents]]
name = "helper"
source = "community"
path = "agents/helper.md"
version = "v1.0.0"
resolved_commit = "def456789abcdef123456789abcdef123456789ab"
checksum = "sha256:38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da"
installed_at = "agents/helper.md"
[[snippets]]
name = "utils"
source = "official"
path = "snippets/utils.md"
version = "v1.0.0"
resolved_commit = "abc123456789abcdef123456789abcdef12345678"
checksum = "sha256:74e6f7298a9c2d168935f58c6b6c5b5ea4c3df6a0b6b8d2e7b2a2b8c3d4e5f6a"
installed_at = "snippets/utils.md"
"#;
fs::write(project.project_path().join("agpm.lock"), lockfile_content).await.unwrap();
let output = project.run_agpm(&["list", "--source", "official"]).unwrap();
assert!(output.success);
assert!(output.stdout.contains("my-agent"));
assert!(output.stdout.contains("utils"));
assert!(!output.stdout.contains("helper")); }
#[tokio::test]
async fn test_list_search_by_name() {
let project = TestProject::new().await.unwrap();
let manifest_content = ManifestFixture::basic().content;
project.write_manifest(&manifest_content).await.unwrap();
let lockfile_content = r#"# Auto-generated lockfile - DO NOT EDIT
version = 1
[[sources]]
name = "official"
url = "https://github.com/example-org/agpm-official.git"
commit = "abc123456789abcdef123456789abcdef12345678"
fetched_at = "2024-01-01T00:00:00Z"
[[sources]]
name = "community"
url = "https://github.com/example-org/agpm-community.git"
commit = "def456789abcdef123456789abcdef123456789ab"
fetched_at = "2024-01-01T00:00:00Z"
[[agents]]
name = "my-agent"
source = "official"
path = "agents/my-agent.md"
version = "v1.0.0"
resolved_commit = "abc123456789abcdef123456789abcdef12345678"
checksum = "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
installed_at = "agents/my-agent.md"
[[agents]]
name = "helper"
source = "community"
path = "agents/helper.md"
version = "v1.0.0"
resolved_commit = "def456789abcdef123456789abcdef123456789ab"
checksum = "sha256:38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da"
installed_at = "agents/helper.md"
[[snippets]]
name = "utils"
source = "official"
path = "snippets/utils.md"
version = "v1.0.0"
resolved_commit = "abc123456789abcdef123456789abcdef12345678"
checksum = "sha256:74e6f7298a9c2d168935f58c6b6c5b5ea4c3df6a0b6b8d2e7b2a2b8c3d4e5f6a"
installed_at = "snippets/utils.md"
"#;
fs::write(project.project_path().join("agpm.lock"), lockfile_content).await.unwrap();
let output = project.run_agpm(&["list", "--search", "agent"]).unwrap();
assert!(output.success);
assert!(output.stdout.contains("my-agent"));
assert!(!output.stdout.contains("utils"));
}
#[tokio::test]
async fn test_list_detailed() {
let project = TestProject::new().await.unwrap();
let manifest_content = ManifestFixture::basic().content;
project.write_manifest(&manifest_content).await.unwrap();
let lockfile_content = r#"# Auto-generated lockfile - DO NOT EDIT
version = 1
[[sources]]
name = "official"
url = "https://github.com/example-org/agpm-official.git"
commit = "abc123456789abcdef123456789abcdef12345678"
fetched_at = "2024-01-01T00:00:00Z"
[[sources]]
name = "community"
url = "https://github.com/example-org/agpm-community.git"
commit = "def456789abcdef123456789abcdef123456789ab"
fetched_at = "2024-01-01T00:00:00Z"
[[agents]]
name = "my-agent"
source = "official"
path = "agents/my-agent.md"
version = "v1.0.0"
resolved_commit = "abc123456789abcdef123456789abcdef12345678"
checksum = "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
installed_at = "agents/my-agent.md"
[[agents]]
name = "helper"
source = "community"
path = "agents/helper.md"
version = "v1.0.0"
resolved_commit = "def456789abcdef123456789abcdef123456789ab"
checksum = "sha256:38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da"
installed_at = "agents/helper.md"
[[snippets]]
name = "utils"
source = "official"
path = "snippets/utils.md"
version = "v1.0.0"
resolved_commit = "abc123456789abcdef123456789abcdef12345678"
checksum = "sha256:74e6f7298a9c2d168935f58c6b6c5b5ea4c3df6a0b6b8d2e7b2a2b8c3d4e5f6a"
installed_at = "snippets/utils.md"
"#;
fs::write(project.project_path().join("agpm.lock"), lockfile_content).await.unwrap();
let output = project.run_agpm(&["list", "--detailed"]).unwrap();
assert!(output.success);
assert!(output.stdout.contains("my-agent"));
assert!(output.stdout.contains("Path:") || output.stdout.contains("agents/my-agent.md"));
}
#[tokio::test]
async fn test_list_installed_files() {
let project = TestProject::new().await.unwrap();
let manifest_content = ManifestFixture::basic().content;
project.write_manifest(&manifest_content).await.unwrap();
let lockfile_content = r#"# Auto-generated lockfile - DO NOT EDIT
version = 1
[[sources]]
name = "official"
url = "https://github.com/example-org/agpm-official.git"
commit = "abc123456789abcdef123456789abcdef12345678"
fetched_at = "2024-01-01T00:00:00Z"
[[sources]]
name = "community"
url = "https://github.com/example-org/agpm-community.git"
commit = "def456789abcdef123456789abcdef123456789ab"
fetched_at = "2024-01-01T00:00:00Z"
[[agents]]
name = "my-agent"
source = "official"
path = "agents/my-agent.md"
version = "v1.0.0"
resolved_commit = "abc123456789abcdef123456789abcdef12345678"
checksum = "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
installed_at = "agents/my-agent.md"
[[agents]]
name = "helper"
source = "community"
path = "agents/helper.md"
version = "v1.0.0"
resolved_commit = "def456789abcdef123456789abcdef123456789ab"
checksum = "sha256:38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da"
installed_at = "agents/helper.md"
[[snippets]]
name = "utils"
source = "official"
path = "snippets/utils.md"
version = "v1.0.0"
resolved_commit = "abc123456789abcdef123456789abcdef12345678"
checksum = "sha256:74e6f7298a9c2d168935f58c6b6c5b5ea4c3df6a0b6b8d2e7b2a2b8c3d4e5f6a"
installed_at = "snippets/utils.md"
"#;
fs::write(project.project_path().join("agpm.lock"), lockfile_content).await.unwrap();
let agents_dir = project.project_path().join("agents");
let snippets_dir = project.project_path().join("snippets");
fs::create_dir_all(&agents_dir).await.unwrap();
fs::create_dir_all(&snippets_dir).await.unwrap();
fs::write(agents_dir.join("my-agent.md"), "# My Agent").await.unwrap();
fs::write(agents_dir.join("helper.md"), "# Helper Agent").await.unwrap();
fs::write(snippets_dir.join("utils.md"), "# Utils Snippet").await.unwrap();
let output = project.run_agpm(&["list", "--files"]).unwrap();
assert!(output.success);
assert!(output.stdout.contains("agents/my-agent.md") || output.stdout.contains("my-agent"));
assert!(output.stdout.contains("agents/helper.md") || output.stdout.contains("helper"));
assert!(output.stdout.contains("snippets/utils.md") || output.stdout.contains("utils"));
}
#[tokio::test]
async fn test_list_sorted_by_name() {
let project = TestProject::new().await.unwrap();
let manifest_content = ManifestFixture::basic().content;
project.write_manifest(&manifest_content).await.unwrap();
let lockfile_content = r#"# Auto-generated lockfile - DO NOT EDIT
version = 1
[[agents]]
name = "my-agent"
source = "official"
path = "agents/my-agent.md"
version = "v1.0.0"
resolved_commit = "abc123456789abcdef123456789abcdef12345678"
checksum = "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
installed_at = "agents/my-agent.md"
"#;
fs::write(project.project_path().join("agpm.lock"), lockfile_content).await.unwrap();
let output = project.run_agpm(&["list", "--sort", "name"]).unwrap();
assert!(output.success);
assert!(output.stdout.contains("my-agent"));
}
#[tokio::test]
async fn test_list_sorted_by_version() {
let project = TestProject::new().await.unwrap();
let manifest_content = ManifestFixture::basic().content;
project.write_manifest(&manifest_content).await.unwrap();
let lockfile_content = r#"# Auto-generated lockfile - DO NOT EDIT
version = 1
[[agents]]
name = "my-agent"
source = "official"
path = "agents/my-agent.md"
version = "v1.0.0"
resolved_commit = "abc123456789abcdef123456789abcdef12345678"
checksum = "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
installed_at = "agents/my-agent.md"
"#;
fs::write(project.project_path().join("agpm.lock"), lockfile_content).await.unwrap();
let output = project.run_agpm(&["list", "--sort", "version"]).unwrap();
assert!(output.success);
assert!(output.stdout.contains("my-agent"));
}
#[tokio::test]
async fn test_list_sorted_by_source() {
let project = TestProject::new().await.unwrap();
let manifest_content = ManifestFixture::basic().content;
project.write_manifest(&manifest_content).await.unwrap();
let lockfile_content = r#"# Auto-generated lockfile - DO NOT EDIT
version = 1
[[agents]]
name = "my-agent"
source = "official"
path = "agents/my-agent.md"
version = "v1.0.0"
resolved_commit = "abc123456789abcdef123456789abcdef12345678"
checksum = "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
installed_at = "agents/my-agent.md"
"#;
fs::write(project.project_path().join("agpm.lock"), lockfile_content).await.unwrap();
let output = project.run_agpm(&["list", "--sort", "source"]).unwrap();
assert!(output.success);
assert!(output.stdout.contains("my-agent"));
}
#[tokio::test]
async fn test_list_local_dependencies() {
let project = TestProject::new().await.unwrap();
let manifest_content = ManifestFixture::with_local().content;
project.write_manifest(&manifest_content).await.unwrap();
let lockfile_content = r#"# Auto-generated lockfile - DO NOT EDIT
version = 1
[[sources]]
name = "official"
url = "https://github.com/example-org/agpm-official.git"
commit = "abc123456789abcdef123456789abcdef12345678"
fetched_at = "2024-01-01T00:00:00Z"
[[agents]]
name = "my-agent"
source = "official"
path = "agents/my-agent.md"
version = "v1.0.0"
resolved_commit = "abc123456789abcdef123456789abcdef12345678"
checksum = "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
installed_at = "agents/my-agent.md"
[[agents]]
name = "local-agent"
path = "../local-agents/helper.md"
version = "local"
checksum = "sha256:local123456789abcdef123456789abcdef123456789abcdef"
installed_at = "agents/local-agent.md"
[[snippets]]
name = "local-utils"
path = "./snippets/local-utils.md"
version = "local"
checksum = "sha256:local987654321fedcba987654321fedcba987654321fedcba"
installed_at = "snippets/local-utils.md"
"#;
fs::write(project.project_path().join("agpm.lock"), lockfile_content).await.unwrap();
let output = project.run_agpm(&["list"]).unwrap();
assert!(output.success);
assert!(output.stdout.contains("local-agent"));
assert!(output.stdout.contains("local-utils"));
assert!(output.stdout.contains("local"));
}
#[tokio::test]
async fn test_list_help() {
let mut cmd = assert_cmd::Command::new(env!("CARGO_BIN_EXE_agpm"));
cmd.arg("list")
.arg("--help")
.assert()
.success()
.stdout(predicate::str::contains("List installed Claude Code resources"))
.stdout(predicate::str::contains("--format"))
.stdout(predicate::str::contains("--source"))
.stdout(predicate::str::contains("--detailed"))
.stdout(predicate::str::contains("--manifest"))
.stdout(predicate::str::contains("--agents"))
.stdout(predicate::str::contains("--snippets"));
}
#[tokio::test]
async fn test_list_empty_project() {
let project = TestProject::new().await.unwrap();
let minimal_manifest = ManifestBuilder::new()
.add_source("official", "https://github.com/example-org/agpm-official.git")
.build();
project.write_manifest(&minimal_manifest).await.unwrap();
let empty_lockfile = r#"# Auto-generated lockfile - DO NOT EDIT
version = 1
"#;
fs::write(project.project_path().join("agpm.lock"), empty_lockfile).await.unwrap();
let output = project.run_agpm(&["list"]).unwrap();
assert!(output.success);
assert!(
output.stdout.contains("No installed resources") || output.stdout.contains("Empty project"),
"Expected no resources message, got: {}",
output.stdout
);
}
#[tokio::test]
async fn test_list_corrupted_lockfile() {
let project = TestProject::new().await.unwrap();
let manifest_content = ManifestFixture::basic().content;
project.write_manifest(&manifest_content).await.unwrap();
fs::write(project.project_path().join("agpm.lock"), "corrupted content").await.unwrap();
let output = project.run_agpm(&["list"]).unwrap();
assert!(!output.success);
assert!(
output.stderr.contains("Invalid or corrupted lockfile detected")
|| output.stderr.contains("Invalid lockfile syntax")
|| output.stderr.contains("Failed to parse lockfile"),
"Expected lockfile error, got: {}",
output.stderr
);
}
#[tokio::test]
async fn test_list_invalid_format() {
let project = TestProject::new().await.unwrap();
let manifest_content = ManifestFixture::basic().content;
project.write_manifest(&manifest_content).await.unwrap();
let lockfile_content = r#"# Auto-generated lockfile - DO NOT EDIT
version = 1
[[agents]]
name = "my-agent"
source = "official"
path = "agents/my-agent.md"
version = "v1.0.0"
resolved_commit = "abc123456789abcdef123456789abcdef12345678"
checksum = "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
installed_at = "agents/my-agent.md"
"#;
fs::write(project.project_path().join("agpm.lock"), lockfile_content).await.unwrap();
let output = project.run_agpm(&["list", "--format", "invalid"]).unwrap();
assert!(!output.success);
assert!(output.stderr.contains("Invalid format") || output.stderr.contains("invalid"));
}