build-cran-binaries/local/tests/test-newer-r-helpers.R
pat-s c3e95f7c69
perf(build-newer-r): skip packages that already have a binary in bulk
Decide the already-built candidates from one listing per slot and one ABI-verdict query instead of a DB connection and several S3 requests per package; anything undecidable still goes through bincraft.
2026-10-23 13:16:33 +00:00

149 lines
4.5 KiB
R

source(file.path("..", "newer-r-helpers.R"))
source(file.path("..", "rebuild-missing-helpers.R"))
test_that("R constraints respect patch versions, bounds, and missing fields", {
expect_true(r_requirement_satisfied(NA_character_, "4.4.3"))
expect_true(r_requirement_satisfied(
"Matrix (>= 1.4-0), R (>= 4.5.0)",
"4.5.3"
))
expect_false(r_requirement_satisfied("R (>= 4.5.0)", "4.4.3"))
expect_false(r_requirement_satisfied("R (>= 4.5.4)", "4.5.3"))
expect_true(r_requirement_satisfied("R (>= 4.5), R (< 4.6)", "4.5.3"))
expect_false(r_requirement_satisfied("R (>= 4.5), R (< 4.6)", "4.6.0"))
expect_true(r_requirement_satisfied("R (== 4.5.3)", "4.5.3"))
expect_true(r_requirement_satisfied("R (> 4.5.2), R (<= 4.5.3)", "4.5.3"))
expect_true(r_requirement_satisfied("R, Rcpp (>= 1.0)", "4.4.3"))
expect_error(r_requirement_satisfied("R (~ 4.5)", "4.5.3"), "Cannot parse")
})
fixture <- function() {
data.frame(
Package = c(
"arules",
"arulesSequences",
"indirect",
"optional",
"ordinary",
"future",
"blocked"
),
Version = rep("1.0", 7L),
Depends = c(
"R (>= 4.5.0)",
"arules",
NA,
NA,
"R (>= 4.0)",
"R (>= 4.7)",
NA
),
Imports = c(NA, NA, "arulesSequences", NA, NA, NA, "arules, future"),
LinkingTo = NA_character_,
Suggests = c(NA, NA, NA, "arules", NA, NA, NA)
)
}
test_that("every compatible newer minor includes required dependents only", {
db <- fixture()
for (target in c("4.5.3", "4.6.0")) {
expect_identical(
newer_r_candidates(db, "4.4.3", target)$Package,
c("arules", "arulesSequences", "indirect")
)
}
expect_equal(nrow(newer_r_candidates(db, "4.4.3", "4.4.3")), 0L)
expect_equal(nrow(newer_r_candidates(db, "4.5.3", "4.4.3")), 0L)
expect_equal(nrow(newer_r_candidates(db, "4.5.3", "4.6.0")), 0L)
})
test_that("LinkingTo, dependency cycles, Windows and empty metadata are handled", {
db <- fixture()
db$LinkingTo[5L] <- "arules"
db$Imports[1L] <- "ordinary"
db$OS_type <- c(NA, "windows", rep(NA_character_, 5L))
expect_identical(
newer_r_candidates(db, "4.4.3", "4.6.0")$Package,
c("arules", "indirect", "ordinary")
)
expect_equal(nrow(newer_r_candidates(db[FALSE, ], "4.4.3", "4.6.0")), 0L)
})
test_that("R-devel Recommended copies cannot block ordinary CRAN dependencies", {
db <- fixture()
db$Path <- NA_character_
future_copy <- db[1L, ]
future_copy$Depends <- "R (>= 4.7)"
future_copy$Path <- "4.7.0/Recommended"
expect_identical(
newer_r_candidates(rbind(future_copy, db), "4.4.3", "4.6.1")$Package,
c("arules", "arulesSequences", "indirect")
)
})
candidates <- function() {
data.frame(
Package = c(
"flat_done",
"flat_todo",
"minor_done",
"minor_flat_only",
"unclassified",
"fallback"
),
Version = c("1.0", "1.0", "2.0", "2.0", "3.0", "4.0")
)
}
verdicts <- c(
flat_done_1.0 = FALSE,
flat_todo_1.0 = FALSE,
minor_done_2.0 = TRUE,
minor_flat_only_2.0 = TRUE,
fallback_4.0 = FALSE
)
flat <- c(
flat_done_1.0.tar.gz = "aaa",
minor_flat_only_2.0.tar.gz = "bbb",
unclassified_3.0.tar.gz = "ccc",
fallback_4.0.tar.gz = "c0ffee"
)
minor <- c(minor_done_2.0.tar.gz = "ddd")
md5 <- c(fallback_4.0 = "c0ffee")
test_that("newer_r_outstanding skips only binaries at the routed path", {
expect_identical(
newer_r_outstanding(candidates(), verdicts, flat, minor, md5)$Package,
# flat_todo: absent; minor_flat_only: sensitive, so a flat copy does not
# count; unclassified: no verdict, left to bincraft; fallback: CRAN source
c("flat_todo", "minor_flat_only", "unclassified", "fallback")
)
})
test_that("newer_r_outstanding keeps a route whose slot could not be listed", {
expect_identical(
newer_r_outstanding(candidates(), verdicts, NULL, minor, md5)$Package,
c("flat_done", "flat_todo", "minor_flat_only", "unclassified", "fallback")
)
expect_identical(
newer_r_outstanding(candidates(), verdicts, flat, NULL, md5)$Package,
c("flat_todo", "minor_done", "minor_flat_only", "unclassified", "fallback")
)
})
test_that("newer_r_outstanding without verdicts or listings changes nothing", {
expect_identical(
newer_r_outstanding(candidates(), logical(), flat, minor, md5),
candidates()
)
empty <- stats::setNames(character(), character())
expect_identical(
nrow(newer_r_outstanding(candidates(), verdicts, empty, empty, md5)),
nrow(candidates())
)
expect_identical(
nrow(newer_r_outstanding(candidates()[0L, ], verdicts, flat, minor, md5)),
0L
)
})