From 41b082145707fa7a74e41d4185e44f136d42c119 Mon Sep 17 00:00:00 2001 From: Rich FitzJohn Date: Fri, 8 Dec 2023 10:54:22 +0000 Subject: [PATCH 1/8] Small ui tweaks --- NAMESPACE | 1 + R/windows.R | 20 +++++++++++++++++ drivers/windows/R/batch.R | 7 ++++++ drivers/windows/R/dide_auth.R | 6 +++++ drivers/windows/R/util.R | 5 +++++ drivers/windows/inst/templates/task_run.bat | 6 +---- drivers/windows/tests/testthat/test-batch.R | 5 +++++ man/windows_credentials.Rd | 25 +++++++++++++++++++++ 8 files changed, 70 insertions(+), 5 deletions(-) create mode 100644 R/windows.R create mode 100644 man/windows_credentials.Rd diff --git a/NAMESPACE b/NAMESPACE index 6256e5ed..9f3e3809 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -16,3 +16,4 @@ export(hermod_task_eval) export(hermod_task_result) export(hermod_task_status) export(hermod_task_submit) +export(windows_credentials) diff --git a/R/windows.R b/R/windows.R new file mode 100644 index 00000000..bbe2ef9a --- /dev/null +++ b/R/windows.R @@ -0,0 +1,20 @@ +##' Register DIDE windows credentials. +##' +##' In order to be able to communicate with the Windows DIDE HPC +##' system, we need to be able to communicate with the HPC portal +##' (), and for this we need your +##' **DIDE** password and username. This is typically, but not always, +##' the same as your Imperial credentials. We store this information +##' securely using the [keyring](https://keyring.r-lib.org/) package, +##' so when unlocking your credentials you will be prompted for your +##' **computer** password, which might differ from either your DIDE or +##' Imperial password if you are not on a windows machine. +##' +##' @title DIDE windows credentials +##' +##' @return Nothing, these functions are called for their side effects. +##' +##' @export +windows_credentials <- function() { + ensure_package("hermod.windows")$dide_credentials() +} diff --git a/drivers/windows/R/batch.R b/drivers/windows/R/batch.R index 3c1dd707..28268be1 100644 --- a/drivers/windows/R/batch.R +++ b/drivers/windows/R/batch.R @@ -38,6 +38,12 @@ template_data <- function(config, path_root) { "ECHO Removing mapping {{drive}}\nnet use {{drive}} /delete /y", network_shares_data) + ## Semicolon delimited list on windows; see "Managing libraries" in + ## https://cran.r-project.org/doc/manuals/r-release/R-admin.html + hermod_library <- paste(unix_path(config$path_lib), + unix_path(config$path_bootstrap), + sep = ";") + list(hostname = hostname(), date = as.character(Sys.time()), hermod_version = hermod_version(), @@ -46,5 +52,6 @@ template_data <- function(config, path_root) { network_shares_delete = paste(network_shares_delete, collapse = "\n"), hermod_root_drive = hermod_root$drive_remote, hermod_root_path = paste0("\\", windows_path(hermod_root$rel)), + hermod_library = hermod_library, cluster_name = config$cluster) } diff --git a/drivers/windows/R/dide_auth.R b/drivers/windows/R/dide_auth.R index 3074379d..08fe35d7 100644 --- a/drivers/windows/R/dide_auth.R +++ b/drivers/windows/R/dide_auth.R @@ -4,6 +4,10 @@ ##' @export dide_authenticate <- function() { if (keyring::keyring_is_locked()) { + cli::cli_text(paste( + "I need to unlock the system keychain in order to load and save your", + "credentials. This might differ from your DIDE password, and will be", + "the password you use to log in to this particular machine")) keyring::keyring_unlock() } @@ -42,6 +46,8 @@ dide_authenticate <- function() { i = "Please try again with 'dide_authenticate()'")) } keyring::key_set_with_value("hermod/dide/username", password = username) + + cli::cli_text("Excellent news! Everything seems to work!") invisible(credentials(username, password)) } diff --git a/drivers/windows/R/util.R b/drivers/windows/R/util.R index c17fae01..d8fc12e1 100644 --- a/drivers/windows/R/util.R +++ b/drivers/windows/R/util.R @@ -103,6 +103,11 @@ windows_path <- function(x) { } +unix_path <- function(x) { + gsub("\\", "/", x, fixed = TRUE) +} + + get_system_username <- function() { Sys.getenv(if (is_windows()) "USERNAME" else "USER", NA_character_) } diff --git a/drivers/windows/inst/templates/task_run.bat b/drivers/windows/inst/templates/task_run.bat index 983f0444..57e74bda 100644 --- a/drivers/windows/inst/templates/task_run.bat +++ b/drivers/windows/inst/templates/task_run.bat @@ -5,10 +5,6 @@ ECHO generated on date: {{date}} ECHO hermod version: {{hermod_version}} ECHO running on: %COMPUTERNAME% -REM variables that get pulled in here -REM * hermod_root_drive - the drive alone (e.g., Q:) -REM * hermod_root_path - the relative path incl. drive to folder with hermod/ - call setr64_{{r_version}}.bat {{network_shares_create}} @@ -17,7 +13,7 @@ call setr64_{{r_version}}.bat cd {{hermod_root_path}} ECHO working directory: %CD% -set R_LIBS_USER=\\fi--didef3.dide.ic.ac.uk\tmp\hermod-testing +set R_LIBS_USER={{hermod_library}} ECHO this is a single task diff --git a/drivers/windows/tests/testthat/test-batch.R b/drivers/windows/tests/testthat/test-batch.R index e41f00dd..e7b4d672 100644 --- a/drivers/windows/tests/testthat/test-batch.R +++ b/drivers/windows/tests/testthat/test-batch.R @@ -14,6 +14,7 @@ test_that("batch data creates entries for share drives", { "network_shares_delete", "hermod_root_drive", "hermod_root_path", + "hermod_library", "cluster_name") expect_setequal(names(dat), nms) expect_true(all(vlapply(dat, function(x) is.character(x) && length(x) == 1))) @@ -22,6 +23,10 @@ test_that("batch data creates entries for share drives", { expect_equal(dat$hermod_root_drive, "X:") expect_equal(dat$hermod_root_path, "\\b\\c") + + expect_equal( + dat$hermod_library, + "hermod/lib/windows/4.3.0;//fi--didef3.dide.ic.ac.uk/tmp/hermod-testing") }) diff --git a/man/windows_credentials.Rd b/man/windows_credentials.Rd new file mode 100644 index 00000000..987690ad --- /dev/null +++ b/man/windows_credentials.Rd @@ -0,0 +1,25 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/windows.R +\name{windows_credentials} +\alias{windows_credentials} +\title{DIDE windows credentials} +\usage{ +windows_credentials() +} +\value{ +Nothing, these functions are called for their side effects. +} +\description{ +Register DIDE windows credentials. +} +\details{ +In order to be able to communicate with the Windows DIDE HPC +system, we need to be able to communicate with the HPC portal +(\url{https::mrcdata.dide.ic.ac.uk/hpc}), and for this we need your +\strong{DIDE} password and username. This is typically, but not always, +the same as your Imperial credentials. We store this information +securely using the \href{https://keyring.r-lib.org/}{keyring} package, +so when unlocking your credentials you will be prompted for your +\strong{computer} password, which might differ from either your DIDE or +Imperial password if you are not on a windows machine. +} From c880255bcc6d72a0988a3b4631098708559ee045 Mon Sep 17 00:00:00 2001 From: Rich FitzJohn Date: Mon, 11 Dec 2023 14:08:50 +0000 Subject: [PATCH 2/8] Generalise test --- drivers/windows/tests/testthat/test-batch.R | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/windows/tests/testthat/test-batch.R b/drivers/windows/tests/testthat/test-batch.R index e7b4d672..d90d1952 100644 --- a/drivers/windows/tests/testthat/test-batch.R +++ b/drivers/windows/tests/testthat/test-batch.R @@ -24,9 +24,10 @@ test_that("batch data creates entries for share drives", { expect_equal(dat$hermod_root_drive, "X:") expect_equal(dat$hermod_root_path, "\\b\\c") - expect_equal( - dat$hermod_library, - "hermod/lib/windows/4.3.0;//fi--didef3.dide.ic.ac.uk/tmp/hermod-testing") + expected <- sprintf( + "hermod/lib/windows/%s;//fi--didef3.dide.ic.ac.uk/tmp/hermod-testing", + version_string(config$r_version, ".")) + expect_equal(dat$hermod_library, expected) }) From b664db46f935db06366769bf4b81ebc27660f821 Mon Sep 17 00:00:00 2001 From: Rich FitzJohn Date: Mon, 11 Dec 2023 14:42:37 +0000 Subject: [PATCH 3/8] Revert additional feature for now --- NAMESPACE | 1 - R/windows.R | 20 -------------------- drivers/windows/R/provision.R | 3 +-- man/windows_credentials.Rd | 25 ------------------------- 4 files changed, 1 insertion(+), 48 deletions(-) delete mode 100644 R/windows.R delete mode 100644 man/windows_credentials.Rd diff --git a/NAMESPACE b/NAMESPACE index 9f3e3809..6256e5ed 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -16,4 +16,3 @@ export(hermod_task_eval) export(hermod_task_result) export(hermod_task_status) export(hermod_task_submit) -export(windows_credentials) diff --git a/R/windows.R b/R/windows.R deleted file mode 100644 index bbe2ef9a..00000000 --- a/R/windows.R +++ /dev/null @@ -1,20 +0,0 @@ -##' Register DIDE windows credentials. -##' -##' In order to be able to communicate with the Windows DIDE HPC -##' system, we need to be able to communicate with the HPC portal -##' (), and for this we need your -##' **DIDE** password and username. This is typically, but not always, -##' the same as your Imperial credentials. We store this information -##' securely using the [keyring](https://keyring.r-lib.org/) package, -##' so when unlocking your credentials you will be prompted for your -##' **computer** password, which might differ from either your DIDE or -##' Imperial password if you are not on a windows machine. -##' -##' @title DIDE windows credentials -##' -##' @return Nothing, these functions are called for their side effects. -##' -##' @export -windows_credentials <- function() { - ensure_package("hermod.windows")$dide_credentials() -} diff --git a/drivers/windows/R/provision.R b/drivers/windows/R/provision.R index fd901c57..fcef9bd0 100644 --- a/drivers/windows/R/provision.R +++ b/drivers/windows/R/provision.R @@ -19,8 +19,7 @@ windows_provision <- function(method, config, path_root, ...) { client <- get_web_client() template <- "BuildQueue" - name <- sprintf("conan:%s", id) - dide_id <- client$submit(path_batch_unc, id, template) + dide_id <- client$submit(path_batch_unc, sprintf("conan:%s", id), template) path_dide_id <- file.path(dirname(path_batch), DIDE_ID) writeLines(dide_id, path_dide_id) diff --git a/man/windows_credentials.Rd b/man/windows_credentials.Rd deleted file mode 100644 index 987690ad..00000000 --- a/man/windows_credentials.Rd +++ /dev/null @@ -1,25 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/windows.R -\name{windows_credentials} -\alias{windows_credentials} -\title{DIDE windows credentials} -\usage{ -windows_credentials() -} -\value{ -Nothing, these functions are called for their side effects. -} -\description{ -Register DIDE windows credentials. -} -\details{ -In order to be able to communicate with the Windows DIDE HPC -system, we need to be able to communicate with the HPC portal -(\url{https::mrcdata.dide.ic.ac.uk/hpc}), and for this we need your -\strong{DIDE} password and username. This is typically, but not always, -the same as your Imperial credentials. We store this information -securely using the \href{https://keyring.r-lib.org/}{keyring} package, -so when unlocking your credentials you will be prompted for your -\strong{computer} password, which might differ from either your DIDE or -Imperial password if you are not on a windows machine. -} From da68b4490df3e53dc92d4149336b4cb57664fbdd Mon Sep 17 00:00:00 2001 From: Rich FitzJohn Date: Tue, 12 Dec 2023 15:24:49 +0000 Subject: [PATCH 4/8] Support for environment provisioning --- DESCRIPTION | 2 +- R/provision.R | 8 +++++--- drivers/windows/R/provision.R | 3 ++- tests/testthat/helper-hermod.R | 3 ++- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 4b0997d0..95879df4 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -25,4 +25,4 @@ Suggests: testthat (>= 3.0.0) Config/testthat/edition: 3 Remotes: - mrc-ide/conan@main-v2 + mrc-ide/conan@environment diff --git a/R/provision.R b/R/provision.R index 22a66eb9..91348011 100644 --- a/R/provision.R +++ b/R/provision.R @@ -14,12 +14,14 @@ ##' @return Nothing ##' ##' @export -hermod_provision <- function(method = NULL, ..., driver = NULL, root = NULL) { +hermod_provision <- function(method = NULL, ..., driver = NULL, + environment = "default", root = NULL) { ## TODO: here, if *no* driver is found that could be that we are ## running on the headnode, either by job submission or directly, ## and we'll need to handle that too. root <- hermod_root(root) - dat <- hermod_driver_prepare(driver, root, environment()) - dat$driver$provision(method, dat$config, root$path$root, ...) + env <- environment_load(environment, root, rlang::current_env()) + dat <- hermod_driver_prepare(driver, root, rlang::current_env()) + dat$driver$provision(method, dat$config, root$path$root, env, ...) invisible() } diff --git a/drivers/windows/R/provision.R b/drivers/windows/R/provision.R index fcef9bd0..656f2d19 100644 --- a/drivers/windows/R/provision.R +++ b/drivers/windows/R/provision.R @@ -1,10 +1,11 @@ ## windows-specific provisioning code, called from hermod -windows_provision <- function(method, config, path_root, ...) { +windows_provision <- function(method, config, path_root, environment, ...) { conan_config <- conan::conan_configure( method, path = path_root, path_lib = config$path_lib, path_bootstrap = config$path_bootstrap, + environment = environment, ...) id <- ids::random_id() diff --git a/tests/testthat/helper-hermod.R b/tests/testthat/helper-hermod.R index 94c74eb2..a71509a2 100644 --- a/tests/testthat/helper-hermod.R +++ b/tests/testthat/helper-hermod.R @@ -60,12 +60,13 @@ elsewhere_result <- function(id, config, path_root) { } -elsewhere_provision <- function(method, config, path_root, ...) { +elsewhere_provision <- function(method, config, path_root, environment, ...) { conan_config <- conan::conan_configure( method, path = path_root, path_lib = file.path("hermod", "lib"), path_bootstrap = .libPaths()[[1]], + environment = environment, ...) stopifnot(conan_config$method == "script") path_there <- config$path From 980848d152a2d0f01422a32ffb0888751eaf96bb Mon Sep 17 00:00:00 2001 From: Rich FitzJohn Date: Tue, 12 Dec 2023 15:25:54 +0000 Subject: [PATCH 5/8] Allow bootstrapping --- drivers/windows/R/bootstrap.R | 10 +++++++ drivers/windows/R/config.R | 6 ++-- drivers/windows/R/util.R | 8 ++++++ drivers/windows/inst/bootstrap.R | 30 ++++++++++++++++++++ drivers/windows/inst/templates/provision.bat | 3 ++ drivers/windows/inst/templates/task_run.bat | 3 ++ 6 files changed, 57 insertions(+), 3 deletions(-) create mode 100644 drivers/windows/R/bootstrap.R create mode 100644 drivers/windows/inst/bootstrap.R diff --git a/drivers/windows/R/bootstrap.R b/drivers/windows/R/bootstrap.R new file mode 100644 index 00000000..24734c78 --- /dev/null +++ b/drivers/windows/R/bootstrap.R @@ -0,0 +1,10 @@ +bootstrap_update <- function(root = NULL) { + path_script <- "hermod/bootstrap-windows.R" + path_root <- hermod:::hermod_root(root)$path$root + path_script_abs <- file.path(path_root, path_script) + dir.create(dirname(path_script_abs), FALSE, TRUE) + writelines_if_different( + readLines(hermod_windows_file("bootstrap.R")), + path_script_abs) + hermod::hermod_provision("script", script = path_script, root = root) +} diff --git a/drivers/windows/R/config.R b/drivers/windows/R/config.R index 9787a0cb..6fae4edb 100644 --- a/drivers/windows/R/config.R +++ b/drivers/windows/R/config.R @@ -1,9 +1,9 @@ windows_configure <- function(shares = NULL, r_version = NULL) { path <- getwd() r_version <- select_r_version(r_version) - path_lib <- file.path("hermod", "lib", "windows", - version_string(r_version, ".")) - path_bootstrap <- "//fi--didef3.dide.ic.ac.uk/tmp/hermod-testing" + r_version_str <- version_string(r_version, ".") + path_lib <- file.path("hermod", "lib", "windows", r_version_str) + path_bootstrap <- sprintf("I:/bootstrap/%s", r_version_str) list(cluster = "wpia-hn", template = "AllNodes", shares = dide_cluster_paths(shares, path), diff --git a/drivers/windows/R/util.R b/drivers/windows/R/util.R index d8fc12e1..097d0c57 100644 --- a/drivers/windows/R/util.R +++ b/drivers/windows/R/util.R @@ -138,6 +138,14 @@ readlines_if_exists <- function(path, ...) { } +writelines_if_different <- function(text, path) { + skip <- file.exists(path) && identical(readLines(path), text) + if (!skip) { + writeLines(text, path) + } +} + + version_string <- function(v, sep = "_") { paste(unclass(v)[[1]], collapse = sep) } diff --git a/drivers/windows/inst/bootstrap.R b/drivers/windows/inst/bootstrap.R new file mode 100644 index 00000000..ae754d43 --- /dev/null +++ b/drivers/windows/inst/bootstrap.R @@ -0,0 +1,30 @@ +path <- sprintf("I:/bootstrap/%s", + paste(unclass(getRversion())[[1]], collapse = ".")) +path_next <- sprintf("%s-next", path) +path_prev <- sprintf("%s-prev", path) +unlink(path_next, recursive = TRUE) +unlink(path_prev, recursive = TRUE) +if (file.exists(path_prev)) { + stop("Failed to remove previous-previous library") +} +if (file.exists(path_next)) { + stop("Failed to remove previous-next library") +} +dir.create(path_next, FALSE, TRUE) +.libPaths(path_next, FALSE) +message(sprintf("Installing packages into %s", path_next)) +pkgs <- c("hermod", "remotes", "pkgdepends") +repos <- c("https://mrc-ide.r-universe.dev", "https://cloud.r-project.org") +install.packages(pkgs, path_next, repos = repos) +ok <- all(file.exists(file.path(path_next, pkgs, "Meta", "package.rds"))) +if (!ok) { + stop("Failed to install all packages") +} +curr_exists <- file.exists(path) +if (curr_exists) { + file.rename(path, path_prev) +} +file.rename(path_next, path) +if (curr_exists) { + unlink(path_prev, recursive = TRUE) +} diff --git a/drivers/windows/inst/templates/provision.bat b/drivers/windows/inst/templates/provision.bat index e897eb3f..7d23f7fc 100644 --- a/drivers/windows/inst/templates/provision.bat +++ b/drivers/windows/inst/templates/provision.bat @@ -5,6 +5,7 @@ ECHO generated on date: {{date}} ECHO hermod version: {{hermod_version}} ECHO running on: %COMPUTERNAME% +net use I: \\wpia-hn\hipercow call setr64_{{r_version}}.bat {{network_shares_create}} @@ -25,6 +26,8 @@ set ErrorCode=%ERRORLEVEL% {{network_shares_delete}} +net use I: /delete /y + set ERRORLEVEL=%ErrorCode% if %ERRORLEVEL% neq 0 ( diff --git a/drivers/windows/inst/templates/task_run.bat b/drivers/windows/inst/templates/task_run.bat index 57e74bda..837a672e 100644 --- a/drivers/windows/inst/templates/task_run.bat +++ b/drivers/windows/inst/templates/task_run.bat @@ -5,6 +5,7 @@ ECHO generated on date: {{date}} ECHO hermod version: {{hermod_version}} ECHO running on: %COMPUTERNAME% +net use I: \\wpia-hn\hipercow call setr64_{{r_version}}.bat {{network_shares_create}} @@ -27,6 +28,8 @@ set ErrorCode=%ERRORLEVEL% {{network_shares_delete}} +net use I: /delete /y + set ERRORLEVEL=%ErrorCode% if %ERRORLEVEL% neq 0 ( From 062219b3770de58d0fd89eb93cbd17c73ab3fc9a Mon Sep 17 00:00:00 2001 From: Rich FitzJohn Date: Tue, 12 Dec 2023 15:44:48 +0000 Subject: [PATCH 6/8] Docs tweaks --- R/provision.R | 3 +++ man/hermod_provision.Rd | 11 ++++++++++- tests/testthat/test-interface.R | 3 ++- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/R/provision.R b/R/provision.R index 91348011..cf29558e 100644 --- a/R/provision.R +++ b/R/provision.R @@ -9,6 +9,9 @@ ##' @param ... Arguments passed through to conan. See docs that we ##' need to write still. ##' +##' @param environment The name of the environment to provision (see +##' [hermod_environment_create] for details). +##' ##' @inheritParams hermod_task_submit ##' ##' @return Nothing diff --git a/man/hermod_provision.Rd b/man/hermod_provision.Rd index 7b6b60c3..975072b0 100644 --- a/man/hermod_provision.Rd +++ b/man/hermod_provision.Rd @@ -4,7 +4,13 @@ \alias{hermod_provision} \title{Provision cluster library} \usage{ -hermod_provision(method = NULL, ..., driver = NULL, root = NULL) +hermod_provision( + method = NULL, + ..., + driver = NULL, + environment = "default", + root = NULL +) } \arguments{ \item{method}{The provisioning method to use, defaulting to @@ -16,6 +22,9 @@ need to write still.} \item{driver}{The name of the driver to use, or you can leave blank if only one is configured (this will be typical).} +\item{environment}{The name of the environment to provision (see +\link{hermod_environment_create} for details).} + \item{root}{The hermod root} } \value{ diff --git a/tests/testthat/test-interface.R b/tests/testthat/test-interface.R index 996a0dbc..d17eb397 100644 --- a/tests/testthat/test-interface.R +++ b/tests/testthat/test-interface.R @@ -129,7 +129,8 @@ test_that("can call provision", { hermod_provision(root = path_here, show_log = FALSE) mockery::expect_called(mock_provision, 1) + environment <- new_environment("default", NULL, NULL) expect_equal( mockery::mock_args(mock_provision)[[1]], - list(NULL, config, path_root, show_log = FALSE)) + list(NULL, config, path_root, environment, show_log = FALSE)) }) From f7030acad7e411684430f62dd61f6383c714a7e9 Mon Sep 17 00:00:00 2001 From: Rich FitzJohn Date: Tue, 12 Dec 2023 16:25:34 +0000 Subject: [PATCH 7/8] Use main-v2 in conan --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 95879df4..4b0997d0 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -25,4 +25,4 @@ Suggests: testthat (>= 3.0.0) Config/testthat/edition: 3 Remotes: - mrc-ide/conan@environment + mrc-ide/conan@main-v2 From 429e57012282e4d98213f02de1a2c2aea9dc2d07 Mon Sep 17 00:00:00 2001 From: Rich FitzJohn Date: Tue, 12 Dec 2023 16:26:03 +0000 Subject: [PATCH 8/8] Fix tests, incl test for bootstrap --- drivers/windows/tests/testthat/test-batch.R | 5 ++--- .../windows/tests/testthat/test-bootstrap.R | 15 ++++++++++++++ drivers/windows/tests/testthat/test-config.R | 3 +-- .../windows/tests/testthat/test-provision.R | 9 +++++---- drivers/windows/tests/testthat/test-util.R | 20 +++++++++++++++++++ 5 files changed, 43 insertions(+), 9 deletions(-) create mode 100644 drivers/windows/tests/testthat/test-bootstrap.R diff --git a/drivers/windows/tests/testthat/test-batch.R b/drivers/windows/tests/testthat/test-batch.R index d90d1952..2df589be 100644 --- a/drivers/windows/tests/testthat/test-batch.R +++ b/drivers/windows/tests/testthat/test-batch.R @@ -24,9 +24,8 @@ test_that("batch data creates entries for share drives", { expect_equal(dat$hermod_root_drive, "X:") expect_equal(dat$hermod_root_path, "\\b\\c") - expected <- sprintf( - "hermod/lib/windows/%s;//fi--didef3.dide.ic.ac.uk/tmp/hermod-testing", - version_string(config$r_version, ".")) + v <- version_string(config$r_version, ".") + expected <- sprintf("hermod/lib/windows/%s;I:/bootstrap/%s", v, v) expect_equal(dat$hermod_library, expected) }) diff --git a/drivers/windows/tests/testthat/test-bootstrap.R b/drivers/windows/tests/testthat/test-bootstrap.R new file mode 100644 index 00000000..8587a596 --- /dev/null +++ b/drivers/windows/tests/testthat/test-bootstrap.R @@ -0,0 +1,15 @@ +test_that("can run bootstrap", { + mount <- withr::local_tempfile() + root <- example_root(mount, "b/c") + mock_hermod_provision <- mockery::mock() + mockery::stub(bootstrap_update, "hermod::hermod_provision", + mock_hermod_provision) + + bootstrap_update(root) + mockery::expect_called(mock_hermod_provision, 1) + expect_true(file.exists( + file.path(root$path$root, "hermod", "bootstrap-windows.R"))) + expect_equal( + mockery::mock_args(mock_hermod_provision)[[1]], + list("script", script = "hermod/bootstrap-windows.R", root = root)) +}) diff --git a/drivers/windows/tests/testthat/test-config.R b/drivers/windows/tests/testthat/test-config.R index 8b1b1e99..c629b4b1 100644 --- a/drivers/windows/tests/testthat/test-config.R +++ b/drivers/windows/tests/testthat/test-config.R @@ -13,8 +13,7 @@ test_that("Can create configuration", { expect_equal(config$shares, list(shares)) expect_equal(config$r_version, numeric_version("4.3.0")) expect_equal(config$path_lib, "hermod/lib/windows/4.3.0") - expect_equal(config$path_bootstrap, - "//fi--didef3.dide.ic.ac.uk/tmp/hermod-testing") + expect_equal(config$path_bootstrap, "I:/bootstrap/4.3.0") }) diff --git a/drivers/windows/tests/testthat/test-provision.R b/drivers/windows/tests/testthat/test-provision.R index 234509a9..525485e2 100644 --- a/drivers/windows/tests/testthat/test-provision.R +++ b/drivers/windows/tests/testthat/test-provision.R @@ -13,18 +13,18 @@ test_that("can run provision script", { config <- root$config$windows msg <- capture_messages( - windows_provision("script", config, path_root, poll = 0)) + windows_provision("script", config, path_root, NULL, poll = 0)) mockery::expect_called(mock_get_client, 1) expect_equal(mockery::mock_args(mock_get_client)[[1]], list()) mockery::expect_called(mock_client$submit, 1) args <- mockery::mock_args(mock_client$submit)[[1]] - expect_match(args[[2]], "^[[:xdigit:]]{32}$") + expect_match(args[[2]], "^conan:[[:xdigit:]]{32}$") id <- args[[2]] batch_path <- windows_path(file.path( "//host.dide.ic.ac.uk/share/path/b/c/hermod/provision", - id, + sub("^conan:", "", id), "provision.bat")) expect_equal(args, list(batch_path, id, "BuildQueue")) @@ -46,6 +46,7 @@ test_that("error on provision script failure", { path_root <- root$path$root config <- root$config$windows expect_error( - suppressMessages(windows_provision("script", config, path_root, poll = 0)), + suppressMessages( + windows_provision("script", config, path_root, NULL, poll = 0)), "Installation failed") }) diff --git a/drivers/windows/tests/testthat/test-util.R b/drivers/windows/tests/testthat/test-util.R index 5344e9ca..e61b4a36 100644 --- a/drivers/windows/tests/testthat/test-util.R +++ b/drivers/windows/tests/testthat/test-util.R @@ -115,3 +115,23 @@ test_that("readlines from file if exists returns null if file missing", { writeLines(c("a", "b"), path) expect_equal(readlines_if_exists(path), c("a", "b")) }) + + +test_that("writelines_if_not_exists updates files when different", { + path <- withr::local_tempfile() + writelines_if_different(c("a", "b"), path) + expect_equal(readLines(path), c("a", "b")) + + writelines_if_different(c("a", "b", "c"), path) + expect_equal(readLines(path), c("a", "b", "c")) +}) + + +test_that("writelines_if_not_exists does not update file when not different", { + path <- withr::local_tempfile() + writeLines(c("a", "b"), path) + mock_writelines <- mockery::mock() + mockery::stub(writelines_if_different, "writeLines", mock_writelines) + writelines_if_different(c("a", "b"), path) + mockery::expect_called(mock_writelines, 0) +})