Skip to content

Match docker's keyset for wslc volume list --format json - #41413

Merged
ggarzia-MSFT merged 2 commits into
masterfrom
user/ggarzia/list-json-keyset-parity
Aug 24, 2026
Merged

Match docker's keyset for wslc volume list --format json#41413
ggarzia-MSFT merged 2 commits into
masterfrom
user/ggarzia/list-json-keyset-parity

Conversation

@ggarzia-MSFT

Copy link
Copy Markdown
Contributor

Summary of the Pull Request

wslc volume list --format json emitted only two keys, Name and Driver, while docker volume ls --format json emits ten. This reshapes the volume list path so the JSON keyset matches docker's.

The blocker was that WSLCVolumeInformation is two fixed char[] arrays and cannot carry a label map. This applies the same fix already used for network list in #41377: IWSLCSession::ListVolumes now returns a JSON string via [out] LPSTR* instead of a struct array. ListVolumes is not part of WSLCCompat.idl, so no SDK-facing or public ABI surface changes.

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

The command now outputs:

{"Availability":"N/A","Driver":"guest","Group":"N/A","Labels":"env=prod","Links":"N/A","Mountpoint":"/var/lib/docker/volumes/parity-check-vol/_data","Name":"parity-check-vol","Scope":"local","Size":"N/A","Status":"N/A"}

The keyset is derived from volumeContext in cli/command/formatter/volume.go, whose MarshalJSON calls formatter.MarshalJSON. Per cli/command/formatter/reflect.go, that reflects over exported methods taking no arguments and returning a single value, which yields exactly Availability, Driver, Group, Labels, Links, Mountpoint, Name, Scope, Size, Status. Note that docker's header map for volumes also lists ID, but volumeContext has no ID() method, so ID is reachable only from Go templates and never appears in JSON.

Links and Size report N/A because docker only populates them when UsageData is set, and Group, Availability, and Status report N/A because docker only populates those for swarm cluster volumes. Both conditions are permanently false here, matching what docker prints outside a cluster.

Layering follows the existing image and network pattern, where a session-layer transport struct with native types is converted by a CLI-layer helper into an all-string output struct that is what actually gets serialized:

  • wslc_schema::VolumeListEntry is the new transport struct: Name, Driver, Mountpoint, Scope, Labels.
  • IWSLCVolume gains a Mountpoint() accessor. Both WSLCGuestVolumeImpl and WSLCVhdVolumeImpl already stored m_mountpoint; this just exposes it.
  • models::VolumeOutputInformation is the new CLI output struct, converted by ToVolumeOutput() in VolumeTasks.cpp.

WSLCVolumeInformation is retained for CreateVolume, which still uses it. Its now-unused adl_serializer in JsonUtils.h is removed, since the volume list path was its only consumer.

Validation Steps Performed

Built clean, deployed with tools\deploy\deploy-to-host.ps1, and ran bin\x64\Debug\test.bat /name:*Volume*: Total=106, Passed=106, Failed=0, Blocked=0, Not Run=0, Skipped=0.

Added WSLCE2E_Volume_List_ReportsFullFieldSet, which asserts the field count is exactly 10 and checks every key and value, so an accidental added or dropped key fails the test instead of silently passing.

Updated the existing tests that consumed the old shape:

  • WSLCTests::ListVolumesFilters and the volume lifecycle tests now go through a new ListVolumeEntries() helper that parses the JSON, mirroring the existing ListNetworks() test helper. The lifecycle test additionally asserts Mountpoint is non-empty and Scope is local.
  • The e2e helpers and WSLCE2EVolumeListTests parse into a new VolumeListOutput mirror struct, matching how NetworkListOutput is already handled.

Also manually confirmed the rendered output shown above, and that volume list (table) and volume list --quiet are unaffected

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

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

This PR updates the internal wslc volume listing pipeline so wslc volume list --format json emits the same 10-key JSON shape as docker volume ls --format json, switching the session/CLI boundary from a fixed-size struct array to a JSON string payload and introducing a transport schema for volume list entries.

Changes:

  • Change IWSLCSession::ListVolumes to return a JSON string (LPSTR*) rather than an out-array of WSLCVolumeInformation, and plumb that through the CLI/service layers.
  • Add wslc_schema::VolumeListEntry (transport) plus a CLI-layer VolumeOutputInformation (all-string JSON output), including mountpoint/labels support.
  • Update and extend unit/E2E tests to parse NDJSON output and assert the full 10-key field set.

Reviewed changes

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

Show a summary per file
File Description
test/windows/WSLCTests.cpp Updates volume-list test helpers to consume JSON output and validate new fields (mountpoint/scope).
test/windows/wslc/WSLCCLIExecutionUnitTests.cpp Adjusts CLI execution test data mappings for the new VolumeListEntry type.
test/windows/wslc/e2e/WSLCE2EVolumeListTests.cpp Switches parsing to the new output shape and adds an E2E assertion for the 10-key JSON field set.
test/windows/wslc/e2e/WSLCE2EHelpers.h Introduces VolumeListOutput struct mirroring the JSON output keys for E2E parsing.
test/windows/wslc/e2e/WSLCE2EHelpers.cpp Updates helper parsing to use VolumeListOutput for JSON volume list output.
src/windows/wslcsession/WSLCVolumes.h Changes WSLCVolumes::ListVolumes return type to wslc_schema::VolumeListEntry.
src/windows/wslcsession/WSLCVolumes.cpp Builds VolumeListEntry results including mountpoint, scope, and labels.
src/windows/wslcsession/WSLCVhdVolume.h Exposes Mountpoint() via IWSLCVolume for VHD-backed volumes.
src/windows/wslcsession/WSLCGuestVolume.h Exposes Mountpoint() via IWSLCVolume for guest volumes.
src/windows/wslcsession/IWSLCVolume.h Adds the Mountpoint() accessor to the volume interface.
src/windows/wslcsession/WSLCSession.h Updates the COM method signature for ListVolumes to return LPSTR* Output.
src/windows/wslcsession/WSLCSession.cpp Implements ListVolumes as JSON serialization to a COM-allocated ANSI string.
src/windows/wslc/tasks/VolumeTasks.cpp Converts list JSON output to the docker-matching 10-key, all-string JSON object per line.
src/windows/wslc/services/VolumeService.h Updates VolumeService::List return type to VolumeListEntry.
src/windows/wslc/services/VolumeService.cpp Calls session ListVolumes JSON API and deserializes to std::vector<VolumeListEntry>.
src/windows/wslc/services/VolumeModel.h Adds VolumeOutputInformation defining the 10-key all-string JSON output schema.
src/windows/wslc/core/ExecutionContextData.h Updates the execution context mapping for volumes to VolumeListEntry.
src/windows/service/inc/wslc.idl Changes IWSLCSession::ListVolumes IDL signature to [out] LPSTR* Output.
src/windows/inc/wslc_schema.h Adds wslc_schema::VolumeListEntry transport schema for volume list.
src/shared/inc/JsonUtils.h Removes the now-unused WSLCVolumeInformation JSON serializer.

💡 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/VolumeTasks.cpp Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings August 21, 2026 20:06

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

@ggarzia-MSFT
ggarzia-MSFT marked this pull request as ready for review August 24, 2026 18:25
@ggarzia-MSFT
ggarzia-MSFT requested review from a team as code owners August 24, 2026 18:25
@ggarzia-MSFT
ggarzia-MSFT enabled auto-merge (squash) August 24, 2026 19:15
@ggarzia-MSFT
ggarzia-MSFT merged commit 6a19064 into master Aug 24, 2026
12 checks passed
@ggarzia-MSFT
ggarzia-MSFT deleted the user/ggarzia/list-json-keyset-parity branch August 24, 2026 20:31
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