mirror of
https://github.com/herdrdev/herdr.git
synced 2026-11-06 00:06:18 +00:00
fix: silence powershell progress clixml on windows remotes (#5282)
PowerShell serializes progress records such as module auto-loading's
"Preparing modules for first use." to the stderr CLIXML stream when stderr is
redirected under `-EncodedCommand`, and Herdr forwards that stderr during
interactive remote setup. Set `$ProgressPreference = 'SilentlyContinue'` in the
shared Windows PowerShell preamble so `machine add` and `--remote` no longer
print raw CLIXML records.
refs #4639
(cherry picked from commit 8a20d0b7b5)
This commit is contained in:
+21
-2
@@ -537,8 +537,12 @@ fn posix_remote_output_command(command: &str) -> String {
|
||||
}
|
||||
|
||||
fn windows_powershell_script_command(script: &str) -> String {
|
||||
// `$ProgressPreference = 'SilentlyContinue'` stops PowerShell from
|
||||
// serializing progress records (for example module auto-loading's
|
||||
// "Preparing modules for first use.") into the stderr CLIXML stream that
|
||||
// Herdr forwards to the terminal.
|
||||
let script = format!(
|
||||
"[Console]::Out.WriteLine(); [Console]::Out.WriteLine('{REMOTE_OUTPUT_READY_MARKER}'); [Console]::Out.Flush(); {script}"
|
||||
"[Console]::Out.WriteLine(); [Console]::Out.WriteLine('{REMOTE_OUTPUT_READY_MARKER}'); [Console]::Out.Flush(); $ProgressPreference = 'SilentlyContinue'; {script}"
|
||||
);
|
||||
let utf16 = script
|
||||
.encode_utf16()
|
||||
@@ -4729,7 +4733,7 @@ mod tests {
|
||||
];
|
||||
|
||||
let preamble = format!(
|
||||
"[Console]::Out.WriteLine(); [Console]::Out.WriteLine('{REMOTE_OUTPUT_READY_MARKER}'); [Console]::Out.Flush(); "
|
||||
"[Console]::Out.WriteLine(); [Console]::Out.WriteLine('{REMOTE_OUTPUT_READY_MARKER}'); [Console]::Out.Flush(); $ProgressPreference = 'SilentlyContinue'; "
|
||||
);
|
||||
for (label, command, expected) in commands {
|
||||
let script = decode_windows_command(&command);
|
||||
@@ -4740,6 +4744,21 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn windows_remote_commands_suppress_powershell_progress_records() {
|
||||
// PowerShell serializes progress records (such as module auto-loading's
|
||||
// "Preparing modules for first use.") to the stderr CLIXML stream when
|
||||
// stderr is redirected under `-EncodedCommand`. Herdr forwards that
|
||||
// stderr, so the shared preamble must silence progress.
|
||||
let script = decode_windows_command(&windows_powershell_script_command("exit 0"));
|
||||
let preference = "$ProgressPreference = 'SilentlyContinue'; ";
|
||||
assert!(script.contains(preference), "{script}");
|
||||
assert!(
|
||||
script.find(preference).unwrap() < script.find("exit 0").unwrap(),
|
||||
"{script}"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn windows_install_commands_copy_zip_and_return_concrete_path() {
|
||||
assert_eq!(
|
||||
|
||||
Reference in New Issue
Block a user