Initialize environment and add E2E tests with formatting#14475
Initialize environment and add E2E tests with formatting#14475AmelBawa-msft wants to merge 20 commits intofeature/wsl-for-appsfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds initial support for passing environment variables from the wslc CLI into container creation/run flows (via -e/--env) and introduces E2E coverage for the new CLI behavior.
Changes:
- Extend
ContainerOptionsto carry environment variables and populate it from CLI args (-e/--env). - Plumb
ContainerOptions.EnvironmentVariablesintoWSLAContainerLauncherduring container creation/run. - Add E2E tests validating
container runenvironment variable propagation.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
test/windows/wslc/e2e/WSLCE2EContainerCreateTests.cpp |
Adds E2E coverage for container run -e/--env and test setup/cleanup env initialization. |
src/windows/wslc/tasks/ContainerTasks.cpp |
Parses -e/--env arguments into ContainerOptions.EnvironmentVariables. |
src/windows/wslc/services/ContainerService.cpp |
Passes EnvironmentVariables into WSLAContainerLauncher for container creation. |
src/windows/wslc/services/ContainerModel.h |
Extends ContainerOptions with an environment variables list. |
There was a problem hiding this comment.
Pull request overview
Adds WSLC support for passing environment variables into containers (via -e/--env and --env-file) and validates the behavior through new unit and end-to-end tests.
Changes:
- Extend
container run/createargument definitions to accept repeated-eand--env-file. - Parse/validate env entries (including key-only resolution from host env) and plumb them through
ContainerOptionsintoWSLAContainerLauncher. - Add new unit tests for env parsing and E2E coverage for env/env-file scenarios and precedence.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| test/windows/wslc/e2e/WSLCE2EContainerCreateTests.cpp | Adds E2E coverage for -e and --env-file behavior (including precedence and error cases). |
| test/windows/wslc/WSLCCLIEnvVarParserUnitTests.cpp | New unit tests for env var parsing and env-file parsing behavior. |
| src/windows/wslc/tasks/ContainerTasks.cpp | Parses --env-file and -e args into ContainerOptions.EnvironmentVariables. |
| src/windows/wslc/services/ContainerService.cpp | Passes environment variables to WSLAContainerLauncher during container create/run. |
| src/windows/wslc/services/ContainerModel.h | Adds ContainerOptions.EnvironmentVariables and declares EnvironmentVariable parsing helpers. |
| src/windows/wslc/services/ContainerModel.cpp | Implements env parsing and env-file parsing/validation. |
| src/windows/wslc/commands/ContainerRunCommand.cpp | Updates container run argument definitions to allow repeated env/env-file. |
| src/windows/wslc/commands/ContainerCreateCommand.cpp | Updates container create argument definitions to allow repeated env/env-file. |
| return std::iswspace(ch) != 0; | ||
| } | ||
|
|
||
| std::optional<std::wstring> EnvironmentVariable::Parse(std::wstring entry) |
There was a problem hiding this comment.
nit: const ref string to avoid copy
| if (valueLength > 0) | ||
| { | ||
| std::wstring envValue(valueLength, L'\0'); | ||
| GetEnvironmentVariableW(key.c_str(), envValue.data(), valueLength); |
There was a problem hiding this comment.
nit: I recommend using wil::GetEnvironmentVariableW() instead
| { | ||
| if (!std::filesystem::exists(filePath)) | ||
| { | ||
| THROW_HR_WITH_USER_ERROR(E_INVALIDARG, std::format(L"Environment file '{}' does not exist", filePath)); |
There was a problem hiding this comment.
std::ifstream will already fail if the file doesn't exist. We don't need to manually check if it exists
| EnsureImageIsLoaded(AlpineImage); | ||
| EnsureImageIsLoaded(DebianImage); | ||
|
|
||
| VERIFY_IS_TRUE(::SetEnvironmentVariableW(HostEnvVariableName.c_str(), HostEnvVariableValue.c_str())); |
There was a problem hiding this comment.
nit:: I recommend using ScopedEnvVariable instead
…into user/amelbawa/env
Summary of the Pull Request
-eoption inwslc run/create/execPR Checklist
Detailed Description of the Pull Request / Additional comments
Validation Steps Performed