diff options
| -rw-r--r-- | apt-private/private-install.cc | 8 | ||||
| -rwxr-xr-x | test/integration/test-solver3-evaluation | 44 |
2 files changed, 47 insertions, 5 deletions
diff --git a/apt-private/private-install.cc b/apt-private/private-install.cc index 7103c6dc7..7c9a27290 100644 --- a/apt-private/private-install.cc +++ b/apt-private/private-install.cc @@ -983,6 +983,7 @@ bool DoCacheManipulationFromCommandLine(CommandLine &CmdL, std::vector<PseudoPkg // Fallback to 3.0 if we don't get a result or apport is installed if (not invalidCombinations && _config->Find("APT::Solver", "internal") == "internal" && (not res || (not Cache->FindPkg("apport").end() && Cache->FindPkg("apport")->CurrentVer))) { + bool isUpgrade = distUpgradeMode || UpgradeMode != APT::Upgrade::ALLOW_EVERYTHING; auto internalBroken = Cache->BrokenCount(); auto internalDel = Cache->DelCount(); auto internalInst = Cache->InstCount(); @@ -1006,6 +1007,11 @@ bool DoCacheManipulationFromCommandLine(CommandLine &CmdL, std::vector<PseudoPkg errors.push_back(str); _config->Set("APT::Solver", "internal"); _error->RevertToStack(); + + // Cost factors to compare two solutions + auto solver3Cost = std::make_tuple(Cache->DelCount(), isUpgrade ? -Cache->UpgradeCount() : 0, Cache->InstCount() - Cache->UpgradeCount(), Cache->UpgradeCount()); + auto internalCost = std::make_tuple(internalDel, isUpgrade ? -internalUpgrade : 0, internalInst - internalUpgrade, internalUpgrade); + // An error summary for apport. std::string error; if (solver3Res && Cache->BrokenCount()) @@ -1027,7 +1033,7 @@ bool DoCacheManipulationFromCommandLine(CommandLine &CmdL, std::vector<PseudoPkg solver3.commit(); res = true; } - else if (std::make_tuple(Cache->DelCount(), -Cache->UpgradeCount(), Cache->KeepCount(), Cache->InstCount()) > std::make_tuple(internalDel, -internalUpgrade, internalKeep, internalInst)) + else if (solver3Cost > internalCost) { error = "Failure: The 3.0 solver produced a worse result"; } diff --git a/test/integration/test-solver3-evaluation b/test/integration/test-solver3-evaluation index 71d117f7d..f5a10f5fa 100755 --- a/test/integration/test-solver3-evaluation +++ b/test/integration/test-solver3-evaluation @@ -11,8 +11,8 @@ insertinstalledpackage 'apport' 'all' '3' insertpackage 'unstable' 'x' 'all' '3' 'Depends: a | b' insertpackage 'unstable' 'y' 'all' '3' 'Depends: b | a' insertpackage 'unstable' 'a' 'all' '3' 'Depends: c' -insertpackage 'unstable' 'b' 'all' '3' -insertpackage 'unstable' 'c' 'all' '3' +insertpackage 'unstable' 'b' 'all' '3' 'Source: src' +insertpackage 'unstable' 'c' 'all' '3' 'Source: src' insertpackage 'unstable' 'unrelated' 'all' '3' setupaptarchive @@ -20,6 +20,7 @@ setupaptarchive rm rootdir/etc/apt/apt.conf.d/disable-solver3-context mkdir rootdir/var/log/apt +msgmsg "Test 'worse result'" testsuccess aptget install y x --solver internal -s -o Dir::Apport=var/crash testsuccess sed -i "s/^Date:.*/Date: Sun Mar 9 00:08:41 2025/" rootdir/var/crash/apt-edsp.$(id -u).crash @@ -59,7 +60,7 @@ Package: b Architecture: all Version: 3 APT-ID: 3 -Source: b +Source: src Source-Version: 3 Priority: optional Section: other @@ -73,7 +74,7 @@ Package: c Architecture: all Version: 3 APT-ID: 4 -Source: c +Source: src Source-Version: 3 Priority: optional Section: other @@ -126,6 +127,7 @@ APT-Pin: 100 APT-Candidate: yes " apthelper cat-file rootdir/var/log/apt/edsp.log.zst +msgmsg "Test that solver 3.0 explanations are shown" testfailureequal "Reading package lists... Building dependency tree... Package 'c' is not installed, so not removed @@ -147,6 +149,8 @@ E: The following information from --solver 3.0 may provide additional context: - c:amd64 is not selected for install" apt install -s a c- --solver internal +msgmsg "Test for 'did not find a result'" + rm rootdir/var/crash/apt-edsp.$(id -u).crash testsuccessequal "Reading package lists... @@ -180,3 +184,35 @@ ErrorMessage: - c:amd64 is not selected for install AptSolverDump: $(cat rootdir/var/log/apt/edsp.log.zst | base64 | sed 's#^# #')" cat rootdir/var/crash/apt-edsp.$(id -u).crash + +msgmsg "Test that more upgrades are not better in installs" +# FIXME: This will fail once 3.0 solver tries upgrading by source package. +insertinstalledpackage 'b' 'all' '2' 'Source: src' +insertinstalledpackage 'c' 'all' '2' 'Source: src' + +# No "Writing error report..." +testsuccess rm rootdir/var/crash/apt-edsp.$(id -u).crash +testsuccessequal "Reading package lists... +Building dependency tree... +Solving dependencies... +The following additional packages will be installed: + c +The following packages will be upgraded: + b c +2 upgraded, 0 newly installed, 0 to remove and 0 not upgraded. +Inst b [2] (3 unstable [all]) +Inst c [2] (3 unstable [all]) +Conf b (3 unstable [all]) +Conf c (3 unstable [all])" apt install --solver internal b -s + +testfailure test -e rootdir/var/crash/apt-edsp.$(id -u).crash + +# Safety check to check that the 3.0 result actually looks worse +testsuccessequal "Reading package lists... +Building dependency tree... +Solving dependencies... +The following packages will be upgraded: + b +1 upgraded, 0 newly installed, 0 to remove and 1 not upgraded. +Inst b [2] (3 unstable [all]) +Conf b (3 unstable [all])" apt install --solver 3.0 b -s |
