wslc: add --size to container list for docker parity - #41477
wslc: add --size to container list for docker parity#41477ggarzia-MSFT wants to merge 6 commits into
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Adds Docker-parity support for --size / -s on wslc container list (and ls / ps aliases) by plumbing a new list-containers flag through the CLI → service/session → Docker API call chain, and displaying a SIZE table column when requested.
Changes:
- Add
--size/-sCLI flag and localized help/table header strings. - Request and propagate
SizeRw/SizeRootFsfrom the Docker daemon (/containers/json?size=...) through WSLC APIs and models. - Update table formatting to conditionally include a
SIZEcolumn; add parser/unit/e2e test coverage for the new option.
Reviewed changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| test/windows/wslc/WSLCCLICommandUnitTests.cpp | Adds a unit test asserting container list registers --size with -s alias as a flag. |
| test/windows/wslc/e2e/WSLCE2EContainerListTests.cpp | Adds end-to-end coverage verifying SIZE column behavior for --size, -s, ps --size, and interaction with --quiet. |
| test/windows/wslc/CommandLineTestCases.h | Adds command-line parser test cases for --size and related forms/alias combinations. |
| src/windows/wslcsession/WSLCSession.cpp | Plumbs the new list-containers flag through the session and copies size fields into output entries. |
| src/windows/wslcsession/DockerHTTPClient.h | Extends ListContainers(...) API to accept a size boolean. |
| src/windows/wslcsession/DockerHTTPClient.cpp | Adds size query parameter to /containers/json request. |
| src/windows/wslc/tasks/ContainerTasks.cpp | Adds FormatContainerSize(...) and conditionally appends the SIZE column for table output. |
| src/windows/wslc/services/ContainerService.h | Extends ContainerService::List(...) signature to accept a size boolean. |
| src/windows/wslc/services/ContainerService.cpp | Sets the new WSLC list-containers flag and copies size fields into the CLI model. |
| src/windows/wslc/services/ContainerModel.h | Extends ContainerInformation with SizeRw / SizeRootFs and updates JSON serialization mapping. |
| src/windows/wslc/commands/ContainerListCommand.cpp | Registers the new ArgType::Size argument for container list. |
| src/windows/wslc/arguments/ArgumentDefinitions.h | Defines ArgType::Size (--size, -s) with localized description. |
| src/windows/service/inc/WSLCShared.idl | Adds WSLCListContainersFlagsSize and updates the valid-flags mask. |
| src/windows/service/inc/wslc.idl | Extends WSLCContainerEntry to include size fields. |
| src/windows/inc/docker_schema.h | Extends docker_schema::ContainerInfo to parse SizeRw / SizeRootFs from daemon JSON. |
| localization/strings/en-US/Resources.resw | Adds localized strings for --size description and SIZE table header. |
Suppressed comments (3)
test/windows/wslc/e2e/WSLCE2EContainerListTests.cpp:190
- The SIZE column presence check uses a substring search over the entire output, which could match container rows. Checking the first (header) line makes the assertion deterministic.
// --size appends a SIZE column reporting the writable layer and the virtual total.
result = RunWslc(L"container list --size");
result.Verify({.Stderr = L"", .ExitCode = 0});
VERIFY_IS_TRUE(result.StdoutContainsSubstring(L"SIZE"));
test/windows/wslc/e2e/WSLCE2EContainerListTests.cpp:198
- This SIZE column assertion is a broad substring check. For stability, it’s better to assert against the header line (first line of stdout).
// -s is the docker alias and produces the same column.
auto aliasResult = RunWslc(L"container list -s");
aliasResult.Verify({.Stderr = L"", .ExitCode = 0});
VERIFY_IS_TRUE(aliasResult.StdoutContainsSubstring(L"SIZE"));
test/windows/wslc/e2e/WSLCE2EContainerListTests.cpp:207
- This test checks for "SIZE" anywhere in stdout; that can be non-deterministic if a row contains the substring. Consider validating the header line instead.
// ps is an alias of list and accepts the option too.
auto psResult = RunWslc(L"ps --size");
psResult.Verify({.Stderr = L"", .ExitCode = 0});
VERIFY_IS_TRUE(psResult.StdoutContainsSubstring(L"SIZE"));
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 16 out of 16 changed files in this pull request and generated no new comments.
Suppressed comments (2)
Previously missed (2) — in code that hasn't changed since the last review.
test/windows/wslc/e2e/WSLCE2EContainerListTests.cpp:242
- This help-text assertion hard-codes the English description string. Since the description is localized (Resources.resw), the test should compare against Localization::WSLCCLI_SizeArgDescription() to avoid breaking when the resource text changes.
result.Verify({.Stderr = L"", .ExitCode = 0});
VERIFY_IS_TRUE(result.StdoutContainsSubstring(L"--size"));
VERIFY_IS_TRUE(result.StdoutContainsSubstring(L"Display total file sizes"));
}
src/windows/wslc/tasks/ContainerTasks.cpp:70
- The "(virtual …)" suffix in the SIZE column is user-facing output but is currently hard-coded in English. Since wslc uses Localization for other user-visible strings (headers/help), this suffix/format should also come from a localized resource string rather than a hard-coded literal.
return std::format(L"{} (virtual {})", writable, FormatHumanReadableSize(static_cast<uint64_t>(SizeRootFs), c_statsIoPrecision));
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…user/ggarzia/wslc-ps-size # Conflicts: # src/windows/wslc/tasks/ContainerTasks.cpp # test/windows/wslc/CommandLineTestCases.h # test/windows/wslc/WSLCCLICommandUnitTests.cpp
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 15 out of 15 changed files in this pull request and generated 1 comment.
Suppressed comments (1)
Previously missed (1) — in code that hasn't changed since the last review.
test/windows/wslc/CommandLineTestCases.h:81
- PR description says
CommandLineTestCases.hadds coverage for--size=true/false,--size=invalid,-as,-s -q, and--size --no-trunc, but those cases aren't present in this file. Either add the missing parser cases or update the PR description so it matches what’s actually covered.
COMMAND_LINE_TEST_CASE(L"container list --size", L"list", true)
COMMAND_LINE_TEST_CASE(L"container list -s", L"list", true)
COMMAND_LINE_TEST_CASE(L"ps --size", L"list", true)
COMMAND_LINE_TEST_CASE(L"container ps -s", L"list", true)
COMMAND_LINE_TEST_CASE(L"container list --size extra", L"list", false)
…widths Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 16 out of 16 changed files in this pull request and generated no new comments.
Suppressed comments (1)
src/windows/wslc/tasks/ContainerTasks.cpp:219
GetContainers()requests container sizes from the daemon whenever--sizeis present, even if--quietis also set. Since the quiet path prints only IDs and ignores the SIZE column, this can trigger unnecessary (and potentially expensive) size computation/server work forcontainer list --quiet --size.
Consider gating the size request on quiet as well, so --quiet avoids the extra API cost while preserving the existing output behavior.
// `container stats` reuses this task and does not register --size.
const bool size = context.Args.Contains(ArgType::Size) && context.Args.GetValue<ArgType::Size>();
context.Data.Add<Data::Containers>(ContainerService::List(session, context.Args.GetValue<ArgType::All>(), limit, filters, size));
Summary of the Pull Request
Adds the
--size/-soption towslc container list(and itsls/psaliases) for docker CLI parity.docker ps --sizeappends aSIZEcolumn showing how much data the container has written to its writable layer, plus the virtual total once the read-only image layers are included.wslc pshad no way to surface that, and the underlyingSizeRw/SizeRootFsfields were never requested from or parsed out of the daemon.PR Checklist
Detailed Description of the Pull Request / Additional comments
Validation Steps Performed
Manual, against a local build:
Parser coverage (
CommandLineTestCases.h) — 12 new cases:container list --size,container list -s,ps --size,container ps -s--size=true/--size=falseexplicit forms,--size=invalidrejected-asand-s -qalias chains,--size --no-trunccontainer list --size extrarejected —pstakes no positional argumentsUnit test (
WSLCCLICommandUnitTests.cpp):ContainerListCommand_HasSizeArgumentWithDockerAlias— asserts the registered argument is namedsize, aliaseds, and is aKind::Flag.AllCommands_NoAmbiguousArgumentNamesOrAliasestree walk still passes, which is the check that matters here:ArgType::Signalalso uses-s, and this confirms no command registers both.End-to-end tests (
WSLCE2EContainerListTests.cpp):WSLCE2E_Container_List_SizeOption— runs a container, confirms plaincontainer listhas noSIZEcolumn, then confirms--size,-s, andps --sizeall produce the column and that the container's row contains the(virtual …)total.WSLCE2E_Container_List_SizeOption_QuietStillOutputsIdsOnly—--quiet --sizestill emits bare IDs with no column headers.WSLCE2E_Container_List_SizeOption_ListedInHelp— the flag and its description appear incontainer list --help.