Skip to content

[bug] bats-core entry chain: exported functions never materialize in the OS environment (BASH_FUNC_name%% absent from child env); exec env chain loses them #253

Closed

Description

@caomengxuan666

From the bats-core acceptance slice (bats-core @ 52439ebf, wt4/ecofix lane). bin/bats test/tagging.bats under rubash dies at libexec/bats-core/bats:119 bats_readlinkf: command not found.

Root cause split

  1. rubash-caused: exported functions are NOT written into the spawned child's OS environment. GNU variables.c:3989-4034 (push_exported_function / initialize_shell_variables) exports export -f f as the env var BASH_FUNC_f%%=() { ... }; GNU env | grep BASH_FUNC shows it. Probe under rubash:
myfn() { echo FN-OK; }
export -f myfn
env | grep -c BASH_FUNC    # rubash: 0; GNU: 1

So every NON-rubash child (env.exe, script shebangs) loses exported functions even though rubash-internal children import them fine. Fix owner: the external spawn env assembly (GNU shell.c/variables.c export path).

  1. environment-bound remainder (not a rubash bug, per AGENTS WinuxCmd/Winuxsh handling): the bats chain is rubash -> external env.exe (~/.local/bin/env on this host) -> PATH bash (the winuxsh shim, an older shell below rubash) -> bats launcher. Even GNU-correct BASH_FUNC_ passthrough needs the CHILD bash to import the function; the shim bash is a separate project. Classification follows rubash#224's note ("that loss point is the external env tool"), refined: rubash also never puts the var in the OS env (point 1).

Consequence

bats-core 3-file slice cannot run under rubash on this host until (1) lands and (2) the inner bash is GNU-compatible. $0/BASH_SOURCE domain fixes (rubash#224) are verified green separately (tests/fixtures/ecosuite/bats/zero_pwd_form.sh).

Activity

  1. caomengxuan666 commented on Sep 27, 2026

    @caomengxuan666
    MemberAuthor

    Fixed in wt5/omb. Root cause: exported functions WERE materialized on the real spawn path (apply_exported_functions_to_child, readonly_functions.rs, driven by the EXPORTED_FUNCTIONS marker that export -f already sets via execute_export_functions) — real externals saw them (printenv BASH_FUNC_myfn%% worked). The missing materialization point was the internal env emulation (external_inner.rs materialize_env_command_environment): it rebuilt the child environment from EXPORTED_VARS + local exports + Windows session vars only, so env | grep BASH_FUNC printed 0 while printenv printed 1. GNU env is an external binary that inherits the OS env where variables.c:3989-4034 (push_exported_function → make_env_array_from_var_list) put every exported function; the emulation now materializes BASH_FUNC_%% entries the same way the spawn path does (skipped under env -i like GNU).

    Verification (WSL GNU 5.3.0 oracle): myfn() { echo FN-OK; }; export -f myfn; env | grep -c BASH_FUNC → rubash 1 (was 0), GNU 1. Value renders () {\n echo FN-OK\n} — re-imports on both sides (rubash imports GNU's form, GNU imports rubash's form); GNU renders () { echo FN-OK on one line (print_cmd.c formatting difference, cosmetic — noted, not blocking). Linux-flavor: the changed code is platform-independent (same HashMap path for both build flavors); runtime verification on the Linux flavor deferred to the linuxfix lane's parity runs.

    bats-core verdict: the 3-file slice (load/tagging/filter @ 52439ebf, LF-forced) entry chain now PASSES the original blocker — the exported bats_readlinkf reaches the exec'd env child and libexec bats runs. GNU reference: 26+10+6 ok. rubash blocks next at bats-gather-tests with Windows path-form mixing (D:\ backslash test-filename args + C:\ host TMPDIR) → filed #259 (platform, split rubash-spawn-argv/PWD normalization vs external mktemp/readlink tool forms).

  2. added a commit that references this issue on Sep 27, 2026
  3. caomengxuan666 commented on Sep 27, 2026

    @caomengxuan666
    MemberAuthor

    已修复并合入 master(commit e22fa3a,lane wt5/omb;验证评论已在本 issue:#251 交互 252/252 环境平价(其余 74 个名字来自 WSL 侧 bash-completion 缺失=环境绑定)、PS1 字节一致;#252 modernish 159/164 rc 向量一致、init 推进到 866 行;#253 env|grep -c BASH_FUNC=1、bats 三文件越过 readlinkf 墙)。后续阻塞已开单 #256-#259。感谢报告!

  4. added
    bug
    area:builtins
    on Oct 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:builtinsbug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions