Skip to content

[WSLC] Add --workdir / -w option to 'wslc exec'#40041

Merged
ptrivedi merged 24 commits intofeature/wsl-for-appsfrom
user/ptrivedi/exec-workingdir
Apr 6, 2026
Merged

[WSLC] Add --workdir / -w option to 'wslc exec'#40041
ptrivedi merged 24 commits intofeature/wsl-for-appsfrom
user/ptrivedi/exec-workingdir

Conversation

@ptrivedi
Copy link
Copy Markdown

@ptrivedi ptrivedi commented Mar 30, 2026

Summary of the Pull Request

  • Adds --workdir / -w option to wslc exec to set the working directory inside the container
  • Passes the value through SetContainerOptionsFromArgs into ContainerOptions.WorkingDirectory
  • Forwards the working directory to the container service via ContainerService::Exec
  • Validates that the --workdir value is non-empty or all-whitespace using std::iswspace (covers all Unicode whitespace characters)

PR Checklist

  • 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

Changes:

  • ArgumentDefinitions.h: register WorkDir argument with long form --workdir and short alias -w (appended at end to preserve sorted order of X-macro list)
  • ContainerExecCommand.cpp: include WorkDir in the exec command's argument list
  • ContainerModel.h: add WorkingDirectory field to ContainerOptions
  • ContainerTasks.cpp: read WorkDir arg and populate options.WorkingDirectory
  • ContainerService.cpp: pass WorkingDirectory when calling exec on the container
  • ArgumentValidation.cpp: validate --workdir is non-empty/non-whitespace using std::all_of with std::iswspace (with explicit wint_t cast) to correctly handle all Unicode whitespace, not just space and tab

Tests:

  • CommandLineTestCases.h: parsing cases for --workdir and -w (valid with option before positional, missing value, invalid specifier after positional)
  • WSLCCLIExecutionUnitTests.cpp: unit tests covering:
    • SetContainerOptionsFromArgs sets WorkingDirectory when --workdir is provided
    • SetContainerOptionsFromArgs leaves WorkingDirectory empty when not provided
    • End-to-end parse of --workdir long option sets WorkingDirectory
    • End-to-end parse of -w short alias sets WorkingDirectory
    • Empty --workdir value throws ArgumentException
  • WSLCE2EContainerExecTests.cpp: E2E tests covering:
    • Help message includes -w,--workdir
    • exec --workdir /tmp <container> pwd prints /tmp
    • exec -w /tmp <container> pwd prints /tmp

Validation Steps Performed

  • Build and run unit tests: bin\<platform>\<target>\test.bat /name:*WSLCCLIExecutionUnitTests*
  • Verify wslc exec --workdir /app <container> pwd prints /app
  • Verify wslc exec -w /tmp <container> pwd prints /tmp
  • Verify wslc exec <container> pwd uses the container's default working directory

Pooja Trivedi added 2 commits March 30, 2026 13:41
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 <[email protected]>
Co-Authored-By: Claude Sonnet 4.6
@ptrivedi ptrivedi requested a review from a team as a code owner March 30, 2026 19:37
Copilot AI review requested due to automatic review settings March 30, 2026 19:37
Copy link
Copy Markdown
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 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 in ContainerExecCommand’s supported arguments.
  • Populate ContainerOptions.WorkingDirectory from parsed args and forward it into WSLCProcessLauncher for 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).

Copilot AI review requested due to automatic review settings March 30, 2026 19:48
Copy link
Copy Markdown
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 7 out of 7 changed files in this pull request and generated 1 comment.

Copilot AI review requested due to automatic review settings March 30, 2026 20:56
Copy link
Copy Markdown
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 7 out of 7 changed files in this pull request and generated no new comments.

Copy link
Copy Markdown

@AmelBawa-msft AmelBawa-msft left a comment

Choose a reason for hiding this comment

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

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 😊

Copy link
Copy Markdown
Member

@dkbennett dkbennett left a comment

Choose a reason for hiding this comment

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

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.

Copilot AI review requested due to automatic review settings April 2, 2026 18:02
Copy link
Copy Markdown
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 7 out of 7 changed files in this pull request and generated 3 comments.

@ptrivedi ptrivedi force-pushed the user/ptrivedi/exec-workingdir branch from 7924dd9 to ce1e458 Compare April 2, 2026 18:32
Copilot AI review requested due to automatic review settings April 2, 2026 18:35
Copy link
Copy Markdown
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 7 out of 7 changed files in this pull request and generated no new comments.

Pooja Trivedi and others added 4 commits April 2, 2026 15:00
- 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 <[email protected]>
- 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 <[email protected]>
Co-Authored-By: Claude Sonnet 4.6
Copilot AI review requested due to automatic review settings April 3, 2026 21:29
@ptrivedi ptrivedi review requested due to automatic review settings April 3, 2026 21:29
Copilot AI review requested due to automatic review settings April 3, 2026 21:33
@ptrivedi ptrivedi review requested due to automatic review settings April 3, 2026 21:33
Copilot AI review requested due to automatic review settings April 3, 2026 21:41
Copy link
Copy Markdown
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 1 comment.

Pooja Trivedi and others added 2 commits April 4, 2026 01:04
- 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
Copilot AI review requested due to automatic review settings April 4, 2026 05:13
Copy link
Copy Markdown
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 11 out of 11 changed files in this pull request and generated 1 comment.

Copilot AI review requested due to automatic review settings April 4, 2026 05:21
Copy link
Copy Markdown
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 11 out of 11 changed files in this pull request and generated no new comments.

Pooja Trivedi and others added 3 commits April 6, 2026 09:37
…flag parse tests

The -v short alias was removed from --verbose (changed to NO_ALIAS) to
resolve a triple alias conflict with --version and --volume. The parser
test cases in the Run argument set still used -v expecting it to resolve
to --verbose, but since neither Version nor Volume are in the Run set,
-v became unresolvable and caused unexpected parse failures.

Replace -v with -h (help flag) in the flag parse test cases to preserve
the same combined-flag parsing coverage with a valid short alias.

Co-authored-by: Copilot <[email protected]>
After merging feature/wsl-for-apps, the --user argument is now active
in ContainerExecCommand (from PR #40101). Update the expected exec help
output to include -u,--user.

Co-authored-by: Copilot <[email protected]>
Copilot AI review requested due to automatic review settings April 6, 2026 16:09
Copy link
Copy Markdown
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 12 out of 12 changed files in this pull request and generated no new comments.

@ptrivedi ptrivedi merged commit 2d8c8cf into feature/wsl-for-apps Apr 6, 2026
11 checks passed
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.

6 participants