Match docker's network list, inspect and prune output in wslc - #41377
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
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::ListNetworksto return a JSON payload (instead of a fixed struct array) and updates service/CLI layers to consume the newwslc_schema::NetworkListEntrymodel. - Aligns
network listtable/JSON output with Docker (sorting, additional columns/keys, docker-style timestamps, all-string JSON list model). - Aligns
network inspect(passthrough + expanded schema) andnetwork pruneoutput 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.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
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 pruneis 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 ifwslcprinted 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));
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Blue (OneBlue)
left a comment
There was a problem hiding this comment.
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()) |
There was a problem hiding this comment.
If we fail to parse I think we should throw an exception here, otherwise this could mask errors
There was a problem hiding this comment.
I guess the easiest way to solve this would be to call Rfc3339ToEpoch here
There was a problem hiding this comment.
Will address in follow up
Summary of the Pull Request
Brings
wslc network list,wslc network inspectandwslc network pruneoutput 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
Detailed Description of the Pull Request / Additional comments
network listbridge,hostandnonenetworks are now listed.ListNetworksqueries the daemon directly instead of returning only the session's managed-network map.SCOPEcolumn, and networks are ordered by name, matching docker.--format jsonnow emits docker's nine all-string keys (CreatedAt,Driver,ID,IPv4,IPv6,Internal,Labels,Name,Scope) via a dedicatedNetworkOutputInformationmodel, following the same pattern already used for image list output.CreatedAtis 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 newFormatDockerTimestamp(std::string_view)overload; the existingLONGLONGoverload, which converts to local time for image and container output, is unchanged.network inspectCreated,EnableIPv4,EnableIPv6,Attachable,Ingress,ConfigOnly,ConfigFrom,Containers,StatusandIPAM.Options.Optionsis emitted as an object rather thannull, and emptyGateway/IPRangeentries are omitted, both matching docker.network pruneDeleted Networks:header followed by bare network names and a trailing blank line, and prints nothing when no networks were removed.Supporting changes
IWSLCSession::ListNetworksnow 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.WSLCNetworkInformationand its serializer are removed. This interface is internal and ships in lockstep with its only clients; the SDK-facingWSLCCompat.idland the plugin API are untouched.docker_schema::Networkanddocker_schema::IPAMuse hand-written deserializers that toleratenull, because the daemon reports some empty maps asnullon predefined networks and the default deserializer rejects that.com.microsoft.wsl.network.managedlabel is stripped from both list and inspect output.ParseDockerTimestampmoved out ofWSLCContainer.cppintodocker_schema::ParseTimestampand 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(-fis already the--filteralias and no wslc prune command prompts).Validation Steps Performed
network list(table,--format json,-q,--no-trunc,-f driver=bridge) is byte-identical apart from the daemon-assigned IDs,network inspectmatches field for field, andnetwork prunematches exactly.Status.IPAMandcom.docker.network.enable_ipv4/6options that the daemon in the WSL VM does not report. Both are passed through unchanged.