Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(#3461,#3487) Prevent dependency resolution from downgrading packages #3486

Open
wants to merge 11 commits into
base: develop
Choose a base branch
from

Conversation

corbob
Copy link
Member

@corbob corbob commented Jul 16, 2024

Description Of Changes

  • Prevent dependency resolution from downgrading packages when --allow-downgrade is not specified.
  • Prevent packages from installing if a dependent package fails installation.

Motivation and Context

  • Chocolatey 2.3.0 incorrectly allows a package to be downgraded to resolve a dependency when it has not been specified to allow downgrades.
  • Chocolatey 2.3.0 installs a package even if one or more of the packages it depends on fails to install resulting in a broken state.

Testing

  1. Run tests through TeamCity/Test Kitchen
  2. Run all integration tests with ./build.bat --testExecutionType=all --shouldRunOpenCover=false
  3. Run a spattering of manual tests.

Operating Systems Testing

  • Windows Server 2019/2016
  • Windows 10

Change Types Made

  • Bug fix (non-breaking change).
  • Feature / Enhancement (non-breaking change).
  • Breaking change (fix or feature that could cause existing functionality to change).
  • Documentation changes.
  • PowerShell code changes.

Change Checklist

  • Requires a change to the documentation.
  • Documentation has been updated.
  • Tests to cover my changes, have been added.
  • All new and existing tests passed?
  • PowerShell code changes: PowerShell v3 compatibility checked?

Related Issue

@corbob
Copy link
Member Author

corbob commented Jul 16, 2024

This PR is in draft as I still need to run more tests as well as add more tests. And apparently bring the branch in line with the develop branch.

@corbob corbob force-pushed the 3461-downgrades branch 2 times, most recently from 64f2ded to 1731d3e Compare August 12, 2024 23:41
@corbob corbob force-pushed the 3461-downgrades branch 2 times, most recently from 37574fb to 7e225aa Compare August 15, 2024 17:47
@corbob
Copy link
Member Author

corbob commented Aug 15, 2024

This PR is currently based upon #3500, while this will make a review of it prior to #3500 being merged a little awkward, the fix from #3500 is required for some of the pester tests to complete successfully.

@corbob corbob changed the title (#3461) Prevent dependency resolution from downgrading packages (#3461,#3487) Prevent dependency resolution from downgrading packages Aug 15, 2024
@corbob corbob force-pushed the 3461-downgrades branch 2 times, most recently from a4cf193 to 8b82e88 Compare August 15, 2024 20:53
@gep13 gep13 self-requested a review August 16, 2024 15:24
@gep13
Copy link
Member

gep13 commented Aug 22, 2024

@corbob I am going to rebase this PR onto the head of develop, since my PR has now been merged, which will make reviewing this PR easier.

Copy link
Member

@gep13 gep13 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have left a few comments for review.

src/chocolatey/infrastructure.app/services/NugetService.cs Outdated Show resolved Hide resolved
src/chocolatey/infrastructure.app/services/NugetService.cs Outdated Show resolved Hide resolved
src/chocolatey/infrastructure.app/services/NugetService.cs Outdated Show resolved Hide resolved
src/chocolatey/infrastructure.app/services/NugetService.cs Outdated Show resolved Hide resolved
src/chocolatey/infrastructure.app/services/NugetService.cs Outdated Show resolved Hide resolved
@@ -0,0 +1,6 @@
These packages can be used to test the installation or upgrading of packages that have require an existing package to downgrade.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sentence doesn't make much sense to me. Can you re-word?

tests/packages/upgradedowngradesdependency/Readme.md Outdated Show resolved Hide resolved
tests/packages/upgradedowngradesdependency/Readme.md Outdated Show resolved Hide resolved
}
}

