use tokio::fs;
mod common;
mod fixtures;
use common::TestProject;
use fixtures::ManifestFixture;
#[tokio::test]
async fn test_outdated_all_up_to_date() {
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"
[[agents]]
name = "my-agent"
source = "official"
path = "agents/my-agent.md"
version = "v2.0.0"
resolved_commit = "abc123456789abcdef123456789abcdef12345678"
checksum = "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
installed_at = "agents/my-agent.md"
resource_type = "agent"
"#;
fs::write(project.project_path().join("agpm.lock"), lockfile_content).await.unwrap();
let output = project.run_agpm(&["outdated", "--no-fetch"]).unwrap();
output.assert_success().assert_stdout_contains("All dependencies are up to date!");
}
#[tokio::test]
async fn test_outdated_with_updates_available() {
let project = TestProject::new().await.unwrap();
let manifest_content = r#"[sources]
official = "https://github.com/example-org/agpm-official.git"
[agents]
my-agent = { source = "official", path = "agents/my-agent.md", version = "^1.0.0" }
"#;
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"
resource_type = "agent"
"#;
fs::write(project.project_path().join("agpm.lock"), lockfile_content).await.unwrap();
}
#[tokio::test]
async fn test_outdated_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(&["outdated"]).unwrap();
assert!(!output.success, "Expected command to fail without lockfile");
assert!(
output.stderr.contains("agpm.lock") || output.stderr.contains("Run 'agpm install' first"),
"Expected lockfile error message, got: {}",
output.stderr
);
}
#[tokio::test]
async fn test_outdated_without_project() {
let project = TestProject::new().await.unwrap();
let output = project.run_agpm(&["outdated"]).unwrap();
assert!(!output.success, "Expected command to fail without project");
assert!(
output.stderr.contains("agpm.toml not found"),
"Expected manifest not found error, got: {}",
output.stderr
);
}
#[tokio::test]
async fn test_outdated_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
[[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"
resource_type = "agent"
"#;
fs::write(project.project_path().join("agpm.lock"), lockfile_content).await.unwrap();
let output = project.run_agpm(&["outdated", "--format", "json", "--no-fetch"]).unwrap();
output.assert_success();
assert!(
output.stdout.contains("{") && output.stdout.contains("}"),
"Expected JSON output, got: {}",
output.stdout
);
assert!(
output.stdout.contains("\"outdated\"") && output.stdout.contains("\"summary\""),
"Expected JSON structure with outdated and summary fields, got: {}",
output.stdout
);
}
#[tokio::test]
async fn test_outdated_check_flag() {
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"
[[agents]]
name = "my-agent"
source = "official"
path = "agents/my-agent.md"
version = "v2.0.0"
resolved_commit = "abc123456789abcdef123456789abcdef12345678"
checksum = "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
installed_at = "agents/my-agent.md"
resource_type = "agent"
"#;
fs::write(project.project_path().join("agpm.lock"), lockfile_content).await.unwrap();
let output = project.run_agpm(&["outdated", "--check", "--no-fetch"]).unwrap();
output.assert_success();
}
#[tokio::test]
async fn test_outdated_specific_dependencies() {
let project = TestProject::new().await.unwrap();
let manifest_content = r#"[sources]
official = "https://github.com/example-org/agpm-official.git"
[agents]
my-agent = { source = "official", path = "agents/my-agent.md", version = "^1.0.0" }
helper = { source = "official", path = "agents/helper.md", version = "^1.0.0" }
"#;
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"
resource_type = "agent"
[[agents]]
name = "helper"
source = "official"
path = "agents/helper.md"
version = "v1.0.0"
resolved_commit = "abc123456789abcdef123456789abcdef12345678"
checksum = "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
installed_at = "agents/helper.md"
resource_type = "agent"
"#;
fs::write(project.project_path().join("agpm.lock"), lockfile_content).await.unwrap();
let output = project.run_agpm(&["outdated", "--no-fetch", "my-agent"]).unwrap();
output.assert_success();
}