Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 41 additions & 4 deletions installer/ArSonMixVBCableInstall.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,33 @@ function Read-BootEpoch($value) {
}
$dir=Join-Path $env:TEMP ("armix-cable-"+[guid]::NewGuid().ToString("N"))
$pending=$false
$driverAttemptUncertain=$false
$unreadablePreviousStatus=$false
$vendorHandoffAttempted=$false
try {
# A driver already queued for reboot must NOT be run again: the VB-Audio
# setup utility can switch into REMOVE mode on a second invocation.
$previous=$null
if(Test-Path -LiteralPath $statusPath -PathType Leaf){
$previous=Get-Content -LiteralPath $statusPath -Raw -ErrorAction Stop | ConvertFrom-Json
$hadPreviousStatus=Test-Path -LiteralPath $statusPath -PathType Leaf
if($hadPreviousStatus){
try {
$previous=Get-Content -LiteralPath $statusPath -Raw -ErrorAction Stop | ConvertFrom-Json -ErrorAction Stop
} catch {
# A damaged record may conceal an interrupted vendor installation.
# Defer the decision until PnP: a healthy, already-installed cable must
# still be recognized, but a missing cable must never reach vendor setup.
$unreadablePreviousStatus=$true
}
}
$pending=$null -ne $previous -and $previous.state -eq 'PENDING_REBOOT'
$previousState=if($null -ne $previous -and $null -ne $previous.PSObject.Properties['state']){
[string]$previous.state
}else{""}
$pending=$previousState -eq 'PENDING_REBOOT'
# A prior invocation may have died after starting the vendor GUI but
# before recording its result. An uncertain or repair-required attempt
# must never launch the same setup automatically again.
$driverAttemptUncertain=$unreadablePreviousStatus -or
($hadPreviousStatus -and $previousState -notin @("ALREADY_PRESENT","FAILED","PENDING_REBOOT"))
$os=Get-CimInstance Win32_OperatingSystem -ErrorAction Stop
$script:bootUtc=$os.LastBootUpTime.ToUniversalTime().ToString('o')
if($pending){
Expand Down Expand Up @@ -76,6 +95,15 @@ try {
Record "ALREADY_PRESENT" "VB-CABLE device already installed; vendor installer skipped"
exit 0
}
if($driverAttemptUncertain){
$detail=if($unreadablePreviousStatus){
"Previous VB-CABLE install record unreadable; inspect Device Manager before manual recovery"
}else{
"Previous VB-CABLE install outcome uncertain; inspect Device Manager before manual recovery"
}
Record "REPAIR_REQUIRED" $detail
exit 3
}
if(-not (Test-Path -LiteralPath $Archive -PathType Leaf)){throw "Bundled driver ZIP absent"}
$hash=(Get-FileHash -LiteralPath $Archive -Algorithm SHA256).Hash.ToLowerInvariant()
if($hash -cne $ExpectedSha256.ToLowerInvariant()){throw "Pinned driver ZIP hash mismatch"}
Expand All @@ -102,6 +130,9 @@ try {
throw "VB-Audio Authenticode signature unavailable or invalid"
}
Record "AWAITING_UAC" "Windows may request approval to install the missing VB-Audio driver"
# Once handed to Windows/ShellExecute, a thrown exception does not prove
# the vendor process never ran. Keep the on-disk attempt fail-closed.
$vendorHandoffAttempted=$true
# Official reference manual requires the vendor GUI, admin and reboot.
# No undocumented silent switches and no TrustedPublisher modification.
$process=Start-Process -FilePath $setups[0].FullName -WorkingDirectory $setups[0].DirectoryName -Verb RunAs -Wait -PassThru
Expand All @@ -110,7 +141,13 @@ try {
exit 0
} catch {
# A failed OS/PnP query is not proof a recorded installation vanished.
if(-not $pending){Record "FAILED" $_.Exception.Message}
if($vendorHandoffAttempted){
# A failure or nonzero exit at/after handoff may still have installed
# drivers. Never overwrite AWAITING_UAC with retryable FAILED.
Record "REPAIR_REQUIRED" ("Vendor handoff/install result uncertain: "+$_.Exception.Message)
} elseif(-not $pending -and -not $driverAttemptUncertain){
Record "FAILED" $_.Exception.Message
}
Write-Warning ("Optional VB-Audio driver step incomplete: "+$_.Exception.Message)
exit 2
} finally {
Expand Down
57 changes: 52 additions & 5 deletions scripts/test_inno_graceful_update_windows.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,16 @@ function Test-VBCableSmartDetection {
if ($case.Device -eq 'absent' -or ($case.Device -eq 'offline' -and $PresentOnly)) { return }
[pscustomobject]@{FriendlyName="CABLE Output (VB-Audio Virtual Cable)";Status="OK"}
}
# Guard the fixture from every attempt to launch a vendor process.
function Start-Process { throw "Unexpected vendor launch in detection fixture" }
# Mock vendor handoff: no real device, driver, elevation, or external EXE.
$global:ArSonMixTestVendorHandoffCount=0
function Start-Process {
$global:ArSonMixTestVendorHandoffCount++
throw "Fixture vendor handoff failure before process handle"
}
function Get-AuthenticodeSignature {
[CmdletBinding()] param([string]$LiteralPath)
[pscustomobject]@{Status='Valid';SignerCertificate=[pscustomobject]@{Subject='CN=VB-Audio'}}
}
try {
foreach ($case in @(
@{Name='healthy'; Device='present'; Expected='ALREADY_PRESENT'},
Expand All @@ -57,14 +65,30 @@ function Test-VBCableSmartDetection {
@{Name='after-reboot'; Device='present'; Expected='ALREADY_PRESENT'; RecordedBoot=$boot.AddDays(-1)},
@{Name='missing-after-reboot'; Device='absent'; Expected='REPAIR_REQUIRED'; RecordedBoot=$boot.AddDays(-1)},
@{Name='missing'; Device='absent'; Expected='FAILED'; Reason='Bundled driver ZIP absent'},
@{Name='query-failure'; Device='error'; Expected='FAILED'; Reason='Fixture PnP query denied'}
@{Name='query-failure'; Device='error'; Expected='FAILED'; Reason='Fixture PnP query denied'},
@{Name='interrupted-uac-missing'; Device='absent'; Expected='REPAIR_REQUIRED'; PreviousState='AWAITING_UAC'},
@{Name='interrupted-uac-present'; Device='present'; Expected='ALREADY_PRESENT'; PreviousState='AWAITING_UAC'},
@{Name='repair-missing'; Device='absent'; Expected='REPAIR_REQUIRED'; PreviousState='REPAIR_REQUIRED'},
@{Name='unknown-state-missing'; Device='absent'; Expected='REPAIR_REQUIRED'; PreviousState='UNKNOWN'},
@{Name='corrupt-status'; Device='absent'; Expected='REPAIR_REQUIRED'; Corrupt=$true},
@{Name='corrupt-status-but-healthy'; Device='present'; Expected='ALREADY_PRESENT'; Corrupt=$true},
@{Name='empty-json-status'; Device='absent'; Expected='REPAIR_REQUIRED'; PreviousState=''}
)) {
$env:APPDATA=Join-Path $work ("cable-"+$case.Name)
$status=Join-Path $env:APPDATA "AR-MIX-Studio/VB-CABLE-STATUS.json"
$statusFixture=@{}
if ($case.ContainsKey('RecordedBoot')) {
$statusFixture.state='PENDING_REBOOT'
$statusFixture.bootUtc=$case.RecordedBoot.ToString('o')
}
if ($case.ContainsKey('PreviousState')) { $statusFixture.state=$case.PreviousState }
if ($statusFixture.Count -gt 0 -or $case.ContainsKey('Corrupt')) {
New-Item -ItemType Directory -Force -Path (Split-Path -Parent $status) | Out-Null
@{state='PENDING_REBOOT';bootUtc=$case.RecordedBoot.ToString('o')} |
ConvertTo-Json | Set-Content -LiteralPath $status
if ($case.ContainsKey('Corrupt')) {
'{ invalid incomplete installer status' | Set-Content -LiteralPath $status
} else {
$statusFixture | ConvertTo-Json | Set-Content -LiteralPath $status
}
}
# Deliberately absent payload: the missing-device case alone should
# check for the archive. Presence and pending must return earlier.
Expand All @@ -75,8 +99,31 @@ function Test-VBCableSmartDetection {
Assert-Condition ($result.reason -ceq $case.Reason) "VB-CABLE reason mismatch for $($case.Name)"
}
}
Assert-Condition ($global:ArSonMixTestVendorHandoffCount -eq 0) "Preflight PnP fixtures unexpectedly launched vendor"
# Use a synthetic ZIP and a mocked signature to enter the *real*
# setup handoff code without ever executing a driver or showing UAC.
$source=Join-Path $work 'vendor-handoff-source'
New-Item -ItemType Directory -Force -Path $source | Out-Null
foreach($name in @('VBCABLE_Setup_x64.exe','README.txt','LICENSE.txt','setup.ini','manifest.txt')){
[IO.File]::WriteAllText((Join-Path $source $name), "FAKE_FIXTURE_ONLY_$name")
}
$archive=Join-Path $work 'synthetic-vendor.zip'
Add-Type -AssemblyName System.IO.Compression.FileSystem
[IO.Compression.ZipFile]::CreateFromDirectory($source,$archive)
$sha=(Get-FileHash -LiteralPath $archive -Algorithm SHA256).Hash
$env:APPDATA=Join-Path $work 'cable-vendor-handoff'
$record=Join-Path $env:APPDATA 'AR-MIX-Studio/VB-CABLE-STATUS.json'
& $bootstrap -Archive $archive -ExpectedSha256 $sha
$outcome=Get-Content -LiteralPath $record -Raw | ConvertFrom-Json
Assert-Condition ($outcome.state -ceq 'REPAIR_REQUIRED') "Failed vendor handoff became retryable: $($outcome.state)"
Assert-Condition ($global:ArSonMixTestVendorHandoffCount -eq 1) "Fixture did not reach single mocked vendor handoff"
& $bootstrap -Archive $archive -ExpectedSha256 $sha
$outcome=Get-Content -LiteralPath $record -Raw | ConvertFrom-Json
Assert-Condition ($outcome.state -ceq 'REPAIR_REQUIRED') "Repeated setup did not remain fail-closed"
Assert-Condition ($global:ArSonMixTestVendorHandoffCount -eq 1) "Repeat setup incorrectly relaunched uncertain vendor installer"
} finally {
$env:APPDATA=$originalAppData
Remove-Variable -Name ArSonMixTestVendorHandoffCount -Scope Global -ErrorAction SilentlyContinue
}
Write-Host 'VBCABLE_SMART_DETECTION_PASS'
}
Expand Down
21 changes: 19 additions & 2 deletions tests/windows_installer_contract_test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,29 @@ test('interactive Setup automatically checks for signed VB-CABLE while mixer lau
assert.match(bootstrap, /Get-PnpDevice -PresentOnly/);
assert.match(bootstrap, /Get-PnpDevice -ErrorAction Stop/);
assert.match(bootstrap, /Get-CimInstance Win32_OperatingSystem/);
assert.match(bootstrap, /previous\.state -eq 'PENDING_REBOOT'/);
assert.match(bootstrap, /previousState -eq 'PENDING_REBOOT'/);
assert.match(bootstrap, /previous\.PSObject\.Properties\['bootUtc'\]/);
assert.match(bootstrap, /PENDING_REBOOT.*Restart Windows|Record "PENDING_REBOOT"/);
assert.match(bootstrap, /Record "REPAIR_REQUIRED"/);
// Interrupted vendor/UAC attempts must not be treated as fresh installs;
// rerunning the vendor GUI can switch into destructive REMOVE mode.
assert.match(bootstrap, /previousState -notin/);
assert.match(bootstrap, /\$driverAttemptUncertain\)\{/);
assert.match(bootstrap, /\$vendorHandoffAttempted=\$true/);
assert.match(bootstrap, /if\(\$vendorHandoffAttempted\)/);
assert.match(bootstrap, /Vendor handoff\/install result uncertain/);
assert.ok(bootstrap.indexOf('Record "AWAITING_UAC"') <
bootstrap.indexOf('$vendorHandoffAttempted=$true') &&
bootstrap.indexOf('$vendorHandoffAttempted=$true') <
bootstrap.indexOf('Start-Process -FilePath $setups[0].FullName'),
'vendor handoff must become fail-closed before invoking ShellExecute');
assert.match(isolatedSmoke, /interrupted-uac-missing/);
assert.match(isolatedSmoke, /interrupted-uac-present/);
assert.match(isolatedSmoke, /corrupt-status-but-healthy/);
assert.match(isolatedSmoke, /cable-vendor-handoff/);
assert.match(isolatedSmoke, /ArSonMixTestVendorHandoffCount -eq 1/);
assert.match(bootstrap, /if\(\$all.Count -gt 0\)\{[\s\S]*?\$present \| Where-Object[\s\S]*?Record "ALREADY_PRESENT"[\s\S]*?exit 0/);
assert.ok(bootstrap.indexOf("previous.state -eq 'PENDING_REBOOT'") <
assert.ok(bootstrap.indexOf("previousState -eq 'PENDING_REBOOT'") <
bootstrap.indexOf('Start-Process -FilePath $setups[0].FullName'),
'pending reboot must be checked before launching a setup that can remove installed cable');
assert.match(bootstrap, /-Verb RunAs/);
Expand Down
Loading