-
Notifications
You must be signed in to change notification settings - Fork 0
Give the manifest env() helper an injectable env seam (#484) #501
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
leynos
merged 9 commits into
main
from
issue-484-inject-env-seam-into-manifest-env-function
Aug 5, 2026
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
e56cef4
Give the manifest env() helper an injectable env seam
402e44f
Thread the env reader through manifest parsing
bf0f96d
Take manifest_env_tests out of the serial-env group
1700f15
Assert exact serial-env membership, not merely presence
45b539a
Drop incidental markdown reflow from the docs tree
d07335e
Describe the reader's actual ownership and test boundary
4e8c341
Document the env() reader seam in the users' guide
3df1c90
Correct the env() reader docs across all three guides
5446272
Mark the env-reader snippet for the documentation harness
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| //! Environment access for the manifest `env()` Jinja helper. | ||
| //! | ||
| //! Isolated from `manifest::mod` so the reader type, its process-backed | ||
| //! default, and the failure mapping sit together, and so neither module | ||
| //! exceeds the repository's 400-line file limit. | ||
| //! | ||
| //! See the "Manifest `env()` reader" section of the developers' guide for this | ||
| //! seam's ownership boundary and composition rules. | ||
|
|
||
| use std::sync::Arc; | ||
|
|
||
| use minijinja::{Error, ErrorKind}; | ||
|
|
||
| use crate::localization::{self, keys}; | ||
|
|
||
| /// Environment reader supplied to the `env()` Jinja helper. | ||
| /// | ||
| /// Shared and `Send + Sync` because `minijinja` requires registered functions | ||
| /// to be both, and the reader is captured by the registered closure. | ||
| pub type EnvReader = | ||
| Arc<dyn Fn(&str) -> std::result::Result<String, std::env::VarError> + Send + Sync>; | ||
|
|
||
| /// Reader backed by the live process environment. | ||
| /// | ||
| /// # Examples | ||
| /// | ||
| /// ```rust,no_run | ||
| /// use netsuke::manifest::process_env_reader; | ||
| /// | ||
| /// // Reads whatever the process has. Not executed: the result depends on the | ||
| /// // caller's environment, so running it would make the doctest a hostage to | ||
| /// // whatever CI happens to export. | ||
| /// let reader = process_env_reader(); | ||
| /// drop(reader("PATH")); | ||
| /// ``` | ||
| #[must_use] | ||
| #[expect( | ||
| clippy::disallowed_methods, | ||
| reason = "composition root: supplies the process environment to the env() Jinja helper" | ||
| )] | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| pub fn process_env_reader() -> EnvReader { | ||
| Arc::new(|key: &str| std::env::var(key)) | ||
| } | ||
|
|
||
| /// Resolve the value of an environment variable for the `env()` Jinja helper. | ||
| /// | ||
| /// Returns the variable's value or a structured error that mirrors Jinja's | ||
| /// failure modes, ensuring templates halt when a variable is missing or not | ||
| /// valid UTF-8. | ||
| /// Resolve `name` through `read_env`, mapping failures to Jinja errors. | ||
| /// | ||
| /// Kept separate from the Jinja registration so all three outcomes — present, absent, and | ||
| /// non-UTF-8 — can be exercised without mutating the process environment. The | ||
| /// non-UTF-8 branch is otherwise unreachable from a test: fabricating such a | ||
| /// value in the live environment needs platform-specific `OsString` surgery, | ||
| /// and the AGENTS.md testing mandate forbids in-process mutation regardless. | ||
| /// | ||
| /// # Examples | ||
| /// | ||
| /// ```rust,ignore | ||
| /// let value = env_var_with("FOO", |_| Ok(String::from("bar"))); | ||
| /// assert_eq!(value.expect("FOO"), "bar"); | ||
| /// ``` | ||
| pub(super) fn env_var_with<F>(name: &str, read_env: F) -> std::result::Result<String, Error> | ||
| where | ||
| F: FnOnce(&str) -> std::result::Result<String, std::env::VarError>, | ||
| { | ||
| match read_env(name) { | ||
| Ok(val) => Ok(val), | ||
| Err(std::env::VarError::NotPresent) => Err(Error::new( | ||
| ErrorKind::UndefinedError, | ||
| localization::message(keys::MANIFEST_ENV_MISSING) | ||
| .with_arg("name", name) | ||
| .to_string(), | ||
| )), | ||
| Err(std::env::VarError::NotUnicode(_)) => Err(Error::new( | ||
| ErrorKind::InvalidOperation, | ||
| localization::message(keys::MANIFEST_ENV_INVALID_UTF8) | ||
| .with_arg("name", name) | ||
| .to_string(), | ||
| )), | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.