Replace cardano-diffusion's ping parser with a local flag-based parser - #1413
Open
Jimbo4350 wants to merge 3 commits into
Open
Replace cardano-diffusion's ping parser with a local flag-based parser#1413Jimbo4350 wants to merge 3 commits into
Jimbo4350 wants to merge 3 commits into
Conversation
The released cardano-cli cannot be built with default cabal flags: Ping.cmdlineParser returns a Parser from plain optparse-applicative unless cardano-diffusion's manual optparse-applicative-fork flag is set, and the cabal.project stanza setting that flag does not ship with the sdist. Parse the ping options locally with optparse-applicative-fork so that no optparse type crosses the package boundary, and drop the flag stanza from cabal.project. This restores the old flag-based ping interface (--host, --unixsock, --port, --magic, --json, --quiet, --query-versions, --tip), allows repeating the endpoint flags to ping multiple endpoints, and exposes the new ping library features via --srv, --srv-prefix, --color and --short-hash.
Jimbo4350
requested review from
carbolymer,
disassembler,
kevinhammond,
newhoggy and
palas
as code owners
August 12, 2026 14:10
Contributor
There was a problem hiding this comment.
Pull request overview
This PR restores cardano-cli ping’s flag-based interface by replacing the dependency on cardano-diffusion:ping’s command-line parser with a local optparse-applicative-fork-based parser, unblocking downstream builds (e.g., CHaP) that cannot flip manual cabal flags in released sdists.
Changes:
- Introduces a local
pingoption parser supporting repeatable endpoints (--host,--unixsock,--srv) plus new flags (--color,--short-hash) and precedence rules (--query-versionsover--tip). - Adds a dedicated
Test.Cli.Pingtest module to lock down endpoint-to-Addressmapping and default option behavior. - Updates golden help output and removes the
cardano-diffusion+optparse-applicative-forkflag override fromcabal.project.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
cardano-cli/src/Cardano/CLI/EraIndependent/Ping/Option.hs |
Implements the local flag-based ping parser and endpoint-to-address conversion logic. |
cardano-cli/test/cardano-cli-test/Test/Cli/Ping.hs |
Adds parser-focused tests for endpoints, defaults, and failure cases. |
cardano-cli/test/cardano-cli-golden/files/golden/help/ping.cli |
Updates command-specific help text to reflect the restored flag interface. |
cardano-cli/test/cardano-cli-golden/files/golden/help.cli |
Updates aggregated CLI help output for the ping command. |
cardano-cli/cardano-cli.cabal |
Registers the new test module and adds needed test-suite dependencies. |
cabal.project |
Removes the cardano-diffusion manual flag override to ensure default-flag buildability. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+44
to
+51
| pHost :: Opt.Parser PingEndPoint | ||
| pHost = | ||
| fmap HostEndPoint $ | ||
| Opt.strOption $ | ||
| mconcat | ||
| [ Opt.long "host" | ||
| , Opt.short 'h' | ||
| , Opt.metavar "HOST" |
Comment on lines
+20
to
+24
| parsePingCmd :: [String] -> Maybe PingCmd | ||
| parsePingCmd = | ||
| Opt.getParseResult | ||
| . Opt.execParserPure Opt.defaultPrefs (Opt.info pPing mempty) | ||
|
|
Per review: drop --srv, --srv-prefix, --color and --short-hash, and the repeatable/inline-port endpoint extensions. The interface is now exactly the pre-11.2 one; the generated help output is byte-identical to 11.1.0.0's apart from a trailing-whitespace line from the newer optparse renderer. The unexposed ping library options are pinned to their old-behaviour values (ColorNever, FullHash). Also restore the pre-11.2 misconfiguration guard: --unixsock without --tip/--query-versions fails again with "Unix sockets only support queries for available versions or a tip." instead of the ping library's silent no-op, and --host values containing a port are rejected at parse time with a pointer to --port.
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.
Changelog
Context
The
cardano-cli-11.2.0.0release cannot be added to CHaP: CHaP PR #1431 failsbuild-new-packages(CI run) becausepPing = uncurry PingCmd <$> Ping.cmdlineParsermixesParsertypes from two different packages: cardano-cli usesoptparse-applicative-fork, whilePing.cmdlineParseris built against plainoptparse-applicativeunless the manual cabal flagoptparse-applicative-forkofcardano-diffusionis set. This repo set that flag incabal.project, butcabal.projectdoes not ship with the sdist and manual flags are never flipped by the solver, so the released package is unbuildable for CHaP CI and for every downstream consumer with default flags.The fix is to stop using
Ping.cmdlineParserand give cardano-cli its own ping parser written againstoptparse-applicative-fork, so no optparse type crosses the package boundary and the flag becomes irrelevant. Thepackage cardano-diffusion / flags: +optparse-applicative-forkstanza is removed fromcabal.projectto prove it: the build now succeeds with cardano-diffusion's default flags, exactly like CHaP CI builds it.The command line interface is restored to exactly what was last on master before the migration (Slack discussion) — the generated help output is byte-identical to the pre-#1384 one (modulo one line of trailing whitespace from the newer optparse renderer) — keeping breaking changes to
cardano-cli pingunder this repo's control. This replaces the positional-argument interface that #1384 introduced viacardano-diffusion:ping(positionalADDRS,--mode,--network-magic,--srv-prefix,--color,--short-hash), which never reached CHaP. In particular-hmeans--hostagain,-m/--magickeeps its old spelling, and-Q/-tmap onto the ping library'sPingMode(-Qtakes precedence, matching the old cardano-ping behaviour). The new ping library options are pinned internally to their old-behaviour values (ColorNever,FullHash); SRV lookups are not reachable from the CLI. All of these can be exposed later as non-breaking additions if wanted.The pre-11.2 misconfiguration guard is also restored:
cardano-cli ping --unixsock ...without--tip/--query-versionsfails with "Unix sockets only support queries for available versions or a tip." (the ping library silently no-ops in that case:(NodeToClient, PingMode) -> pure ()).Known behavioural deltas vs the pre-#1384 implementation, either pre-existing consequences of the library migration or deliberate tightening:
--portaccepts only numbers now (the old implementation passed a string togetAddrInfo, so/etc/servicesnames technically worked);dnspackage) instead ofgetAddrInfo, so/etc/hosts-only names may not resolve on machines without an NSS-aware stub resolver; IP literals are unaffected (they bypass DNS entirely);--hostvalues containing a port (host:3001) are rejected at parse time with a pointer to--port(they never worked — the old implementation failed on them at resolution time with an obscuregetAddrInfoerror).The follow-up release
cardano-cli-11.2.1.0will supersede CHaP PR #1431 (the11.2.0.0sdist cannot be fixed in place). Once released, the network team can drop theoptparse-applicative-forkflag fromcardano-diffusion(added as a stopgap in ouroboros-network#5392).How to trust this PR
cabal.projectno longer sets+optparse-applicative-forkforcardano-diffusion, so CI now buildscardano-diffusion:pingexactly as CHaP CI does — with plainoptparse-applicative— and cardano-cli still compiles.help/ping.cliis byte-identical to the one last on master before Integration for Node release 11.1 #1384 (82a19b757^) apart from a trailing-whitespace line emitted by the newer optparse usage renderer. (That help, and the whole ping implementation, is in turn identical between82a19b757^and thecardano-cli-11.1.0.0tag, so the restored interface also matches the last release consumers could actually build.)Test.Cli.Pinglocks down the endpoint-to-Addressmapping (IP literals bypass DNS via theIPconstructor, bare unix socket names are not mistaken for domain names bymkAddress's heuristic), the option defaults, the pinned library options, and the restored unix-socket misconfiguration guard.Checklist