From 522c706b7539f9aaff9703de1a5818a4ff9e8fcb Mon Sep 17 00:00:00 2001 From: Cory Knox Date: Tue, 14 Oct 2025 14:24:35 -0700 Subject: [PATCH 1/6] (#3804) Add source location to package information This commit adds the source location for a package to the .chocolatey directory, and adds the printing of the location to the `choco list` verbose output (and also `choco info --local-only`). --- .../domain/ChocolateyPackageInformation.cs | 1 + .../ChocolateyPackageInformationService.cs | 30 +++++++++++++++++++ .../services/ChocolateyPackageService.cs | 1 + .../services/NugetService.cs | 10 +++++-- .../infrastructure/results/PackageResult.cs | 8 ++++- 5 files changed, 46 insertions(+), 4 deletions(-) diff --git a/src/chocolatey/infrastructure.app/domain/ChocolateyPackageInformation.cs b/src/chocolatey/infrastructure.app/domain/ChocolateyPackageInformation.cs index 8ff44c3c2..b5d8ec042 100644 --- a/src/chocolatey/infrastructure.app/domain/ChocolateyPackageInformation.cs +++ b/src/chocolatey/infrastructure.app/domain/ChocolateyPackageInformation.cs @@ -37,5 +37,6 @@ public ChocolateyPackageInformation(IPackageMetadata package) public bool IsPinned { get; set; } public string ExtraInformation { get; set; } public string DeploymentLocation { get; set; } + public string PackageInstalledFrom { get; set; } } } diff --git a/src/chocolatey/infrastructure.app/services/ChocolateyPackageInformationService.cs b/src/chocolatey/infrastructure.app/services/ChocolateyPackageInformationService.cs index 882c51eb1..aa5729c6b 100644 --- a/src/chocolatey/infrastructure.app/services/ChocolateyPackageInformationService.cs +++ b/src/chocolatey/infrastructure.app/services/ChocolateyPackageInformationService.cs @@ -45,6 +45,7 @@ public class ChocolateyPackageInformationService : IChocolateyPackageInformation private const string ExtraFile = ".extra"; private const string VersionOverrideFile = ".version"; private const string DeploymentLocationFile = ".deploymentLocation"; + private const string PackageInstalledFromFile = ".packageInstalledFrom"; // We need to store the package identifiers we have warned about // to prevent duplicated outputs. @@ -194,6 +195,20 @@ has errored attempting to read it. This file will be renamed to ); } + var packageInstalledFromFile = _fileSystem.CombinePaths(pkgStorePath, PackageInstalledFromFile); + if (_fileSystem.FileExists(packageInstalledFromFile)) + { + FaultTolerance.TryCatchWithLoggingException( + () => + { + packageInformation.PackageInstalledFrom = _fileSystem.ReadFile(packageInstalledFromFile); + }, + "Unable to read package installed from file", + throwError: false, + logWarningInsteadOfError: true + ); + } + return packageInformation; } @@ -310,6 +325,21 @@ public void Save(ChocolateyPackageInformation packageInformation) { _fileSystem.DeleteFile(_fileSystem.CombinePaths(pkgStorePath, DeploymentLocationFile)); } + + if (!string.IsNullOrWhiteSpace(packageInformation.PackageInstalledFrom)) + { + var packageInstallFromFile = _fileSystem.CombinePaths(pkgStorePath, PackageInstalledFromFile); + if (_fileSystem.FileExists(packageInstallFromFile)) + { + _fileSystem.DeleteFile(packageInstallFromFile); + } + + _fileSystem.WriteFile(packageInstallFromFile, packageInformation.PackageInstalledFrom); + } + else + { + _fileSystem.DeleteFile(_fileSystem.CombinePaths(pkgStorePath, PackageInstalledFromFile)); + } } public void Remove(IPackageMetadata package) diff --git a/src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs b/src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs index 317d27b1f..db7ad36a3 100644 --- a/src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs +++ b/src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs @@ -565,6 +565,7 @@ public virtual void HandlePackageResult(PackageResult packageResult, ChocolateyC } pkgInfo.DeploymentLocation = Environment.GetEnvironmentVariable(EnvironmentVariables.Package.ChocolateyPackageInstallLocation); + pkgInfo.PackageInstalledFrom = packageResult.SourceUri; UpdatePackageInformation(pkgInfo); EnsureBadPackagesPathIsClean(packageResult); diff --git a/src/chocolatey/infrastructure.app/services/NugetService.cs b/src/chocolatey/infrastructure.app/services/NugetService.cs index 5f5690519..b0917678e 100644 --- a/src/chocolatey/infrastructure.app/services/NugetService.cs +++ b/src/chocolatey/infrastructure.app/services/NugetService.cs @@ -217,6 +217,8 @@ it is possible that incomplete package lists are returned from a command ChocolateyPackageMetadata packageLocalMetadata; string packageInstallLocation = null; + string packageInstalledFrom = null; + if (package.PackagePath != null && !string.IsNullOrWhiteSpace(package.PackagePath)) { packageLocalMetadata = new ChocolateyPackageMetadata(package.PackagePath, _fileSystem); @@ -235,6 +237,7 @@ it is possible that incomplete package lists are returned from a command if (config.ListCommand.LocalOnly && packageLocalMetadata != null) { packageInfo = _packageInfoService.Get(packageLocalMetadata); + packageInstalledFrom = packageInfo.PackageInstalledFrom; if (config.ListCommand.IncludeVersionOverrides) { @@ -294,7 +297,7 @@ Package url{6} Tags: {9} Software Site: {10} Software License: {11}{12}{13}{14}{15}{16} - Description: {17}{18}{19} + Description: {17}{18}{19}{20} ".FormatWith( package.Title.EscapeCurlyBraces(), package.Published.GetValueOrDefault().UtcDateTime.ToShortDateString(), @@ -329,6 +332,7 @@ Package url{6} package.Summary != null && !string.IsNullOrWhiteSpace(package.Summary.ToStringSafe()) ? "\r\n Summary: {0}".FormatWith(package.Summary.EscapeCurlyBraces().ToStringSafe()) : string.Empty, package.Description.EscapeCurlyBraces().Replace("\n ", "\n").Replace("\n", "\n "), !string.IsNullOrWhiteSpace(package.ReleaseNotes.ToStringSafe()) ? "{0} Release Notes: {1}".FormatWith(Environment.NewLine, package.ReleaseNotes.EscapeCurlyBraces().Replace("\n ", "\n").Replace("\n", "\n ")) : string.Empty, + !string.IsNullOrWhiteSpace(packageInstalledFrom) ? "{0} Package Installed From: '{1}'".FormatWith(Environment.NewLine, packageInstalledFrom) : string.Empty, packageArgumentsUnencrypted != null ? packageArgumentsUnencrypted : string.Empty )); } @@ -994,7 +998,7 @@ Version was specified as '{0}'. It is possible that version packageRemoteMetadata.PackageTestResultStatus == "Failing" && packageRemoteMetadata.IsDownloadCacheAvailable ? " - Likely broken for FOSS users (due to download location changes)" : packageRemoteMetadata.PackageTestResultStatus == "Failing" ? " - Possibly broken" : string.Empty )); - var packageResult = packageResultsToReturn.GetOrAdd(packageDependencyInfo.Id.ToLowerSafe(), new PackageResult(packageMetadata, packageRemoteMetadata, installedPath)); + var packageResult = packageResultsToReturn.GetOrAdd(packageDependencyInfo.Id.ToLowerSafe(), new PackageResult(packageMetadata, packageRemoteMetadata, installedPath, null, packageDependencyInfo.Source.ToStringSafe())); if (shouldAddForcedResultMessage) { packageResult.Messages.Add(new ResultMessage(ResultType.Note, "Backing up and removing old version")); @@ -1819,7 +1823,7 @@ public virtual ConcurrentDictionary Upgrade(ChocolateyCon packageRemoteMetadata.PackageTestResultStatus == "Failing" && packageRemoteMetadata.IsDownloadCacheAvailable ? " - Likely broken for FOSS users (due to download location changes)" : packageRemoteMetadata.PackageTestResultStatus == "Failing" ? " - Possibly broken" : string.Empty )); - var upgradePackageResult = packageResultsToReturn.GetOrAdd(packageDependencyInfo.Id.ToLowerSafe(), new PackageResult(packageMetadata, packageRemoteMetadata, installedPath)); + var upgradePackageResult = packageResultsToReturn.GetOrAdd(packageDependencyInfo.Id.ToLowerSafe(), new PackageResult(packageMetadata, packageRemoteMetadata, installedPath, null, packageDependencyInfo.Source.ToStringSafe())); upgradePackageResult.ResetMetadata(packageMetadata, packageRemoteMetadata); upgradePackageResult.InstallLocation = installedPath; diff --git a/src/chocolatey/infrastructure/results/PackageResult.cs b/src/chocolatey/infrastructure/results/PackageResult.cs index 95327340f..d8e9f9c5e 100644 --- a/src/chocolatey/infrastructure/results/PackageResult.cs +++ b/src/chocolatey/infrastructure/results/PackageResult.cs @@ -103,7 +103,12 @@ public PackageResult(IPackageSearchMetadata packageSearch, string installLocatio */ } - public PackageResult(IPackageMetadata packageMetadata, IPackageSearchMetadata packageSearch, string installLocation, string source = null) : this(packageMetadata.Id, packageMetadata.Version.ToNormalizedStringChecked(), installLocation) + [Obsolete("This overload is deprecated and will be removed in v3.")] + public PackageResult(IPackageMetadata packageMetadata, IPackageSearchMetadata packageSearch, string installLocation, string source = null) : this(packageMetadata, packageSearch, installLocation, source, null) + { + } + + public PackageResult(IPackageMetadata packageMetadata, IPackageSearchMetadata packageSearch, string installLocation, string source, string sourceUri) : this(packageMetadata.Id, packageMetadata.Version.ToNormalizedStringChecked(), installLocation) { SearchMetadata = packageSearch; PackageMetadata = packageMetadata; @@ -123,6 +128,7 @@ public PackageResult(IPackageMetadata packageMetadata, IPackageSearchMetadata pa } Source = sources.FirstOrDefault(uri => uri.IsFile || uri.IsUnc).ToStringSafe(); + SourceUri = sourceUri; } public PackageResult(string name, string version, string installLocation, string source = null) From d37569daf677337bcada0a73b604423db3fa69ca Mon Sep 17 00:00:00 2001 From: Cory Knox Date: Wed, 15 Oct 2025 14:06:30 -0700 Subject: [PATCH 2/6] (#1901) Re-add display of deployment location This commit reverts c74a19cdcf20942d3fda5383d821a78c1d6c6a4a where we had reverted the initial work to display the deployment location. As we are releasing a new version of CLE that can take this newer version as a breaking change, we can add this functionality in there too. --- src/chocolatey/infrastructure.app/services/NugetService.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/chocolatey/infrastructure.app/services/NugetService.cs b/src/chocolatey/infrastructure.app/services/NugetService.cs index b0917678e..a521e7031 100644 --- a/src/chocolatey/infrastructure.app/services/NugetService.cs +++ b/src/chocolatey/infrastructure.app/services/NugetService.cs @@ -217,6 +217,7 @@ it is possible that incomplete package lists are returned from a command ChocolateyPackageMetadata packageLocalMetadata; string packageInstallLocation = null; + string deploymentlocation = null; string packageInstalledFrom = null; if (package.PackagePath != null && !string.IsNullOrWhiteSpace(package.PackagePath)) @@ -237,6 +238,7 @@ it is possible that incomplete package lists are returned from a command if (config.ListCommand.LocalOnly && packageLocalMetadata != null) { packageInfo = _packageInfoService.Get(packageLocalMetadata); + deploymentlocation = packageInfo.DeploymentLocation; packageInstalledFrom = packageInfo.PackageInstalledFrom; if (config.ListCommand.IncludeVersionOverrides) @@ -297,7 +299,7 @@ Package url{6} Tags: {9} Software Site: {10} Software License: {11}{12}{13}{14}{15}{16} - Description: {17}{18}{19}{20} + Description: {17}{18}{19}{20}{21} ".FormatWith( package.Title.EscapeCurlyBraces(), package.Published.GetValueOrDefault().UtcDateTime.ToShortDateString(), @@ -332,6 +334,7 @@ Package url{6} package.Summary != null && !string.IsNullOrWhiteSpace(package.Summary.ToStringSafe()) ? "\r\n Summary: {0}".FormatWith(package.Summary.EscapeCurlyBraces().ToStringSafe()) : string.Empty, package.Description.EscapeCurlyBraces().Replace("\n ", "\n").Replace("\n", "\n "), !string.IsNullOrWhiteSpace(package.ReleaseNotes.ToStringSafe()) ? "{0} Release Notes: {1}".FormatWith(Environment.NewLine, package.ReleaseNotes.EscapeCurlyBraces().Replace("\n ", "\n").Replace("\n", "\n ")) : string.Empty, + !string.IsNullOrWhiteSpace(deploymentlocation) ? "{0} Deployed to: '{1}'".FormatWith(Environment.NewLine, deploymentlocation) :string.Empty, !string.IsNullOrWhiteSpace(packageInstalledFrom) ? "{0} Package Installed From: '{1}'".FormatWith(Environment.NewLine, packageInstalledFrom) : string.Empty, packageArgumentsUnencrypted != null ? packageArgumentsUnencrypted : string.Empty )); From 59db2e9ec3914b9980258bda9da0ce592842fd9e Mon Sep 17 00:00:00 2001 From: Cory Knox Date: Wed, 15 Oct 2025 14:41:57 -0700 Subject: [PATCH 3/6] (#1901,#3804) Add pester tests for info output This adds pester tests to ensure the deployment location and the source repository are correctly output when running `choco info --local-only` --- .../commands/choco-info.Tests.ps1 | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/pester-tests/commands/choco-info.Tests.ps1 b/tests/pester-tests/commands/choco-info.Tests.ps1 index de12208bc..19ec2432a 100644 --- a/tests/pester-tests/commands/choco-info.Tests.ps1 +++ b/tests/pester-tests/commands/choco-info.Tests.ps1 @@ -34,6 +34,27 @@ } } + Context "Should display source and deployment locations when using --local-only" { + BeforeAll { + Initialize-ChocolateyTestInstall -Source $PSScriptRoot\testpackages + + $Setup = Invoke-Choco install installpackage + + $Setup.ExitCode | Should -Be 0 -Because $Setup.String + + $Output = Invoke-Choco info installpackage --local-only + } + + It "Exits with Success (0)" { + $Output.ExitCode | Should -Be 0 -Because $Output.String + } + + It "Should contain source and deployment location summary" { + $Output.Lines | Should -Contain "Package installed from: $PSScriptRoot\testpackages" -Because $Output.String + $Output.String | Should -Match "Deployed to:" + } + } + Context "Should include configured sources" { BeforeAll { Initialize-ChocolateyTestInstall -Source $PSScriptRoot\testpackages From 68ecb905321a490c8d275568aa5e4f18bc8fb0f0 Mon Sep 17 00:00:00 2001 From: Cory Knox Date: Thu, 16 Oct 2025 10:54:19 -0700 Subject: [PATCH 4/6] (#3804) Update source location variable name This commit renames the SourceInstalledFrom variable to the decided variable name. This also removes the uses of the deprecated PackageResult constructor. --- .../domain/ChocolateyPackageInformation.cs | 2 +- .../ChocolateyPackageInformationService.cs | 20 +++++++++---------- .../services/ChocolateyPackageService.cs | 2 +- .../services/NugetService.cs | 10 +++++----- .../infrastructure/results/PackageResult.cs | 13 ++++++++++-- .../commands/choco-info.Tests.ps1 | 2 +- 6 files changed, 29 insertions(+), 20 deletions(-) diff --git a/src/chocolatey/infrastructure.app/domain/ChocolateyPackageInformation.cs b/src/chocolatey/infrastructure.app/domain/ChocolateyPackageInformation.cs index b5d8ec042..697675b5a 100644 --- a/src/chocolatey/infrastructure.app/domain/ChocolateyPackageInformation.cs +++ b/src/chocolatey/infrastructure.app/domain/ChocolateyPackageInformation.cs @@ -37,6 +37,6 @@ public ChocolateyPackageInformation(IPackageMetadata package) public bool IsPinned { get; set; } public string ExtraInformation { get; set; } public string DeploymentLocation { get; set; } - public string PackageInstalledFrom { get; set; } + public string SourceInstalledFrom { get; set; } } } diff --git a/src/chocolatey/infrastructure.app/services/ChocolateyPackageInformationService.cs b/src/chocolatey/infrastructure.app/services/ChocolateyPackageInformationService.cs index aa5729c6b..368232522 100644 --- a/src/chocolatey/infrastructure.app/services/ChocolateyPackageInformationService.cs +++ b/src/chocolatey/infrastructure.app/services/ChocolateyPackageInformationService.cs @@ -45,7 +45,7 @@ public class ChocolateyPackageInformationService : IChocolateyPackageInformation private const string ExtraFile = ".extra"; private const string VersionOverrideFile = ".version"; private const string DeploymentLocationFile = ".deploymentLocation"; - private const string PackageInstalledFromFile = ".packageInstalledFrom"; + private const string SourceInstalledFromFile = ".sourceInstalledFrom"; // We need to store the package identifiers we have warned about // to prevent duplicated outputs. @@ -195,13 +195,13 @@ has errored attempting to read it. This file will be renamed to ); } - var packageInstalledFromFile = _fileSystem.CombinePaths(pkgStorePath, PackageInstalledFromFile); - if (_fileSystem.FileExists(packageInstalledFromFile)) + var sourceInstalledFromFile = _fileSystem.CombinePaths(pkgStorePath, SourceInstalledFromFile); + if (_fileSystem.FileExists(sourceInstalledFromFile)) { FaultTolerance.TryCatchWithLoggingException( () => { - packageInformation.PackageInstalledFrom = _fileSystem.ReadFile(packageInstalledFromFile); + packageInformation.SourceInstalledFrom = _fileSystem.ReadFile(sourceInstalledFromFile); }, "Unable to read package installed from file", throwError: false, @@ -326,19 +326,19 @@ public void Save(ChocolateyPackageInformation packageInformation) _fileSystem.DeleteFile(_fileSystem.CombinePaths(pkgStorePath, DeploymentLocationFile)); } - if (!string.IsNullOrWhiteSpace(packageInformation.PackageInstalledFrom)) + if (!string.IsNullOrWhiteSpace(packageInformation.SourceInstalledFrom)) { - var packageInstallFromFile = _fileSystem.CombinePaths(pkgStorePath, PackageInstalledFromFile); - if (_fileSystem.FileExists(packageInstallFromFile)) + var sourceInstalledFromFile = _fileSystem.CombinePaths(pkgStorePath, SourceInstalledFromFile); + if (_fileSystem.FileExists(sourceInstalledFromFile)) { - _fileSystem.DeleteFile(packageInstallFromFile); + _fileSystem.DeleteFile(sourceInstalledFromFile); } - _fileSystem.WriteFile(packageInstallFromFile, packageInformation.PackageInstalledFrom); + _fileSystem.WriteFile(sourceInstalledFromFile, packageInformation.SourceInstalledFrom); } else { - _fileSystem.DeleteFile(_fileSystem.CombinePaths(pkgStorePath, PackageInstalledFromFile)); + _fileSystem.DeleteFile(_fileSystem.CombinePaths(pkgStorePath, SourceInstalledFromFile)); } } diff --git a/src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs b/src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs index db7ad36a3..14742a25a 100644 --- a/src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs +++ b/src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs @@ -565,7 +565,7 @@ public virtual void HandlePackageResult(PackageResult packageResult, ChocolateyC } pkgInfo.DeploymentLocation = Environment.GetEnvironmentVariable(EnvironmentVariables.Package.ChocolateyPackageInstallLocation); - pkgInfo.PackageInstalledFrom = packageResult.SourceUri; + pkgInfo.SourceInstalledFrom = packageResult.SourceInstalledFrom; UpdatePackageInformation(pkgInfo); EnsureBadPackagesPathIsClean(packageResult); diff --git a/src/chocolatey/infrastructure.app/services/NugetService.cs b/src/chocolatey/infrastructure.app/services/NugetService.cs index a521e7031..9258522f4 100644 --- a/src/chocolatey/infrastructure.app/services/NugetService.cs +++ b/src/chocolatey/infrastructure.app/services/NugetService.cs @@ -218,7 +218,7 @@ it is possible that incomplete package lists are returned from a command ChocolateyPackageMetadata packageLocalMetadata; string packageInstallLocation = null; string deploymentlocation = null; - string packageInstalledFrom = null; + string sourceInstalledFrom = null; if (package.PackagePath != null && !string.IsNullOrWhiteSpace(package.PackagePath)) { @@ -239,7 +239,7 @@ it is possible that incomplete package lists are returned from a command { packageInfo = _packageInfoService.Get(packageLocalMetadata); deploymentlocation = packageInfo.DeploymentLocation; - packageInstalledFrom = packageInfo.PackageInstalledFrom; + sourceInstalledFrom = packageInfo.SourceInstalledFrom; if (config.ListCommand.IncludeVersionOverrides) { @@ -335,7 +335,7 @@ Package url{6} package.Description.EscapeCurlyBraces().Replace("\n ", "\n").Replace("\n", "\n "), !string.IsNullOrWhiteSpace(package.ReleaseNotes.ToStringSafe()) ? "{0} Release Notes: {1}".FormatWith(Environment.NewLine, package.ReleaseNotes.EscapeCurlyBraces().Replace("\n ", "\n").Replace("\n", "\n ")) : string.Empty, !string.IsNullOrWhiteSpace(deploymentlocation) ? "{0} Deployed to: '{1}'".FormatWith(Environment.NewLine, deploymentlocation) :string.Empty, - !string.IsNullOrWhiteSpace(packageInstalledFrom) ? "{0} Package Installed From: '{1}'".FormatWith(Environment.NewLine, packageInstalledFrom) : string.Empty, + !string.IsNullOrWhiteSpace(sourceInstalledFrom) ? "{0} Source package was installed from: '{1}'".FormatWith(Environment.NewLine, sourceInstalledFrom) : string.Empty, packageArgumentsUnencrypted != null ? packageArgumentsUnencrypted : string.Empty )); } @@ -361,7 +361,7 @@ Package url{6} } else { - yield return new PackageResult(packageLocalMetadata, package, config.ListCommand.LocalOnly ? packageInstallLocation : null, config.Sources); + yield return new PackageResult(packageLocalMetadata, package, config.ListCommand.LocalOnly ? packageInstallLocation : null, config.Sources, null); } } @@ -2902,7 +2902,7 @@ protected virtual void BackupAndRunBeforeModify( { "chocolatey".Log().Debug("Running beforeModify step for '{0}'", packageResult.PackageMetadata.Id); - var packageResultCopy = new PackageResult(packageResult.PackageMetadata, packageResult.SearchMetadata, packageResult.InstallLocation, packageResult.Source); + var packageResultCopy = new PackageResult(packageResult.PackageMetadata, packageResult.SearchMetadata, packageResult.InstallLocation, packageResult.Source, null); beforeModifyAction(packageResultCopy, config); diff --git a/src/chocolatey/infrastructure/results/PackageResult.cs b/src/chocolatey/infrastructure/results/PackageResult.cs index d8e9f9c5e..144320df1 100644 --- a/src/chocolatey/infrastructure/results/PackageResult.cs +++ b/src/chocolatey/infrastructure/results/PackageResult.cs @@ -48,6 +48,7 @@ public bool Warning public string InstallLocation { get; set; } public string Source { get; set; } public string SourceUri { get; set; } + public string SourceInstalledFrom { get; set; } public int ExitCode { get; set; } public void ResetMetadata(IPackageMetadata metadata, IPackageSearchMetadata search) @@ -108,7 +109,15 @@ public PackageResult(IPackageMetadata packageMetadata, IPackageSearchMetadata pa { } - public PackageResult(IPackageMetadata packageMetadata, IPackageSearchMetadata packageSearch, string installLocation, string source, string sourceUri) : this(packageMetadata.Id, packageMetadata.Version.ToNormalizedStringChecked(), installLocation) + /// + /// Initializes a new instance of the class. + /// + /// + /// + /// + /// The sources configured at the time of package installation. + /// The package source used to install the package. + public PackageResult(IPackageMetadata packageMetadata, IPackageSearchMetadata packageSearch, string installLocation, string source, string sourceInstalledFrom) : this(packageMetadata.Id, packageMetadata.Version.ToNormalizedStringChecked(), installLocation) { SearchMetadata = packageSearch; PackageMetadata = packageMetadata; @@ -128,7 +137,7 @@ public PackageResult(IPackageMetadata packageMetadata, IPackageSearchMetadata pa } Source = sources.FirstOrDefault(uri => uri.IsFile || uri.IsUnc).ToStringSafe(); - SourceUri = sourceUri; + SourceInstalledFrom = sourceInstalledFrom; } public PackageResult(string name, string version, string installLocation, string source = null) diff --git a/tests/pester-tests/commands/choco-info.Tests.ps1 b/tests/pester-tests/commands/choco-info.Tests.ps1 index 19ec2432a..8a5e77cc0 100644 --- a/tests/pester-tests/commands/choco-info.Tests.ps1 +++ b/tests/pester-tests/commands/choco-info.Tests.ps1 @@ -50,7 +50,7 @@ } It "Should contain source and deployment location summary" { - $Output.Lines | Should -Contain "Package installed from: $PSScriptRoot\testpackages" -Because $Output.String + $Output.Lines | Should -Contain "Source package was installed from: $PSScriptRoot\testpackages" -Because $Output.String $Output.String | Should -Match "Deployed to:" } } From e138382bf59c0c952f99416a47232ac73b289c80 Mon Sep 17 00:00:00 2001 From: Cory Knox Date: Fri, 17 Oct 2025 14:01:02 -0700 Subject: [PATCH 5/6] (maint) Document and format for PackageResult This commit adds documentation to the PackageResult class, and slightly adjusts the formatting of the constructors to make them clearer. --- .../infrastructure/results/PackageResult.cs | 69 +++++++++++++++---- 1 file changed, 57 insertions(+), 12 deletions(-) diff --git a/src/chocolatey/infrastructure/results/PackageResult.cs b/src/chocolatey/infrastructure/results/PackageResult.cs index 144320df1..a64d5f8d7 100644 --- a/src/chocolatey/infrastructure/results/PackageResult.cs +++ b/src/chocolatey/infrastructure/results/PackageResult.cs @@ -41,13 +41,35 @@ public bool Warning get { return Messages.Any(x => x.MessageType == ResultType.Warn); } } + /// + /// Name of the package installed. + /// public string Name { get; private set; } + /// + /// Version of the package installed. + /// public string Version { get; private set; } + /// + /// Instance of representing the nuspec file in memory. + /// public IPackageMetadata PackageMetadata { get; private set; } + /// + /// Instance of representing the package data returned from a repository. + /// public IPackageSearchMetadata SearchMetadata { get; private set; } + /// + /// Location on disk that the package has been installed to. + /// public string InstallLocation { get; set; } + /// + /// Sources available during package installation. + /// public string Source { get; set; } + [Obsolete("This property is deprecated and will be removed in v3.")] public string SourceUri { get; set; } + /// + /// The package source used to install the package. + /// public string SourceInstalledFrom { get; set; } public int ExitCode { get; set; } @@ -59,13 +81,27 @@ public void ResetMetadata(IPackageMetadata metadata, IPackageSearchMetadata sear Version = metadata.Version.ToNormalizedStringChecked(); } - public PackageResult(IPackageMetadata packageMetadata, string installLocation, string source = null) : this(packageMetadata.Id, packageMetadata.Version.ToNormalizedStringChecked(), installLocation) + /// + /// Initializes a new instance of the class. + /// + /// Instance of representing the nuspec file in memory. Assigned to + /// Assigned to + /// Sources available during package installation. Assigned to + public PackageResult(IPackageMetadata packageMetadata, string installLocation, string source = null) + : this(packageMetadata.Id, packageMetadata.Version.ToNormalizedStringChecked(), installLocation) { PackageMetadata = packageMetadata; Source = source; } - public PackageResult(IPackageSearchMetadata packageSearch, string installLocation, string source = null) : this(packageSearch.Identity.Id, packageSearch.Identity.Version.ToNormalizedStringChecked(), installLocation) + /// + /// Initializes a new instance of the class. + /// + /// Instance of representing the package data returned from a repository. Assigned to + /// Assigned to + /// Sources available during package installation. Assigned to + public PackageResult(IPackageSearchMetadata packageSearch, string installLocation, string source = null) + : this(packageSearch.Identity.Id, packageSearch.Identity.Version.ToNormalizedStringChecked(), installLocation) { SearchMetadata = packageSearch; Source = source; @@ -105,22 +141,23 @@ public PackageResult(IPackageSearchMetadata packageSearch, string installLocatio } [Obsolete("This overload is deprecated and will be removed in v3.")] - public PackageResult(IPackageMetadata packageMetadata, IPackageSearchMetadata packageSearch, string installLocation, string source = null) : this(packageMetadata, packageSearch, installLocation, source, null) - { - } + public PackageResult(IPackageMetadata packageMetadata, IPackageSearchMetadata packageSearch, string installLocation, string source = null) + : this(packageMetadata, packageSearch, installLocation, source, null) { } /// /// Initializes a new instance of the class. /// - /// - /// - /// - /// The sources configured at the time of package installation. - /// The package source used to install the package. - public PackageResult(IPackageMetadata packageMetadata, IPackageSearchMetadata packageSearch, string installLocation, string source, string sourceInstalledFrom) : this(packageMetadata.Id, packageMetadata.Version.ToNormalizedStringChecked(), installLocation) + /// Instance of representing the nuspec file in memory. Assigned to + /// Instance of representing the package data returned from a repository. Assigned to + /// Assigned to + /// Sources available during package installation. Assigned to + /// The package source used to install the package. Assigned to + public PackageResult(IPackageMetadata packageMetadata, IPackageSearchMetadata packageSearch, string installLocation, string source, string sourceInstalledFrom) + : this(packageMetadata.Id, packageMetadata.Version.ToNormalizedStringChecked(), installLocation) { SearchMetadata = packageSearch; PackageMetadata = packageMetadata; + SourceInstalledFrom = sourceInstalledFrom; var sources = new List(); if (!string.IsNullOrEmpty(source)) { @@ -132,14 +169,22 @@ public PackageResult(IPackageMetadata packageMetadata, IPackageSearchMetadata pa { this.Log().Debug("Unable to determine sources from '{0}'. Using value as is.{1} {2}".FormatWith(source, Environment.NewLine, ex.ToStringSafe())); // source is already set above + // Note: Where above? This seems to be copied/pasted from the overload above, but forgot to actually set the source. + // While this seems like it may be incorrect, we do not currently know if this is an issue at all. return; } } Source = sources.FirstOrDefault(uri => uri.IsFile || uri.IsUnc).ToStringSafe(); - SourceInstalledFrom = sourceInstalledFrom; } + /// + /// Initializes a new instance of the class. + /// + /// Name of the package installed. Assigned to + /// Version of the package installed. Assigned to + /// Location on disk the package was installed to. Assigned to + /// Sources available during package installation. Assigned to public PackageResult(string name, string version, string installLocation, string source = null) { Name = name; From 69a7ac8a77b3f3d11e04be6a018fa54736182a8e Mon Sep 17 00:00:00 2001 From: Cory Knox Date: Mon, 20 Oct 2025 08:19:16 -0700 Subject: [PATCH 6/6] (tests) Include license files in snapshot creation This commit adds the license packages in the snapshot creation. Some of the licensed tests rely on the license packages to ensure it has access to the expected license files. --- .../common/Chocolatey/Initialize-ChocolateyTestInstall.ps1 | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/helpers/common/Chocolatey/Initialize-ChocolateyTestInstall.ps1 b/tests/helpers/common/Chocolatey/Initialize-ChocolateyTestInstall.ps1 index 9019d35ae..e662af7fe 100644 --- a/tests/helpers/common/Chocolatey/Initialize-ChocolateyTestInstall.ps1 +++ b/tests/helpers/common/Chocolatey/Initialize-ChocolateyTestInstall.ps1 @@ -28,6 +28,9 @@ $null = robocopy $env:ChocolateyInstall/lib/chocolatey $Directory/lib/chocolatey /MIR $null = robocopy $env:ChocolateyInstall/lib/chocolatey.extension $Directory/lib/chocolatey.extension /MIR $null = robocopy $env:ChocolateyInstall/lib/chocolatey-agent $Directory/lib/chocolatey-agent /MIR + Get-ChildItem $env:ChocolateyInstall/lib -Filter chocolatey-license-* | ForEach-Object { + $null = robocopy "$($_.FullName)" "$Directory/lib/$($_.Name)" /MIR + } $env:ChocolateyInstall = $Directory Set-ChocolateyTestLocation -Directory $Directory