Skip to content

feat: warn when dev scaffolding fns are called in prod mode#1249

Merged
ColinFay merged 2 commits into
masterfrom
warn-dev-fns-in-prod-master
May 19, 2026
Merged

feat: warn when dev scaffolding fns are called in prod mode#1249
ColinFay merged 2 commits into
masterfrom
warn-dev-fns-in-prod-master

Conversation

@ColinFay
Copy link
Copy Markdown
Member

Closes #808.

Summary

  • New internal helper warn_if_in_prod_mode() in R/make_dev.R emits a warning() whenever getOption('golem.app.prod') is TRUE. The caller name is inferred via sys.call(-1), so the message reads like \`use_external_file()\` is a development function and should not be called when {golem} is in production mode.
  • Wired into 50 exported scaffolding functions across the use_*, add_* and set_golem_* families. add_resource_path() is intentionally left out since it is part of the runtime, not the scaffolding.
  • Tests cover the helper in isolation (TRUE / FALSE / NULL cases) and three representative call sites (use_external_file(), add_module(), set_golem_name()).

NEWS.md

New features

Test plan

  • devtools::test() — 637 PASS, 0 FAIL.
  • devtools::check() — 0 errors, 0 warnings, 1 environmental NOTE.

🤖 Generated with Claude Code

Closes #808.

- New internal helper `warn_if_in_prod_mode()` in `R/make_dev.R` emits a
  `warning()` when `getOption('golem.app.prod')` is TRUE, naming the
  caller via `sys.call(-1)`.
- Wired into 50 exported scaffolding functions across `use_*`, `add_*`
  and `set_golem_*` families so that calling them from a deployed app
  surfaces a visible alert. `add_resource_path()` is intentionally left
  out since it is part of the runtime, not the scaffolding.

- `devtools::test()` — 608 PASS, 0 FAIL.
- `devtools::check()` — 0 errors, 0 warnings, 1 NOTE (environmental
  "unable to verify current time").
- New tests cover the helper in isolation (TRUE/FALSE/NULL cases) and
  three representative call sites (`use_external_file()`, `add_module()`,
  `set_golem_name()`).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a guard to ~50 dev-time scaffolding functions (use_*, add_*, set_golem_*) so they emit a warning when invoked while options('golem.app.prod') is TRUE, addressing #808. A new internal helper warn_if_in_prod_mode() infers the caller via sys.call(-1) and warns; add_resource_path() is deliberately excluded.

Changes:

  • New warn_if_in_prod_mode() helper in R/make_dev.R.
  • Calls inserted at the top of all in-scope scaffolding functions across many R/ files.
  • Tests added in tests/testthat/test-make_dev.R and NEWS entry added.

Reviewed changes

Copilot reviewed 19 out of 19 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
R/make_dev.R New warn_if_in_prod_mode() helper.
R/add_files.R, R/add_r_files.R, R/add_rstudio_files.R, R/add_ci_files.R, R/add_dockerfiles.R, R/add_dockerfiles_renv.R Insert guard in each add_* scaffolding function.
R/use_files_external.R, R/use_files_internal.R, R/use_utils.R, R/use_readme.R, R/use_recommended.R, R/use_favicon.R, R/use_agent_skills.R Insert guard in each use_* scaffolding function.
R/modules_fn.R Guard in add_module().
R/golem-yaml-set.R, R/set_golem_options.R Guard in set_golem_* functions.
tests/testthat/test-make_dev.R Tests for helper and three representative call sites.
NEWS.md Documents the new warning.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread R/make_dev.R
Comment thread tests/testthat/test-make_dev.R
Comment thread tests/testthat/test-make_dev.R Outdated
- `warn_if_in_prod_mode()` now uses `deparse(fun_call[[1L]])` instead of
  `as.character()` so the caller name is rendered correctly when the
  function is invoked as `golem::use_external_file()` (previously the
  message read ```::()` is a development function``` because
  `as.character()` on a `::` call returns `c("::", "golem", "fn")`).
- New test exercises the namespaced call form to lock the behavior.
- Test side-effects move from the shared `tempdir()` to
  `withr::local_tempdir()` for proper sandboxing.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@ColinFay ColinFay merged commit 06b3abd into master May 19, 2026
12 checks passed
@ColinFay ColinFay deleted the warn-dev-fns-in-prod-master branch May 19, 2026 14:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

dev functions should print an alert if not in dev mode

2 participants