fixed bug

This commit is contained in:
2026-10-14 16:59:15 -04:00
parent 53b55ca0eb
commit 11bc57e665
2 changed files with 60 additions and 3 deletions
+56 -2
View File
@@ -21,9 +21,9 @@ function Read-OfficeAst {
return $ast
}
try {
# Use the real boolean/logging helpers, without Tools.ps1's machine initialization.
# Use the real boolean/logging helpers and archive override, without machine initialization.
$toolsAst = Read-OfficeAst 'Tools.ps1'
$toolHelpers = @($toolsAst.FindAll({ param($node) $node -is [Management.Automation.Language.FunctionDefinitionAst] -and $node.Name -in @('ConvertTo-RmmBoolean', 'Write-Output', 'Write-Error') }, $false))
$toolHelpers = @($toolsAst.FindAll({ param($node) $node -is [Management.Automation.Language.FunctionDefinitionAst] -and $node.Name -in @('ConvertTo-RmmBoolean', 'Write-Output', 'Write-Error', 'Expand-Archive') }, $false))
foreach ($definition in $toolHelpers) { . ([scriptblock]::Create($definition.Extent.Text)) }
$Global:LogFile = Join-Path $testRoot 'management.log'
$coreAst = Read-OfficeAst 'Install-MicrosoftOffice365.ps1'
@@ -106,6 +106,60 @@ try {
Assert-OfficeThrows { Assert-OfficeCompanionPlatform -Build 20348 -ProductType 3 -Revision 2401 } 'Server 2022'
Assert-OfficeThrows { Assert-OfficeCompanionPlatform -Build 19044 -ProductType 1 -EditionId EnterpriseS -InstallTeams $true } 'LTSC'
Assert-OfficeCompanionPlatform -Build 19044 -ProductType 1 -EditionId EnterpriseS -InstallTeams $false
# Exercise actual ZIP extraction in media staging under the Tools.ps1 command scope.
# Network requests, Microsoft signatures, and executable launches are mocked; files are inert.
& {
$archiveCommand = Get-Command Expand-Archive
Assert-OfficeTest ($archiveCommand.CommandType -eq 'Function' -and !$archiveCommand.Parameters.ContainsKey('LiteralPath')) 'The real Tools archive override must be present for this regression.'
$mediaWorkspace = Join-Path $testRoot 'media [literal]'
$null = [IO.Directory]::CreateDirectory($mediaWorkspace)
$zipSource = Join-Path $testRoot 'zip-source'
$null = [IO.Directory]::CreateDirectory($zipSource)
[IO.File]::WriteAllText((Join-Path $zipSource 'GetHelpCmd.exe'), 'Inert scrubber fixture; never executed.')
$mediaFixtureZip = Join-Path $testRoot 'gethelp-fixture.zip'
Add-Type -AssemblyName System.IO.Compression.FileSystem
[IO.Compression.ZipFile]::CreateFromDirectory($zipSource, $mediaFixtureZip)
$script:mediaSignatures = @(); $script:mediaProcesses = @()
function Invoke-WebRequest {
[CmdletBinding()]
param([switch]$UseBasicParsing, [string]$Uri, [int]$TimeoutSec)
[pscustomobject]@{Content='https://download.microsoft.com/test/officedeploymenttool_test.exe'}
}
function Save-OfficeDownload {
param([string]$Uri, [string]$Path)
if ([IO.Path]::GetFileName($Path) -eq 'GetHelp.zip') {
[IO.File]::Copy($mediaFixtureZip, $Path)
} elseif ([IO.Path]::GetFileName($Path) -eq 'Office-UserCleanup.ps1') {
[IO.File]::WriteAllText($Path, '# ' + (Get-OfficeDeploymentDefinitions).HelperVersion)
} else {
[IO.File]::WriteAllText($Path, 'Inert installer fixture; never executed.')
}
}
function Assert-OfficeMicrosoftSignature {
param([string]$Path)
if (!(Test-Path -LiteralPath $Path -PathType Leaf)) { throw "Missing staged signature target: $Path" }
$script:mediaSignatures += $Path
}
function Invoke-OfficeProcess {
param([string]$FilePath, [string]$Arguments, [string]$LogPrefix)
$script:mediaProcesses += [IO.Path]::GetFileName($FilePath)
if ([IO.Path]::GetFileName($FilePath) -eq 'odt.exe' -and $Arguments -like '/quiet /extract:*') {
[IO.File]::WriteAllText((Join-Path $mediaWorkspace 'ODT\setup.exe'), 'Inert ODT fixture; never executed.')
} elseif ([IO.Path]::GetFileName($FilePath) -eq 'setup.exe' -and $Arguments -like '/download *') {
$payload = Join-Path $mediaWorkspace 'ODT\Office\Data\16.0.12345.67890'
$null = [IO.Directory]::CreateDirectory($payload)
foreach ($name in @('stream.x64.x-none.dat', 'stream.x64.en-us.dat')) { [IO.File]::WriteAllText((Join-Path $payload $name), 'Inert Office payload.') }
} else { throw "Unexpected executable requested during staging: $FilePath $Arguments" }
return 0
}
$options = Get-OfficeDeploymentOptions @{OfficeSubscription='Microsoft/Office 365 E3/E5 (no Teams)'; OfficeArchitecture='64'}
$media = Initialize-OfficeMedia $options $mediaWorkspace
Assert-OfficeTest ((Get-Content -LiteralPath $media.Scrubber -Raw) -eq 'Inert scrubber fixture; never executed.') 'Get Help ZIP did not extract correctly with Tools loaded and a literal path.'
Assert-OfficeTest ($media.Scrubber -in $script:mediaSignatures -and $media.Setup -in $script:mediaSignatures) 'Extracted Get Help and ODT must still pass signature checks.'
Assert-OfficeTest ($media.Version -eq '16.0.12345.67890' -and $media.Companions.Count -eq 3 -and !$media.Companions.ContainsKey('Teams')) 'Media staging lost its build or no-Teams selection.'
Assert-OfficeTest (([xml](Get-Content -LiteralPath $media.Config -Raw)).Configuration.Add.Version -eq $media.Version) 'Staged configuration must pin the downloaded build.'
Assert-OfficeTest (($script:mediaProcesses -join ',') -eq 'odt.exe,setup.exe') 'Staging attempted to run a scrubber or companion installer.'
}
& {
$script:staged = @(); $script:verified = @()
function Save-OfficeDownload { param($Uri,$Path) $script:staged += $Path }