diff --git a/guest/migrate-connections-test.nix b/guest/migrate-connections-test.nix index a1621a7..0b16fd8 100644 --- a/guest/migrate-connections-test.nix +++ b/guest/migrate-connections-test.nix @@ -49,6 +49,13 @@ in pkgs.testers.runNixOSTest { name = "hermenix-migrate-connections"; + # This test only boots once and copies a few small files locally — it + # should finish in well under a minute. Bound it far below the framework's + # 1-hour default so a regression (e.g. a prompt silently blocking on + # terminal input instead of reading piped stdin) fails fast instead of + # burning a full hour before being reported. + globalTimeout = 300; + nodes.machine = { environment.systemPackages = [ hermenix ]; }; diff --git a/guest/vm-test.nix b/guest/vm-test.nix index b1d051f..d4326b3 100644 --- a/guest/vm-test.nix +++ b/guest/vm-test.nix @@ -19,6 +19,12 @@ pkgs.testers.runNixOSTest { name = "hermenix-guest-config"; + # This test boots, reboots once, and runs only quick local checks — a few + # minutes is generous. Bound it far below the framework's 1-hour default so + # a genuine hang (boot failure, a blocked prompt, a stuck reboot) fails + # fast instead of burning a full hour before being reported. + globalTimeout = 600; + nodes.machine = { lib, ... }: { diff --git a/nu/lib/common.nu b/nu/lib/common.nu index 396844d..9ca18f4 100644 --- a/nu/lib/common.nu +++ b/nu/lib/common.nu @@ -19,19 +19,38 @@ def die [msg: string] { } def step [n: int, title: string] { print $"\n(ansi attr_bold)== ($n). ($title)(ansi reset)" } +# Read a line of user input. On a real terminal this prompts interactively +# via `input`. When stdin isn't a terminal (e.g. piped in from a test or +# script), `input` would otherwise try to read from the controlling terminal +# and hang forever waiting for a keystroke that never comes — so read the +# piped stdin directly instead. +def read-line [prompt: string] { + if (is-terminal --stdin) { + input $prompt + } else { + print -n $prompt + ( + ^cat + | lines + | first + | str trim + ) + } +} + def ask [prompt: string, default: string = ""] { let suffix = if $default != "" { $" [($default)]" } else { "" } - let reply = (input $" ($prompt)($suffix): ") + let reply = (read-line $" ($prompt)($suffix): ") if $reply == "" { $default } else { $reply } } def confirm [prompt: string] { - let reply = (input $" ($prompt) [y/N] ") + let reply = (read-line $" ($prompt) [y/N] ") (($reply | str starts-with "y") or ($reply | str starts-with "Y")) } def confirm-word [word: string, prompt: string] { - (input $" ($prompt) ") == $word + (read-line $" ($prompt) ") == $word } # Single-quote a string for safe embedding in a remote shell command line.