functional2: hermatic env / overhaul Command environment #847

Open
opened 2025-06-08 18:36:23 +00:00 by commentatorforall · 1 comment

Currently, when using Nix, it creates a "hermetic_env" to set up config and prevent leakage from the global config.
The described env is neither complete nor hermetic at all, which causes tests to fail (e.g. https://gerrit.lix.systems/c/lix/+/3266/2)
Additionally, the paths it sets, aren't created, which leads to them being invalid, causing flakynes elsewhere.

Describe the solution you'd like

The creation and setup of the test environment should be moved to the Command class.
As we rely on the tmp_path for setting some of the variables, a full rework is likely needed to get access to said information. This could be done similar to how Nix acquires the information currently.

Additionally, using os.environ should be disallowed. For some tests to still be able to access the system PATH (esp builders), there should either be an option to inherit PATH or to provide a specific program to add to PATH (preferred; could be determined using shutil.which())

The new Command should also offer an interface for setting and also unsetting (which is currenlty not possible) singular environment variables.

Describe alternatives you've considered

It was dicussed in the lix-dev matrix channel to move environment handling to NixCommand instead, but was decided against to make all command executions consistent and ensure no configuration leakage when using Command.

Additional context

insert list of environment variables, directories and files created by the functional runner here when done compiling

## Is your feature request related to a problem? Please describe. Currently, when using `Nix`, it creates a "`hermetic_env`" to set up config and prevent leakage from the global config. The described env is neither complete nor hermetic at all, which causes tests to fail (e.g. https://gerrit.lix.systems/c/lix/+/3266/2) Additionally, the paths it sets, aren't created, which leads to them being invalid, causing flakynes elsewhere. ## Describe the solution you'd like The creation and setup of the test environment should be moved to the `Command` class. As we rely on the `tmp_path` for setting some of the variables, a full rework is likely needed to get access to said information. This could be done similar to how `Nix` acquires the information currently. Additionally, using `os.environ` should be disallowed. For some tests to still be able to access the system `PATH` (esp builders), there should either be an option to inherit `PATH` or to provide a specific program to add to `PATH` (preferred; could be determined using `shutil.which()`) The new `Command` should also offer an interface for setting and also unsetting (which is currenlty not possible) singular environment variables. ## Describe alternatives you've considered It was dicussed in the lix-dev matrix channel to move environment handling to `NixCommand` instead, but was decided against to make all command executions consistent and ensure no configuration leakage when using `Command`. ## Additional context `insert list of environment variables, directories and files created by the functional runner here when done compiling`
Member

This issue was mentioned on Gerrit on the following CLs:

  • commit message in cl/3333 ("tests/functional2: Make Command Environment actually declarative")
<!-- GERRIT_LINKBOT: {"cls": [{"backlink": "https://gerrit.lix.systems/c/lix/+/3333", "number": 3333, "kind": "commit message"}], "cl_meta": {"3333": {"change_title": "tests/functional2: Make Command Environment actually declarative"}}} --> This issue was mentioned on Gerrit on the following CLs: * commit message in [cl/3333](https://gerrit.lix.systems/c/lix/+/3333) ("tests/functional2: Make Command Environment actually declarative")
Sign in to join this conversation.
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: lix-project/lix#847
No description provided.