CLI: Add container prune command#40547
Open
ptrivedi wants to merge 3 commits into
Open
Conversation
Implement the 'wslc container prune' command to remove all stopped containers. The backend IWSLCSession::PruneContainers API already exists; this adds the CLI frontend. Changes: - ContainerPruneCommand: new command class with --session arg - ContainerService::Prune(): service layer using RAII PruneResult - PruneContainers task: prints pruned container IDs and reclaimed space - PruneContainersResult model struct - 3 localization strings (desc, long desc, space reclaimed) - CLI parsing unit tests in CommandLineTestCases.h - E2E tests: help, no-stopped, stopped, running-preserved, multi-stopped - Updated container help output test to include prune subcommand Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
dkbennett
reviewed
May 15, 2026
Member
dkbennett
left a comment
There was a problem hiding this comment.
Implementation looks good; have same feedback as Amir regarding some of the test code.
- Add StdoutContainsSubstring() to WSLCExecutionResult for reusable substring matching (per reviewer suggestion to move to WSLCExecutor) - Replace manual container list loops with VerifyContainerIsNotListed() and VerifyContainerIsListed() helpers - Use exact localized string match for zero-reclaimed-space assertion - Remove private VerifyStdoutContains helper (now in WSLCExecutor) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
dkbennett
approved these changes
May 18, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
Adds the wslc container prune CLI frontend for the existing backend prune API, including command registration, service/task plumbing, localization, and tests.
Changes:
- Adds
ContainerPruneCommand,ContainerService::Prune, and task output for deleted container IDs plus reclaimed space. - Adds a prune result model and localized CLI/help strings.
- Adds command-line parsing and E2E coverage for prune scenarios.
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
src/windows/wslc/commands/ContainerPruneCommand.cpp |
Implements the new prune command. |
src/windows/wslc/commands/ContainerCommand.h |
Declares the prune command type. |
src/windows/wslc/commands/ContainerCommand.cpp |
Registers prune under container. |
src/windows/wslc/tasks/ContainerTasks.h |
Declares the prune task. |
src/windows/wslc/tasks/ContainerTasks.cpp |
Calls prune service and prints results. |
src/windows/wslc/services/ContainerService.h |
Exposes prune service API. |
src/windows/wslc/services/ContainerService.cpp |
Wraps backend prune API and copies results. |
src/windows/wslc/services/ContainerModel.h |
Adds prune result model. |
localization/strings/en-US/Resources.resw |
Adds prune descriptions and reclaimed-space text. |
test/windows/wslc/CommandLineTestCases.h |
Adds prune parsing cases. |
test/windows/wslc/e2e/WSLCExecutor.h |
Adds stdout substring helper declaration. |
test/windows/wslc/e2e/WSLCExecutor.cpp |
Adds stdout substring helper implementation. |
test/windows/wslc/e2e/WSLCE2EContainerTests.cpp |
Updates container help expectation. |
test/windows/wslc/e2e/WSLCE2EContainerPruneTests.cpp |
Adds prune E2E tests. |
Comments suppressed due to low confidence (1)
test/windows/wslc/e2e/WSLCE2EContainerPruneTests.cpp:106
- The multiple-container case verifies removal but not that all pruned IDs are printed. If the task only printed one deleted container (or none), this test would still pass; assert both created container IDs are present in stdout.
const auto result = RunWslc(L"container prune");
result.Verify({.Stderr = L"", .ExitCode = 0});
VERIFY_IS_TRUE(result.StdoutContainsSubstring(L"Total reclaimed space:"));
Comment on lines
+26
to
+30
| TEST_CLASS_SETUP(ClassSetup) | ||
| { | ||
| EnsureImageIsLoaded(DebianImage); | ||
| return true; | ||
| } |
| const auto result = RunWslc(L"container prune"); | ||
| result.Verify({.Stderr = L"", .ExitCode = 0}); | ||
|
|
||
| VERIFY_IS_TRUE(result.StdoutContainsSubstring(L"Total reclaimed space:")); |
|
|
||
| struct PruneContainersResult | ||
| { | ||
| std::vector<std::string> Containers; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implement the
wslc container prunecommand to remove all stopped containers. The backendIWSLCSession::PruneContainersAPI already exists; this adds the CLI frontend.Changes
--sessionargPruneResultfor exception-safe CoTaskMem cleanupprunesubcommand