use std::{ffi::OsString, fs::OpenOptions};
use clap::Parser;
use midenup::{
channel::{self, InstalledFile},
commands::Midenup,
miden_wrapper, utils, version,
};
mod common;
use common::*;
#[test]
fn integration_install_stable() {
let test_name = "integration_install_stable";
let test_env = environment_setup(test_name);
const FILE: &str = full_path_manifest!("manifest/channel-manifest.json");
let (mut local_manifest, config) = test_setup(&test_env, FILE);
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 = test_env.midenup_home.join("manifest").with_extension("json");
assert!(manifest.exists());
let stable_dir = test_env.midenup_home.join("toolchains").join("stable");
assert!(stable_dir.exists());
assert!(stable_dir.is_symlink());
let stable_channel = local_manifest
.get_latest_stable()
.expect("No stable channel found; despite having installed stable");
assert_eq!(stable_channel.alias, Some(channel::ChannelAlias::Stable));
assert_eq!(
local_manifest
.get_channels()
.next()
.expect(
"ERROR: The local_manifest in the filesystem has no alias, when it should have \
stable alias"
)
.alias
.as_ref()
.expect(
"ERROR: The installed stable toolchain should be marked as stable in the local \
manifest"
),
&channel::ChannelAlias::Stable
);
}
#[test]
fn integration_install_from_non_cargo() {
let test_name = "integration_install_from_non_cargo";
let test_env = environment_setup(test_name);
let miden_vm_clone_path = test_env.present_working_dir.join("miden-vm");
{
let miden_vm_repo = "https://github.com/0xMiden/miden-vm.git";
let vm_release_16 = "fc368686bd1e6e171a51a1a5b365ef5400e4b8d5";
utils::git::clone_specific_revision(miden_vm_repo, vm_release_16, &miden_vm_clone_path)
.unwrap();
};
let manifest: &str = full_path_manifest!(
"tests/data/integration_install_from_non_cargo/channel-manifest-1.json"
);
let (mut local_manifest, config) = test_setup(&test_env, manifest);
let command = Midenup::try_parse_from(["midenup", "install", "stable"]).unwrap();
command
.execute_with_manifest(&config, &mut local_manifest)
.expect("failed to install stable");
let (time_when_installed, hash_when_installed) = {
let stable_channel = local_manifest
.get_latest_stable()
.expect("No stable channel found; despite having installed stable")
.clone();
let vm_from_path = stable_channel.get_component("vm").unwrap();
let last_modification = match vm_from_path.version {
version::Authority::Path { last_modification, .. } => last_modification.unwrap(),
_ => panic!(
"Failed to recognize miden-vm's Authority as Path, despite being installed like \
so."
),
};
let client_from_git = stable_channel.get_component("client").unwrap();
let revision = match &client_from_git.version {
version::Authority::Git {
target: version::GitTarget::Revision { hash },
..
} => hash.clone(),
authority => panic!(
"Failed to recognize miden_client's Authority as Git, despite being installed \
like so. Found: {authority}"
),
};
(last_modification, revision)
};
let command = Midenup::try_parse_from(["midenup", "update"]).unwrap();
command
.execute_with_manifest(&config, &mut local_manifest)
.expect("failed to update");
let (new_time, new_revision) = {
let stable_channel = local_manifest
.get_latest_stable()
.expect("No stable channel found; despite having installed stable")
.clone();
let vm_from_path = stable_channel.get_component("vm").unwrap();
let last_modification = match vm_from_path.version {
version::Authority::Path { last_modification, .. } => last_modification.unwrap(),
_ => panic!(
"Failed to recognize miden-vm's Authority as Path, despite being installed like \
so."
),
};
let client_from_git = stable_channel.get_component("client").unwrap();
let revision = match &client_from_git.version {
version::Authority::Git {
target: version::GitTarget::Revision { hash },
..
} => hash.clone(),
authority => panic!(
"Failed to recognize miden_client's Authority as Git, despite being installed \
like so. Found: {authority}"
),
};
(last_modification, revision)
};
assert_eq!(new_time, time_when_installed);
assert_eq!(new_revision, hash_when_installed);
let manifest: &str = full_path_manifest!(
"tests/data/integration_install_from_non_cargo/channel-manifest-2.json"
);
let (_, config) = test_setup(&test_env, manifest);
{
OpenOptions::new()
.read(true)
.write(true)
.create(true)
.truncate(false)
.open(miden_vm_clone_path.join("miden-vm").join("trigger-update"))
.unwrap();
}
let command = Midenup::try_parse_from(["midenup", "update", "--path-update=all"]).unwrap();
command
.execute_with_manifest(&config, &mut local_manifest)
.expect("failed to update");
let (new_time, new_revision) = {
let stable_channel = local_manifest
.get_latest_stable()
.expect("No stable channel found; despite having installed stable")
.clone();
let vm_from_path = stable_channel.get_component("vm").unwrap();
let last_modification = match vm_from_path.version {
version::Authority::Path { last_modification, .. } => last_modification.unwrap(),
_ => panic!(
"Failed to recognize miden-vm's Authority as Path, despite being installed like \
so."
),
};
let client_from_git = stable_channel.get_component("client").unwrap();
let revision = match &client_from_git.version {
version::Authority::Git {
target: version::GitTarget::Revision { hash },
..
} => hash.clone(),
authority => panic!(
"Failed to recognize miden_client's Authority as Git, despite being installed \
like so. Found: {authority}"
),
};
(last_modification, revision)
};
assert!(new_time > time_when_installed);
assert_ne!(new_revision, hash_when_installed);
}
#[test]
fn integration_test_components_are_runnable() {
let test_name = "integration_test_components";
let test_env = environment_setup(test_name);
const FILE: &str = full_path_manifest!("manifest/channel-manifest.json");
let (mut local_manifest, config) = test_setup(&test_env, FILE);
let command =
Midenup::try_parse_from(["midenup", "install", "stable", "--profile", "complete"]).unwrap();
command
.execute_with_manifest(&config, &mut local_manifest)
.expect("failed to install stable");
let stable_channel = local_manifest
.get_latest_stable()
.expect("No stable channel found after installing stable")
.clone();
println!("Installed: {}", stable_channel);
for component in &stable_channel.components {
let component_type = component.get_installed_file();
if matches!(component_type, InstalledFile::Library { .. }) {
continue;
}
if matches!(component_type, InstalledFile::Executable { alias_only: true, .. }) {
continue;
}
let argv: Vec<OsString> =
vec!["miden".into(), "help".into(), component.name.as_ref().into()];
miden_wrapper::miden_wrapper(&argv, &config, &mut local_manifest).unwrap_or_else(|err| {
panic!(
"Component '{}' is not runnable through the 'miden' interface: {}",
component.name, err
)
});
}
}