mirror of
https://github.com/ScoopInstaller/Scoop.git
synced 2025-10-30 06:07:56 +00:00
Compare commits
27 Commits
9fa53a0255
...
feature/in
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5d46f67e34 | ||
|
|
1fae80b2c2 | ||
|
|
cf345e272e | ||
|
|
99fb8383b7 | ||
|
|
0a52f0d0de | ||
|
|
becd429581 | ||
|
|
d3f681ce03 | ||
|
|
9f62e55862 | ||
|
|
887f79d2d7 | ||
|
|
5bae77eebb | ||
|
|
210b5e45a0 | ||
|
|
3aa64baeb1 | ||
|
|
0470ba2d04 | ||
|
|
398aaa2330 | ||
|
|
4585f50a54 | ||
|
|
9a6cdc7328 | ||
|
|
039d2d77c2 | ||
|
|
ec44c6c7b2 | ||
|
|
c264afc6bd | ||
|
|
4061bff270 | ||
|
|
3e3ce096b8 | ||
|
|
83696854a8 | ||
|
|
82a35323d3 | ||
|
|
dfadfcc1dc | ||
|
|
0ade4a5344 | ||
|
|
ce95819fa5 | ||
|
|
c7795b44af |
@@ -2,6 +2,7 @@
|
||||
|
||||
### Features
|
||||
|
||||
- **install:** Add support for historical manifests ([#6370](https://github.com/ScoopInstaller/Scoop/issues/6370))
|
||||
- **scoop-uninstall**: Allow access to `$bucket` in uninstall scripts ([#6380](https://github.com/ScoopInstaller/Scoop/issues/6380))
|
||||
- **install:** Add separator at the end of notes, highlight suggestions ([#6418](https://github.com/ScoopInstaller/Scoop/issues/6418))
|
||||
|
||||
@@ -18,7 +19,7 @@
|
||||
|
||||
### Features
|
||||
|
||||
**autoupdate:** GitHub predefined hashes support ([#6416](https://github.com/ScoopInstaller/Scoop/issues/6416), [#6435](https://github.com/ScoopInstaller/Scoop/issues/6435))
|
||||
- **autoupdate:** GitHub predefined hashes support ([#6416](https://github.com/ScoopInstaller/Scoop/issues/6416), [#6435](https://github.com/ScoopInstaller/Scoop/issues/6435))
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
|
||||
@@ -264,9 +264,11 @@ function Select-ScoopDBItem {
|
||||
[void]$dbAdapter.Fill($result)
|
||||
}
|
||||
end {
|
||||
$resultCopy = $result.Copy()
|
||||
$dbAdapter.Dispose()
|
||||
$db.Dispose()
|
||||
return $result
|
||||
# Use Write-Output to ensure PowerShell properly returns the DataTable
|
||||
Write-Output $resultCopy -NoEnumerate
|
||||
}
|
||||
}
|
||||
|
||||
@@ -293,13 +295,13 @@ function Select-ScoopDBItem {
|
||||
function Get-ScoopDBItem {
|
||||
[CmdletBinding()]
|
||||
param (
|
||||
[Parameter(Mandatory, Position = 0, ValueFromPipeline)]
|
||||
[Parameter(Mandatory, Position = 0, ValueFromPipeline, ValueFromPipelineByPropertyName)]
|
||||
[string]
|
||||
$Name,
|
||||
[Parameter(Mandatory, Position = 1)]
|
||||
[Parameter(Mandatory, Position = 1, ValueFromPipelineByPropertyName)]
|
||||
[string]
|
||||
$Bucket,
|
||||
[Parameter(Position = 2)]
|
||||
[Parameter(Position = 2, ValueFromPipelineByPropertyName)]
|
||||
[string]
|
||||
$Version
|
||||
)
|
||||
@@ -307,28 +309,46 @@ function Get-ScoopDBItem {
|
||||
begin {
|
||||
$db = Open-ScoopDB
|
||||
$dbAdapter = New-Object -TypeName System.Data.SQLite.SQLiteDataAdapter
|
||||
$dbCommand = $db.CreateCommand()
|
||||
$dbCommand.CommandType = [System.Data.CommandType]::Text
|
||||
$dbAdapter.SelectCommand = $dbCommand
|
||||
}
|
||||
|
||||
process {
|
||||
$result = New-Object System.Data.DataTable
|
||||
|
||||
# Build query based on whether version is specified
|
||||
$dbQuery = 'SELECT * FROM app WHERE name = @Name AND bucket = @Bucket'
|
||||
if ($Version) {
|
||||
$dbQuery += ' AND version = @Version'
|
||||
} else {
|
||||
$dbQuery += ' ORDER BY version DESC LIMIT 1'
|
||||
}
|
||||
$dbCommand = $db.CreateCommand()
|
||||
|
||||
$dbCommand.CommandText = $dbQuery
|
||||
$dbCommand.CommandType = [System.Data.CommandType]::Text
|
||||
$dbAdapter.SelectCommand = $dbCommand
|
||||
}
|
||||
process {
|
||||
$dbCommand.Parameters.Clear()
|
||||
|
||||
# Add parameters for this specific query
|
||||
$dbCommand.Parameters.AddWithValue('@Name', $Name) | Out-Null
|
||||
$dbCommand.Parameters.AddWithValue('@Bucket', $Bucket) | Out-Null
|
||||
$dbCommand.Parameters.AddWithValue('@Version', $Version) | Out-Null
|
||||
if ($Version) {
|
||||
$dbCommand.Parameters.AddWithValue('@Version', $Version) | Out-Null
|
||||
}
|
||||
|
||||
[void]$dbAdapter.Fill($result)
|
||||
|
||||
# Create a copy of the DataTable to avoid disposal issues
|
||||
$resultCopy = $result.Copy()
|
||||
|
||||
# Use Write-Output to ensure PowerShell properly returns the DataTable
|
||||
Write-Output $resultCopy -NoEnumerate
|
||||
}
|
||||
|
||||
end {
|
||||
# Clean up all resources
|
||||
$dbAdapter.Dispose()
|
||||
$dbCommand.Dispose()
|
||||
$db.Dispose()
|
||||
return $result
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
209
lib/manifest.ps1
209
lib/manifest.ps1
@@ -172,38 +172,200 @@ function Get-SupportedArchitecture($manifest, $architecture) {
|
||||
}
|
||||
}
|
||||
|
||||
function Get-RelativePathCompat($from, $to) {
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Cross-platform compatible relative path function
|
||||
.DESCRIPTION
|
||||
Falls back to custom implementation for Windows PowerShell compatibility
|
||||
#>
|
||||
if ($PSVersionTable.PSVersion.Major -ge 6) {
|
||||
# PowerShell Core/7+ - use built-in method
|
||||
try {
|
||||
return [System.IO.Path]::GetRelativePath($from, $to)
|
||||
} catch {
|
||||
# Fallback if method fails
|
||||
}
|
||||
}
|
||||
|
||||
# Windows PowerShell compatible implementation
|
||||
$fromUri = New-Object System.Uri($from.TrimEnd('\') + '\')
|
||||
$toUri = New-Object System.Uri($to)
|
||||
|
||||
if ($fromUri.Scheme -ne $toUri.Scheme) {
|
||||
return $to # Cannot make relative path between different schemes
|
||||
}
|
||||
|
||||
$relativeUri = $fromUri.MakeRelativeUri($toUri)
|
||||
$relativePath = [System.Uri]::UnescapeDataString($relativeUri.ToString())
|
||||
|
||||
return $relativePath -replace '/', '\'
|
||||
}
|
||||
|
||||
function Find-HistoricalManifestInCache($app, $bucket, $requestedVersion) {
|
||||
if (!(get_config USE_SQLITE_CACHE)) {
|
||||
return $null
|
||||
}
|
||||
|
||||
# Return null if bucket is null or empty
|
||||
if (!$bucket) {
|
||||
return $null
|
||||
}
|
||||
|
||||
# Import database functions if not already loaded
|
||||
if (!(Get-Command 'Get-ScoopDBItem' -ErrorAction SilentlyContinue)) {
|
||||
. "$PSScriptRoot\database.ps1"
|
||||
}
|
||||
|
||||
$dbResult = Get-ScoopDBItem -Name $app -Bucket $bucket -Version $requestedVersion
|
||||
|
||||
# Strictly follow DB contract: must be DataTable with at least one row
|
||||
if (-not ($dbResult -is [System.Data.DataTable])) { return $null }
|
||||
if ($dbResult.Rows.Count -eq 0) { return $null }
|
||||
|
||||
$manifestText = $dbResult.Rows[0]['manifest']
|
||||
if ([string]::IsNullOrWhiteSpace($manifestText)) { return $null }
|
||||
|
||||
$manifestObj = $null
|
||||
try { $manifestObj = $manifestText | ConvertFrom-Json -ErrorAction Stop } catch {}
|
||||
$manifestVersion = if ($manifestObj -and $manifestObj.version) { $manifestObj.version } else { $requestedVersion }
|
||||
|
||||
return @{ ManifestText = $manifestText; version = $manifestVersion; source = "sqlite_exact_match" }
|
||||
|
||||
return $null
|
||||
}
|
||||
|
||||
function Find-HistoricalManifestInGit($app, $bucket, $requestedVersion) {
|
||||
# Only proceed if git history is enabled
|
||||
if (!(get_config USE_GIT_HISTORY $true)) {
|
||||
return $null
|
||||
}
|
||||
|
||||
if (!$bucket) {
|
||||
return $null
|
||||
}
|
||||
|
||||
$bucketDir = Find-BucketDirectory $bucket -Root
|
||||
if (!(Test-Path "$bucketDir\.git")) {
|
||||
warn "Bucket '$bucket' is not a git repository. Cannot search historical versions."
|
||||
return $null
|
||||
}
|
||||
|
||||
$manifestPath = "$app.json"
|
||||
$innerBucketDir = Find-BucketDirectory $bucket # Non-root path
|
||||
|
||||
if (-not (Test-Path $innerBucketDir -PathType Container)) {
|
||||
warn "Could not find inner bucket directory for '$bucket' at '$innerBucketDir'."
|
||||
return $null
|
||||
}
|
||||
$relativeManifestPath = Get-RelativePathCompat $bucketDir (Join-Path $innerBucketDir $manifestPath)
|
||||
$relativeManifestPath = $relativeManifestPath -replace '\\', '/'
|
||||
|
||||
try {
|
||||
# Prefer precise regex match on version line, fallback to -S literal
|
||||
$pattern = '"version"\s*:\s*"' + [regex]::Escape($requestedVersion) + '"'
|
||||
$commits = @()
|
||||
$outG = Invoke-Git -Path $bucketDir -ArgumentList @('log','--follow','-n','1','--format=%H','-G',$pattern,'--',$relativeManifestPath)
|
||||
if ($outG) { $commits = @($outG | Where-Object { -not [string]::IsNullOrWhiteSpace($_) }) }
|
||||
|
||||
if ($commits.Count -eq 0) {
|
||||
$searchLiteral = '"version": "' + $requestedVersion + '"'
|
||||
$outS = Invoke-Git -Path $bucketDir -ArgumentList @('log','--follow','-n','1','--format=%H','-S',$searchLiteral,'--',$relativeManifestPath)
|
||||
if ($outS) { $commits = @($outS | Where-Object { -not [string]::IsNullOrWhiteSpace($_) }) }
|
||||
}
|
||||
|
||||
if ($commits.Count -eq 0) { return $null }
|
||||
|
||||
$h = $commits[0]
|
||||
|
||||
# First try parent snapshot (latest state before change), then the change itself
|
||||
foreach ($spec in @("$h^","$h")) {
|
||||
$content = Invoke-Git -Path $bucketDir -ArgumentList @('show', "$spec`:$relativeManifestPath")
|
||||
if (-not $content -or ($LASTEXITCODE -ne 0)) { continue }
|
||||
if ($content -is [Array]) { $content = $content -join "`n" }
|
||||
try {
|
||||
$obj = $content | ConvertFrom-Json -ErrorAction Stop
|
||||
} catch { continue }
|
||||
if ($obj -and $obj.version -eq $requestedVersion) {
|
||||
return @{ ManifestText = $content; version = $requestedVersion; source = "git_manifest:$spec" }
|
||||
}
|
||||
}
|
||||
|
||||
# Fallback: iterate recent commits that touched the version string and validate
|
||||
$outAll = Invoke-Git -Path $bucketDir -ArgumentList @('log','--follow','--format=%H','-G',$pattern,'--',$relativeManifestPath)
|
||||
$allCommits = @()
|
||||
if ($outAll) { $allCommits = @($outAll | Where-Object { -not [string]::IsNullOrWhiteSpace($_) }) }
|
||||
|
||||
foreach ($c in $allCommits) {
|
||||
$content = Invoke-Git -Path $bucketDir -ArgumentList @('show', "$c`:$relativeManifestPath")
|
||||
if (-not $content -or ($LASTEXITCODE -ne 0)) { continue }
|
||||
if ($content -is [Array]) { $content = $content -join "`n" }
|
||||
try { $obj = $content | ConvertFrom-Json -ErrorAction Stop } catch { continue }
|
||||
if ($obj -and $obj.version -eq $requestedVersion) {
|
||||
return @{ ManifestText = $content; version = $requestedVersion; source = "git_manifest:$c" }
|
||||
}
|
||||
}
|
||||
|
||||
return $null
|
||||
} catch { return $null }
|
||||
}
|
||||
|
||||
function Find-HistoricalManifest($app, $bucket, $version) {
|
||||
# Orchestrates historical manifest lookup using available providers (DB → Git)
|
||||
$result = $null
|
||||
|
||||
if (get_config USE_SQLITE_CACHE) {
|
||||
$result = Find-HistoricalManifestInCache $app $bucket $version
|
||||
if ($result) {
|
||||
if ($result.ManifestText) {
|
||||
$path = Write-ManifestToUserCache -App $app -ManifestText $result.ManifestText
|
||||
return @{ path = $path; version = $result.version; source = $result.source }
|
||||
}
|
||||
return $result
|
||||
}
|
||||
}
|
||||
|
||||
if (get_config USE_GIT_HISTORY $true) {
|
||||
$result = Find-HistoricalManifestInGit $app $bucket $version
|
||||
if ($result) {
|
||||
if ($result.ManifestText) {
|
||||
$path = Write-ManifestToUserCache -App $app -ManifestText $result.ManifestText
|
||||
return @{ path = $path; version = $result.version; source = $result.source }
|
||||
}
|
||||
return $result
|
||||
}
|
||||
}
|
||||
|
||||
return $null
|
||||
}
|
||||
|
||||
|
||||
function generate_user_manifest($app, $bucket, $version) {
|
||||
# 'autoupdate.ps1' 'buckets.ps1' 'manifest.ps1'
|
||||
$app, $manifest, $bucket, $null = Get-Manifest "$bucket/$app"
|
||||
if ("$($manifest.version)" -eq "$version") {
|
||||
return manifest_path $app $bucket
|
||||
}
|
||||
warn "Given version ($version) does not match manifest ($($manifest.version))"
|
||||
warn "Attempting to generate manifest for '$app' ($version)"
|
||||
|
||||
# Try historical providers via orchestrator
|
||||
$historicalResult = Find-HistoricalManifest $app $bucket $version
|
||||
if ($historicalResult) { return $historicalResult.path }
|
||||
|
||||
# No historical manifest; try autoupdate if available
|
||||
if (!($manifest.autoupdate)) {
|
||||
abort "Could not find manifest for '$app@$version' and no autoupdate is available"
|
||||
}
|
||||
|
||||
ensure (usermanifestsdir) | Out-Null
|
||||
$manifest_path = "$(usermanifestsdir)\$app.json"
|
||||
|
||||
if (get_config USE_SQLITE_CACHE) {
|
||||
$cached_manifest = (Get-ScoopDBItem -Name $app -Bucket $bucket -Version $version).manifest
|
||||
if ($cached_manifest) {
|
||||
$cached_manifest | Out-UTF8File $manifest_path
|
||||
return $manifest_path
|
||||
}
|
||||
}
|
||||
|
||||
if (!($manifest.autoupdate)) {
|
||||
abort "'$app' does not have autoupdate capability`r`ncouldn't find manifest for '$app@$version'"
|
||||
}
|
||||
|
||||
try {
|
||||
Invoke-AutoUpdate $app $manifest_path $manifest $version $(@{ })
|
||||
return $manifest_path
|
||||
} catch {
|
||||
Write-Host -ForegroundColor DarkRed "Could not install $app@$version"
|
||||
warn "Autoupdate failed for '$app@$version'"
|
||||
abort "Installation of '$app@$version' is not possible"
|
||||
}
|
||||
|
||||
return $null
|
||||
}
|
||||
|
||||
function url($manifest, $arch) { arch_specific 'url' $manifest $arch }
|
||||
@@ -212,3 +374,16 @@ function uninstaller($manifest, $arch) { arch_specific 'uninstaller' $manifest $
|
||||
function hash($manifest, $arch) { arch_specific 'hash' $manifest $arch }
|
||||
function extract_dir($manifest, $arch) { arch_specific 'extract_dir' $manifest $arch }
|
||||
function extract_to($manifest, $arch) { arch_specific 'extract_to' $manifest $arch }
|
||||
|
||||
# Helper: write manifest text to user manifests cache directory and return path
|
||||
function Write-ManifestToUserCache {
|
||||
param(
|
||||
[Parameter(Mandatory=$true, Position=0)][string]$App,
|
||||
[Parameter(Mandatory=$true, Position=1)][string]$ManifestText
|
||||
)
|
||||
ensure (usermanifestsdir) | Out-Null
|
||||
$tempManifestPath = "$(usermanifestsdir)\$App.json"
|
||||
$ManifestText | Out-UTF8File -FilePath $tempManifestPath
|
||||
return $tempManifestPath
|
||||
}
|
||||
|
||||
|
||||
@@ -30,6 +30,11 @@
|
||||
# use_sqlite_cache: $true|$false
|
||||
# Use SQLite database for caching. This is useful for speeding up 'scoop search' and 'scoop shim' commands.
|
||||
#
|
||||
# use_git_history: $true|$false
|
||||
# Enable searching for specific versions in git history when installing apps with version specifiers.
|
||||
# When enabled, Scoop will first search the bucket's git history for the exact version before falling back to autoupdate.
|
||||
# (Default is $true)
|
||||
#
|
||||
# no_junction: $true|$false
|
||||
# The 'current' version alias will not be used. Shims and shortcuts will point to specific version instead.
|
||||
#
|
||||
@@ -166,7 +171,7 @@ if (!$name) {
|
||||
Write-Host "'$name' has been set to '$value'"
|
||||
} else {
|
||||
$value = get_config $name
|
||||
if($null -eq $value) {
|
||||
if ($null -eq $value) {
|
||||
Write-Host "'$name' is not set"
|
||||
} else {
|
||||
if ($value -is [System.DateTime]) {
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
# scoop install git
|
||||
#
|
||||
# To install a different version of the app
|
||||
# (note that this will auto-generate the manifest using current version):
|
||||
# (will search sqlite cache if enabled, then git history (if use_git_history is $true), then auto-generate manifest as fallback):
|
||||
# scoop install gh@2.7.0
|
||||
#
|
||||
# To install an app from a manifest at a URL:
|
||||
|
||||
@@ -1,15 +1,25 @@
|
||||
BeforeAll {
|
||||
. "$PSScriptRoot\..\lib\json.ps1"
|
||||
. "$PSScriptRoot\..\lib\core.ps1"
|
||||
. "$PSScriptRoot\..\lib\manifest.ps1"
|
||||
. "$PSScriptRoot\..\lib\buckets.ps1"
|
||||
. "$PSScriptRoot\..\lib\database.ps1"
|
||||
. "$PSScriptRoot\..\lib\autoupdate.ps1"
|
||||
}
|
||||
|
||||
Describe 'JSON parse and beautify' -Tag 'Scoop' {
|
||||
Context 'Parse JSON' {
|
||||
It 'success with valid json' {
|
||||
{ parse_json "$PSScriptRoot\fixtures\manifest\wget.json" } | Should -Not -Throw
|
||||
$parsed = parse_json "$PSScriptRoot\fixtures\manifest\wget.json"
|
||||
$parsed | Should -Not -Be $null
|
||||
}
|
||||
It 'fails with invalid json' {
|
||||
{ parse_json "$PSScriptRoot\fixtures\manifest\broken_wget.json" } | Should -Throw
|
||||
It 'returns null and warns with invalid json' {
|
||||
Mock warn {}
|
||||
{ parse_json "$PSScriptRoot\fixtures\manifest\broken_wget.json" } | Should -Not -Throw
|
||||
$parsed = parse_json "$PSScriptRoot\fixtures\manifest\broken_wget.json"
|
||||
$parsed | Should -Be $null
|
||||
Should -Invoke -CommandName warn -Times 1
|
||||
}
|
||||
}
|
||||
Context 'Beautify JSON' {
|
||||
@@ -84,3 +94,144 @@ Describe 'Manifest Validator' -Tag 'Validator' {
|
||||
$validator.Errors | Select-Object -Last 1 | Should -Match 'Required properties are missing from object: version\.'
|
||||
}
|
||||
}
|
||||
|
||||
Describe 'Get-RelativePathCompat' -Tag 'Scoop' {
|
||||
It 'returns relative path for child path' {
|
||||
$from = 'C:\root\bucket'
|
||||
$to = 'C:\root\bucket\foo\bar.json'
|
||||
Get-RelativePathCompat $from $to | Should -Be 'foo\bar.json'
|
||||
}
|
||||
It 'returns original when different drive/scheme' {
|
||||
$from = 'C:\root\bucket'
|
||||
$to = 'D:\other\file.json'
|
||||
Get-RelativePathCompat $from $to | Should -Be $to
|
||||
}
|
||||
}
|
||||
|
||||
Describe 'Find-HistoricalManifestInCache' -Tag 'Scoop' {
|
||||
It 'returns $null when sqlite cache disabled' {
|
||||
Mock get_config -ParameterFilter { $name -eq 'use_sqlite_cache' } { $false }
|
||||
$result = Find-HistoricalManifestInCache 'foo' 'main' '1.0.0'
|
||||
$result | Should -Be $null
|
||||
}
|
||||
|
||||
It 'returns manifest text and version when cache has exact match' {
|
||||
$tempUM = Join-Path $env:TEMP 'ScoopTestsUM'
|
||||
Mock get_config -ParameterFilter { $name -in @('use_sqlite_cache','use_git_history') } { $true }
|
||||
Mock Get-ScoopDBItem {
|
||||
$dt = New-Object System.Data.DataTable
|
||||
[void]$dt.Columns.Add('manifest')
|
||||
$row = $dt.NewRow()
|
||||
$row['manifest'] = '{"version":"1.2.3"}'
|
||||
[void]$dt.Rows.Add($row)
|
||||
Write-Output $dt -NoEnumerate
|
||||
}
|
||||
Mock ensure {}
|
||||
$result = Find-HistoricalManifestInCache 'foo' 'main' '1.2.3'
|
||||
$result | Should -Not -BeNullOrEmpty
|
||||
$result.version | Should -Be '1.2.3'
|
||||
$result.ManifestText | Should -Match '"version":"1.2.3"'
|
||||
}
|
||||
}
|
||||
|
||||
Describe 'Find-HistoricalManifestInGit' -Tag 'Scoop' {
|
||||
It 'returns $null when git history search disabled' {
|
||||
Mock get_config -ParameterFilter { $name -eq 'use_git_history' } { $false }
|
||||
$result = Find-HistoricalManifestInGit 'foo' 'main' '1.0.0'
|
||||
$result | Should -Be $null
|
||||
}
|
||||
|
||||
It 'returns manifest text on version match' {
|
||||
$bucketRoot = 'C:\b\root'
|
||||
$innerBucket = 'C:\b\root\bucket'
|
||||
$umdir = Join-Path $env:TEMP 'ScoopTestsUM'
|
||||
Mock get_config -ParameterFilter { $name -eq 'use_git_history' } { $true }
|
||||
Mock Find-BucketDirectory -ParameterFilter { $Root } { $bucketRoot }
|
||||
Mock Find-BucketDirectory -ParameterFilter { -not $Root } { $innerBucket }
|
||||
Mock Test-Path -ParameterFilter { $Path -eq (Join-Path $bucketRoot '.git') } { $true }
|
||||
Mock Test-Path -ParameterFilter { $Path -eq $innerBucket -and $PathType -eq 'Container' } { $true }
|
||||
# Behavior-oriented mocks: using HEAD should yield a wrong version
|
||||
Mock Invoke-Git -ParameterFilter { $ArgumentList[0] -eq 'show' -and $ArgumentList[1] -like 'HEAD*' } { $global:LASTEXITCODE = 0; return '{"version":"2.0.0"}' }
|
||||
Mock Invoke-Git -ParameterFilter { $ArgumentList[0] -eq 'show' } { $global:LASTEXITCODE = 0; return '{"version":"1.0.0"}' }
|
||||
Mock Invoke-Git -ParameterFilter { $ArgumentList[0] -eq 'log' } { @('abcdef0123456789') }
|
||||
|
||||
$result = Find-HistoricalManifestInGit 'foo' 'main' '1.0.0'
|
||||
$result | Should -Not -BeNullOrEmpty
|
||||
$result.version | Should -Be '1.0.0'
|
||||
$result.ManifestText | Should -Match '"version":"1.0.0"'
|
||||
}
|
||||
}
|
||||
|
||||
Describe 'generate_user_manifest (history-aware)' -Tag 'Scoop' {
|
||||
It 'returns manifest_path when versions match' {
|
||||
Mock Get-Manifest -ParameterFilter { $app -eq 'main/foo' } { 'foo', [pscustomobject]@{ version='1.0.0' }, 'main', $null }
|
||||
Mock manifest_path { 'C:\path\foo.json' }
|
||||
$p = generate_user_manifest 'foo' 'main' '1.0.0'
|
||||
$p | Should -Be 'C:\path\foo.json'
|
||||
}
|
||||
|
||||
It 'prefers history orchestrator hit (cache) when enabled' {
|
||||
Mock Get-Manifest -ParameterFilter { $app -eq 'main/foo' } { 'foo', [pscustomobject]@{ version='2.0.0' }, 'main', $null }
|
||||
Mock get_config -ParameterFilter { $name -in @('use_sqlite_cache','use_git_history') } { $true }
|
||||
Mock Find-HistoricalManifest { @{ path = 'C:\cache\foo.json'; version = '1.0.0'; source='sqlite_exact_match' } }
|
||||
|
||||
Mock info {}
|
||||
Mock warn {}
|
||||
$p = generate_user_manifest 'foo' 'main' '1.0.0'
|
||||
$p | Should -Be 'C:\cache\foo.json'
|
||||
Should -Invoke -CommandName Find-HistoricalManifest -Times 1
|
||||
|
||||
}
|
||||
|
||||
It 'falls back to git history when cache misses' {
|
||||
Mock Get-Manifest -ParameterFilter { $app -eq 'main/foo' } { 'foo', [pscustomobject]@{ version='2.0.0' }, 'main', $null }
|
||||
Mock get_config -ParameterFilter { $name -in @('use_sqlite_cache','use_git_history') } { $true }
|
||||
Mock Find-HistoricalManifest { @{ path = 'C:\git\foo.json'; version = '1.0.0'; source='git_manifest:hash' } }
|
||||
Mock info {}
|
||||
Mock warn {}
|
||||
$p = generate_user_manifest 'foo' 'main' '1.0.0'
|
||||
$p | Should -Be 'C:\git\foo.json'
|
||||
Should -Invoke -CommandName Find-HistoricalManifest -Times 1
|
||||
|
||||
}
|
||||
|
||||
It 'uses autoupdate when no history found and autoupdate exists' {
|
||||
$umdir = Join-Path $env:TEMP 'ScoopTestsUM'
|
||||
Mock Get-Manifest -ParameterFilter { $app -eq 'main/foo' } { 'foo', [pscustomobject]@{ version='2.0.0'; autoupdate=@{} }, 'main', $null }
|
||||
Mock get_config -ParameterFilter { $name -eq 'use_sqlite_cache' } { $false }
|
||||
Mock Find-HistoricalManifest { $null }
|
||||
|
||||
Mock ensure {}
|
||||
Mock usermanifestsdir { $umdir }
|
||||
Mock Invoke-AutoUpdate {}
|
||||
$p = generate_user_manifest 'foo' 'main' '1.0.0'
|
||||
$p | Should -Be (Join-Path $umdir 'foo.json')
|
||||
}
|
||||
|
||||
It 'on autoupdate failure aborts with concise message' {
|
||||
$umdir = Join-Path $env:TEMP 'ScoopTestsUM'
|
||||
Mock Get-Manifest -ParameterFilter { $app -eq 'main/foo' } { 'foo', [pscustomobject]@{ version='2.0.0'; autoupdate=@{} }, 'main', $null }
|
||||
Mock get_config -ParameterFilter { $name -eq 'use_sqlite_cache' } { $false }
|
||||
Mock Find-HistoricalManifest { $null }
|
||||
Mock ensure {}
|
||||
Mock usermanifestsdir { $umdir }
|
||||
Mock Invoke-AutoUpdate { throw 'fail' }
|
||||
Mock warn {}
|
||||
Mock info {}
|
||||
Mock Write-Host {}
|
||||
Mock abort { throw 'aborted' }
|
||||
{ generate_user_manifest 'foo' 'main' '1.0.0' } | Should -Throw
|
||||
}
|
||||
|
||||
It 'aborts when no history and no autoupdate' {
|
||||
Mock Get-Manifest -ParameterFilter { $app -eq 'main/foo' } { 'foo', [pscustomobject]@{ version='2.0.0' }, 'main', $null }
|
||||
Mock get_config -ParameterFilter { $name -eq 'use_sqlite_cache' } { $false }
|
||||
Mock Find-HistoricalManifest { $null }
|
||||
|
||||
Mock warn {}
|
||||
Mock info {}
|
||||
Mock abort { throw 'aborted' }
|
||||
{ generate_user_manifest 'foo' 'main' '1.0.0' } | Should -Throw
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user