Skip to content

Initialize environment and add E2E tests with formatting#14475

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

Initialize environment and add E2E tests with formatting#14475
AmelBawa-msft wants to merge 23 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.

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

Copy link
Collaborator

Choose a reason for hiding this comment

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

Reopening since this isn't resolved on the latest iteration

Copilot AI review requested due to automatic review settings March 23, 2026 17:36
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 9 out of 9 changed files in this pull request and generated 2 comments.

Copilot AI review requested due to automatic review settings March 23, 2026 22:06
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 9 out of 9 changed files in this pull request and generated 1 comment.

@AmelBawa-msft AmelBawa-msft requested a review from OneBlue March 24, 2026 02:58
Copy link
Collaborator

@OneBlue OneBlue left a comment

Choose a reason for hiding this comment

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

LGTM, minor comments


static inline bool IsSpace(wchar_t ch)
{
return std::iswspace(ch) != 0;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could we use iswpace directly instead ?

if (!value.has_value())
{
wil::unique_hglobal_string envValue;
auto hr = wil::GetEnvironmentVariableW(key.c_str(), envValue);
Copy link
Collaborator

Choose a reason for hiding this comment

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

wil::GetEnvironmentVariableW can be templated on std::wstring to avoid the need for copy below

while (std::getline(file, line))
{
// Remove leading whitespace
line.erase(line.begin(), std::find_if(line.begin(), line.end(), [](unsigned char ch) { return !std::isspace(ch); }));
Copy link
Collaborator

Choose a reason for hiding this comment

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

This looks like it will only remove the first whitespace character. Instead we should probably loop and delete the first character as long as line is not empty and line[0] is a space

continue;
}

auto envVar = Parse(wsl::shared::string::MultiByteToWide(line));
Copy link
Collaborator

Choose a reason for hiding this comment

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

I recommend using std::string in Parse as well, since that's what the service will expect

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.

Reopening since this isn't resolved on the latest iteration

TEST_METHOD(WSLCCLIEnvVarParser_UsesProcessEnvWhenValueMissing)
{
constexpr const auto key = L"WSLC_TEST_ENV_FROM_PROCESS";
VERIFY_IS_TRUE(SetEnvironmentVariableW(key, L"process_value"));
Copy link
Collaborator

Choose a reason for hiding this comment

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

I recommend using ScopedEnvVariable here as well


TEST_METHOD(WSLCCLIEnvVarParser_InvalidKeysThrow)
{
VERIFY_THROWS(models::EnvironmentVariable::Parse(L"=value"), std::exception);
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 validating that the error message is what we expect

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