[WSLC] Add --workdir / -w option to 'wslc exec'#40041
[WSLC] Add --workdir / -w option to 'wslc exec'#40041ptrivedi wants to merge 21 commits intofeature/wsl-for-appsfrom
Conversation
Adds a --workdir (-w) argument to the exec command that sets the working directory inside the container for the executed process. Wires the value through ContainerOptions into WSLAProcessLauncher::SetWorkingDirectory. Co-authored-by: Pooja Trivedi <trivedipooja@microsoft.com> Co-Authored-By: Claude Sonnet 4.6
There was a problem hiding this comment.
Pull request overview
Adds support for specifying a working directory for wslc exec, wiring a new --workdir/-w CLI argument through argument parsing into ContainerOptions and down to the container exec launcher.
Changes:
- Add
ArgType::WorkDir(--workdir/-w) and include it inContainerExecCommand’s supported arguments. - Populate
ContainerOptions.WorkingDirectoryfrom parsed args and forward it intoWSLCProcessLauncherfor container exec. - Add/extend unit tests and command-line parsing test cases for the new option.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| test/windows/wslc/WSLCCLIExecutionUnitTests.cpp | Adds unit tests validating WorkingDirectory is set/empty appropriately and parsed via ContainerExecCommand. |
| test/windows/wslc/CommandLineTestCases.h | Adds command-line parsing cases covering --workdir / -w usage and a missing-value case. |
| src/windows/wslc/tasks/ContainerTasks.cpp | Reads WorkDir and sets ContainerOptions.WorkingDirectory. |
| src/windows/wslc/services/ContainerService.cpp | Applies WorkingDirectory to the WSLCProcessLauncher before launching container exec. |
| src/windows/wslc/services/ContainerModel.h | Adds WorkingDirectory field to ContainerOptions. |
| src/windows/wslc/commands/ContainerExecCommand.cpp | Registers WorkDir as an accepted argument for container exec. |
| src/windows/wslc/arguments/ArgumentDefinitions.h | Defines the new WorkDir argument (--workdir / -w). |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
AmelBawa-msft
left a comment
There was a problem hiding this comment.
LGTM! I suspect E2E tests will fail because we need to update the expected E2E test help messages. We should consider adding E2E tests as well but possibly in a separate PR since we still have a lot more E2E tests to write 😊
dkbennett
left a comment
There was a problem hiding this comment.
Looks good, like the setting unit tests. An E2E with working directory would be nice but this looks like we are correctly setting the value in the CLI and passing it into the container runtime. Assuming that has tests this should be good, though it doesn't hurt to have a CLI E2E or two for this.
nit: sort order of _WorkDir as Amir mentioned.
7924dd9 to
ce1e458
Compare
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
- Port existing exec E2E tests from feature branch - Add WSLCE2E_Container_Exec_WorkDir and WSLCE2E_Container_Exec_WorkDir_ShortAlias tests - Update help message in GetAvailableOptions to include -w,--workdir Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Reject empty or whitespace-only --workdir in Argument::Validate - Add ExecCommand_ParseWorkDirEmptyValue_ThrowsArgumentException unit test - Add empty-workdir failing case to CommandLineTestCases.h Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6
Remove tests that duplicate existing coverage in WSLCE2EContainerCreateTests.cpp. Keep only the help message test (validates --workdir appears in output) and the two workdir-specific E2E tests. Co-Authored-By: Claude Sonnet 4.6
Added E2E tests. @dkbennett @AmelBawa-msft PTAL and please hit merge if good. thanks! |
…code coverage Agent-Logs-Url: https://github.com/microsoft/WSL/sessions/b21d1a57-bb3f-4a12-84cf-8e414a453890 Co-authored-by: ptrivedi <1638019+ptrivedi@users.noreply.github.com>
Agent-Logs-Url: https://github.com/microsoft/WSL/sessions/b21d1a57-bb3f-4a12-84cf-8e414a453890 Co-authored-by: ptrivedi <1638019+ptrivedi@users.noreply.github.com>
…crosoft/WSL into user/ptrivedi/exec-workingdir
- Revert Version ArgType alias from NO_ALIAS back to L"v" to preserve existing -v short option - Restore WSLCE2EContainerExecTests.cpp lost in merge conflict resolution Co-Authored-By: Pooja Trivedi
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Summary of the Pull Request
--workdir/-woption towslc execto set the working directory inside the containerSetContainerOptionsFromArgsintoContainerOptions.WorkingDirectoryContainerService::Exec--workdirvalue is non-empty or all-whitespace usingstd::iswspace(covers all Unicode whitespace characters)PR Checklist
Detailed Description of the Pull Request / Additional comments
Changes:
ArgumentDefinitions.h: registerWorkDirargument with long form--workdirand short alias-w(appended at end to preserve sorted order of X-macro list)ContainerExecCommand.cpp: includeWorkDirin the exec command's argument listContainerModel.h: addWorkingDirectoryfield toContainerOptionsContainerTasks.cpp: readWorkDirarg and populateoptions.WorkingDirectoryContainerService.cpp: passWorkingDirectorywhen calling exec on the containerArgumentValidation.cpp: validate--workdiris non-empty/non-whitespace usingstd::all_ofwithstd::iswspace(with explicitwint_tcast) to correctly handle all Unicode whitespace, not just space and tabTests:
CommandLineTestCases.h: parsing cases for--workdirand-w(valid with option before positional, missing value, invalid specifier after positional)WSLCCLIExecutionUnitTests.cpp: unit tests covering:SetContainerOptionsFromArgssetsWorkingDirectorywhen--workdiris providedSetContainerOptionsFromArgsleavesWorkingDirectoryempty when not provided--workdirlong option setsWorkingDirectory-wshort alias setsWorkingDirectory--workdirvalue throwsArgumentExceptionWSLCE2EContainerExecTests.cpp: E2E tests covering:-w,--workdirexec --workdir /tmp <container> pwdprints/tmpexec -w /tmp <container> pwdprints/tmpValidation Steps Performed
bin\<platform>\<target>\test.bat /name:*WSLCCLIExecutionUnitTests*wslc exec --workdir /app <container> pwdprints/appwslc exec -w /tmp <container> pwdprints/tmpwslc exec <container> pwduses the container's default working directory