CLI: Add container prune command#40547
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>
| // Prune when no stopped containers exist should succeed with zero reclaimed space | ||
| const auto result = RunWslc(L"container prune"); | ||
| result.Verify({.Stderr = L"", .ExitCode = 0}); | ||
|
|
||
| VerifyStdoutContains(result, L"Total reclaimed space:"); |
There was a problem hiding this comment.
Since it's zero reclaimed, can we use the .Verify({.Stdout = "...: 0", ...}); instead?
| const auto result = RunWslc(L"container prune"); | ||
| result.Verify({.Stderr = L"", .ExitCode = 0}); | ||
|
|
||
| VerifyStdoutContains(result, L"Total reclaimed space:"); |
There was a problem hiding this comment.
Is there a chance we can hardcode the values here based on manual test, or they are unpredictable?
| auto listResult = RunWslc(L"container list --all"); | ||
| listResult.Verify({.Stderr = L"", .ExitCode = 0}); | ||
| for (const auto& line : listResult.GetStdoutLines()) | ||
| { | ||
| VERIFY_IS_FALSE( | ||
| line.find(L"prune-test-container") != std::wstring::npos, | ||
| L"Container 'prune-test-container' should have been pruned"); | ||
| } |
There was a problem hiding this comment.
We have a method for this VerifyContainerIsNotListed 😊
There was a problem hiding this comment.
Same for the other methods
| private: | ||
| const TestImage& DebianImage = DebianTestImage(); | ||
|
|
||
| static void VerifyStdoutContains(const WSLCExecutionResult& result, const std::wstring& substring) |
There was a problem hiding this comment.
Unless my comment suggestion above does not help eliminate the need for this method, I would suggest moving this method to the WSLCExecutor where another method called StdoutContainsLine method exist.
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.
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