Robustness & maintenance follow-ups from a code audit

Open
#1,262 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
38/100
Issue type
Refactor
Clarity
Mostly clear
Activity status
Active
Tech stack
docker, javascript, r
Domain
ci-cd, tooling

Research direction

This is a grab-bag; pick one bullet first. For the locale bug, sanitize_r_name() lives in R/add_r_files.R and tests/testthat/test-add_r_files.R:244 is the failing case — reproduce with LANG=C. For deployment, compare add_dockerfile() with add_dockerfile_with_renv() under R/. The test bullets touch tests/testthat/test-install_dev_deps.R and the root .lintr. Done means a fix plus a regression test per bullet, with the Suggests-check script from the issue passing.

Written by the indexing model from the issue text.

Description

enhancement

Smaller points found while auditing master (9938a41). Each one was checked against the code; they're grouped here to avoid flooding the tracker and can be split into dedicated issues if needed.

Robustness
  • sanitize_r_name() depends on the locale. iconv(name, to = "ASCII//TRANSLIT") returns NA in a non-UTF-8 locale (e.g. LANG=C, common in Docker images), and the fallback keeps the raw name, so "éclair" becomes "clair". test-add_r_files.R:244 fails under LANG=C. ?iconv also notes that //TRANSLIT results are platform-dependent. A small explicit transliteration table, or a warning when transliteration fails, would make the result deterministic.
  • The generated "app launches" test never runs in CI. expect_running() calls testthat::skip_if_not(rlang_is_interactive()), so the test added by use_recommended_tests() is always skipped in R CMD check / CI. Related to #690.
  • Production mode is inconsistent across deployment helpers. add_dockerfile(), add_dockerfile_shinyproxy() and add_dockerfile_heroku() don't set golem.app.prod = TRUE in the CMD, while the add_dockerfile_with_renv*() variants do by default. Also, the app_prod key of golem-config.yml is not read by app_prod() (which only reads the R option), which is confusing.
  • run_dev() installs missing packages without asking by default. install_required_packages = TRUE is forwarded as force_install = TRUE to install_dev_deps().
  • Remote agent skills (source = "remote"):
    • the main branch is used with no pinned ref;
    • manifest.yml and the zip archive are downloaded separately, so they can come from different commits;
    • target paths are built from manifest values (targets.*.path, main_file_name, skill names) without validation. A guard against .. / absolute paths would make sure nothing is written outside the project.
  • bundle_resources():
    • CSS files are added as hand-built <link href = "<basename(path)>/...">, which assumes the resource prefix equals basename(path). htmltools::htmlDependency(stylesheet = ) would handle this;
    • version = "0.0.1" is fixed, so the dependency URL never changes between app releases. Defaulting to the app version would help with browser caching.
Tests & tooling
  • Guard against regressions like #1251. Add a test asserting that runtime functions (favicon(), bundle_resources(), add_resource_path(), with_golem_options(), golem_welcome_page(), maintenance_page(), get_golem_options(), app_prod(), activate_js(), invoke_js()) never reach a Suggests-backed helper (fs_*, cli_*, desc_*, ...). They're all clean today; a codetools::findGlobals() walk over the namespace is enough to check it (script below).
  • test-install_dev_deps.R performs real network installs without skip_on_cran() / skip_if_offline(), and asserts nothing when the packages are already installed. Mocking the installer would make it deterministic.
  • .lintr can't be read by lintr. It has no final newline, so lintr fails with "Malformed config file". Either fix it or remove it, since air is the formatter.
  • Dead code: ask_golem_creation_upon_config(), set_name(), and the getRversion() >= "3.5" branch in use_favicon() (Depends: R (>= 3.5.0)).
  • add_js_input_binding() / add_js_output_binding() generate JS through ~80 write_there() calls. A template file in inst/ with placeholders would be easier to read and maintain.
Script used to check runtime functions against Suggests
ns <- asNamespace("golem")
runtime <- c(
  "favicon",
  "bundle_resources",
  "add_resource_path",
  "with_golem_options",
  "golem_welcome_page",
  "maintenance_page",
  "get_golem_options",
  "app_prod",
  "app_dev",
  "activate_js",
  "invoke_js",
  "is_running"
)
suggest_wrappers <- grep(
  "^(fs_|cli_|desc_|usethis_|rstudioapi_|roxygen2_|pkgload_|testthat_|attachment_|dockerfiler_)",
  ls(
    ns,
    all.names = TRUE
  ),
  value = TRUE
)
reach <- function(
  f,
  seen = character()
) {
  if (f %in% seen || !exists(f, ns, inherits = FALSE) || !is.function(ns[[f]])) {
    return(seen)
  }
  seen <- c(
    seen,
    f
  )
  calls <- codetools::findGlobals(
    ns[[f]],
    merge = FALSE
  )$functions
  for (g in intersect(calls, ls(ns, all.names = TRUE))) {
    seen <- reach(
      g,
      seen
    )
  }
  seen
}
for (f in runtime) {
  bad <- intersect(
    reach(f),
    suggest_wrappers
  )
  stopifnot(
    length(bad) == 0
  )
}

Generated by Claude Code

Dominant language
R
Stars
947
Forks
135
PR merge metrics
No merged PRs in 30d

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from ThinkR-open/golem

All issues in ThinkR-open/golem

Similar issues

More R issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.