Context 'Installing a package with argument (<Argument>) should (<AllowsDowngrade>) downgrade an existing package dependency.' -Tag Downgrade, StopOnFirstPackageFailure -ForEach @(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this test name mention that it includes usage of the StopOnFirstPackageFailure feature?

Copy link
Member Author

@corbob corbob Aug 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It definitely should. I copied it from the other tests, and didn't update the name of it apparently.

Naming is hard, I've tried to encompass what the test is doing...

Comment on lines 10 to 11
<summary>__REPLACE__</summary>
<description>__REPLACE__MarkDown_Okay </description>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should there be words in here to say what this package is for?

Comment on lines 10 to 11
<summary>__REPLACE__</summary>
<description>__REPLACE__MarkDown_Okay </description>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should there be words here to say what this package is for?

Comment on lines 10 to 11
<description>__REPLACE__</description>
<summary>__REPLACE__</summary>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same question again.

Comment on lines +10 to +11
<description>__REPLACE__</description>
<summary>__REPLACE__</summary>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And here

@corbob
Copy link
Member Author

corbob commented Aug 26, 2024

@gep13 I'll add it here instead of in the conversations... The var x and var nullResult I think were taken from my re-use of this code that is currently line 1187 in the PR:

    var nullResult = packageResultsToReturn.GetOrAdd(packageName, new PackageResult(installedPackage.PackageMetadata, pathResolver.GetInstallPath(installedPackage.PackageMetadata.Id)));
    nullResult.Messages.Add(new ResultMessage(ResultType.Error, logMessage));

I think, I did the var x as while debugging I wanted to investiage the object to see if there was anything I could do with it in lieu of what I was.

The var nullResult was a direct copy of the existing code, but as discussed earlier today, it is better to be clear about what the object is for, so I'll either come up with a better name, add a comment, or perhaps not even use a variable...

When a package dependency fails to install, we will now fail the
package as well.
Some of these package already existed on our internal repository, while
some of them have been added for the tests being added.
@corbob corbob marked this pull request as ready for review August 27, 2024 14:49
We have added some tests for the install all command. This adds a new
package source to the testing environment so that we can run the tests
locally and in Test Kitchen.
Add a number of tests for dependency scenarios where we did not have
tests before.
In the NugetService we were using a nullResult variable to allow us to
add messages to the result. We do not need this variable if we're only
adding a single message. This commit removes the unnecessary variables.
This updates the `test-chocolateypath` package to have a description and
removes the unneeded comments. This is related to a GitLab MR that noted
these things when bringing this package into the internal repository.

This reverts commit ffd9aab4b40dc8b47b84de5f3ce91ea22fda7a6d.
Comment on lines +10 to +11
<description>__REPLACE__</description>
<summary>__REPLACE__</summary>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this was missed to be updated with information about what this package is about.

Can we get the description and summary updated to say what the package is for?

packageResultsToReturn
.GetOrAdd(
packageDependencyInfo.Id,
new PackageResult(packageDependencyInfo.Id, packageDependencyInfo.Version.ToStringSafe(), string.Empty)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason you are using ToStringSafe instead of ToNormalizedVersionChecked here?

Or is that method not available here?

@@ -793,6 +800,26 @@ Version was specified as '{0}'. It is possible that version

foreach (SourcePackageDependencyInfo packageDependencyInfo in resolvedPackages)
{
// Don't attempt to action this package if dependencies failed.
if (packageDependencyInfo != null && packageResultsToReturn.Any(r => r.Value.Success != true && packageDependencyInfo.Dependencies.Any(d => d.Id == r.Value.Identity.Id)))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make this dependency any check be case-insensitive?

Just using == here makes it case-sensitive.

@@ -1559,6 +1608,25 @@ public virtual ConcurrentDictionary<string, PackageResult> Upgrade(ChocolateyCon
break;
}

// Don't attempt to action this package if dependencies failed.
if (packageResultsToReturn.Any(r => r.Value.Success != true && packageDependencyInfo.Dependencies.Any(d => d.Id == r.Value.Identity.Id)))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as earlier, can we make this dependency any check case-insensitive?

var logMessage = StringResources.ErrorMessages.DependencyFailedToInstall.FormatWith(packageDependencyInfo.Id, packageDependencyInfo.Version);
packageResultsToReturn.GetOrAdd(
packageDependencyInfo.Id,
new PackageResult(packageDependencyInfo.Id, packageDependencyInfo.Version.ToStringSafe(), string.Empty)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use ToNormalizedVersionChecked?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants