Repository navigation
Lua API: env shortcode reads the per-render environment snapshot (stacked on #949) - #950
Merged
Merged
Conversation
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>
Contributor
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
…nv-shortcode-snapshot
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.
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_environmentfile values for missing keys, thenQUARTO_PROFILEforced to the active profile list). Before this,EnvShortcodeHandlerre-did that three-way merge at every lookup withstd::env::varon 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_supportand the two pipeline builders (build_transform_pipeline,build_q2_preview_transform_pipeline) take anOption<Arc<EnvSnapshot>>in place of theproject_env+quarto_profilepair. The transform hands the sameArcto theenvhandler and to the Lua engine'sHostContext.RenderContext.env_snapshotbridge 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.Default::default(), Noneshape and were rewritten by script; no behavior change at any of them.Verification
cargo clippy -p quarto-core --all-targets -- -D warningsclean;cargo nextest run -p quarto-core -p quartogreen (includes thecontract-envsmoke fixture and thelua_host_context_clie2e test, whose shortcode half exercises the transform-held snapshot).🤖 Generated with Claude Code