Skip to content

fix(env): an empty .env entry no longer clobbers the caller's value#883

Merged
Chemaclass merged 2 commits into
mainfrom
fix/env-file-precedence
Jul 25, 2026
Merged

fix(env): an empty .env entry no longer clobbers the caller's value#883
Chemaclass merged 2 commits into
mainfrom
fix/env-file-precedence

Conversation

@Chemaclass

Copy link
Copy Markdown
Member

🤔 Background

Related #865

.env is sourced under set -o allexport so it can hold arbitrary shell, which made
every KEY= line an unconditional assignment. Merely listing a name blanked it, so
BASHUNIT_OUTPUT_FORMAT=tap ./bashunit silently stopped working in any project whose
.env mentioned that setting — and a project could not document a setting without
breaking it.

This was concealing defects, not just causing annoyance: two of the bugs fixed in #879
were not reproducible from inside a repo checkout, because .env blanked the very
variable under test.

💡 Changes

  • Snapshot the caller's non-empty BASHUNIT_* values before sourcing .env and restore any the file blanked; an entry with a value still wins, only an empty one is treated as "not configured here"
  • Drop the --skip-env-file workaround from the two threshold tests, so they exercise the real path; correct the .env.example header and the precedence list in Configuration, which conflated .env with environment variables
  • Verified on real Bash 3.0 in Docker (compgen -v accepts a prefix there) and under CI conditions with cp .env.example .env

.env is sourced under 'set -o allexport' so it can hold arbitrary shell,
which made every KEY= line an unconditional assignment. Merely listing a
name blanked it, so 'BASHUNIT_OUTPUT_FORMAT=tap ./bashunit' stopped
working in any project whose .env mentioned that setting -- and a project
could not document a setting without breaking it.

Snapshot the caller's non-empty BASHUNIT_* values and restore any the
file blanked. An entry with a value still wins, which is what a committed
project config is for; only an empty one is treated as 'not configured
here', matching how .bashunitrc already applies values.

This had been concealing defects rather than merely annoying: two bugs
fixed in #879 were not reproducible from inside a repo checkout because
.env blanked the very variable under test. The two tests that needed
--skip-env-file as a workaround now exercise the real path.

Verified on real bash 3.0 (compgen -v accepts a prefix there) and under
CI conditions with 'cp .env.example .env'.

Closes #865
@Chemaclass Chemaclass added the bug Something isn't working label Jul 25, 2026
@Chemaclass Chemaclass self-assigned this Jul 25, 2026
…new test

CI caught SC2164/SC1007 in the new test file that 'make sa' had passed.
Cause: since #863 the file list comes from 'git ls-files', which only
lists TRACKED files, so a brand-new script was invisible locally and
first failed in CI -- exactly backwards. Add --others
--exclude-standard.

Verified by dropping an untracked offending script in the tree: make sa
now fails on it.
@Chemaclass
Chemaclass merged commit 7909de5 into main Jul 25, 2026
37 checks passed
@Chemaclass
Chemaclass deleted the fix/env-file-precedence branch July 25, 2026 13:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant