Context
#835 fixed five run-mode flags (--stop-on-failure, --log-junit, --report-html, --report-tap, --report-json) that were exported by src/main.sh's flag parser and therefore leaked into nested bashunit runs — a script under test that itself calls bashunit, or bashunit's own acceptance suite under build.sh --verify. The observed damage there: nested runs aborted before persisting the rerun cache, overwrote the parent's report files, and blew the per-run awk fork budget.
src/main.sh still has ~40 more export BASHUNIT_* sites in the same flag-parsing loop (grep -c 'export BASHUNIT_' src/main.sh), all of the same class: --parallel, --filter, --no-output, --simple, --verbose, shard vars, etc. Any of them changes the behavior of a nested bashunit invocation the user did not configure.
Task
Audit every export BASHUNIT_* in src/main.sh and convert this-process-only flags to the #835 pattern:
BASHUNIT_FOO=value
export -n BASHUNIT_FOO
The export -n matters: a set -o allexport .env load (env.sh:65) stamps the export attribute on every var listed in .env, so a plain unexported assignment is not enough for anyone whose .env was copied from .env.example (which lists every var). CI has no .env, dev repos usually do — behaviors diverge exactly as they did in #835.
Audit rules (per flag, don't blanket-strip)
Keep the export only when a process other than the main bashunit shell genuinely reads the variable via the environment:
- Parallel workers and test bodies are subshells — they inherit unexported vars; export is never needed for them
- Export is only meaningful for exec'd children: nested bashunit, user commands run by tests, bootstrap scripts
- Suspected legitimate exports (verify before keeping):
BASHUNIT_SHARD_INDEX/BASHUNIT_SHARD_TOTAL if any child consumes them; anything documented as readable by user test code
- When in doubt, strip: the user can always export explicitly; the framework silently reconfiguring nested runs is the bug
Acceptance criteria
Constraints
- Bash 3.0+ (
export -n is fine on 3.x)
- One PR; this is a single mechanical audit, not per-flag PRs
- TDD: extend the leak probe first (RED against current main), then convert
Verification
./bashunit tests/ && ./bashunit --parallel --simple --strict tests/
make sa && make lint
./build.sh --verify
Context
#835 fixed five run-mode flags (
--stop-on-failure,--log-junit,--report-html,--report-tap,--report-json) that wereexported bysrc/main.sh's flag parser and therefore leaked into nested bashunit runs — a script under test that itself calls bashunit, or bashunit's own acceptance suite underbuild.sh --verify. The observed damage there: nested runs aborted before persisting the rerun cache, overwrote the parent's report files, and blew the per-run awk fork budget.src/main.shstill has ~40 moreexport BASHUNIT_*sites in the same flag-parsing loop (grep -c 'export BASHUNIT_' src/main.sh), all of the same class:--parallel,--filter,--no-output,--simple,--verbose, shard vars, etc. Any of them changes the behavior of a nested bashunit invocation the user did not configure.Task
Audit every
export BASHUNIT_*insrc/main.shand convert this-process-only flags to the #835 pattern:BASHUNIT_FOO=value export -n BASHUNIT_FOOThe
export -nmatters: aset -o allexport.envload (env.sh:65) stamps the export attribute on every var listed in.env, so a plain unexported assignment is not enough for anyone whose.envwas copied from.env.example(which lists every var). CI has no.env, dev repos usually do — behaviors diverge exactly as they did in #835.Audit rules (per flag, don't blanket-strip)
Keep the export only when a process other than the main bashunit shell genuinely reads the variable via the environment:
BASHUNIT_SHARD_INDEX/BASHUNIT_SHARD_TOTALif any child consumes them; anything documented as readable by user test codeAcceptance criteria
export BASHUNIT_*insrc/main.sheither converted to assign+export -nor annotated with a one-line comment naming the exec'd consumer that needs ittests/acceptance/fixtures/flag_env_leak/leak_probe.shextended to assert the full converted flag list is absent from a nested run's environment (the existingbashunit_flag_env_leak_test.shshows the pattern)BASHUNIT_PARALLEL_RUN=true ./bashunit tests/etc. must behave as before (env.sh:=chain reads inherited values — only the flag→export direction changes)./build.sh --verifygreen (the strictest nested-run consumer)./bashunit tests/acceptance/earlyConstraints
export -nis fine on 3.x)Verification