feat(config): Add Tera template support to miserc.toml#8867
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces Tera template support for .miserc.toml configuration files, allowing for dynamic settings based on environment variables, XDG paths, and OS-level context. The implementation includes a lazy-loaded Tera instance with a restricted context to prevent circular dependencies during early initialization. Documentation and tests have been updated to reflect these changes. Feedback suggests adding a warning log if the current working directory cannot be retrieved during template rendering to improve debuggability.
Greptile SummaryThis PR introduces Tera template support for The implementation is clean and well-considered: Tera is lazily initialized only when template markers ( Key changes:
Confidence Score: 5/5Safe to merge; all prior P1 concerns are resolved and only a P2 test coverage gap remains All three previously flagged issues (misleading get_miserc_tera doc comment, TERA_ACCESSED_FILES pollution, test using wrong env source) have been correctly addressed. The remaining finding is a P2 test quality issue — the e2e tests don't assert that rendering actually happened, but the feature itself is functionally correct and well-guarded by the unit tests in miserc.rs. No logic, data-integrity, or security issues found. e2e/config/test_miserc — the two new template test scenarios do not strongly verify that Tera rendering occurred; a false regression in render_miserc_template could go undetected Important Files Changed
Sequence DiagramsequenceDiagram
participant main as mise init
participant miserc as miserc::init()
participant load as load_miserc_settings()
participant render as render_miserc_template()
participant tera as Tera (TERA static)
participant toml as TOML parser
main->>miserc: init()
miserc->>load: load_miserc_settings()
load->>load: find_miserc_files()
loop for each miserc file (reversed precedence)
load->>render: &mut tera, content, config_root
alt content contains {{ or {% or {#
render->>tera: get_or_insert_with(get_miserc_tera)
tera-->>render: TERA.clone()
render->>render: build Context (env/config_root/cwd/xdg_*)
render->>tera: render_str(content, context)
alt render OK
tera-->>render: rendered string
else render Err
tera-->>render: error
render->>render: warn! + return raw content
end
else no template syntax detected
render-->>render: return content unchanged (fast path)
end
render-->>load: final content string
load->>toml: from_str::<MisercSettings>(&content)
toml-->>load: Ok(settings) or warn on Err
load->>load: merge_settings()
end
load-->>miserc: MisercSettings
miserc->>miserc: MISERC.set(settings)
miserc->>miserc: take_tera_accessed_files() — discard file-tracking artifacts
miserc-->>main: Ok(())
Reviews (11): Last reviewed commit: "test(config): fix e2e dummy version asse..." | Re-trigger Greptile |
Render Tera templates in .miserc.toml before TOML parsing, enabling
expressions like `ceiling_paths = ["{{ env.HOME }}"]`. Uses a minimal
context (env, cwd, config_root, xdg_*, arch/os functions) safe for
early initialization — before Settings or main config are loaded.
Unavailable: mise_env (circular), exec()/read_file() (need Settings).
Falls back to raw content with a warning on render failure.
https://claude.ai/code/session_01525Mu3hgS2M2rKtDUv6CpT
- Remove useless format!() macro in test (clippy::useless_format) - Fix duplicate ceiling_paths key in docs example (invalid TOML) - Replace misleading e2e test that used uname instead of os() template https://claude.ai/code/session_01525Mu3hgS2M2rKtDUv6CpT
- Avoid redundant TERA clones: create Tera instance once before the
file loop instead of once per file (render_str requires &mut Tera)
- Fix incorrect docs claim that read_file() requires Settings — it
does not; it is excluded to keep early-init context minimal
- Document {% raw %} escape for users with literal {{ in miserc values
https://claude.ai/code/session_01525Mu3hgS2M2rKtDUv6CpT
The previous refactor unintentionally cloned TERA unconditionally on every startup, even when no miserc files exist or none contain template syntax. Switch to Option<Tera> so the clone only occurs when a file with template syntax is actually encountered. Also fix the inline docstring which still incorrectly stated that read_file() depends on Settings (it does not). https://claude.ai/code/session_01525Mu3hgS2M2rKtDUv6CpT
The docstring incorrectly stated read_file depends on Settings. Only exec() depends on Settings; read_file() is excluded because it needs per-file directory context not available at this stage. https://claude.ai/code/session_01525Mu3hgS2M2rKtDUv6CpT
- Clear TERA_ACCESSED_FILES after miserc loading so hash_file/file_size/ last_modified filters don't silently pollute hook-env's file-watch list - Fix get_miserc_tera() docstring: exec/read_file are absent because they are only registered in get_tera(), not in the TERA static itself - Fix test_render_miserc_template_env_var to read HOME from PRISTINE_ENV (same source as the template context) rather than std::env::var - Log current_dir() failures at debug level so the missing `cwd` context is diagnosable with MISE_DEBUG=1 https://claude.ai/code/session_01525Mu3hgS2M2rKtDUv6CpT
563fd7c to
62fedc2
Compare
- Also clear TERA_ACCESSED_FILES in miserc::get() fallback path, not
just miserc::init(), so the cleanup is consistent regardless of which
path triggers loading
- Break long debug!() line for rustfmt compliance
- Wrap miserc template examples in <div v-pre> to prevent VitePress/Vue
from interpreting {{ }} as interpolation (fixes docs build CI failure)
https://claude.ai/code/session_01525Mu3hgS2M2rKtDUv6CpT
- Wrap {{ }} and {% %} in <div v-pre> and <span v-pre> to prevent
VitePress/Vue from treating them as interpolation (fixes CI build)
- Add explicit {#miserc-template-support} anchor to heading with dots
to avoid ambiguous GFM anchor generation (fixes MD051)
- Rename duplicate '### Examples' heading to '### miserc.toml Examples'
(fixes MD024)
- Update cross-references to use the explicit anchor ID
https://claude.ai/code/session_01525Mu3hgS2M2rKtDUv6CpT
dummy '1' resolves to 1.1.0 in the e2e environment (established by the existing MISE_ENV=ci test at line 14). Our new template tests incorrectly asserted 1.0.0. https://claude.ai/code/session_01525Mu3hgS2M2rKtDUv6CpT
### 🚀 Features - **(config)** Add Tera template support to miserc.toml by @richardthe3rd in [#8867](#8867) ### 🐛 Bug Fixes - **(env)** include tools-only redactions in `mise env --redacted` by @jakedgy in [#8956](#8956) - **(env)** pass dependency env to vfox backend plugin hooks by @cprecioso in [#8952](#8952) - **(shim)** fix race condition when removing in make_shim, when multiple plugins provide the same shim by @brander-john in [#8947](#8947) - **(spm)** derive API URL from host for self-hosted instances by @ThomasDutartre in [#8955](#8955) - **(task)** resolve env vars in usage tera templates when flags are provided by @jdx in [#8957](#8957) ### 📚 Documentation - **(python)** clarify attestation settings must be under [settings] in mise.toml by @fru1tworld in [#8939](#8939) ### 📦 Registry - added sing-box by @tony-sol in [#8944](#8944) ### Chore - **(ci)** remove auto-draft PR workflow by @jdx in [#8945](#8945) ### New Contributors - @ThomasDutartre made their first contribution in [#8955](#8955) - @jakedgy made their first contribution in [#8956](#8956) - @brander-john made their first contribution in [#8947](#8947) - @fru1tworld made their first contribution in [#8939](#8939)
This pull request adds support for Tera templating in
.miserc.tomlfiles, allowing users to use environment variables and other OS-level context in their configuration. The implementation ensures templates are rendered safely during early initialization, and provides documentation, tests, and end-to-end validation for this feature.Template support in
.miserc.toml:.miserc.tomlfiles, enabling use of environment variables and other OS-level context in configuration values. The context includesenv,config_root,cwd, XDG directories, and basic functions/filters, but excludes settings-dependent or self-referential values. [1] [2] [3]docs/configuration/environments.mdanddocs/templates.mdto describe template support, available context, usage examples, and caveats for.miserc.toml. [1] [2] [3]Testing and validation:
.miserc.toml, covering environment variable expansion, function calls, context injection, and fallback behavior on errors..miserc.tomlscenarios.Internal changes:
get_miserc_tera, ensuring correct function/filter registration for early config parsing.