From 29d67b95392c1a9d2e9130dad7746fa0eb0e2aca Mon Sep 17 00:00:00 2001 From: Colin Gillespie Date: Fri, 16 Oct 2026 13:35:40 +0100 Subject: [PATCH 1/3] fix: Say CONNECT_API_KEY is missing instead of erroring on NA set_key() called nchar() on the NA from an unset variable, so check() failed with "missing value where TRUE/FALSE needed". It now rejects NA before storing the value, and check_api_key() checks the key first. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01BEZ4ZUv51gFQjAe1WePbJF --- DESCRIPTION | 1 + R/set_key.R | 4 ++-- R/summarise_setup.R | 5 +++-- tests/testthat/test-set_key.R | 16 ++++++++++++++++ 4 files changed, 22 insertions(+), 4 deletions(-) create mode 100644 tests/testthat/test-set_key.R diff --git a/DESCRIPTION b/DESCRIPTION index f578d5f..88d0bd9 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -32,6 +32,7 @@ Suggests: gtExtras, htmltools, testthat (>= 3.0.0), + withr, yaml Remotes: jumpingrivers/audit.base, diff --git a/R/set_key.R b/R/set_key.R index 5a70c9b..cb197db 100644 --- a/R/set_key.R +++ b/R/set_key.R @@ -1,9 +1,9 @@ set_key = function(name, value) { - .connect[[name]] = value - if (is.null(value) || nchar(value) == 0L) { + if (length(value) != 1L || is.na(value) || !nzchar(value)) { error_msg = paste0("Missing ", name) stop(error_msg, call. = FALSE) } + .connect[[name]] = value invisible(value) } diff --git a/R/summarise_setup.R b/R/summarise_setup.R index b7fd43a..11f8282 100644 --- a/R/summarise_setup.R +++ b/R/summarise_setup.R @@ -55,10 +55,11 @@ check_server_accessibility = function(server) { } check_api_key = function(token) { - value = set_key("connect_api_key", get_value("CONNECT_API_KEY", token)) - if (is.na(value)) { + value = get_value("CONNECT_API_KEY", token) + if (is.na(value) || !nzchar(value)) { cli::cli_abort("CONNECT_API_KEY missing") } + set_key("connect_api_key", value) cli::cli_alert_info("API KEY: {cli::col_green(cli::symbol$tick)}") invisible(TRUE) } diff --git a/tests/testthat/test-set_key.R b/tests/testthat/test-set_key.R new file mode 100644 index 0000000..8dfe449 --- /dev/null +++ b/tests/testthat/test-set_key.R @@ -0,0 +1,16 @@ +test_that("set_key() rejects missing values without storing them", { + withr::defer(rm(list = intersect("test_key", ls(.connect)), envir = .connect)) + for (value in list(NULL, NA_character_, "", character(0))) { + expect_error(set_key("test_key", value), "Missing test_key") + } + expect_null(.connect[["test_key"]]) + expect_identical(set_key("test_key", "abc"), "abc") + expect_identical(.connect[["test_key"]], "abc") +}) + +test_that("check_api_key() says when CONNECT_API_KEY is missing", { + withr::local_envvar(CONNECT_API_KEY = NA) + expect_error(check_api_key(NULL), "CONNECT_API_KEY missing") + withr::local_envvar(CONNECT_API_KEY = "") + expect_error(check_api_key(NULL), "CONNECT_API_KEY missing") +}) From 92254011e7db09be041f9395aea4c23a6e9882c2 Mon Sep 17 00:00:00 2001 From: Colin Gillespie Date: Fri, 16 Oct 2026 13:35:40 +0100 Subject: [PATCH 2/3] chore: Bump version to 0.8.6 --- DESCRIPTION | 2 +- NEWS.md | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 88d0bd9..9c5fe63 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Type: Package Package: audit.connect Title: Posit Connect Health Check -Version: 0.8.5 +Version: 0.8.6 Authors@R: person("Jumping", "Rivers", , "info@jumpingrivers.com", role = c("aut", "cre")) Description: Posit Connect Health Check. Deploys various content types to diff --git a/NEWS.md b/NEWS.md index d303b82..ed59889 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,9 @@ +# audit.connect 0.8.6 + +## Bug fixes and minor improvements + +* `check()` says "CONNECT_API_KEY missing" when the key is unset, instead of "missing value where TRUE/FALSE needed" (#71). + # audit.connect 0.8.5 ## New features From 4f6d3bc2a89abcfa1dcf0aaac6ccd4e01f0035fe Mon Sep 17 00:00:00 2001 From: Colin Gillespie Date: Fri, 16 Oct 2026 13:48:40 +0100 Subject: [PATCH 3/3] refactor: Share one missing-value test between set_key() and check_api_key() Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01BEZ4ZUv51gFQjAe1WePbJF --- R/set_key.R | 6 +++++- R/summarise_setup.R | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/R/set_key.R b/R/set_key.R index cb197db..4d556d4 100644 --- a/R/set_key.R +++ b/R/set_key.R @@ -1,5 +1,9 @@ +is_missing = function(value) { + length(value) != 1L || is.na(value) || !nzchar(value) +} + set_key = function(name, value) { - if (length(value) != 1L || is.na(value) || !nzchar(value)) { + if (is_missing(value)) { error_msg = paste0("Missing ", name) stop(error_msg, call. = FALSE) } diff --git a/R/summarise_setup.R b/R/summarise_setup.R index 11f8282..4ae95ec 100644 --- a/R/summarise_setup.R +++ b/R/summarise_setup.R @@ -56,7 +56,7 @@ check_server_accessibility = function(server) { check_api_key = function(token) { value = get_value("CONNECT_API_KEY", token) - if (is.na(value) || !nzchar(value)) { + if (is_missing(value)) { cli::cli_abort("CONNECT_API_KEY missing") } set_key("connect_api_key", value)