feat: warn when dev scaffolding fns are called in prod mode#1249
Merged
Conversation
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>
There was a problem hiding this comment.
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 inR/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.Rand 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.
- `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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #808.
Summary
warn_if_in_prod_mode()in R/make_dev.R emits awarning()whenevergetOption('golem.app.prod')isTRUE. The caller name is inferred viasys.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.use_*,add_*andset_golem_*families.add_resource_path()is intentionally left out since it is part of the runtime, not the scaffolding.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