75 lines
7.7 KiB
PowerShell
75 lines
7.7 KiB
PowerShell
[CmdletBinding()]
|
|
param(
|
|
[Parameter(Mandatory)][string]$FailedSetupDirectory,
|
|
[Parameter(Mandatory)][string]$CorrectedSetupDirectory,
|
|
[Parameter(Mandatory)][string]$ReportPath
|
|
)
|
|
$ErrorActionPreference='Stop'
|
|
$checks=[Collections.Generic.List[string]]::new()
|
|
function Assert-Upgrade([bool]$condition,[string]$message){if(!$condition){throw "Upgrade regression failed: $message"};$checks.Add($message)}
|
|
function Com($object,[string]$member,[object[]]$arguments,[switch]$Property){$values=@(foreach($v in $arguments){$v.PSObject.BaseObject});$flags=if($Property){[Reflection.BindingFlags]::GetProperty}else{[Reflection.BindingFlags]::InvokeMethod};$object.GetType().InvokeMember($member,$flags,$null,$object,$values)}
|
|
function Rows($database,[string]$table){
|
|
$view=Com $database 'OpenView' @('SELECT * FROM `'+$table+'`');$null=Com $view 'Execute' @()
|
|
$columns=Com $view 'ColumnInfo' @(0) -Property;$count=Com $columns 'FieldCount' @() -Property;$rows=@()
|
|
while($null -ne ($record=Com $view 'Fetch' @())){$row=[ordered]@{};for($i=1;$i -le $count;$i++){$row[(Com $columns 'StringData' @($i) -Property)]=Com $record 'StringData' @($i) -Property};$rows+=,[pscustomobject]$row}
|
|
$null=Com $view 'Close' @();return $rows
|
|
}
|
|
function Authoring($installer,[string]$path){
|
|
# OpenDatabase mode0 only. Never open an installation session or execute actions.
|
|
$db=Com $installer 'OpenDatabase' @($path,0)
|
|
$properties=@{};foreach($row in @(Rows $db 'Property')){$properties[$row.Property]=$row.Value}
|
|
$features=@(Rows $db 'Feature');$upgrade=@(Rows $db 'Upgrade');$sequence=@(Rows $db 'InstallExecuteSequence')
|
|
$problems=[Collections.Generic.List[string]]::new()
|
|
if($properties.ADDLOCAL -ne 'Complete'){$problems.Add('No explicit local Complete feature selection')}
|
|
if(@($features | Where-Object {$_.Feature -eq 'Complete' -and ([int]$_.Attributes -band 8) -eq 8 -and ([int]$_.Attributes -band 16) -eq 16 -and [int]$_.Level -gt 0}).Count -ne 1){$problems.Add('Complete can be advertised or absent')}
|
|
if(@($upgrade | Where-Object {([int]$_.Attributes -band 1) -ne 0}).Count){$problems.Add('Old advertised feature state is eligible for migration')}
|
|
if(@($sequence | Where-Object Action -eq 'MigrateFeatureStates').Count){$problems.Add('MigrateFeatureStates action is scheduled')}
|
|
return @{problems=@($problems);properties=$properties;files=@(Rows $db 'File');components=@(Rows $db 'FeatureComponents')}
|
|
}
|
|
$fixture=Get-Content -Raw (Join-Path $PSScriptRoot 'Fixtures\Advertised-Version10-Upgrade.txt')
|
|
Assert-Upgrade ($fixture -match "setting feature 'Complete' to 'Advertise'" -and $fixture -match 'Request: Null; Action: Null') 'Regression fixture records the real advertised-feature/no-file-action failure'
|
|
$installer=New-Object -ComObject WindowsInstaller.Installer
|
|
$failed=Authoring $installer (Join-Path $FailedSetupDirectory 'PlotDirectorCompanion.msi')
|
|
$corrected=Authoring $installer (Join-Path $CorrectedSetupDirectory 'PlotDirectorCompanion.msi')
|
|
Assert-Upgrade ($failed.problems.Count -eq 4) 'Negative control: original released version12 MSI fails all four local-install invariants'
|
|
Assert-Upgrade ($corrected.problems.Count -eq 0) 'Corrected MSI cannot inherit the recorded advertised feature selection'
|
|
Assert-Upgrade ($failed.properties.ProductCode -eq $corrected.properties.ProductCode -and $corrected.properties.ProductVersion -eq '1.0.12') 'Existing partially registered version12 remains repairable under the same product identity'
|
|
$exe=Join-Path $CorrectedSetupDirectory 'PlotDirectorCompanionSetup.exe'
|
|
$assembly=[Reflection.Assembly]::Load([IO.File]::ReadAllBytes($exe))
|
|
$policy=$assembly.GetType('CompanionUpgradePolicy',$true)
|
|
foreach($scenario in @(@{name='version10 advertised-feature major upgrade';registered=$false},@{name='partially registered version12 repair';registered=$true})){
|
|
# Invoke only the compiled pure policy, never Setup.Main or any MSI API action.
|
|
$properties=[string]$policy.GetMethod('InstallProperties').Invoke($null,@([bool]$scenario.registered))
|
|
Assert-Upgrade ($properties -match '(^| )ADDLOCAL=Complete( |$)' -and $properties -match 'REINSTALLMODE=vamus' -and $properties -notmatch 'ADVERTISE=') "Compiled bootstrapper requests local files: $($scenario.name)"
|
|
Assert-Upgrade (($properties -match 'REINSTALL=ALL') -eq [bool]$scenario.registered) "Compiled bootstrapper chooses correct repair mode: $($scenario.name)"
|
|
}
|
|
foreach($versions in @(@{word='1.0.0.10';agent='1.0.0.10'},@{word='1.0.0.12';agent='1.0.0.10'},@{word='1.0.0.10';agent='1.0.0.12'})){
|
|
$message=$null;try{$policy.GetMethod('VerifyVersions').Invoke($null,@('1.0.0.12',$versions.word,$versions.agent))}catch{$message=$_.Exception.GetBaseException().Message}
|
|
Assert-Upgrade ($message -like '*Expected 1.0.0.12*' -and $message.Contains('Word add-in detected '+$versions.word) -and $message.Contains('tray executable detected '+$versions.agent)) "Strict check rejects and diagnoses old/mixed files: $($versions.word) / $($versions.agent)"
|
|
}
|
|
$null=$policy.GetMethod('VerifyVersions').Invoke($null,@('1.0.0.12','1.0.0.12','1.0.0.12'));$checks.Add('Strict check accepts matching version12 files')
|
|
$transition=$policy.GetMethod('EnsureLocalFeature')
|
|
$query=[Func[int]]{$script:stateValue};$logger=[Action[string]]{param($message)}
|
|
foreach($initial in @(1,2,4)){
|
|
$script:stateValue=$initial;$script:configureCalls=0
|
|
$configure=[Func[uint32]]{$script:configureCalls++;$script:stateValue=3;return [uint32]0}
|
|
$null=$transition.Invoke($null,@($query,$configure,$logger))
|
|
Assert-Upgrade ($script:configureCalls -eq 1 -and $script:stateValue -eq 3) "Compiled control flow explicitly promotes feature state $initial to Local before accepting versions"
|
|
}
|
|
$script:stateValue=3;$script:configureCalls=0
|
|
$null=$transition.Invoke($null,@($query,$configure,$logger))
|
|
Assert-Upgrade ($script:configureCalls -eq 0) 'Already Local feature is not needlessly configured again'
|
|
foreach($failure in @('native-error','still-advertised','unknown-state')){
|
|
$script:stateValue=if($failure -eq 'unknown-state'){-1}else{1};$script:configureCalls=0
|
|
$configure=[Func[uint32]]{$script:configureCalls++;if($failure -eq 'native-error'){return [uint32]1603};return [uint32]0}
|
|
$refused=$false;try{$null=$transition.Invoke($null,@($query,$configure,$logger))}catch{$refused=$true}
|
|
Assert-Upgrade $refused "Compiled feature transition refuses $failure instead of trusting result0 or old files"
|
|
if($failure -eq 'unknown-state'){Assert-Upgrade ($script:configureCalls -eq 0) 'Unknown native state is rejected before any configuration request'}
|
|
}
|
|
$bootstrap=Get-Content -Raw (Join-Path $PSScriptRoot 'Setup.cs')
|
|
Assert-Upgrade ($bootstrap.IndexOf('CompanionUpgradePolicy.EnsureLocalFeature(') -lt $bootstrap.IndexOf('CompanionUpgradePolicy.VerifyVersions(') -and $bootstrap.Contains('MsiConfigureFeature(SetupRelease.ProductCode, "Complete", 3)')) 'Bootstrapper wires explicit native Local configuration before strict version validation'
|
|
$required=@('PlotDirector.WordAddIn.dll','PlotDirector.Companion.Agent.exe')
|
|
foreach($name in $required){$file=@($corrected.files | Where-Object {($_.FileName -split '\|')[-1] -eq $name});Assert-Upgrade ($file.Count -eq 1 -and @($corrected.components | Where-Object {$_.Component_ -eq $file[0].Component_ -and $_.Feature_ -eq 'Complete'}).Count -eq 1) "Required file belongs to the locally selected Complete feature: $name"}
|
|
@{passed=$checks;rejectedOriginalAuthoring=$failed.problems;correctedSetupSha256=(Get-FileHash $exe).Hash;scope='Read-only MSI tables and compiled pure policy only. No installed upgrade was executed.'} | ConvertTo-Json -Depth 6 | Set-Content -LiteralPath $ReportPath -Encoding UTF8
|
|
Write-Output "PASS exact advertised-feature upgrade regression: $($checks.Count) assertions; original package rejected, corrected package accepted without installation."
|