Skip to content

Initialize environment and add E2E tests with formatting#14475

Open
AmelBawa-msft wants to merge 20 commits intofeature/wsl-for-appsfrom
user/amelbawa/env
Open

Initialize environment and add E2E tests with formatting#14475
AmelBawa-msft wants to merge 20 commits intofeature/wsl-for-appsfrom
user/amelbawa/env

Conversation

@AmelBawa-msft
Copy link

@AmelBawa-msft AmelBawa-msft commented Mar 19, 2026

Summary of the Pull Request

  • Added support for -e option in wslc run/create/exec
  • Added E2E tests

PR Checklist

  • Closes: Link to issue #xxx
  • Communication: I've discussed this with core contributors already. If work hasn't been agreed, this work might be rejected
  • Tests: Added/updated if needed and all pass
  • Localization: All end user facing strings can be localized
  • Dev docs: Added/updated if needed
  • Documentation updated: If checked, please file a pull request on our docs repo and link it here: #xxx

Detailed Description of the Pull Request / Additional comments

Validation Steps Performed

Copilot AI review requested due to automatic review settings March 19, 2026 00:21
@AmelBawa-msft AmelBawa-msft marked this pull request as ready for review March 19, 2026 00:24
@AmelBawa-msft AmelBawa-msft requested a review from a team as a code owner March 19, 2026 00:24
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ContainerOptions to carry environment variables and populate it from CLI args (-e/--env).
  • Plumb ContainerOptions.EnvironmentVariables into WSLAContainerLauncher during container creation/run.
  • Add E2E tests validating container run environment 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.

@AmelBawa-msft AmelBawa-msft marked this pull request as draft March 19, 2026 00:49
Copilot AI review requested due to automatic review settings March 19, 2026 22:47
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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/create argument definitions to accept repeated -e and --env-file.
  • Parse/validate env entries (including key-only resolution from host env) and plumb them through ContainerOptions into WSLAContainerLauncher.
  • 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.

Copilot AI review requested due to automatic review settings March 20, 2026 17:32
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated 6 comments.

@AmelBawa-msft AmelBawa-msft marked this pull request as ready for review March 20, 2026 21:07
Copilot AI review requested due to automatic review settings March 20, 2026 21:07
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.

return std::iswspace(ch) != 0;
}

std::optional<std::wstring> EnvironmentVariable::Parse(std::wstring entry)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: const ref string to avoid copy

if (valueLength > 0)
{
std::wstring envValue(valueLength, L'\0');
GetEnvironmentVariableW(key.c_str(), envValue.data(), valueLength);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:: I recommend using ScopedEnvVariable instead

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants