(#3461,#3487) Prevent dependency resolution from downgrading packages
Description Of Changes
- Prevent dependency resolution from downgrading packages when
--allow-downgradeis 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
- Run tests through TeamCity/Test Kitchen
- Run all integration tests with
./build.bat --testExecutionType=all --shouldRunOpenCover=false - Run a spattering of manual tests.
Operating Systems Testing
- Windows Server 2019/2016
- Windows 10
Change Types Made
- [x] 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.
- [x] Tests to cover my changes, have been added.
- [x] All new and existing tests passed?
- [ ] PowerShell code changes: PowerShell v3 compatibility checked?
Related Issue
- Fixes #3461
- Fixes #3487
- ENGTASKS-3814
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.
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 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.
@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...