test_that("ILandRuntimeManager can register and activate local runtimes", { cfg <- ILandConfig$new(config_path = tempfile(fileext = ".json")) data_dir <- tempfile("iland-data-") dir.create(data_dir, recursive = TRUE) rmgr <- ILandRuntimeManager$new(config = cfg, data_dir = data_dir) exe <- tempfile(fileext = if (.Platform$OS.type == "windows") ".exe" else "") file.create(exe) rt <- rmgr$register_runtime( tag = "test-runtime", executable = exe, set_active = TRUE ) expect_equal(rt$tag, "test-runtime") expect_equal(rmgr$get_active_runtime_tag(), "test-runtime") expect_equal(rmgr$get_runtime("test-runtime")$tag, "test-runtime") expect_null(rmgr$get_runtime("missing-runtime")) expect_false(rmgr$set_active_runtime("missing-runtime")) exe_norm <- normalizePath(exe, winslash = "/", mustWork = FALSE) expect_equal(rmgr$get_active_executable(), exe_norm) listed <- rmgr$list_runtimes() expect_true("test-runtime" %in% listed$tag) }) test_that("ILandRuntimeManager ensures runtime from local discovery", { cfg <- ILandConfig$new(config_path = tempfile(fileext = ".json")) data_dir <- tempfile("iland-data-") dir.create(data_dir, recursive = TRUE) repo_root <- tempfile("iland-repo-") dir.create(file.path(repo_root, "build"), recursive = TRUE) exe_name <- if (.Platform$OS.type == "windows") "iLANDc.exe" else "iLANDc" exe_path <- file.path(repo_root, "build", exe_name) file.create(exe_path) cfg$set_repo_root(repo_root) cfg$save() rmgr <- ILandRuntimeManager$new(config = cfg, data_dir = data_dir) resolved <- rmgr$ensure_runtime( repo_root = repo_root, local_tag = "auto-local-test", auto_install_windows = FALSE ) expect_true(is.character(resolved) && length(resolved) == 1L) expect_equal(normalizePath(resolved, winslash = "/", mustWork = FALSE), normalizePath(exe_path, winslash = "/", mustWork = FALSE)) expect_equal(rmgr$get_active_runtime_tag(), "auto-local-test") expect_equal(rmgr$get_active_executable(), normalizePath(exe_path, winslash = "/", mustWork = FALSE)) }) test_that("iland_runtime_ensure wrapper resolves local executable", { cfg <- ILandConfig$new(config_path = tempfile(fileext = ".json")) data_dir <- tempfile("iland-data-") dir.create(data_dir, recursive = TRUE) repo_root <- tempfile("iland-repo-") dir.create(repo_root, recursive = TRUE) exe_name <- if (.Platform$OS.type == "windows") "iLANDc.exe" else "iLANDc" exe_path <- file.path(repo_root, exe_name) file.create(exe_path) cfg$set_repo_root(repo_root) cfg$save() resolved <- iland_runtime_ensure( config = cfg, data_dir = data_dir, repo_root = repo_root, auto_install_windows = FALSE ) expect_equal(normalizePath(resolved, winslash = "/", mustWork = FALSE), normalizePath(exe_path, winslash = "/", mustWork = FALSE)) }) test_that("ILandSession builds quoted command strings", { sess <- iland_session() executable <- file.path(tempdir(), "my runtime", "iLand c.exe") project <- file.path(tempdir(), "my project", "project file.xml") args <- c("--flag", "value with space") command <- sess$build_command( executable = executable, project_file = project, extra_args = args ) expected <- paste(vapply(c(executable, project, args), shQuote, FUN.VALUE = character(1L)), collapse = " ") expect_equal(command, expected) }) test_that("ILandSession start stop and run_once lifecycle works", { rscript <- if (.Platform$OS.type == "windows") { file.path(R.home("bin"), "Rscript.exe") } else { file.path(R.home("bin"), "Rscript") } if (!file.exists(rscript)) { skip("Rscript executable not found") } sess <- iland_session() on.exit(sess$stop(), add = TRUE) sess$start( executable = rscript, extra_args = c("-e", "Sys.sleep(2)") ) expect_true(sess$is_running()) expect_true(sess$status()$running) cmd <- sess$session_command("ping") expect_equal(cmd$command, "ping") exit_status <- sess$wait(timeout = 5) expect_equal(exit_status, 0) res <- sess$run_once( executable = rscript, extra_args = c("-e", "cat('ok')") ) expect_equal(res$status, 0) expect_true(grepl("ok", res$stdout, fixed = TRUE)) sess$stop() expect_false(sess$is_running()) })