Skip to content

Commit

Permalink
Fix solver when top direct version is ruled out
Browse files Browse the repository at this point in the history
I.e. there are multiple versions of a direct ref,
so the latest (possible) should be installed.

Closes r-lib/pak#538.
  • Loading branch information
gaborcsardi committed Sep 22, 2023
1 parent b254f65 commit 9718c02
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
3 changes: 2 additions & 1 deletion R/solve.R
Expand Up @@ -437,7 +437,8 @@ pkgplan_i_lp_satisfy_direct <- function(lp) {
}
}
}
lapply(seq_len(lp$num_candidates)[lp$pkgs$direct], satisfy)
direct <- setdiff(which(lp$pkgs$direct), lp$ruled_out)
lapply(direct, satisfy)

lp
}
Expand Down
35 changes: 35 additions & 0 deletions tests/testthat/test-solve-conflicts.R
Expand Up @@ -107,3 +107,38 @@ test_that("failed resolution", {
suppressMessages(p2$solve())
expect_snapshot(error = TRUE, p2$stop_for_solution_error())
})

test_that("ruled out direct dep", {
# I.e. there are multiple versions, the newer version is ruled out
# for the current R version, but the older vresion is fine.

# pkgcache::cran_app cannot seem to do this with a single repo
repo1 <- dcf("
Package: pkg1
Version: 1.0.0
")

repo2 <- dcf("
Package: pkg1
Version: 1.0.1
Depends: R (>= 20000.0.0)
")

fake1 <- webfakes::new_app_process(cran_app(repo1))
fake2 <- webfakes::new_app_process(cran_app(repo2))
withr::local_options(repos = c(CRAN = fake1$url(), X = fake2$url()))

lib <- tempfile()
lock <- tempfile()
on.exit(unlink(c(lib, lock), recursive = TRUE), add = TRUE)

p <- suppressMessages(new_pkg_installation_proposal(
c("pkg1"),
config = list(
dependencies = TRUE,
library = lib
)
))
suppressMessages(p$solve())
expect_equal(p$get_solution()$data$version, "1.0.0")
})

0 comments on commit 9718c02

Please sign in to comment.