Skip to content

CLI: Add container prune command#40547

Open
ptrivedi wants to merge 3 commits into
masterfrom
user/ptrivedi/container-prune
Open

CLI: Add container prune command#40547
ptrivedi wants to merge 3 commits into
masterfrom
user/ptrivedi/container-prune

Conversation

@ptrivedi
Copy link
Copy Markdown
Contributor

Summary

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 for exception-safe CoTaskMem cleanup
  • PruneContainers task: Prints pruned container IDs and total reclaimed space
  • PruneContainersResult: New model struct in ContainerModel.h
  • Localization: 3 new strings (description, long description, space reclaimed format)
  • Unit tests: CLI parsing test cases in CommandLineTestCases.h
  • E2E tests: Help output, no-stopped containers, stopped container pruned, running container preserved, multiple stopped containers
  • Updated container help output test to include prune subcommand

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>
Comment thread test/windows/wslc/e2e/WSLCE2EContainerPruneTests.cpp Outdated
Comment thread test/windows/wslc/e2e/WSLCE2EContainerPruneTests.cpp Outdated
Comment thread test/windows/wslc/e2e/WSLCE2EContainerPruneTests.cpp Outdated
Comment thread test/windows/wslc/e2e/WSLCE2EContainerPruneTests.cpp Outdated
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.

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>
Copilot AI review requested due to automatic review settings May 18, 2026 20:53
@ptrivedi ptrivedi marked this pull request as ready for review May 18, 2026 20:54
@ptrivedi ptrivedi requested a review from a team as a code owner May 18, 2026 20:54
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 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;
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.

4 participants