fix!: make network inspect Docker-compatible#48
Open
jahirvidrio wants to merge 2 commits into
Open
Conversation
'mocker network inspect' returned the internal NetworkInfo shape via
TableFormatter.printJSON (a single lowercase object). Add a NetworkInspect
DTO + pure mapToNetworkInspect mapper (mirroring the image- and
container-inspect pattern), add an inspectNetworks collector with
Docker-compatible accumulate-then-fail multi-arg semantics, and migrate
the subcommand to InspectFormat.emitArray so it emits a Docker-shaped
JSON array with unescaped slashes.
Containers map is always {} in v0.6.0 — Apple-runtime enrichment is
deferred to a non-breaking follow-up PR.
BREAKING CHANGE: 'mocker network inspect' now returns a Docker-compatible
JSON array with the moby v29.6.1 network.Inspect shape (PascalCase keys,
nested IPAM, Containers map) instead of the previous lowercase NetworkInfo
object. Scripts consuming '.subnet' / '.gateway' / '.containers' (string
array) must migrate to '.IPAM.Config[0].Subnet' / '.IPAM.Config[0].Gateway'
/ '.Containers' (map). Multi-arg invocation now returns one combined array
(previously single-arg only).
'mocker inspect --type=network' was rejected at parse time because the InspectObjectType enum only knew image and container. Extend the enum with .network, add the .network branch in Inspect.run() that routes through the NetworkInspect DTO from the prior commit, and expand the auto-fallback loop with a third attempt after containers and images so 'mocker inspect <name>' resolves to a network when neither matches. Both invocation paths emit byte-identical Docker-shaped JSON arrays because they share inspectNetworks + InspectFormat.emitArray.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What problem does this solve?
mocker network inspect <name>andmocker inspect --type=network <name>emit mocker's internalNetworkInfoshape — a single lowercase JSON object viaTableFormatter.printJSON, not the Dockernetwork.Inspectarray of objects with PascalCase keys and nested IPAM. Scripts that pipe tojqand expect Docker fields (.IPAM.Config[0].Subnet,.Containers, top-level array) break.mocker inspect --type=network <name>is also rejected at parse time today: theInspectObjectTypeenum only knowsimage | container, so the route is silently absent. Same for the auto-fallback path —mocker inspect <name>never tries network even when the target exists as a network.This closes the last shipped command in the Docker-parity gap after #25 (image inspect) and #40 (container inspect).
What changed
NetworkInspectDTO + puremapToNetworkInspectmapper inSources/MockerKit/Models/NetworkInspect.swift, mirroring the image- and container-inspect pattern.NetworkIPAMconforms toEncodableonly with a customencode(to:)that callsencodeNil(forKey: .Options)— Docker emits literal"Options": nullfor an unset IPAM driver-options map, not{}, and the default SwiftCodablewould have emitted{}.inspectNetworkscollector inSources/MockerKit/Models/InspectOperations.swiftwith accumulate-then-fail multi-arg semantics: unknown targets emitError response from daemon: network <name> not foundto stderr, processing continues, exit 1 at the end. This intentionally diverges frominspectContainers(which throws on first miss) — copying that pattern would break multi-arg parity withdocker network inspect a b c.Sources/Mocker/Commands/Network.swift: rewiredNetworkInspectto variadicnames: [String], removed the--verboseflag (was a no-op), and migrated output fromTableFormatter.printJSONtoInspectFormat.emitArrayso the subcommand emits a Docker-shaped JSON array with unescaped slashes and honors--format/--format jsonthe same way image and container inspect already do.Sources/Mocker/Commands/Inspect.swift: extendedInspectObjectTypewith.network, added the.networkbranch inrun(), and added network as a third attempt in the auto-fallback loop after containers and images somocker inspect <name>resolves to a network when neither matches.Containersmap ships as{}empty for v0.6.0. Apple-runtime enrichment (realEndpointID/MacAddress/IPv4Addressfromcontainer network inspect <id>) is intentionally deferred to a non-breaking follow-up so the breaking-shape change lands within the review budget. Fabricating Name-only stub entries was considered and rejected: Docker never emits entries with empty runtime-field strings, so doing so would invent a shape Docker would never produce.Breaking change
mocker network inspectno longer emits the lowercaseNetworkInfoobject. Scripts that read.subnet,.gateway, or.containersfrom a top-level object must migrate to.IPAM.Config[0].Subnet,.IPAM.Config[0].Gateway, and.Containers(a map, empty{}in v0.6.0 until the enrichment follow-up). The top-level is now a JSON array, sojqfilters need.[0].Nameinstead of.name.mocker inspect --type=network <id>is a new route — it did not exist before — so nothing breaks there. Multi-argnetwork inspect a b cnow returns one combined array (previously rejected: single-arg only).