hermes-agent/tests/install/e2e-assets/windows-bundle-metadata.ps1
ethernet b37acb8389 feat(release): dynamic R2-owned channels and preview retirement (rounds 1-2)
Checkpoint before round-3 reduction (two-tier retirement derived from
product identity). Includes:

- R2 channel protocol (release_channels.py, channel-protocol.ts): records,
  builds, manifests, retired channels with pinned destinationHead and
  receiverProtocol; fail-closed readers in both languages
- One shared native manifest/feed writer (scripts/bundles/channel_artifacts.py)
- Scoped/disposable R2 publication, fork isolation before credential
  access, canary bootstrap verification of its own promoted outputs
- Channel source CLI: typed SourceTarget, source-channel resolution,
  retirement downgrade refusal
- Desktop channel resolver/strategy, install-stamp/build-stamp receiver
  ownership (stable-owned S/T candidates), single-flight updater operation
- Cross-package retirement machinery (receiver/host/preservation/
  compatibility/connections/dialog/discovery, backup_migration strict
  snapshots with retained-link inventory, empty-dir preservation,
  connection-collision resolution, URL-credential rejection)
- Native install harness (tests/install/channel-retirement-*) and
  install-e2e retirement jobs
- checkout-source.test.ts transport shim now covers build_opener().open
  (was silently hitting the real network in CI)

Removed secondary certification protocol (channel_qualification.py) per
approved round-2 plan. All focused suites green at checkpoint; native
cross-package journeys unverified (to be deleted in round 3).
2026-09-14 10:26:36 -04:00

74 lines
No EOL
4.2 KiB
PowerShell

# Metadata-only readers shared by native admission and pure XML/archive tests.
function Read-SmokeXmlEntry($Zip, [string]$Name) {
$entries = @($Zip.Entries | Where-Object { $_.FullName -ceq $Name })
if ($entries.Count -ne 1) { throw "Expected exactly one $Name" }
$settings = [Xml.XmlReaderSettings]::new()
$settings.DtdProcessing = [Xml.DtdProcessing]::Prohibit
$settings.XmlResolver = $null
$stream = $entries[0].Open()
$reader = [Xml.XmlReader]::Create($stream, $settings)
try {
$xml = [Xml.XmlDocument]::new()
$xml.XmlResolver = $null
$xml.Load($reader)
return ,$xml
} finally { $reader.Dispose(); $stream.Dispose() }
}
function Assert-SmokeIdentity($Identity, $Expected) {
if (-not $Identity -or $Identity.GetAttribute('Name') -cne $Expected.msixIdentity -or
$Identity.GetAttribute('Publisher') -cne $Expected.publisher) { throw 'Package identity/publisher mismatch' }
$version = $Identity.GetAttribute('Version')
if ($version -cnotmatch '^\d+\.\d+\.\d+\.\d+$' -or
@($version.Split('.') | Where-Object { [int]$_ -gt 65535 }).Count) { throw 'Invalid package version' }
if ($Expected.PSObject.Properties['windowsVersion'] -and $version -cne $Expected.windowsVersion) {
throw 'Package version disagrees with channel request'
}
return $version
}
function Assert-SmokeRelativePath([string]$Path) {
if (-not $Path -or $Path -match '^[\\/]|:|(^|[\\/])\.\.?([\\/]|$)') {
throw "Unsafe package relative path: $Path"
}
}
function Read-SmokePackageManifest([xml]$Xml, [string]$Arch, $Expected) {
$identities = @($Xml.SelectNodes('/*[local-name()="Package"]/*[local-name()="Identity"]'))
if ($identities.Count -ne 1) { throw 'Expected one package identity' }
$identity = $identities[0]
$version = Assert-SmokeIdentity $identity $Expected
if ($identity.GetAttribute('ProcessorArchitecture') -cne $Arch) { throw 'Package lacks requested native architecture' }
$applications = @($Xml.SelectNodes('/*[local-name()="Package"]/*[local-name()="Applications"]/*[local-name()="Application"]') |
Where-Object { $_.GetAttribute('Id') -ceq $Expected.applicationId })
if ($applications.Count -ne 1) { throw 'Expected exactly one desktop applicationId' }
$exe = $applications[0].GetAttribute('Executable')
Assert-SmokeRelativePath $exe
return [pscustomobject]@{ Version=$version; Architecture=$Arch; Executable=$exe; Slice=$null }
}
function Read-BundleSmokeMetadata([string]$Artifact, [string]$Arch, $Expected) {
$zip = [IO.Compression.ZipFile]::OpenRead($Artifact)
try {
switch ([IO.Path]::GetExtension($Artifact).ToLowerInvariant()) {
'.msix' {
return Read-SmokePackageManifest (Read-SmokeXmlEntry $zip 'AppxManifest.xml') $Arch $Expected
}
'.msixbundle' {
$xml = Read-SmokeXmlEntry $zip 'AppxMetadata/AppxBundleManifest.xml'
$identities = @($xml.SelectNodes('/*[local-name()="Bundle"]/*[local-name()="Identity"]'))
if ($identities.Count -ne 1) { throw 'Expected one bundle identity' }
$version = Assert-SmokeIdentity $identities[0] $Expected
$slices = @($xml.SelectNodes('/*[local-name()="Bundle"]/*[local-name()="Packages"]/*[local-name()="Package"]') |
Where-Object { $_.GetAttribute('Type') -ceq 'application' -and $_.GetAttribute('Architecture') -ceq $Arch })
if ($slices.Count -ne 1) { throw 'Expected exactly one native application slice (no emulation fallback)' }
$slice = $slices[0].GetAttribute('FileName')
Assert-SmokeRelativePath $slice
if (@($zip.Entries | Where-Object { $_.FullName -ceq $slice }).Count -ne 1) { throw 'Native package bytes missing or ambiguous' }
if ($slices[0].GetAttribute('Version') -cne $version) { throw 'Native slice and bundle version mismatch' }
return [pscustomobject]@{ Version=$version; Architecture=$Arch; Executable=$null; Slice=$slice }
}
default { throw 'Expected a receipt-selected MSIX or MSIXBUNDLE' }
}
} finally { $zip.Dispose() }
}