Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,22 @@ steps = [
# The fixture payload has no `vp` binary, so this error proves that the upgrade ran instead of reporting that it is up to date.
{ argv = ["vp", "upgrade", "999.0.1", "--silent"], envs = [["VP_HOME", "${workspace}/home"]], continue-on-failure = true },
]

[[case]]
name = "command_upgrade_rollback_missing_binary"
vp = "global"
skip-platforms = ["windows"]
comment = "A rollback target without its vp binary fails and leaves `current` and `.previous-version` unchanged."
env = { VP_SKIP_DEPS_INSTALL = "1", VP_NODE_MANAGER = "no", VP_SELF_SETUP_NO_MODIFY_PATH = "1" }
steps = [
{ argv = ["vpt", "mkdir", "external"], snapshot = false },
{ argv = ["vpt", "cp", "$VP_HOME/bin/vp", "external/vp"], snapshot = false },
{ argv = ["vpt", "chmod", "+x", "external/vp"], snapshot = false },
{ argv = ["./external/vp"], tty = false, envs = [["VP_HOME", "${workspace}/home"], ["VP_VERSION", "rollback-a"]], comment = "Deploy the first version", snapshot = false },
{ argv = ["./external/vp"], tty = false, envs = [["VP_HOME", "${workspace}/home"], ["VP_VERSION", "rollback-b"]], comment = "Deploy the second version, which records the first as the rollback target", snapshot = false },
{ argv = ["vpt", "rm", "home/rollback-a/bin/vp"], comment = "Break the rollback target but keep its directory", snapshot = false },
# `--silent` keeps the running CLI version out of the snapshot.
{ argv = ["vp", "upgrade", "--rollback", "--silent"], envs = [["VP_HOME", "${workspace}/home"]], continue-on-failure = true },
["vpt", "print-file", "home/.previous-version"],
["vpt", "stat-file", "home/current/bin/vp", "--assert", "file"],
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# command_upgrade_rollback_missing_binary

A rollback target without its vp binary fails and leaves `current` and `.previous-version` unchanged.

## `vpt mkdir external`


## `vpt cp $VP_HOME/bin/vp external/vp`


## `vpt chmod +x external/vp`


## `VP_HOME=${workspace}/home VP_VERSION=rollback-a ./external/vp`

Deploy the first version


## `VP_HOME=${workspace}/home VP_VERSION=rollback-b ./external/vp`

Deploy the second version, which records the first as the rollback target


## `vpt rm home/rollback-a/bin/vp`

Break the rollback target but keep its directory


## `VP_HOME=${workspace}/home vp upgrade --rollback --silent`

**Exit code:** 1

```
error: Upgrade error: Previous version (rollback-a) has no vp binary. Cannot rollback.
```

## `vpt print-file home/.previous-version`

```
rollback-a
```

## `vpt stat-file home/current/bin/vp --assert file`

```
home/current/bin/vp: file
```
11 changes: 9 additions & 2 deletions crates/vp_global_cli/src/commands/upgrade/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,14 +428,21 @@ async fn execute_rollback(
));
}

// Switching to a directory without the binary would remove the `vp` command.
let prev_binary = prev_dir.join("bin").join(vp_setup::VP_BINARY_NAME);
if !tokio::fs::metadata(&prev_binary).await.is_ok_and(|m| m.is_file()) {
return Err(Error::Upgrade(
format!("Previous version ({previous}) has no vp binary. Cannot rollback.").into(),
));
}

if !silent {
let current_version = env!("CARGO_PKG_VERSION");
output::info("rolling back to previous version...");
output::info(&format!("switching from {} {} {}", current_version, output::ARROW, previous));
}

ensure_env_forbidden_support(&prev_dir.join("bin").join(vp_setup::VP_BINARY_NAME), &previous)
.await?;
ensure_env_forbidden_support(&prev_binary, &previous).await?;

// Save the current version as the new "previous" before swapping
install::save_previous_version(install_dir).await?;
Expand Down
Loading