Skip to content

Commit af0e922

Browse files
committed
fix: address CodeRabbit review on PR #19
- self_update: fall back to CARGO_PKG_VERSION when PVM_VERSION is not valid semver so non-tagged/CI builds still parse a usable version. - self_update: propagate dialoguer prompt errors via .context()? instead of silently mapping them to a user cancellation. - tests: isolate the two new self-update CLI tests with tempdir + PVM_DIR per the project's integration-test convention.
1 parent f1f306c commit af0e922

2 files changed

Lines changed: 13 additions & 7 deletions

File tree

src/commands/self_update.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,14 @@ fn current_version() -> Result<semver::Version> {
2626
let trimmed = token.trim_start_matches('v');
2727
// git-describe extras (e.g. "-2-gabc") are not valid semver; drop them.
2828
let core = trimmed.split('-').next().unwrap_or(trimmed);
29-
semver::Version::parse(core).with_context(|| {
30-
format!(
31-
"Failed to parse current pvm version '{}' from '{}'",
32-
core, raw
33-
)
34-
})
29+
semver::Version::parse(core)
30+
.or_else(|_| semver::Version::parse(env!("CARGO_PKG_VERSION")))
31+
.with_context(|| {
32+
format!(
33+
"Failed to parse current pvm version '{}' from '{}'",
34+
core, raw
35+
)
36+
})
3537
}
3638

3739
fn parse_remote_version(tag: &str) -> Result<semver::Version> {
@@ -174,7 +176,7 @@ impl SelfUpdate {
174176
.with_prompt(format!("Update pvm to {}?", remote_str).bold().to_string())
175177
.default(true)
176178
.interact_opt()
177-
.unwrap_or(Some(false))
179+
.context("Failed to read update confirmation from terminal")?
178180
.unwrap_or(false);
179181

180182
if !confirmed {

tests/cli.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ fn test_version_short() {
2929

3030
#[test]
3131
fn test_self_update_help() {
32+
let temp_dir = tempfile::tempdir().unwrap();
3233
let mut cmd = assert_cmd::cargo::cargo_bin_cmd!("pvm");
34+
cmd.env("PVM_DIR", temp_dir.path());
3335
cmd.arg("self-update").arg("--help");
3436
cmd.assert()
3537
.success()
@@ -38,7 +40,9 @@ fn test_self_update_help() {
3840

3941
#[test]
4042
fn test_help_lists_self_update() {
43+
let temp_dir = tempfile::tempdir().unwrap();
4144
let mut cmd = assert_cmd::cargo::cargo_bin_cmd!("pvm");
45+
cmd.env("PVM_DIR", temp_dir.path());
4246
cmd.arg("--help");
4347
cmd.assert()
4448
.success()

0 commit comments

Comments
 (0)