refactor(deploy): stream shell scripts over SSH and support binary-only updates

This commit is contained in:
lda committed 2026-10-19 18:44:12 +07:00 Verified
1 parent eb55554806
commit 134738cd32
6 files changed
+319 -131

No files matched your search

+34
View File
@@ -0,0 +1,34 @@
#!/usr/bin/env pwsh
# Run with pwsh -NoProfile -File scripts/tests/ssh_stdin.ps1 on Linux/WSL.
$ErrorActionPreference = 'Stop'
. "$PSScriptRoot/../lib.ps1"
# Exercise the real native-command pipeline without contacting a server.
$body = "printf '%s\n' `"owner's directory`"`nprintf '%s\n' 'second line'"
$output = @(Invoke-Ext -Exe sh -Arguments @('-s') -Label test -Stdin $body)
if (($output -join '|') -cne "owner's directory|second line") { throw 'stdin script changed in transit' }
$output = @(Invoke-Ext -Exe sh -Arguments @('-c', 'printf command-only') -Label test)
if (($output -join '') -cne 'command-only') { throw 'Command-only execution changed' }
$failed = $false
try { Invoke-Ext -Exe sh -Arguments @('-s') -Label test -Stdin 'exit 7' } catch { $failed = $true }
if (-not $failed) { throw 'stdin execution swallowed a failure' }
# Test SSH argument and stdin forwarding independently of native SSH availability.
function Test-IsWsl { return $true }
function Get-SshpassCommand { return $script:Sshpass }
function Invoke-Ext {
param($Exe, $Arguments, $Label, [string]$Stdin)
$script:Call = @{ Exe = $Exe; Arguments = $Arguments; Stdin = $Stdin; HasStdin = $PSBoundParameters.ContainsKey('Stdin') }
}
$script:Sshpass = $null
Invoke-Ssh -Cmd 'sh -s' -User root -Remote test -Stdin "printf ok`r`n"
if ($script:Call.Exe -ne 'ssh' -or $script:Call.Stdin.Contains("`r") -or -not $script:Call.HasStdin) {
throw 'SSH stdin was not normalized and forwarded'
}
if (($script:Call.Arguments[-2..-1] -join '|') -ne 'root@test|sh -s') { throw 'SSH command changed' }
Invoke-Ssh -Cmd 'true' -User root -Remote test
if ($script:Call.HasStdin) { throw 'Command-only SSH unexpectedly redirects stdin' }
$script:Sshpass = '/fake/sshpass'
Invoke-Ssh -Cmd 'sh -s' -User root -Remote test -Pass test-only -Stdin $body
if ($script:Call.Exe -ne '/fake/sshpass' -or $script:Call.Stdin -cne $body) { throw 'sshpass lost stdin' }
Write-Host 'SSH stdin tests passed'