Skip to content

Inject an Env seam into the manifest env() Jinja function #484

Description

@leynos

Context

The manifest env() Jinja function reads the process environment directly at src/manifest/mod.rs:85:

fn env_var(name: &str) -> std::result::Result<String, Error> {
    match std::env::var(name) {

The function has three distinct outcomes — present, NotPresent, and NotUnicode — and the last two are precisely the cases that are awkward to reach without mutating the real environment. Under the AGENTS.md testing mandate, in-process mutation is no longer available, so these branches currently have no legitimate route to coverage.

The doc comment on env_var already advertises a test_support::env::VarGuard that mutates global state; that example must go with the implementation.

Required work

  • Give env_var an injected environment, and carry it on the value registered into the Jinja environment so manifest::from_str can supply one.
  • Supply the process-backed default reader (process_env_reader) at the manifest public boundary.
  • Rewrite the env_var doc example to construct a MockEnv rather than a mutating guard.
  • Migrate tests/manifest_env_tests.rs onto the injected seam, covering all three outcomes including the non-UTF-8 branch.

Acceptance criteria

  • No std::env::var call remains in src/manifest/mod.rs.
  • tests/manifest_env_tests.rs no longer acquires EnvLock or mutates the process environment.
  • The NotUnicode branch is covered by a test.
  • make check-fmt, make lint, and make test pass.

Amended: the seam is a closure (EnvReader), not &impl mockable::Env.
The requirement above has been rewritten to match; see the discussion below for
the reasoning. mockable is a dev-dependency, and the proportionality argument
is that a production dependency is a large price for reading one variable when
the repository already uses closure seams of the same shape in stdlib::path,
output_mode, output_prefs, and theme.

Metadata

Metadata

Assignees

No one assigned

    Labels

    concurrencyConcurrency, parallelism, and synchronization work, including races and deadlocks.enhancementNew feature or requestmediumRoadmap items to schedule within the current quarter. Clear scope, normal review cycles.refactorBehaviour-preserving restructuring that improves code health.testingTest coverage, test infrastructure, and verification tooling work.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions