wslc: remove redundant short-alias E2E tests for --workdir#40192
wslc: remove redundant short-alias E2E tests for --workdir#40192ptrivedi wants to merge 2 commits intofeature/wsl-for-appsfrom
Conversation
Extends the --workdir flag (already supported by container exec) to the container create and run commands, passing the working directory through to the container launcher. Adds CLI parse tests, unit tests, and E2E tests for both commands. Co-Authored-By: Claude Sonnet
Short-alias (-w) coverage is already provided by the help message test method and CLI parse tests. Remove the duplicate E2E tests for container create and run per reviewer feedback. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR adds --workdir/-w support for wslc container run and wslc container create, and updates tests/help output accordingly.
Changes:
- Add
WorkDirargument wiring forcontainer runandcontainer create. - Apply the working directory to the container launcher (
SetWorkingDirectory). - Add/adjust E2E tests, CLI execution unit tests, command-line test cases, and help-text expectations for
--workdir/-w.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 10 comments.
Show a summary per file
| File | Description |
|---|---|
| test/windows/wslc/e2e/WSLCE2EContainerRunTests.cpp | Adds E2E coverage for container run --workdir and updates expected help output. |
| test/windows/wslc/e2e/WSLCE2EContainerCreateTests.cpp | Adds E2E coverage for container create --workdir and updates expected help output. |
| test/windows/wslc/WSLCCLIExecutionUnitTests.cpp | Adds unit tests to validate parsing/validation of --workdir/-w for run/create. |
| test/windows/wslc/CommandLineTestCases.h | Extends CLI parsing test matrix for --workdir/-w and invalid cases. |
| src/windows/wslc/services/ContainerService.cpp | Sets working directory on container launcher from options. |
| src/windows/wslc/commands/ContainerRunCommand.cpp | Registers WorkDir argument for run. |
| src/windows/wslc/commands/ContainerCreateCommand.cpp | Registers WorkDir argument for create. |
| Argument::Create(ArgType::User), | ||
| Argument::Create(ArgType::Volume, false, NO_LIMIT), | ||
| // Argument::Create(ArgType::Virtual), | ||
| Argument::Create(ArgType::WorkDir), |
There was a problem hiding this comment.
The PR title/description indicates this change is about removing redundant short-alias E2E tests, but this diff introduces new product behavior (wiring up ArgType::WorkDir for container run) plus additional tests/help expectations. Please update the PR title/description to match the scope (adding --workdir/-w support), or split the behavior change into its own PR to keep the stated intent accurate.
| // Test: Full parse of 'run --workdir "" image cmd' rejects empty working directory | ||
| TEST_METHOD(RunCommand_ParseWorkDirEmptyValue_ThrowsArgumentException) | ||
| { | ||
| auto invocation = CreateInvocationFromCommandLine(L"wslc --workdir \"\" ubuntu sh"); |
There was a problem hiding this comment.
These tests are named/commented as parsing run ... and create ..., but the command lines passed to CreateInvocationFromCommandLine don’t include the run/create subcommand. This can cause the tests to exercise a different parsing path (or pass/fail for the wrong reason). Update the test command lines to include the explicit subcommand, e.g. wslc run --workdir ... and wslc create --workdir ... (and the -w variants) so the tests accurately cover the intended commands.
| // Test: Full parse of 'run --workdir /path image cmd' sets WorkingDirectory | ||
| TEST_METHOD(RunCommand_ParseWorkDirLongOption_SetsWorkingDirectory) | ||
| { | ||
| auto invocation = CreateInvocationFromCommandLine(L"wslc --workdir /tmp/mydir ubuntu sh"); |
There was a problem hiding this comment.
These tests are named/commented as parsing run ... and create ..., but the command lines passed to CreateInvocationFromCommandLine don’t include the run/create subcommand. This can cause the tests to exercise a different parsing path (or pass/fail for the wrong reason). Update the test command lines to include the explicit subcommand, e.g. wslc run --workdir ... and wslc create --workdir ... (and the -w variants) so the tests accurately cover the intended commands.
| // Test: Full parse of 'run -w /path image cmd' (short alias) sets WorkingDirectory | ||
| TEST_METHOD(RunCommand_ParseWorkDirShortOption_SetsWorkingDirectory) | ||
| { | ||
| auto invocation = CreateInvocationFromCommandLine(L"wslc -w /app ubuntu sh"); |
There was a problem hiding this comment.
These tests are named/commented as parsing run ... and create ..., but the command lines passed to CreateInvocationFromCommandLine don’t include the run/create subcommand. This can cause the tests to exercise a different parsing path (or pass/fail for the wrong reason). Update the test command lines to include the explicit subcommand, e.g. wslc run --workdir ... and wslc create --workdir ... (and the -w variants) so the tests accurately cover the intended commands.
| // Test: Full parse of 'create --workdir "" image cmd' rejects empty working directory | ||
| TEST_METHOD(CreateCommand_ParseWorkDirEmptyValue_ThrowsArgumentException) | ||
| { | ||
| auto invocation = CreateInvocationFromCommandLine(L"wslc --workdir \"\" ubuntu sh"); |
There was a problem hiding this comment.
These tests are named/commented as parsing run ... and create ..., but the command lines passed to CreateInvocationFromCommandLine don’t include the run/create subcommand. This can cause the tests to exercise a different parsing path (or pass/fail for the wrong reason). Update the test command lines to include the explicit subcommand, e.g. wslc run --workdir ... and wslc create --workdir ... (and the -w variants) so the tests accurately cover the intended commands.
| // Test: Full parse of 'create --workdir /path image cmd' sets WorkingDirectory | ||
| TEST_METHOD(CreateCommand_ParseWorkDirLongOption_SetsWorkingDirectory) | ||
| { | ||
| auto invocation = CreateInvocationFromCommandLine(L"wslc --workdir /tmp/mydir ubuntu sh"); |
There was a problem hiding this comment.
These tests are named/commented as parsing run ... and create ..., but the command lines passed to CreateInvocationFromCommandLine don’t include the run/create subcommand. This can cause the tests to exercise a different parsing path (or pass/fail for the wrong reason). Update the test command lines to include the explicit subcommand, e.g. wslc run --workdir ... and wslc create --workdir ... (and the -w variants) so the tests accurately cover the intended commands.
| // Test: Full parse of 'create -w /path image cmd' (short alias) sets WorkingDirectory | ||
| TEST_METHOD(CreateCommand_ParseWorkDirShortOption_SetsWorkingDirectory) | ||
| { | ||
| auto invocation = CreateInvocationFromCommandLine(L"wslc -w /app ubuntu sh"); |
There was a problem hiding this comment.
These tests are named/commented as parsing run ... and create ..., but the command lines passed to CreateInvocationFromCommandLine don’t include the run/create subcommand. This can cause the tests to exercise a different parsing path (or pass/fail for the wrong reason). Update the test command lines to include the explicit subcommand, e.g. wslc run --workdir ... and wslc create --workdir ... (and the -w variants) so the tests accurately cover the intended commands.
| command.ParseArguments(invocation, context.Args); | ||
|
|
||
| VERIFY_THROWS_SPECIFIC( | ||
| command.ValidateArguments(context.Args), wsl::windows::wslc::ArgumentException, [](const auto&) { return true; }); |
There was a problem hiding this comment.
The exception predicate always returns true, so these tests will pass for any ArgumentException (including ones thrown for unrelated validation failures). Make the predicate validate something specific to the --workdir empty-value case (e.g., the parameter name/flag in the message or an error code field, if available) so the test can’t succeed for the wrong reason.
| command.ValidateArguments(context.Args), wsl::windows::wslc::ArgumentException, [](const auto&) { return true; }); | |
| command.ValidateArguments(context.Args), | |
| wsl::windows::wslc::ArgumentException, | |
| [](const auto& ex) | |
| { | |
| const std::string message = ex.what(); | |
| const bool mentionsWorkDir = | |
| message.find("--workdir") != std::string::npos || | |
| message.find("workdir") != std::string::npos || | |
| message.find("-w") != std::string::npos; | |
| const bool mentionsEmptyOrInvalidValue = | |
| message.find("empty") != std::string::npos || | |
| message.find("invalid") != std::string::npos || | |
| message.find("value") != std::string::npos; | |
| return mentionsWorkDir && mentionsEmptyOrInvalidValue; | |
| }); |
| command.ParseArguments(invocation, context.Args); | ||
|
|
||
| VERIFY_THROWS_SPECIFIC( | ||
| command.ValidateArguments(context.Args), wsl::windows::wslc::ArgumentException, [](const auto&) { return true; }); |
There was a problem hiding this comment.
The exception predicate always returns true, so these tests will pass for any ArgumentException (including ones thrown for unrelated validation failures). Make the predicate validate something specific to the --workdir empty-value case (e.g., the parameter name/flag in the message or an error code field, if available) so the test can’t succeed for the wrong reason.
| command.ValidateArguments(context.Args), wsl::windows::wslc::ArgumentException, [](const auto&) { return true; }); | |
| command.ValidateArguments(context.Args), | |
| wsl::windows::wslc::ArgumentException, | |
| [](const auto& ex) | |
| { | |
| const std::string message = ex.what(); | |
| return message.find("workdir") != std::string::npos; | |
| }); |
|
|
||
| if (!options.WorkingDirectory.empty()) | ||
| { | ||
| containerLauncher.SetWorkingDirectory(std::string(options.WorkingDirectory)); |
There was a problem hiding this comment.
The std::string(options.WorkingDirectory) construction is redundant if options.WorkingDirectory is already a std::string (it forces an extra copy). Prefer passing options.WorkingDirectory directly, or std::move(options.WorkingDirectory) if ownership transfer is intended and options won’t use it afterward.
| containerLauncher.SetWorkingDirectory(std::string(options.WorkingDirectory)); | |
| containerLauncher.SetWorkingDirectory(options.WorkingDirectory); |
Addresses review feedback from @AmelBawa-msft on #40190: removes redundant short-alias E2E tests since coverage is already provided by help message tests and CLI parse tests.