Import-Module "$PSScriptRoot/../src/PortablePackages.psm1" -Force Describe 'Portable package lifecycle' { InModuleScope PortablePackages { BeforeEach { $root = Join-Path $TestDrive ([guid]::NewGuid().ToString('N') + ' espace é') $bundle = Join-Path $TestDrive ([guid]::NewGuid().ToString('N')) [void][IO.Directory]::CreateDirectory("$bundle/bundle") [IO.File]::WriteAllText("$bundle/bundle/app.exe", 'test executable') [IO.File]::WriteAllText("$bundle/bundle/library.dll", 'test dependency') $script:fixtureZip = "$bundle.zip" [IO.Compression.ZipFile]::CreateFromDirectory($bundle, $script:fixtureZip) $package = [pscustomobject]@{ id = 'presenter'; provider = 'portable'; source = 'gitea'; version = '1.2.3'; update = 'pinned'; url = 'https://example.org/app.zip'; sha256 = (Get-FileHash $script:fixtureZip).Hash; executable = 'bundle/app.exe' } Mock Get-PortableProgramsPath { Join-Path $root 'test-programs' } Mock Assert-PortablePlatform {} Mock Assert-PortableStopped {} Mock Test-PortableShortcut { Test-Path -LiteralPath $Path -PathType Leaf } Mock Test-PortableFileAssociations { $true } Mock Set-PortableFileAssociations {} Mock Remove-PortableFileAssociations {} Mock Set-PortableShortcut { [void][IO.Directory]::CreateDirectory((Split-Path -Parent $Paths.Shortcut)) [IO.File]::WriteAllText($Paths.Shortcut, 'mock shortcut') } Mock Invoke-WebRequest { Copy-Item -LiteralPath $script:fixtureZip -Destination $OutFile } } It 'plans without writes or downloads, installs, and verifies an unchanged rerun' { $plan = Get-PortablePackagePlan $package $root $plan.action | Should -Be 'Install' Test-Path $root | Should -BeFalse Should -Invoke Invoke-WebRequest -Times 0 (Invoke-PortablePackageOperation $plan).status | Should -Be 'Succeeded' $again = Get-PortablePackagePlan $package $root $again.action | Should -Be 'None' (Invoke-PortablePackageOperation $again).status | Should -Be 'None' Should -Invoke Invoke-WebRequest -Times 1 } It 'removes the previous version only after activating the update' { $paths = Get-PortablePaths $package $root (Invoke-PortablePackageOperation (Get-PortablePackagePlan $package $root)).status | Should -Be 'Succeeded' $old = Get-Content $paths.Receipt -Raw | ConvertFrom-Json $settings = Join-Path $paths.Root "$($old.directory)/settings.json" 'user settings' | Set-Content $settings $unmanaged = Join-Path $paths.Root 'versions/unmanaged-settings' [void][IO.Directory]::CreateDirectory($unmanaged) $package.version = '2.0' (Invoke-PortablePackageOperation (Get-PortablePackagePlan $package $root)).status | Should -Be 'Succeeded' Test-Path (Join-Path $paths.Root $old.directory) | Should -BeFalse Test-Path $unmanaged | Should -BeTrue (Get-Content $paths.Receipt -Raw | ConvertFrom-Json).version | Should -Be '2.0' } It 'repairs missing files but refuses modified files' { $paths = Get-PortablePaths $package $root [void](Invoke-PortablePackageOperation (Get-PortablePackagePlan $package $root)) $receipt = Get-Content $paths.Receipt -Raw | ConvertFrom-Json Remove-Item (Join-Path $paths.Root "$($receipt.directory)/bundle/library.dll") (Get-PortablePackagePlan $package $root).action | Should -Be 'Install' (Invoke-PortablePackageOperation (Get-PortablePackagePlan $package $root)).status | Should -Be 'Succeeded' $receipt = Get-Content $paths.Receipt -Raw | ConvertFrom-Json 'local edit' | Set-Content (Join-Path $paths.Root "$($receipt.directory)/bundle/app.exe") (Get-PortablePackagePlan $package $root).action | Should -Be 'Conflict' (Invoke-PortablePackageOperation (Get-PortablePackagePlan $package $root)).status | Should -Be 'Conflict' } It 'repairs a legacy PowerShell shortcut on the next apply' { [void](Invoke-PortablePackageOperation (Get-PortablePackagePlan $package $root)) Mock Test-PortableShortcut { $false } $plan = Get-PortablePackagePlan $package $root $plan.action | Should -Be 'Install' $plan.reason | Should -Match 'shortcut' } It 'registers declared file handlers and repairs missing registration' { $package | Add-Member displayName 'Test Presenter' $package | Add-Member fileAssociations @('.pdf') $package | Add-Member fileAssociationIcon 'assets/pdf-presenter-pdf.ico' Mock Test-PortableFileAssociations { $false } (Invoke-PortablePackageOperation (Get-PortablePackagePlan $package $root)).status | Should -Be 'Succeeded' Test-Path (Get-PortablePaths $package $root).AssociationIcon | Should -BeTrue Should -Invoke Set-PortableFileAssociations -Times 1 -Exactly -ParameterFilter { $Package.id -eq 'presenter' -and $Executable -like '*bundle*app.exe' } (Get-PortablePackagePlan $package $root).reason | Should -Match 'file associations' Mock Test-PortableFileAssociations { $true } Remove-Item (Get-PortablePaths $package $root).AssociationIcon (Get-PortablePackagePlan $package $root).action | Should -Be 'Install' } It 'migrates the previous managed launcher without treating it as a local edit' { $paths = Get-PortablePaths $package $root [void](Invoke-PortablePackageOperation (Get-PortablePackagePlan $package $root)) [IO.File]::WriteAllText($paths.Launcher, 'previous managed launcher') Mock Test-PortableLegacyLauncher { $true } $plan = Get-PortablePackagePlan $package $root $plan.action | Should -Be 'Install' (Invoke-PortablePackageOperation $plan).status | Should -Be 'Succeeded' [IO.File]::ReadAllText($paths.Launcher) | Should -BeExactly (Get-PortableLauncherContent) } It 'keeps the active receipt on checksum or shortcut failure and recovers on retry' { $paths = Get-PortablePaths $package $root [void](Invoke-PortablePackageOperation (Get-PortablePackagePlan $package $root)) $before = Get-Content $paths.Receipt -Raw $package.version = '2.0' $hash = $package.sha256 $package.sha256 = '0' * 64 $result = Invoke-PortablePackageOperation (Get-PortablePackagePlan $package $root) $result.status | Should -Be 'Failed' $result.message | Should -Match 'SHA-256' Get-Content $paths.Receipt -Raw | Should -Be $before $old = Get-Content $paths.Receipt -Raw | ConvertFrom-Json Test-Path (Join-Path $paths.Root $old.directory) | Should -BeTrue $package.sha256 = $hash Mock Set-PortableShortcut { throw 'Shortcut failure' } (Invoke-PortablePackageOperation (Get-PortablePackagePlan $package $root)).status | Should -Be 'Failed' Get-Content $paths.Receipt -Raw | Should -Be $before Mock Set-PortableShortcut { [void][IO.Directory]::CreateDirectory((Split-Path -Parent $Paths.Shortcut)) [IO.File]::WriteAllText($Paths.Shortcut, 'mock shortcut') } (Invoke-PortablePackageOperation (Get-PortablePackagePlan $package $root)).status | Should -Be 'Succeeded' } It 'retries interrupted old-version cleanup without another download' { $paths = Get-PortablePaths $package $root [void](Invoke-PortablePackageOperation (Get-PortablePackagePlan $package $root)) $old = Join-Path $paths.Root ('versions/0.9-' + ('a' * 32)) [void][IO.Directory]::CreateDirectory($old) [IO.File]::WriteAllText((Join-Path $old 'old.exe'), 'old') (Get-PortablePackagePlan $package $root).action | Should -Be 'Cleanup' (Invoke-PortablePackageOperation (Get-PortablePackagePlan $package $root)).status | Should -Be 'Succeeded' Test-Path $old | Should -BeFalse Should -Invoke Invoke-WebRequest -Times 1 -Exactly } It 'removes a replaced managed package only after activating its successor' { $oldPaths = Get-PortablePaths $package $root (Invoke-PortablePackageOperation (Get-PortablePackagePlan $package $root)).status | Should -Be 'Succeeded' $successor = $package.PSObject.Copy() $successor.id = 'deckstride' $successor | Add-Member replaces @([pscustomobject]@{ source = 'gitea'; id = 'presenter'; fileAssociations = @('.pdf') }) $verifiedHash = $successor.sha256 $successor.sha256 = '0' * 64 (Invoke-PortablePackageOperation (Get-PortablePackagePlan $successor $root)).status | Should -Be 'Failed' Test-Path $oldPaths.Root | Should -BeTrue $successor.sha256 = $verifiedHash $result = Invoke-PortablePackageOperation (Get-PortablePackagePlan $successor $root) $result.status | Should -Be 'Succeeded' $result.message | Should -Match 'removed 1 replaced package' Test-Path $oldPaths.Root | Should -BeFalse Test-Path (Get-PortablePaths $successor $root).Receipt | Should -BeTrue Should -Invoke Remove-PortableFileAssociations -Times 1 -Exactly -ParameterFilter { $Replacement.id -eq 'presenter' } } It 'retries replacement cleanup without downloading the successor again' { $oldPaths = Get-PortablePaths $package $root [void](Invoke-PortablePackageOperation (Get-PortablePackagePlan $package $root)) $successor = $package.PSObject.Copy() $successor.id = 'deckstride' $successor | Add-Member replaces @([pscustomobject]@{ source = 'gitea'; id = 'presenter' }) Mock Assert-PortableManagedReplacement { throw 'old app is locked' } $first = Invoke-PortablePackageOperation (Get-PortablePackagePlan $successor $root) $first.status | Should -Be 'Warning' Test-Path $oldPaths.Root | Should -BeTrue (Get-PortablePackagePlan $successor $root).action | Should -Be 'Cleanup' Mock Assert-PortableManagedReplacement {} (Invoke-PortablePackageOperation (Get-PortablePackagePlan $successor $root)).status | Should -Be 'Succeeded' Test-Path $oldPaths.Root | Should -BeFalse Should -Invoke Invoke-WebRequest -Times 2 -Exactly } It 'preserves a replaced package when its managed files were locally modified' { $oldPaths = Get-PortablePaths $package $root [void](Invoke-PortablePackageOperation (Get-PortablePackagePlan $package $root)) $oldReceipt = Get-Content $oldPaths.Receipt -Raw | ConvertFrom-Json 'local edit' | Set-Content (Join-Path $oldPaths.Root "$($oldReceipt.directory)/$($oldReceipt.executable)") $successor = $package.PSObject.Copy() $successor.id = 'deckstride' $successor | Add-Member replaces @([pscustomobject]@{ source = 'gitea'; id = 'presenter' }) $result = Invoke-PortablePackageOperation (Get-PortablePackagePlan $successor $root) $result.status | Should -Be 'Warning' $result.message | Should -Match 'locally modified' Test-Path $oldPaths.Root | Should -BeTrue Test-Path (Get-PortablePaths $successor $root).Receipt | Should -BeTrue } It 'recovers a first install interrupted after launcher creation' { Mock Set-PortableShortcut { throw 'Shortcut failure' } (Invoke-PortablePackageOperation (Get-PortablePackagePlan $package $root)).status | Should -Be 'Failed' Mock Set-PortableShortcut { [void][IO.Directory]::CreateDirectory((Split-Path -Parent $Paths.Shortcut)) [IO.File]::WriteAllText($Paths.Shortcut, 'mock shortcut') } (Invoke-PortablePackageOperation (Get-PortablePackagePlan $package $root)).status | Should -Be 'Succeeded' } It 'blocks a running application before downloading' { Mock Assert-PortableStopped { throw 'Close presenter before updating' } $result = Invoke-PortablePackageOperation (Get-PortablePackagePlan $package $root) $result.status | Should -Be 'Failed' $result.message | Should -Match 'Close presenter' Should -Invoke Invoke-WebRequest -Times 0 } It 'honors install-only and newer-version policies and rejects a republished hash' { [void](Invoke-PortablePackageOperation (Get-PortablePackagePlan $package $root)) $package.update = 'install-only'; $package.version = '2.0' (Get-PortablePackagePlan $package $root).action | Should -Be 'None' $package.update = 'pinned'; $package.version = '1.0' (Get-PortablePackagePlan $package $root).action | Should -Be 'Warning' $package.version = '1.2.3'; $package.sha256 = '0' * 64 (Get-PortablePackagePlan $package $root).action | Should -Be 'Conflict' } It 'rejects a missing executable and returns a structured failure without activating it' { $package.executable = 'absent.exe' $result = Invoke-PortablePackageOperation (Get-PortablePackagePlan $package $root) $result.status | Should -Be 'Failed' $result.message | Should -Match 'does not contain' Test-Path (Get-PortablePaths $package $root).Receipt | Should -BeFalse { $result | ConvertTo-Json | ConvertFrom-Json } | Should -Not -Throw } It 'rejects unsafe archive entries before extraction' -ForEach @( @{ Name = '../escape.exe'; Attributes = 0 } @{ Name = 'C:/escape.exe'; Attributes = 0 } @{ Name = 'safe/../../escape.exe'; Attributes = 0 } @{ Name = 'app.exe:stream'; Attributes = 0 } @{ Name = 'con/file.exe'; Attributes = 0 } @{ Name = 'link'; Attributes = -1577123840 } ) { $bad = "$bundle-bad.zip" $zip = [IO.Compression.ZipFile]::Open($bad, 'Create') $entry = $zip.CreateEntry($Name) $entry.ExternalAttributes = $Attributes $zip.Dispose() { Expand-PortableArchive $bad "$bundle-expanded" } | Should -Throw Test-Path "$bundle-expanded" | Should -BeFalse } It 'rejects archive paths that collide on Windows' { $bad = "$bundle-bad.zip" $zip = [IO.Compression.ZipFile]::Open($bad, 'Create') [void]$zip.CreateEntry('App.exe') [void]$zip.CreateEntry('app.exe') $zip.Dispose() { Expand-PortableArchive $bad "$bundle-expanded" } | Should -Throw '*colliding*' } It 'rejects linked installation directories' -Skip:$IsWindows { [void][IO.Directory]::CreateDirectory("$root/apps") [void](New-Item -ItemType SymbolicLink -Path "$root/apps/gitea" -Target $bundle) { Get-PortablePackagePlan $package $root } | Should -Throw '*link*' } } } Describe 'Standalone portable shortcut' { InModuleScope PortablePackages { It 'targets the GUI executable directly and uses its embedded icon' { $root = Join-Path $TestDrive 'standalone shortcut' [void][IO.Directory]::CreateDirectory("$root/app") $executable = Join-Path $root 'app/presenter.exe' [IO.File]::WriteAllText($executable, 'gui') $paths = [pscustomobject]@{ Root = $root; Shortcut = Join-Path $root 'menu/presenter.lnk' } $script:shortcutObject = [pscustomobject]@{ TargetPath = ''; Arguments = 'old'; WorkingDirectory = ''; IconLocation = ''; Description = ''; TemporaryPath = '' } $script:shortcutObject | Add-Member -MemberType ScriptMethod -Name Save -Value { [IO.File]::WriteAllText($this.TemporaryPath, 'shortcut') } $script:shell = [pscustomobject]@{} $script:shell | Add-Member -MemberType ScriptMethod -Name CreateShortcut -Value { param($path) $script:shortcutObject.TemporaryPath = $path return $script:shortcutObject } Mock New-PortableShortcutShell { $script:shell } Set-PortableShortcut -Paths $paths -Executable $executable $script:shortcutObject.TargetPath | Should -Be $executable $script:shortcutObject.Arguments | Should -BeNullOrEmpty $script:shortcutObject.WorkingDirectory | Should -Be (Split-Path -Parent $executable) $script:shortcutObject.IconLocation | Should -Be "$executable,0" $script:shortcutObject.Description | Should -Be 'Managed by Config Central' Test-Path $paths.Shortcut | Should -BeTrue } It 'recognizes only argument-free shortcuts to the active executable' { $executable = Join-Path $TestDrive 'active/app.exe' [void][IO.Directory]::CreateDirectory((Split-Path -Parent $executable)) [IO.File]::WriteAllText($executable, 'gui') $shortcut = Join-Path $TestDrive 'app.lnk' [IO.File]::WriteAllText($shortcut, 'shortcut') Mock Get-PortableShortcutDetails { [pscustomobject]@{ TargetPath = $executable; Arguments = ''; WorkingDirectory = ''; IconLocation = '' } } Test-PortableShortcut -Path $shortcut -Executable $executable | Should -BeTrue Mock Get-PortableShortcutDetails { [pscustomobject]@{ TargetPath = (Join-Path $PSHOME 'pwsh.exe'); Arguments = '-File launch.ps1'; WorkingDirectory = ''; IconLocation = '' } } Test-PortableShortcut -Path $shortcut -Executable $executable | Should -BeFalse } } } Describe 'Portable file association registration' { InModuleScope PortablePackages { It 'builds a stable per-user PDF handler around the active executable' { $package = [pscustomobject]@{ id = 'pdf-presenter'; source = 'idle-org'; displayName = 'PDF Presenter'; fileAssociations = @('.pdf') } $spec = Get-PortableAssociationSpec -Package $package -Executable "$TestDrive/app/pdf-presenter.exe" $spec.registeredName | Should -Be 'ConfigCentral.idle-org.pdf-presenter' $spec.progId | Should -Be 'ConfigCentral.idle-org.pdf-presenter.pdf' $spec.capabilitiesPath | Should -Be 'Software\ConfigCentral\Applications\idle-org\pdf-presenter\Capabilities' $spec.extension | Should -Be '.pdf' $spec.icon | Should -Be $spec.executable } It 'uses a dedicated document icon when one is supplied' { $package = [pscustomobject]@{ id = 'pdf-presenter'; source = 'idle-org'; displayName = 'PDF Presenter'; fileAssociations = @('.pdf') } $executable = [IO.Path]::GetFullPath("$TestDrive/app/pdf-presenter.exe") $icon = [IO.Path]::GetFullPath("$TestDrive/app/file-association.ico") (Get-PortableAssociationSpec -Package $package -Executable $executable -Icon $icon).icon | Should -Be $icon } It 'writes a quoted PDF open command and per-user Default Apps registration' { $package = [pscustomobject]@{ id = 'pdf-presenter'; source = 'idle-org'; displayName = 'PDF Presenter'; fileAssociations = @('.pdf') } $executable = [IO.Path]::GetFullPath("$TestDrive/path with spaces/pdf-presenter.exe") $icon = [IO.Path]::GetFullPath("$TestDrive/path with spaces/file-association.ico") Mock Set-PortableRegistryValue {} Set-PortableFileAssociations -Package $package -Executable $executable -Icon $icon Should -Invoke Set-PortableRegistryValue -Times 8 -Exactly Should -Invoke Set-PortableRegistryValue -Times 1 -Exactly -ParameterFilter { $Path -eq 'Software\RegisteredApplications' -and $Name -eq 'ConfigCentral.idle-org.pdf-presenter' } Should -Invoke Set-PortableRegistryValue -Times 1 -Exactly -ParameterFilter { $Path -like '*\shell\open\command' -and $Name -eq '' -and $Value -eq ('"' + $executable + '" "%1"') } Should -Invoke Set-PortableRegistryValue -Times 1 -Exactly -ParameterFilter { $Path -like '*\DefaultIcon' -and $Name -eq '' -and $Value -eq ($icon + ',0') } } It 'removes a predecessor application own PDF registration' { $replacement = [pscustomobject]@{ source = 'idle-org'; id = 'pdf-presenter'; fileAssociations = @('.pdf') legacyRegistration = [pscustomobject]@{ registeredApplication = 'PDF Presenter'; progIds = @('PDFPresenter.Document') } } Mock Remove-PortableRegistryValue {} Mock Remove-PortableRegistryTree {} Remove-PortableLegacyRegistration -Replacement $replacement Should -Invoke Remove-PortableRegistryValue -Times 1 -Exactly -ParameterFilter { $Path -eq 'Software\RegisteredApplications' -and $Name -eq 'PDF Presenter' } Should -Invoke Remove-PortableRegistryValue -Times 1 -Exactly -ParameterFilter { $Path -eq 'Software\Classes\.pdf\OpenWithProgids' -and $Name -eq 'PDFPresenter.Document' } Should -Invoke Remove-PortableRegistryTree -Times 1 -Exactly -ParameterFilter { $Path -eq 'Software\Classes\PDFPresenter.Document' } Should -Invoke Remove-PortableRegistryTree -Times 1 -Exactly -ParameterFilter { $Path -eq 'Software\PDF Presenter\Capabilities' } } It 'detects a predecessor registration after managed files are gone' { $replacement = [pscustomobject]@{ source = 'idle-org'; id = 'pdf-presenter'; fileAssociations = @('.pdf') legacyRegistration = [pscustomobject]@{ registeredApplication = 'PDF Presenter'; progIds = @('PDFPresenter.Document') } } Mock Get-PortableRegistryValue { if ($Path -eq 'Software\Classes\.pdf\OpenWithProgids' -and $Name -eq 'PDFPresenter.Document') { return '' } return $null } Mock Test-PortableRegistryTree { $false } Test-PortableLegacyRegistrationPresent -Replacement $replacement | Should -BeTrue } } } Describe 'Portable launcher presentation' { It 'reports missing receipts concisely with a failing process exit code' { $launcher = Join-Path $TestDrive 'launch.ps1' Copy-Item "$PSScriptRoot/../src/portable-launcher.ps1" $launcher $output = & (Join-Path $PSHOME $(if ($IsWindows) { 'pwsh.exe' } else { 'pwsh' })) -NoProfile -File $launcher 2>&1 $LASTEXITCODE | Should -Be 1 ($output | Out-String) | Should -Match 'Cannot launch portable application:.*Run cc apply' ($output | Out-String) | Should -Not -Match 'CategoryInfo|FullyQualifiedErrorId|\x1b' } } Describe 'Portable launcher process status' { It 'preserves the application exit code and literal arguments' -Skip:$IsWindows { $root = Join-Path $TestDrive 'launcher status' [void][IO.Directory]::CreateDirectory("$root/versions/1.0") Copy-Item "$PSScriptRoot/../src/portable-launcher.ps1" "$root/launch.ps1" [IO.File]::WriteAllText("$root/versions/1.0/app.exe", "#!/bin/sh`nprintf '%s' `"`$1`"`nexit 7`n") & chmod +x "$root/versions/1.0/app.exe" @{ directory = 'versions/1.0'; executable = 'app.exe' } | ConvertTo-Json | Set-Content "$root/current.json" $output = & (Join-Path $PSHOME 'pwsh') -NoProfile -File "$root/launch.ps1" 'document with spaces.pdf' $LASTEXITCODE | Should -Be 7 $output | Should -Be 'document with spaces.pdf' } } Describe 'Portable release discovery' { InModuleScope PortablePackages { BeforeEach { $package = [pscustomobject]@{ id = 'presenter'; provider = 'portable'; source = 'gitea'; version = '1.2.3'; update = 'pinned' url = 'https://example.org/download/v1.2.3/presenter-1.2.3.zip'; sha256 = ('a' * 64); executable = 'presenter-1.2.3/app.exe' releaseApi = 'https://example.org/api/v1/repos/owner/project/releases'; releaseChannel = 'prerelease' assetTemplate = 'presenter-{version}.zip'; executableTemplate = 'presenter-{version}/app.exe'; checksumAsset = 'SHA256SUMS' } $script:releases = @( [pscustomobject]@{ tag_name = 'v2.0.0'; draft = $false; prerelease = $true; assets = @( [pscustomobject]@{ name = 'presenter-2.0.0.zip'; browser_download_url = 'https://example.org/download/v2.0.0/presenter-2.0.0.zip' }, [pscustomobject]@{ name = 'SHA256SUMS'; browser_download_url = 'https://example.org/download/v2.0.0/SHA256SUMS' } ) }, [pscustomobject]@{ tag_name = 'v1.5.0'; draft = $false; prerelease = $false; assets = @( [pscustomobject]@{ name = 'presenter-1.5.0.zip'; browser_download_url = 'https://example.org/download/v1.5.0/presenter-1.5.0.zip' }, [pscustomobject]@{ name = 'SHA256SUMS'; browser_download_url = 'https://example.org/download/v1.5.0/SHA256SUMS' } ) } ) Mock Invoke-PortableReleaseRequest { if ($Kind -eq 'Json') { return $script:releases } return ('b' * 64) + ' presenter-2.0.0.zip' } } It 'selects the newest eligible release and resolves exact install fields' { $resolved = Resolve-PortablePackageRelease $package $resolved.version | Should -Be '2.0.0' $resolved.url | Should -Be 'https://example.org/download/v2.0.0/presenter-2.0.0.zip' $resolved.sha256 | Should -Be ('b' * 64) $resolved.executable | Should -Be 'presenter-2.0.0/app.exe' $package.version | Should -Be '1.2.3' Should -Invoke Invoke-PortableReleaseRequest -Times 2 -Exactly } It 'ignores prereleases on the stable channel' { $package.releaseChannel = 'stable' Mock Invoke-PortableReleaseRequest { if ($Kind -eq 'Json') { return $script:releases } return ('c' * 64) + ' presenter-1.5.0.zip' } (Resolve-PortablePackageRelease $package).version | Should -Be '1.5.0' } It 'rejects cross-host assets and ambiguous checksums' { $script:releases[0].assets[0].browser_download_url = 'https://attacker.invalid/presenter-2.0.0.zip' { Resolve-PortablePackageRelease $package } | Should -Throw '*release API host*' $script:releases[0].assets[0].browser_download_url = 'https://example.org/download/v2.0.0/presenter-2.0.0.zip' Mock Invoke-PortableReleaseRequest { if ($Kind -eq 'Json') { return $script:releases } return (('b' * 64) + " presenter-2.0.0.zip`n" + ('c' * 64) + ' presenter-2.0.0.zip') } { Resolve-PortablePackageRelease $package } | Should -Throw '*exactly one SHA-256*' } It 'rejects a changed checksum for the pinned release' { $script:releases = @([pscustomobject]@{ tag_name = 'v1.2.3'; draft = $false; prerelease = $true; assets = @( [pscustomobject]@{ name = 'presenter-1.2.3.zip'; browser_download_url = 'https://example.org/download/v1.2.3/presenter-1.2.3.zip' }, [pscustomobject]@{ name = 'SHA256SUMS'; browser_download_url = 'https://example.org/download/v1.2.3/SHA256SUMS' } ) }) Mock Invoke-PortableReleaseRequest { if ($Kind -eq 'Json') { return $script:releases } return ('b' * 64) + ' presenter-1.2.3.zip' } { Resolve-PortablePackageRelease $package } | Should -Throw '*differs from the manifest*' } It 'rejects duplicate release versions and missing exact assets' { $script:releases += $script:releases[0].PSObject.Copy() { Resolve-PortablePackageRelease $package } | Should -Throw '*duplicate version*' $script:releases = @($script:releases[0]) $script:releases[0].assets[0].name = 'wrong.zip' { Resolve-PortablePackageRelease $package } | Should -Throw '*exactly one*' } } }