Skip to content

Lua API: env shortcode reads the per-render environment snapshot (stacked on #949) - #950

Merged
cscheid merged 2 commits into
mainfrom
feature/bd-irkfpip1-env-shortcode-snapshot
Oct 28, 2026
Merged

cscheid merged 2 commits into
mainfrom
feature/bd-irkfpip1-env-shortcode-snapshot

Conversation

@cscheid

@cscheid cscheid commented Oct 27, 2026

Copy link
Copy Markdown
Member

Stacked on #949 (base: feature/lua-api-q1-parity). Strand bd-irkfpip1, a follow-up noted in #949's plan.

What changes

The {{< env NAME >}} shortcode now reads the same per-render environment snapshot that #949 introduced for Lua filters' and shortcode scripts' os.getenv (StageContext::env_snapshot: real environment, then _environment file values for missing keys, then QUARTO_PROFILE forced to the active profile list). Before this, EnvShortcodeHandler re-did that three-way merge at every lookup with std::env::var on a worker thread, so the shortcode and a filter could in principle disagree, and the real environment was read in two places.

  • ShortcodeResolveTransform::with_lua_support and the two pipeline builders (build_transform_pipeline, build_q2_preview_transform_pipeline) take an Option<Arc<EnvSnapshot>> in place of the project_env + quarto_profile pair. The transform hands the same Arc to the env handler and to the Lua engine's HostContext.
  • That made the RenderContext.env_snapshot bridge added in Lua API: quarto.project, quarto.doc paths, comparable quarto.version, os.exit fails the document (GH #939-#942) #949 unnecessary; it is removed.
  • Without a snapshot (custom pipelines, unit tests that build a transform directly) the handler reads the real process environment, exactly as before.
  • All 47 builder call sites had the same trailing Default::default(), None shape and were rewritten by script; no behavior change at any of them.
  • The handler's tests now drive a snapshot directly instead of mutating the process environment, except the one that pins the no-snapshot fallback.

Verification

🤖 Generated with Claude Code

The env shortcode handler merged QUARTO_PROFILE, the real environment and
_environment file values at every lookup, while Lua filters and shortcode
scripts read os.getenv from the snapshot StageContext::new takes once per
document (GH #939). Two sources for one environment can drift and the
handler's std::env::var ran at resolve time on a worker thread.

ShortcodeResolveTransform now carries the snapshot: with_lua_support and
the two pipeline builders take an Option<Arc<EnvSnapshot>> in place of
the project_env + quarto_profile pair, the env handler holds the same
Arc, and the Lua engine's HostContext takes it from the transform. That
made the RenderContext.env_snapshot bridge unnecessary, so it is gone.
Without a snapshot (custom pipelines, unit tests) the handler reads the
real process environment, as before. All 47 builder call sites had the
same trailing-argument shape and were rewritten mechanically.

Handler tests now drive the snapshot directly instead of mutating the
process environment, except the one that pins the no-snapshot fallback.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@posit-snyk-bot

posit-snyk-bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

✅ Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
✅ Open Source Security 0 0 0 0 0 issues
✅ Licenses 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

Base automatically changed from feature/lua-api-q1-parity to main October 27, 2026 23:44
@cscheid
cscheid merged commit 4675b55 into main Oct 28, 2026
17 checks passed
@cscheid
cscheid deleted the feature/bd-irkfpip1-env-shortcode-snapshot branch October 28, 2026 00:37
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.

2 participants