CLI: Added container prune#40306
Conversation
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds a new wslc container prune command to remove stopped containers and reports reclaimed space, with accompanying localization strings and E2E coverage.
Changes:
- Registers a new
container prunesubcommand and wires it into task/service layers. - Implements prune logic in
ContainerServiceand output formatting inContainerTasks. - Adds E2E tests and new localized strings for prune output/help text.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| test/windows/wslc/e2e/WSLCE2EContainerTests.cpp | Adds prune to the container command list verification. |
| test/windows/wslc/e2e/WSLCE2EContainerPruneTests.cpp | New E2E test suite validating prune help and behavior. |
| src/windows/wslc/tasks/ContainerTasks.h | Exposes PruneContainers task entrypoint. |
| src/windows/wslc/tasks/ContainerTasks.cpp | Implements CLI output for deleted containers and reclaimed space. |
| src/windows/wslc/services/ContainerService.h | Exposes ContainerService::Prune. |
| src/windows/wslc/services/ContainerService.cpp | Calls session prune API and maps results into a model. |
| src/windows/wslc/services/ContainerModel.h | Introduces PruneContainersResult model. |
| src/windows/wslc/commands/ContainerPruneCommand.cpp | New command implementation wiring session creation + prune task. |
| src/windows/wslc/commands/ContainerCommand.h | Declares ContainerPruneCommand. |
| src/windows/wslc/commands/ContainerCommand.cpp | Registers ContainerPruneCommand under container. |
| localization/strings/en-US/Resources.resw | Adds localized strings for prune descriptions and output. |
| models::PruneContainersResult ContainerService::Prune(models::Session& session) | ||
| { | ||
| WSLCPruneContainersResults results{}; | ||
| THROW_IF_FAILED(session.Get()->PruneContainers(nullptr, 0, 0, &results)); | ||
|
|
||
| models::PruneContainersResult result; | ||
| result.SpaceReclaimed = results.SpaceReclaimed; | ||
| for (ULONG i = 0; i < results.ContainersCount; ++i) | ||
| { | ||
| result.DeletedContainers.push_back(results.Containers[i]); | ||
| } |
There was a problem hiding this comment.
This assumes results.Containers is valid and populated after calling PruneContainers(nullptr, 0, 0, &results), but no buffer is allocated/provided for container IDs. If the underlying API expects a caller-provided buffer (common for COM-style “get required size then allocate then call again”), this will read from an uninitialized pointer and/or produce incomplete results. If the API allocates memory, there’s also no ownership/cleanup shown, which risks leaking. Please update this to follow the API’s documented allocation pattern (e.g., two-pass call to obtain required size then allocate, or wrap returned memory in an owning RAII type and free it appropriately) and only iterate when the container list pointer is valid for the duration needed.
| 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.
The test asserts English output directly. Since prune output strings are now localized (and this test already uses Localization::... for help text), this can become brittle if tests run under a non-en-US locale or if the localized string changes. Prefer asserting using the localized resource (or a helper that derives the expected prefix from Localization::WSLCCLI_ContainerPruneSpaceReclaimed(...)) rather than hardcoding L"Total reclaimed space:".
|
PruneContainers allocates results. Containers via COM task memory but the caller never frees it. ImageService::Prune handles this correctly with wil::unique_cotaskmem_array_ptr — same pattern should be used here. |
Summary of the Pull Request
PR Checklist
Detailed Description of the Pull Request / Additional comments
Validation Steps Performed