Skip to content

Match docker's network list, inspect and prune output in wslc - #41377

Merged
ggarzia-MSFT merged 3 commits into
masterfrom
user/ggarzia/network-output-parity
Aug 20, 2026
Merged

Match docker's network list, inspect and prune output in wslc#41377
ggarzia-MSFT merged 3 commits into
masterfrom
user/ggarzia/network-output-parity

Conversation

@ggarzia-MSFT

Copy link
Copy Markdown
Contributor

Summary of the Pull Request

Brings wslc network list, wslc network inspect and wslc network prune output in line with docker. A side-by-side parity harness run against docker showed eleven divergences in the network command; this change addresses all of them except error message wording, which is tracked separately.

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

network list

  • Docker's predefined bridge, host and none networks are now listed. ListNetworks queries the daemon directly instead of returning only the session's managed-network map.
  • Added the SCOPE column, and networks are ordered by name, matching docker.
  • Table columns use docker's minimum column width so spacing is identical.
  • --format json now emits docker's nine all-string keys (CreatedAt, Driver, ID, IPv4, IPv6, Internal, Labels, Name, Scope) via a dedicated NetworkOutputInformation model, following the same pattern already used for image list output.
  • CreatedAt is rendered the way docker renders network timestamps: UTC, with the daemon's fractional-second digits preserved verbatim (2026-08-18 23:35:57.900958925 +0000 UTC). This is a new FormatDockerTimestamp(std::string_view) overload; the existing LONGLONG overload, which converts to local time for image and container output, is unchanged.

network inspect

  • Now a live passthrough of the daemon's inspect response instead of being reconstructed from cached session state, so predefined networks are inspectable and values cannot drift.
  • Emits docker's full field set: Created, EnableIPv4, EnableIPv6, Attachable, Ingress, ConfigOnly, ConfigFrom, Containers, Status and IPAM.Options.
  • Options is emitted as an object rather than null, and empty Gateway/IPRange entries are omitted, both matching docker.

network prune

  • Prints docker's Deleted Networks: header followed by bare network names and a trailing blank line, and prints nothing when no networks were removed.

Supporting changes

  • The internal IWSLCSession::ListNetworks now returns JSON instead of a fixed-size struct array. The list shape includes variable-length labels, which cannot be marshaled safely inside an out-array of structs. WSLCNetworkInformation and its serializer are removed. This interface is internal and ships in lockstep with its only clients; the SDK-facing WSLCCompat.idl and the plugin API are untouched.
  • docker_schema::Network and docker_schema::IPAM use hand-written deserializers that tolerate null, because the daemon reports some empty maps as null on predefined networks and the default deserializer rejects that.
  • The internal com.microsoft.wsl.network.managed label is stripped from both list and inspect output.
  • ParseDockerTimestamp moved out of WSLCContainer.cpp into docker_schema::ParseTimestamp and is now shared.

Deliberately out of scope: error message wording, the global JSON indent width and key ordering (shared by container, image and volume inspect), and network prune --force (-f is already the --filter alias and no wslc prune command prompts).

Validation Steps Performed

  • Full x64 Debug build clean; clang-format 19.1.5 clean.
  • Deployed to the host and re-ran the wslc-vs-docker parity harness (81 command pairs). All network cases now match docker: network list (table, --format json, -q, --no-trunc, -f driver=bridge) is byte-identical apart from the daemon-assigned IDs, network inspect matches field for field, and network prune matches exactly.
  • Remaining inspect differences are daemon-version artifacts, not CLI behavior: the host daemon populates Status.IPAM and com.docker.network.enable_ipv4/6 options that the daemon in the WSL VM does not report. Both are passed through unchanged.
  • Tests updated and added: service-level list tests reworked for the JSON API and predefined networks; new E2E coverage for predefined networks in list and inspect, the nine-key JSON shape, the UTC timestamp suffix, the new inspect fields, and the prune output format.

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

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

Updates WSLC’s network command output and underlying session/service plumbing to align wslc network list/inspect/prune behavior with Docker’s CLI output and JSON shapes, including predefined networks and additional inspect fields.

Changes:

  • Reworks IWSLCSession::ListNetworks to return a JSON payload (instead of a fixed struct array) and updates service/CLI layers to consume the new wslc_schema::NetworkListEntry model.
  • Aligns network list table/JSON output with Docker (sorting, additional columns/keys, docker-style timestamps, all-string JSON list model).
  • Aligns network inspect (passthrough + expanded schema) and network prune output formatting (header, names, blank trailing line; no output when nothing pruned).

Reviewed changes

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

