Skip to content

wslc: add --size to container list for docker parity - #41477

Draft
ggarzia-MSFT wants to merge 6 commits into
masterfrom
user/ggarzia/wslc-ps-size
Draft

wslc: add --size to container list for docker parity#41477
ggarzia-MSFT wants to merge 6 commits into
masterfrom
user/ggarzia/wslc-ps-size

Conversation

@ggarzia-MSFT

Copy link
Copy Markdown
Contributor

Summary of the Pull Request

Adds the --size / -s option to wslc container list (and its ls / ps aliases) for docker CLI parity.

docker ps --size appends a SIZE column 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 ps had no way to surface that, and the underlying SizeRw / SizeRootFs fields were never requested from or parsed out of the daemon.

PR Checklist

  • Closes: Link to issue #xxx
  • Communication: I've discussed this with core contributors already. If work hasn't been agreed, this work might be rejected
  • Tests: Added/updated if needed and all pass
  • Localization: All end user facing strings can be localized
  • Dev docs: Added/updated if needed
  • Documentation updated: If checked, please file a pull request on our docs repo and link it here: #xxx

Detailed Description of the Pull Request / Additional comments

Validation Steps Performed

Manual, against a local build:

> wslc container list --help
  -q  --quiet     Outputs the container IDs only
  -s  --size      Display total file sizes

> wslc container list extra
Found a positional argument when none was expected: 'extra'

Parser coverage (CommandLineTestCases.h) — 12 new cases:

  • container list --size, container list -s, ps --size, container ps -s
  • --size=true / --size=false explicit forms, --size=invalid rejected
  • -as and -s -q alias chains, --size --no-trunc
  • container list --size extra rejected — ps takes no positional arguments

Unit test (WSLCCLICommandUnitTests.cpp):

  • ContainerListCommand_HasSizeArgumentWithDockerAlias — asserts the registered argument is named size, aliased s, and is a Kind::Flag.
  • The pre-existing AllCommands_NoAmbiguousArgumentNamesOrAliases tree walk still passes, which is the check that matters here: ArgType::Signal also uses -s, and this confirms no command registers both.

End-to-end tests (WSLCE2EContainerListTests.cpp):

  • WSLCE2E_Container_List_SizeOption — runs a container, confirms plain container list has no SIZE column, then confirms --size, -s, and ps --size all produce the column and that the container's row contains the (virtual …) total.
  • WSLCE2E_Container_List_SizeOption_QuietStillOutputsIdsOnly--quiet --size still emits bare IDs with no column headers.
  • WSLCE2E_Container_List_SizeOption_ListedInHelp — the flag and its description appear in container list --help.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI lite review requested due to automatic review settings August 28, 2026 22:42

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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/-s CLI flag and localized help/table header strings.
  • Request and propagate SizeRw / SizeRootFs from the Docker daemon (/containers/json?size=...) through WSLC APIs and models.
  • Update table formatting to conditionally include a SIZE column; 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.

Comment thread src/windows/wslc/tasks/ContainerTasks.cpp
Comment thread test/windows/wslc/e2e/WSLCE2EContainerListTests.cpp Outdated
Comment thread src/windows/service/inc/wslc.idl
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings August 31, 2026 17:44

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 16 out of 16 changed files in this pull request and generated 1 comment.

Comment thread src/windows/wslc/services/ContainerModel.h
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings August 31, 2026 21:35

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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));

ggarzia-MSFT and others added 2 commits August 31, 2026 15:55
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
Copilot AI review requested due to automatic review settings August 31, 2026 22:56

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.h adds 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)

Comment thread src/windows/wslc/tasks/ContainerTasks.cpp
…widths

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings September 1, 2026 16:39

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 --size is present, even if --quiet is 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 for container 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));

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.

2 participants