From b730fab286b95082b015b4e20b5519c42fd96a25 Mon Sep 17 00:00:00 2001 From: Raito Bezarius Date: Sat, 3 Jan 2026 22:27:39 +0100 Subject: [PATCH] f2/testlib/env: build initial path via build_env `build_env` is assumed to be a certain trivial environment, e.g. a singleton search path. An environment in general is either empty, contain one or more search paths separated by a colon. It seems that the intent was to set the `build_shell` first as a prepended path in the managed environment then extend via the `build_env` parts. This fixes a usecase when the `BUILD_TEST_ENV` is non-trivial. Change-Id: If5b8ab976d867a57ce0b8d29255f64695e30a8b2 Signed-off-by: Raito Bezarius --- tests/functional2/testlib/fixtures/env.py | 8 ++++++-- tests/functional2/testlib/fixtures/test_env.py | 7 +++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/tests/functional2/testlib/fixtures/env.py b/tests/functional2/testlib/fixtures/env.py index 4e6457c4b..ff1e1e526 100644 --- a/tests/functional2/testlib/fixtures/env.py +++ b/tests/functional2/testlib/fixtures/env.py @@ -21,12 +21,16 @@ class _ManagedPath: """ build_shell: dataclasses.InitVar[str | None] + build_env: dataclasses.InitVar[str | None] = None """statically linked shell to use within builds which provides coreutils functionality""" _path: list[str] = dataclasses.field(default_factory=list) - def __post_init__(self, build_shell: str | None): + def __post_init__(self, build_shell: str | None, build_env: str | None): if build_shell: self.prepend(build_shell) + if build_env: + for part in build_env.split(":"): + self.append(part) def to_path(self) -> str: """ @@ -177,7 +181,7 @@ class ManagedEnv: lix_bin = Path(environ.get("NIX_BIN_DIR", lix_base_folder / "outputs/out/bin")) self._env = {} - self.path = _ManagedPath(build_env) + self.path = _ManagedPath(build_shell, build_env) self._tmp_path = tmp_path self.shell_dir = build_shell or "/bin" self.build_env = build_env diff --git a/tests/functional2/testlib/fixtures/test_env.py b/tests/functional2/testlib/fixtures/test_env.py index c5cf49b79..c4576016c 100644 --- a/tests/functional2/testlib/fixtures/test_env.py +++ b/tests/functional2/testlib/fixtures/test_env.py @@ -225,6 +225,13 @@ def test_path_sandbox_entire_store_package(): assert re.fullmatch(r"^/nix/store/\w{32}-python3-3\.\d{1,2}\.\d{1,2}-[^/]+$", sb_paths[1]) +def test_path_nontrivial_build_env(): + path = _ManagedPath("/path/to/build_shell", "/path/to/busybox/bin:/path/to/acl/bin") + sb_paths = path.to_sandbox_paths() + assert len(sb_paths) == 3 + assert sb_paths[0] == "/path/to/build_shell" + + def test_path_which(): path = _ManagedPath("/path/to/build_shell") with pytest.raises(ValueError, match="not in configured path"):