From 5474dc9b5bb3f93601a64a0c818e65279cee65da Mon Sep 17 00:00:00 2001 From: Yanick Witschi Date: Wed, 13 Sep 2023 10:42:47 +0200 Subject: [PATCH] Fixed replaced packages being incorrectly missing when unlocked by an old version (#11629) Co-authored-by: Nils Adermann --- .../DependencyResolver/PoolBuilder.php | 4 ++ ...aced-root-package-if-replacer-dropped.test | 49 +++++++++++++++++++ ...multi-repo-replace-partial-update-all.test | 2 + 3 files changed, 55 insertions(+) create mode 100644 tests/Composer/Test/DependencyResolver/Fixtures/poolbuilder/load-replaced-root-package-if-replacer-dropped.test diff --git a/src/Composer/DependencyResolver/PoolBuilder.php b/src/Composer/DependencyResolver/PoolBuilder.php index 58dfd7967..aa6f5019b 100644 --- a/src/Composer/DependencyResolver/PoolBuilder.php +++ b/src/Composer/DependencyResolver/PoolBuilder.php @@ -672,6 +672,10 @@ class PoolBuilder private function markPackageNameForLoadingIfRequired(Request $request, string $name): void { + if ($this->isRootRequire($request, $name)) { + $this->markPackageNameForLoading($request, $name, $request->getRequires()[$name]); + } + foreach ($this->packages as $package) { foreach ($package->getRequires() as $link) { if ($name === $link->getTarget()) { diff --git a/tests/Composer/Test/DependencyResolver/Fixtures/poolbuilder/load-replaced-root-package-if-replacer-dropped.test b/tests/Composer/Test/DependencyResolver/Fixtures/poolbuilder/load-replaced-root-package-if-replacer-dropped.test new file mode 100644 index 000000000..7e78503d6 --- /dev/null +++ b/tests/Composer/Test/DependencyResolver/Fixtures/poolbuilder/load-replaced-root-package-if-replacer-dropped.test @@ -0,0 +1,49 @@ +--TEST-- +Ensure that a root package gets loaded which is replaced by old versions of another requirement + +--REQUEST-- +{ + "require": { + "root/dep": "*", + "replaced/pkg": "1.0.0" + }, + "locked": [ + {"name": "root/dep", "version": "1.1.0", "require": {"replacer/pkg": "1.*"}}, + {"name": "replacer/pkg", "version": "1.1.0"}, + {"name": "replaced/pkg", "version": "1.0.0"} + ], + "allowList": [ + "root/dep" + ], + "allowTransitiveDeps": true +} + +--FIXED-- +[ +] + +--PACKAGE-REPOS-- +[ + [ + {"name": "root/dep", "version": "1.2.0", "require": {"replacer/pkg": "1.*"}}, + {"name": "replacer/pkg", "version": "1.0.0", "replace": {"replaced/pkg": "1.0.0"}}, + {"name": "replacer/pkg", "version": "1.1.0"}, + {"name": "replaced/pkg", "version": "1.0.0"} + ] +] + +--EXPECT-- +[ + "replaced/pkg-1.0.0.0", + "replacer/pkg-1.0.0.0", + "replacer/pkg-1.1.0.0", + "root/dep-1.2.0.0" +] + +--EXPECT-OPTIMIZED-- +[ + "replaced/pkg-1.0.0.0", + "replacer/pkg-1.0.0.0", + "replacer/pkg-1.1.0.0", + "root/dep-1.2.0.0" +] diff --git a/tests/Composer/Test/DependencyResolver/Fixtures/poolbuilder/multi-repo-replace-partial-update-all.test b/tests/Composer/Test/DependencyResolver/Fixtures/poolbuilder/multi-repo-replace-partial-update-all.test index 5ffd3ce14..b681f26cd 100644 --- a/tests/Composer/Test/DependencyResolver/Fixtures/poolbuilder/multi-repo-replace-partial-update-all.test +++ b/tests/Composer/Test/DependencyResolver/Fixtures/poolbuilder/multi-repo-replace-partial-update-all.test @@ -97,6 +97,7 @@ Check that replacers from additional repositories are loaded when doing a partia --EXPECT-- [ + "base/package-1.0.0.0", "indirect/replacer-1.2.0.0", "indirect/replacer-1.0.0.0", "replacer/package-1.2.0.0", @@ -107,6 +108,7 @@ Check that replacers from additional repositories are loaded when doing a partia --EXPECT-OPTIMIZED-- [ + "base/package-1.0.0.0", "indirect/replacer-1.2.0.0", "indirect/replacer-1.0.0.0", "replacer/package-1.2.0.0",