Show a summary per file
File Description
test/windows/WSLCTests.cpp Updates service-level tests to consume JSON ListNetworks output and validate new fields/label stripping.
test/windows/wslc/WSLCCLIExecutionUnitTests.cpp Adjusts CLI unit test data wiring for the new network list entry type.
test/windows/wslc/e2e/WSLCE2ENetworkPruneTests.cpp Updates E2E expectations for Docker-like prune output formatting.
test/windows/wslc/e2e/WSLCE2ENetworkListTests.cpp Extends/updates E2E coverage for the 9-key JSON list shape and predefined networks.
test/windows/wslc/e2e/WSLCE2ENetworkInspectTests.cpp Adds/updates E2E coverage for predefined-network inspect and expanded inspect fields.
test/windows/wslc/e2e/WSLCE2ENetworkCreateTests.cpp Updates expectations for inspect Options now being an object/map rather than optional/null.
test/windows/wslc/e2e/WSLCE2EHelpers.h Adds a test-only NetworkListOutput model matching the CLI network list --format json shape.
test/windows/wslc/e2e/WSLCE2EHelpers.cpp Updates helper parsing for the new list JSON output model.
src/windows/wslcsession/WSLCSession.h Updates ListNetworks signature to return JSON via LPSTR* Output.
src/windows/wslcsession/WSLCSession.cpp Implements daemon-backed list + passthrough inspect, expands schema mapping, strips managed label from outputs.
src/windows/wslcsession/WSLCContainer.cpp Switches to shared docker_schema::ParseTimestamp helper.
src/windows/wslc/tasks/NetworkTasks.cpp Implements Docker-like list ordering/columns and prune output formatting; introduces shared list output model.
src/windows/wslc/services/NetworkService.h Updates List return type to wslc_schema::NetworkListEntry.
src/windows/wslc/services/NetworkService.cpp Parses JSON list payload from session into NetworkListEntry objects.
src/windows/wslc/services/NetworkModel.h Adds NetworkOutputInformation (all-string) model for Docker-like JSON list output.
src/windows/wslc/core/ExecutionContextData.h Updates execution context mapping to store NetworkListEntry vectors.
src/windows/service/inc/wslc.idl Removes WSLCNetworkInformation struct and updates ListNetworks IDL signature to return JSON.
src/windows/inc/wslc_schema.h Expands network schema (inspect fields, containers, status, IPAM options) and adds NetworkListEntry.
src/windows/inc/docker_schema.h Adds null-tolerant deserialization helpers and expands docker network schema; adds shared timestamp parser.
src/windows/common/string.hpp Adds FormatDockerTimestamp(std::string_view) overload for Docker-like network timestamps.
src/windows/common/string.cpp Implements Docker-like network timestamp formatting preserving fractional seconds.
src/shared/inc/JsonUtils.h Removes WSLCNetworkInformation JSON serializer (no longer used).
localization/strings/en-US/Resources.resw Updates prune strings to Docker-like “Deleted Networks:” header.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/windows/service/inc/wslc.idl Outdated
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings August 19, 2026 17:12

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 23 out of 23 changed files in this pull request and generated no new comments.

Suppressed comments (1)

test/windows/wslc/e2e/WSLCE2ENetworkPruneTests.cpp:60

  • network prune is intended (per updated behavior) to print nothing when no networks are removed, but this test only asserts that the output does not contain the test network names. That would still pass if wslc printed an unexpected header/whitespace or other unrelated output. Tighten the assertion to require an empty stdout string so the test actually enforces the contract.
    WSLC_TEST_METHOD(WSLCE2E_Network_Prune_NoNetworks)
    {
        // Prune when no unused networks exist should succeed without reporting any of our test networks.
        const auto result = RunWslc(L"network prune");
        result.Verify({.Stderr = L"", .ExitCode = 0});

        VERIFY_IS_FALSE(result.StdoutContainsLine(TestNetworkName));
        VERIFY_IS_FALSE(result.StdoutContainsLine(TestNetworkName2));

@ggarzia-MSFT
ggarzia-MSFT marked this pull request as ready for review August 19, 2026 17:23
@ggarzia-MSFT
ggarzia-MSFT requested review from a team as code owners August 19, 2026 17:23
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings August 19, 2026 17:52

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 24 out of 24 changed files in this pull request and generated 1 comment.

Comment thread src/windows/common/string.cpp

@OneBlue Blue (OneBlue) left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM. Feel free to resolve the minor comments in a followup PR

std::chrono::sys_seconds parsed{};
std::istringstream stream(parsable);
stream >> std::chrono::parse("%FT%H:%M:%S%Z", parsed);
if (stream.fail())

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

If we fail to parse I think we should throw an exception here, otherwise this could mask errors

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I guess the easiest way to solve this would be to call Rfc3339ToEpoch here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Will address in follow up

@ggarzia-MSFT
ggarzia-MSFT merged commit fc0e0b0 into master Aug 20, 2026
12 checks passed
@ggarzia-MSFT
ggarzia-MSFT deleted the user/ggarzia/network-output-parity branch August 20, 2026 17:37
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.

3 participants