Skip to content

Commit 92b0218

Browse files
authored
Merge pull request #1 from nikomatsakis/versioned-agents
Fix versioned package bug - prevent @latest appending to already vers…
2 parents 4ecbf3e + c6ad029 commit 92b0218

3 files changed

Lines changed: 43 additions & 2 deletions

File tree

src/agent.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@ pub async fn run_agent(agent: &Agent, cache_dir: &PathBuf, force: Option<&ForceO
1212
info!("Executing npx package: {}", npx.package);
1313
let mut cmd = Command::new("npx");
1414
cmd.arg("-y");
15-
cmd.arg(format!("{}@latest", npx.package));
15+
let package_arg = if npx.package.contains('@') && npx.package.matches('@').count() > 1 {
16+
npx.package.clone()
17+
} else {
18+
format!("{}@latest", npx.package)
19+
};
20+
cmd.arg(package_arg);
1621
cmd.args(&npx.args);
1722
cmd.stdin(Stdio::inherit()).stdout(Stdio::inherit()).stderr(Stdio::inherit());
1823
cmd.status().await?;

tests/fixtures/test-registry.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,18 @@
2727
}
2828
}
2929
}
30+
},
31+
{
32+
"id": "test-versioned-npx-agent",
33+
"name": "Test Versioned NPX Agent",
34+
"version": "1.0.0",
35+
"description": "Test agent using npx with versioned package",
36+
"distribution": {
37+
"npx": {
38+
"package": "@google/gemini-cli@0.38.2",
39+
"args": []
40+
}
41+
}
3042
}
3143
]
3244
}

tests/integration_tests.rs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ async fn test_fetch_custom_registry() {
1111
let registry_path = PathBuf::from("tests/fixtures/test-registry.json");
1212
let registry = fetch_registry(&cache_dir, None, Some(&registry_path)).await.unwrap();
1313

14-
assert_eq!(registry.agents.len(), 2);
14+
assert_eq!(registry.agents.len(), 3);
1515
assert_eq!(registry.agents[0].id, "test-npx-agent");
1616
assert_eq!(registry.agents[1].id, "test-binary-agent");
17+
assert_eq!(registry.agents[2].id, "test-versioned-npx-agent");
1718
}
1819

1920
#[tokio::test]
@@ -95,4 +96,27 @@ async fn test_binary_caching() {
9596
let binary_path3 = download_binary(&agent, binary_dist, &cache_dir, Some(&ForceOption::Binary)).await.unwrap();
9697
assert_eq!(path1, binary_path3);
9798
}
99+
}
100+
101+
#[test]
102+
fn test_versioned_package_handling() {
103+
// Test that versioned packages don't get @latest appended
104+
let versioned_package = "@google/gemini-cli@0.38.2";
105+
let unversioned_package = "cowsay";
106+
107+
// Simulate the logic from run_agent
108+
let versioned_arg = if versioned_package.contains('@') && versioned_package.matches('@').count() > 1 {
109+
versioned_package.to_string()
110+
} else {
111+
format!("{}@latest", versioned_package)
112+
};
113+
114+
let unversioned_arg = if unversioned_package.contains('@') && unversioned_package.matches('@').count() > 1 {
115+
unversioned_package.to_string()
116+
} else {
117+
format!("{}@latest", unversioned_package)
118+
};
119+
120+
assert_eq!(versioned_arg, "@google/gemini-cli@0.38.2");
121+
assert_eq!(unversioned_arg, "cowsay@latest");
98122
}

0 commit comments

Comments
 (0)