use clap::Parser;
use midenup::{channel, commands::Midenup, version};
mod common;
use common::*;
#[test]
fn integration_update_test() {
let test_name = "integration_update_test";
let test_env = environment_setup(test_name);
eprintln!("KEEPING temp dir at: {}", test_env.tmp_dir.path().display());
let manifest: &str =
full_path_manifest!("tests/data/integration_update_test/channel-manifest-1.json");
let (mut local_manifest, config) = test_setup(&test_env, manifest);
let toolchain_dir = test_env.midenup_home.join("toolchains");
let command = Midenup::try_parse_from(["midenup", "init"]).unwrap();
command
.execute_with_manifest(&config, &mut local_manifest)
.expect("failed to initialize");
let command = Midenup::try_parse_from(["midenup", "install", "stable"]).unwrap();
command
.execute_with_manifest(&config, &mut local_manifest)
.expect("failed to install stable");
let manifest: &str =
full_path_manifest!("tests/data/integration_update_test/channel-manifest-2.json");
let (_, config) = test_setup(&test_env, manifest);
let command = Midenup::try_parse_from(["midenup", "update", "stable"]).unwrap();
command
.execute_with_manifest(&config, &mut local_manifest)
.expect("failed to update stable");
let toolchain_v14 = toolchain_dir.join("0.14.0");
assert!(toolchain_v14.exists());
let toolchain_v15 = toolchain_dir.join("0.15.0");
assert!(toolchain_v15.exists());
let toolchain_stable = toolchain_dir.join("stable");
assert!(toolchain_stable.exists());
assert!(toolchain_stable.is_symlink());
let resolved_stable_toolchain = std::fs::read_link(toolchain_stable.as_path())
.expect("Couldn't obtain directory where the stable directory is pointing to");
assert_eq!(resolved_stable_toolchain.file_name(), toolchain_v15.file_name());
let manifest: &str =
full_path_manifest!("tests/data/integration_update_test/channel-manifest-3.json");
let (_, config) = test_setup(&test_env, manifest);
let command = Midenup::try_parse_from(["midenup", "update"]).unwrap();
command
.execute_with_manifest(&config, &mut local_manifest)
.expect("failed to update");
assert!(toolchain_stable.exists());
assert!(toolchain_stable.is_symlink());
let resolved_stable_toolchain = std::fs::read_link(toolchain_stable.as_path())
.expect("Couldn't obtain directory where the stable directory is pointing to");
assert_eq!(resolved_stable_toolchain.file_name(), toolchain_v15.file_name());
let vm_exe_stable = toolchain_stable.join("bin").join("miden-vm");
let command = std::process::Command::new(&vm_exe_stable)
.arg("--version")
.output()
.unwrap_or_else(|err| {
panic!("error occurred executing {}: {err}", vm_exe_stable.display())
});
assert_eq!(String::from_utf8(command.stdout).unwrap(), "miden-vm 0.16.2\n");
assert!(!toolchain_v15.join("lib").join("base.masp").exists());
let std_version = &local_manifest
.get_channel(&channel::UserChannel::Version(semver::Version::new(0, 14, 0)))
.expect("Couldn't find toolchain 0.14.0 in local manifest")
.get_component("std")
.expect("Couldn't find std library despite being listed in manifest.")
.version;
assert!(
matches!(std_version, version::Authority::Git { .. }),
"expected git authority for {std_version:#?}"
);
let vm_exe_v14 = toolchain_v14.join("bin").join("miden");
let command = std::process::Command::new(vm_exe_v14).arg("--version").output().unwrap();
assert_eq!(String::from_utf8(command.stdout).unwrap(), "Miden 0.13.0\n");
let client_v14 = toolchain_v14.join("bin").join("miden-client");
assert!(client_v14.exists());
let command = Midenup::try_parse_from(["midenup", "update", "stable"]).unwrap();
command
.execute_with_manifest(&config, &mut local_manifest)
.expect("failed to update stable");
let toolchain_v16 = toolchain_dir.join("0.16.0");
assert!(toolchain_v16.exists());
let stable_toolchain = std::fs::read_link(toolchain_stable.as_path())
.expect("Couldn't obtain directory where the stable directory is pointing to");
assert_eq!(stable_toolchain.file_name(), toolchain_v16.file_name());
}