use clap::Parser;
use midenup::commands::Midenup;
mod common;
use common::*;
#[test]
fn integration_channel_migration_test() {
let test_name = "integration_channel_migration_test";
let test_env = environment_setup(test_name);
let toolchain_dir = test_env.midenup_home.join("toolchains");
let manifest: &str =
full_path_manifest!("tests/data/integration_migration_test/channel-manifest-1.json");
let (mut local_manifest, config) = test_setup(&test_env, manifest);
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");
assert!(toolchain_dir.join("0.20.3").join("bin").join("miden-vm").exists());
assert!(toolchain_dir.join("0.20.3").join("lib").join("core.masp").exists());
let manifest: &str =
full_path_manifest!("tests/data/integration_migration_test/channel-manifest-2.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_dir.join("0.13.0").exists());
assert!(!toolchain_dir.join("0.20.3").exists());
let stable_symlink = toolchain_dir.join("stable");
assert!(stable_symlink.exists(), "stable symlink should exist after migration");
let symlink_target = std::fs::read_link(&stable_symlink).expect("stable should be a symlink");
assert_eq!(
symlink_target.file_name(),
toolchain_dir.join("0.13.0").file_name(),
"stable symlink should point to the migrated channel"
);
}