From 7bc9cddc6d4b6680d571efd395d3c646a001b3dc Mon Sep 17 00:00:00 2001 From: ruihan Date: Fri, 30 Oct 2026 04:53:08 -0300 Subject: [PATCH] fix(dualboot): stop dry runs before accessing target state --- tests/test_dualboot.bats | 25 +++++++++++++++++++++++++ unleash | 5 +++++ unleash-standalone.sh | 5 +++++ 3 files changed, 35 insertions(+) create mode 100644 tests/test_dualboot.bats diff --git a/tests/test_dualboot.bats b/tests/test_dualboot.bats new file mode 100644 index 0000000..848c38b --- /dev/null +++ b/tests/test_dualboot.bats @@ -0,0 +1,25 @@ +#!/usr/bin/env bats + +@test "dualboot dry run returns before target access with or without root" { + local entrypoint root_status + for entrypoint in unleash unleash-standalone.sh; do + local script="$BATS_TEST_DIRNAME/../$entrypoint" + local definitions="$BATS_TEST_TMPDIR/$entrypoint.functions" + sed '/^main "\$@"$/d' "$script" > "$definitions" + for root_status in 0 1; do + run "${UNLEASH_TEST_SHELL:-bash}" -u -c ' + source "$1" + root_status="$2" + load_config() { :; } + is_root() { return "$root_status"; } + resolve_target_volumes() { echo TARGET_WAS_ACCESSED; return 97; } + create_admin_user() { echo USER_WAS_WRITTEN; return 97; } + main --dry-run dualboot + ' "$script" "$definitions" "$root_status" + [ "$status" -eq 0 ] + [[ "$output" == *"[DRY RUN] Would select an external macOS installation"* ]] + [[ "$output" != *"TARGET_WAS_ACCESSED"* ]] + [[ "$output" != *"USER_WAS_WRITTEN"* ]] + done + done +} diff --git a/unleash b/unleash index 93e1d35..67db02f 100755 --- a/unleash +++ b/unleash @@ -203,6 +203,11 @@ cmd_restore() { } cmd_dualboot() { + if [ "$DRY_RUN" = true ]; then + info "[DRY RUN] Would select an external macOS installation and create an admin account." + info "[DRY RUN] Would update its hosts file and enrollment markers." + return 0 + fi if ! is_root; then error_exit "Dual-boot needs sudo: sudo ./unleash dualboot" fi diff --git a/unleash-standalone.sh b/unleash-standalone.sh index 6904e9d..0a8c989 100755 --- a/unleash-standalone.sh +++ b/unleash-standalone.sh @@ -2886,6 +2886,11 @@ cmd_restore() { } cmd_dualboot() { + if [ "$DRY_RUN" = true ]; then + info "[DRY RUN] Would select an external macOS installation and create an admin account." + info "[DRY RUN] Would update its hosts file and enrollment markers." + return 0 + fi if ! is_root; then error_exit "Dual-boot needs sudo: sudo ./unleash dualboot" fi