Prepare portable rename migrations
Config Central CI Config Central passed all CI integrity checks.
Beffroi/config-central/pipeline/head This commit looks good Details

This commit is contained in:
Dandaedre 2026-11-21 11:51:25 +01:00
parent 7f0240b916
commit 9343602764
10 changed files with 285 additions and 7 deletions

View File

@ -97,6 +97,13 @@ Default Apps page, right-click a PDF, choose **Open with → Choose another app*
select **PDF Presenter**, and enable **Always**. Windows requires this one-time
user confirmation and Config Central preserves that choice across updates.
PDF Presenter is being renamed to
[Deckstride](https://proxy.dandaedre.com/gitea/idle-org/Deckstride). The existing
PDF Presenter release remains pinned until the first Deckstride Windows release
is available and verified. The prepared migration will install Deckstride first,
then remove the managed PDF Presenter files, Start menu shortcut and old handler
registration. Windows will require one new Default Apps selection for Deckstride.
Like `cc sync`, `update-software` refuses to fetch while the checkout contains
uncommitted or untracked files. It does not reset or overwrite those edits.
For the release declaration and manual pin-review workflow, see

View File

@ -164,6 +164,8 @@ open until it is run on disposable machines with the required account setups.
- [x] Register PDF Presenter as a per-user `.pdf` handler and document the one-time supported Windows Default Apps selection (167 Linux Pester tests pass; Windows acceptance remains open above).
- [x] Remove superseded portable versions after successful activation while retaining the working version on failed updates and retrying interrupted cleanup (168 Linux Pester tests pass; 5 Windows-only skips).
- [x] Give PDF Presenter associations a dedicated branded PDF document icon that remains stable across portable updates (169 Linux Pester tests pass; 5 Windows-only skips).
- [x] Support explicit portable rename migrations that activate the successor before removing the verified old installation and handler registration, preserve local edits, and retry cleanup (189 Linux Pester tests pass; 5 Windows-only skips).
- [ ] Replace the PDF Presenter declaration with the verified Deckstride release from `idle-org/Deckstride`, then select Deckstride once as the Windows `.pdf` default.
## PowerShell prerequisite reliability

View File

@ -397,6 +397,17 @@ Start-Process 'ms-settings:defaultapps?registeredAppUser=ConfigCentral.idle-org.
Updates repair the registration to point at the new verified executable without
rewriting the user's default-app preference.
PDF Presenter is being renamed to Deckstride and moved to
`idle-org/Deckstride`. The current 0.1.91 pin remains active until a Deckstride
release with verified Windows assets is available. That release declaration will
use Deckstride's new portable identity and a `replaces` entry for
`idle-org/pdf-presenter`. On the first successful update, Config Central will
activate Deckstride before removing PDF Presenter's managed files, shortcut and
old `.pdf` registration. If the old installation was locally modified or cannot
be removed, Deckstride stays installed and cleanup is retried later. Select
Deckstride once in Windows Default Apps afterward because Windows does not allow
software to transfer the protected `.pdf` default choice to a renamed handler.
On a failed download, checksum check or setup step, fix the reported cause and
retry. Missing managed files are repaired. Locally changed binaries or launchers
are conflicts: inspect and save those changes elsewhere, then remove the affected

View File

@ -114,6 +114,16 @@ An optional repository-relative `fileAssociationIcon` below `assets/` supplies
a stable `.ico` for associated documents. Config Central copies and verifies it
in the package root instead of pointing Explorer at a versioned executable icon.
A renamed portable package may declare `replaces` with the old lowercase
`source` and `id`, plus any old `fileAssociations` that must be unregistered.
This is an explicit removal request. Config Central activates and verifies the
new package first, then removes the old managed root, Start menu shortcut,
Default Apps registration and listed ProgIDs. Missing or locally modified files
in the old active installation stop removal with a warning. Cleanup is retried
on the next package run without downloading the new version again. Windows owns
the protected default-app choice, so a renamed handler must be selected once
under its new name.
Apply downloads and verifies the pinned archive, rejects unsafe ZIP paths and
links, stages a new directory, and only then switches the receipt. After
activation, older managed version directories are removed. Download,

View File

@ -134,6 +134,35 @@
"fileAssociationIcon": {
"type": "string",
"pattern": "^assets/[A-Za-z0-9_-][A-Za-z0-9._/-]*\\.ico$"
},
"replaces": {
"type": "array",
"minItems": 1,
"uniqueItems": true,
"items": {
"type": "object",
"additionalProperties": false,
"required": ["source", "id"],
"properties": {
"source": {
"type": "string",
"pattern": "^[a-z0-9][a-z0-9-]{0,63}$"
},
"id": {
"type": "string",
"pattern": "^[a-z0-9][a-z0-9-]{0,63}$"
},
"fileAssociations": {
"type": "array",
"minItems": 1,
"uniqueItems": true,
"items": {
"type": "string",
"pattern": "^\\.[a-z0-9]{1,16}$"
}
}
}
}
}
},
"allOf": [
@ -257,6 +286,11 @@
"fileAssociationIcon"
]
},
{
"required": [
"replaces"
]
},
{
"required": [
"executable"

View File

@ -79,6 +79,28 @@ function Assert-PortableDeclaration {
@($associationIcon -split '/' | Where-Object { $_ -in @('', '.', '..') }).Count) { throw 'Unsafe portable fileAssociationIcon path.' }
}
$replacementProperty = $Item.PSObject.Properties['replaces']
if ($null -ne $replacementProperty) {
if ($replacementProperty.Value -isnot [Array] -or $replacementProperty.Value.Count -eq 0) { throw 'Portable replaces must be a non-empty array.' }
$seenReplacements = [Collections.Generic.HashSet[string]]::new([StringComparer]::OrdinalIgnoreCase)
foreach ($replacement in @($replacementProperty.Value)) {
Assert-AllowedProperties $replacement @('source', 'id', 'fileAssociations') 'portable replacement'
$replacementSource = [string](Get-OptionalProperty $replacement 'source')
$replacementId = [string](Get-OptionalProperty $replacement 'id')
if ($replacementSource -cnotmatch '^[a-z0-9][a-z0-9-]{0,63}$' -or $replacementId -cnotmatch '^[a-z0-9][a-z0-9-]{0,63}$') { throw 'Portable replacement source and id must be lowercase slugs.' }
if ($replacementSource -match '^(con|prn|aux|nul|com[1-9]|lpt[1-9])$' -or $replacementId -match '^(con|prn|aux|nul|com[1-9]|lpt[1-9])$') { throw 'Portable replacement identity cannot use reserved Windows device names.' }
$key = "$replacementSource/$replacementId"
if ($key -eq "$Source/$($Item.id)" -or -not $seenReplacements.Add($key)) { throw "Invalid or duplicate portable replacement '$key'." }
$replacementAssociationProperty = $replacement.PSObject.Properties['fileAssociations']
if ($null -ne $replacementAssociationProperty -and $replacementAssociationProperty.Value -isnot [Array]) { throw 'Portable replacement fileAssociations must be an array.' }
$replacementAssociations = @(if ($null -ne $replacementAssociationProperty) { $replacementAssociationProperty.Value })
$seenExtensions = [Collections.Generic.HashSet[string]]::new([StringComparer]::OrdinalIgnoreCase)
foreach ($extension in @($replacementAssociations)) {
if ($extension -cnotmatch '^\.[a-z0-9]{1,16}$' -or -not $seenExtensions.Add($extension)) { throw "Invalid or duplicate portable replacement file association '$extension'." }
}
}
}
$releaseFields = @('releaseApi', 'releaseChannel', 'assetTemplate', 'executableTemplate')
$hasReleaseField = [bool]($releaseFields | Where-Object { $null -ne $Item.PSObject.Properties[$_] })
if ($hasReleaseField) {
@ -116,7 +138,7 @@ function Assert-ItemList {
if ($Kind -eq 'package') {
Assert-AllowedProperties $item @(
'id', 'source', 'scope', 'version', 'update', 'enabled', 'provider', 'url', 'sha256', 'executable',
'releaseApi', 'releaseChannel', 'assetTemplate', 'executableTemplate', 'checksumAsset', 'displayName', 'fileAssociations', 'fileAssociationIcon'
'releaseApi', 'releaseChannel', 'assetTemplate', 'executableTemplate', 'checksumAsset', 'displayName', 'fileAssociations', 'fileAssociationIcon', 'replaces'
) "$Location[$index]"
if ([string]::IsNullOrWhiteSpace([string](Get-OptionalProperty $item 'id'))) { throw "$Location[$index].id is required." }
$source = [string](Get-OptionalProperty $item 'source' 'winget')
@ -127,7 +149,7 @@ function Assert-ItemList {
$key = "portable/$key"
Assert-PortableDeclaration $item $source
}
elseif (@('url', 'sha256', 'executable', 'releaseApi', 'releaseChannel', 'assetTemplate', 'executableTemplate', 'checksumAsset', 'displayName', 'fileAssociations', 'fileAssociationIcon') | Where-Object { $null -ne $item.PSObject.Properties[$_] }) { throw 'Portable fields cannot be used by WinGet packages.' }
elseif (@('url', 'sha256', 'executable', 'releaseApi', 'releaseChannel', 'assetTemplate', 'executableTemplate', 'checksumAsset', 'displayName', 'fileAssociations', 'fileAssociationIcon', 'replaces') | Where-Object { $null -ne $item.PSObject.Properties[$_] }) { throw 'Portable fields cannot be used by WinGet packages.' }
$scope = Get-OptionalProperty $item 'scope'
if ($null -ne $scope -and $scope -notin @('user', 'machine')) { throw "Invalid package scope at $Location[$index]." }
$update = [string](Get-OptionalProperty $item 'update' 'latest')
@ -198,11 +220,11 @@ function Add-ManifestItems {
$normalized = [ordered]@{ id = [string]$item.id; source = $source; update = [string](Get-OptionalProperty $item 'update' 'latest') }
foreach ($field in @(
'scope', 'version', 'provider', 'url', 'sha256', 'executable',
'releaseApi', 'releaseChannel', 'assetTemplate', 'executableTemplate', 'checksumAsset', 'displayName', 'fileAssociations', 'fileAssociationIcon'
'releaseApi', 'releaseChannel', 'assetTemplate', 'executableTemplate', 'checksumAsset', 'displayName', 'fileAssociations', 'fileAssociationIcon', 'replaces'
)) {
$value = Get-OptionalProperty $item $field
if ($null -ne $value) {
if ($field -eq 'fileAssociations') { $normalized[$field] = [object[]]@($value) }
if ($field -in @('fileAssociations', 'replaces')) { $normalized[$field] = [object[]]@($value) }
else { $normalized[$field] = [string]$value }
}
}

View File

@ -101,6 +101,19 @@ function Set-PortableRegistryValue {
finally { $key.Dispose() }
}
function Remove-PortableRegistryValue {
param([Parameter(Mandatory)][string]$Path, [Parameter(Mandatory)][AllowEmptyString()][string]$Name)
$key = [Microsoft.Win32.Registry]::CurrentUser.OpenSubKey($Path, $true)
if ($null -eq $key) { return }
try { $key.DeleteValue($Name, $false) }
finally { $key.Dispose() }
}
function Remove-PortableRegistryTree {
param([Parameter(Mandatory)][string]$Path)
[Microsoft.Win32.Registry]::CurrentUser.DeleteSubKeyTree($Path, $false)
}
function Test-PortableFileAssociations {
param($Package, [Parameter(Mandatory)][string]$Executable, [string]$Icon)
$specs = @(Get-PortableAssociationSpec -Package $Package -Executable $Executable -Icon $Icon)
@ -133,6 +146,77 @@ function Set-PortableFileAssociations {
}
}
function Remove-PortableFileAssociations {
param($Replacement)
if (-not $IsWindows) { return }
$registeredName = "ConfigCentral.$($Replacement.source).$($Replacement.id)"
$capabilitiesPath = "Software\ConfigCentral\Applications\$($Replacement.source)\$($Replacement.id)\Capabilities"
Remove-PortableRegistryValue -Path 'Software\RegisteredApplications' -Name $registeredName
$extensions = if ($Replacement.PSObject.Properties['fileAssociations']) { @($Replacement.fileAssociations) } else { @() }
foreach ($extension in $extensions) {
$progId = "$registeredName.$($extension.TrimStart('.').ToLowerInvariant())"
Remove-PortableRegistryValue -Path "Software\Classes\$($extension.ToLowerInvariant())\OpenWithProgids" -Name $progId
Remove-PortableRegistryTree -Path "Software\Classes\$progId"
}
Remove-PortableRegistryTree -Path $capabilitiesPath
}
function Test-PortableReplacementPresent {
param($Replacement, [string]$DataRoot)
$paths = Get-PortablePaths -Package $Replacement -DataRoot $DataRoot
if ((Test-Path -LiteralPath $paths.Root) -or ($paths.Shortcut -and (Test-Path -LiteralPath $paths.Shortcut))) { return $true }
if (-not $IsWindows) { return $false }
$registeredName = "ConfigCentral.$($Replacement.source).$($Replacement.id)"
return $null -ne (Get-PortableRegistryValue -Path 'Software\RegisteredApplications' -Name $registeredName)
}
function Assert-PortableManagedReplacement {
param($Paths)
if (-not (Test-Path -LiteralPath $Paths.Root -PathType Container)) { return }
Assert-PortableNoLinks $Paths.Root
if (-not (Test-Path -LiteralPath $Paths.Receipt -PathType Leaf)) { throw "Replacement root '$($Paths.Root)' has no managed receipt; inspect it before removal." }
$receipt = Get-Content -LiteralPath $Paths.Receipt -Raw | ConvertFrom-Json -AsHashtable
if ($receipt.schemaVersion -ne 1 -or $receipt.directory -notmatch '^versions/[0-9.]+-[a-f0-9]{32}$' -or
-not $receipt.executable -or $receipt.files.Count -eq 0) { throw "Replacement root '$($Paths.Root)' has an invalid managed receipt." }
Assert-PortableRelativePath $receipt.executable
if (-not $receipt.files.ContainsKey($receipt.executable)) { throw "Replacement root '$($Paths.Root)' has an invalid managed receipt." }
foreach ($relative in $receipt.files.Keys) {
Assert-PortableRelativePath $relative
$path = Join-Path $Paths.Root "$($receipt.directory)/$relative"
Assert-PortableNoLinks $path
if (-not (Test-Path -LiteralPath $path -PathType Leaf) -or (Get-FileHash -LiteralPath $path -Algorithm SHA256).Hash -ne $receipt.files[$relative]) {
throw "Replacement file '$path' is missing or locally modified; inspect it before removal."
}
}
if (-not (Test-Path -LiteralPath $Paths.Launcher -PathType Leaf)) { throw "Replacement launcher '$($Paths.Launcher)' is missing; inspect the installation before removal." }
$launcherMatches = [IO.File]::ReadAllText($Paths.Launcher) -ceq (Get-PortableLauncherContent)
if (-not $launcherMatches -and -not (Test-PortableLegacyLauncher -Path $Paths.Launcher)) { throw "Replacement launcher '$($Paths.Launcher)' is locally modified; inspect it before removal." }
}
function Remove-PortableReplacement {
param($Replacement, [string]$DataRoot)
$paths = Get-PortablePaths -Package $Replacement -DataRoot $DataRoot
Assert-PortableManagedReplacement -Paths $paths
if (Test-Path -LiteralPath $paths.Root -PathType Container) {
Assert-PortableStopped $paths.Root
Remove-Item -LiteralPath $paths.Root -Recurse -Force -ErrorAction Stop
}
if ($paths.Shortcut -and (Test-Path -LiteralPath $paths.Shortcut)) { Remove-Item -LiteralPath $paths.Shortcut -Force -ErrorAction Stop }
Remove-PortableFileAssociations -Replacement $Replacement
}
function Remove-PortableReplacements {
param($Package, [string]$DataRoot)
if (-not $Package.PSObject.Properties['replaces']) { return 0 }
$removed = 0
foreach ($replacement in @($Package.replaces)) {
if (-not (Test-PortableReplacementPresent -Replacement $replacement -DataRoot $DataRoot)) { continue }
Remove-PortableReplacement -Replacement $replacement -DataRoot $DataRoot
$removed++
}
return $removed
}
function Get-PortablePreviousVersionPaths {
param($Paths, [Parameter(Mandatory)][string]$CurrentDirectory)
$versionsRoot = Join-Path $Paths.Root 'versions'
@ -284,6 +368,10 @@ function Get-PortablePackagePlan {
if ($action -eq 'None' -and $previousVersions.Count) {
$action = 'Cleanup'; $reason = 'Remove previous portable versions'
}
if ($action -eq 'None' -and $Package.PSObject.Properties['replaces'] -and
@($Package.replaces | Where-Object { Test-PortableReplacementPresent -Replacement $_ -DataRoot $DataRoot }).Count) {
$action = 'Cleanup'; $reason = 'Remove replaced portable package(s) after successful activation'
}
}
elseif (Test-Path -LiteralPath $paths.Launcher) {
Assert-PortableNoLinks $paths.Launcher
@ -394,10 +482,11 @@ function Invoke-PortablePackageOperation {
$receipt = Get-Content -LiteralPath $paths.Receipt -Raw | ConvertFrom-Json -AsHashtable
try {
$removed = Remove-PortablePreviousVersions -Paths $paths -CurrentDirectory $receipt.directory
return [pscustomobject]@{ name = $plan.name; status = 'Succeeded'; rebootRequired = $false; exitCode = 0; message = "Removed $removed previous portable version(s)" }
$replacements = Remove-PortableReplacements -Package $plan.package -DataRoot $Operation.dataRoot
return [pscustomobject]@{ name = $plan.name; status = 'Succeeded'; rebootRequired = $false; exitCode = 0; message = "Removed $removed previous version(s) and $replacements replaced package(s)" }
}
catch {
return [pscustomobject]@{ name = $plan.name; status = 'Warning'; rebootRequired = $false; exitCode = 0; message = "Could not remove previous portable versions: $($_.Exception.Message). Rerun cc update-software to retry." }
return [pscustomobject]@{ name = $plan.name; status = 'Warning'; rebootRequired = $false; exitCode = 0; message = "Could not complete portable cleanup: $($_.Exception.Message). Rerun cc update-software to retry." }
}
}
if ($plan.action -in @('None', 'Warning')) {
@ -448,9 +537,14 @@ function Invoke-PortablePackageOperation {
catch {
return [pscustomobject]@{ name = $plan.name; status = 'Warning'; rebootRequired = $false; exitCode = 0; message = "Installed portable version $($package.version), but could not remove previous versions: $($_.Exception.Message). Rerun cc update-software to retry." }
}
try { $replacements = Remove-PortableReplacements -Package $package -DataRoot $Operation.dataRoot }
catch {
return [pscustomobject]@{ name = $plan.name; status = 'Warning'; rebootRequired = $false; exitCode = 0; message = "Installed portable version $($package.version), but could not remove replaced package(s): $($_.Exception.Message). Rerun cc apply to retry." }
}
$associationMessage = if ($package.PSObject.Properties['fileAssociations']) { "; registered for $(@($package.fileAssociations) -join ', ') (choose it once in Windows Default Apps)" } else { '' }
$cleanupMessage = if ($removed) { "; removed $removed previous version(s)" } else { '' }
[pscustomobject]@{ name = $plan.name; status = 'Succeeded'; rebootRequired = $false; exitCode = 0; message = "Installed portable version $($package.version)$cleanupMessage$associationMessage" }
$replacementMessage = if ($replacements) { "; removed $replacements replaced package(s)" } else { '' }
[pscustomobject]@{ name = $plan.name; status = 'Succeeded'; rebootRequired = $false; exitCode = 0; message = "Installed portable version $($package.version)$cleanupMessage$replacementMessage$associationMessage" }
}
catch {
[pscustomobject]@{ name = $Operation.name; status = 'Failed'; rebootRequired = $false; exitCode = 1; message = $_.Exception.Message }

View File

@ -56,6 +56,36 @@ Describe 'Portable declarations' {
$items['portable/gitea/presenter'].assetTemplate | Should -Be 'presenter-v{version}.zip'
}
It 'accepts and preserves an explicit portable replacement declaration' {
$item | Add-Member -NotePropertyName replaces -NotePropertyValue ([object[]]@(
[pscustomobject]@{ source = 'idle-org'; id = 'pdf-presenter'; fileAssociations = [object[]]@('.pdf') }
))
Assert-ItemList @($item) package test
$items = [ordered]@{}
Add-ManifestItems $items @($item) package
$replacement = $items['portable/gitea/presenter'].replaces[0]
$replacement.source | Should -Be 'idle-org'
$replacement.id | Should -Be 'pdf-presenter'
$replacement.fileAssociations | Should -Be @('.pdf')
}
It 'rejects unsafe, duplicate, or self-referential portable replacements' -ForEach @(
@{ Replacements = @([pscustomobject]@{ source = 'Gitea'; id = 'old' }) }
@{ Replacements = @([pscustomobject]@{ source = 'con'; id = 'old' }) }
@{ Replacements = @([pscustomobject]@{ source = 'gitea'; id = 'presenter' }) }
@{ Replacements = @([pscustomobject]@{ source = 'old'; id = 'app' }, [pscustomobject]@{ source = 'OLD'; id = 'app' }) }
@{ Replacements = @([pscustomobject]@{ source = 'old'; id = 'app'; fileAssociations = @('pdf') }) }
@{ Replacements = @([pscustomobject]@{ source = 'old'; id = 'app'; unknown = 'value' }) }
) {
$item | Add-Member replaces $Replacements
{ Assert-ItemList @($item) package test } | Should -Throw
}
It 'rejects a scalar portable replacement list' {
$item | Add-Member replaces ([pscustomobject]@{ source = 'old'; id = 'app' })
{ Assert-ItemList @($item) package test } | Should -Throw '*non-empty array*'
}
It 'rejects incomplete or unsafe release discovery declarations' -ForEach @(
@{ Field = 'releaseApi'; Value = 'http://example.org/api/v1/repos/a/b/releases' }
@{ Field = 'releaseApi'; Value = 'https://example.org/not-gitea' }

View File

@ -16,6 +16,7 @@ Describe 'Portable package lifecycle' {
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')
@ -125,6 +126,58 @@ Describe 'Portable package lifecycle' {
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'

View File

@ -30,4 +30,19 @@ Describe 'Published manifest schemas' {
$package.fileAssociationIcon = 'assets/example.ico'
$profile | ConvertTo-Json -Depth 8 | Test-Json -SchemaFile $schema | Should -BeTrue
}
It 'accepts only safe portable replacement declarations' {
$schema = "$PSScriptRoot/../schemas/profile.schema.json"
$package = [ordered]@{
id = 'deckstride'; provider = 'portable'; source = 'idle-org'; version = '1.0'; update = 'pinned'
url = 'https://example.org/deckstride.zip'; executable = 'deckstride.exe'; sha256 = 'a' * 64
replaces = @([ordered]@{ source = 'idle-org'; id = 'pdf-presenter'; fileAssociations = @('.pdf') })
}
$profile = [ordered]@{ schemaVersion = 1; name = 'test'; packages = @($package) }
$profile | ConvertTo-Json -Depth 8 | Test-Json -SchemaFile $schema | Should -BeTrue
$package.replaces[0].fileAssociations = @('pdf')
$profile | ConvertTo-Json -Depth 8 | Test-Json -SchemaFile $schema -ErrorAction SilentlyContinue | Should -BeFalse
$package.replaces[0].fileAssociations = @('.pdf')
$package.replaces[0].unknown = 'value'
$profile | ConvertTo-Json -Depth 8 | Test-Json -SchemaFile $schema -ErrorAction SilentlyContinue | Should -BeFalse
}
}