[tx-generator] Add --testnet-config-dir flag to json_highlevel#6529
[tx-generator] Add --testnet-config-dir flag to json_highlevel#6529
Conversation
Add a `--testnet-config-dir` flag that auto-discovers the 4 infrastructure parameters (socket path, signing key, node config file, target nodes) from a `cardano-testnet` output directory. Discovered infrastructure always overrides user-provided values; all other config fields must be supplied by the user.
e8b7377 to
ffba8e5
Compare
ffba8e5 to
0154393
Compare
| deriving instance Show SignalSpecificInfo | ||
| #endif | ||
|
|
||
| data JsonHLSource |
|
|
||
| case Aeson.fromJSON merged of | ||
| Aeson.Success opts -> pure opts | ||
| Aeson.Error err -> die $ "Failed to parse merged config: " ++ err |
There was a problem hiding this comment.
Prefix the name of the function to the error message.
| validateFileExists portPath ("port file for " ++ defaultNodeName idx) | ||
| portStr <- readFile portPath | ||
| case readMaybe portStr :: Maybe PortNumber of | ||
| Nothing -> die $ "Invalid port number in: " ++ portPath |
There was a problem hiding this comment.
Prefix the function name in the error message.
|
|
||
| -- Property test -- | ||
|
|
||
| -- | Non-infra required field names. |
There was a problem hiding this comment.
Don't use the infra terminology it is confusing.
| -- | Property: infrastructure fields always come from the testnet directory | ||
| -- regardless of what the user supplies; non-infra fields come from the user | ||
| -- config; missing required non-infra fields cause failure. | ||
| prop_infraOverride :: Property |
There was a problem hiding this comment.
again, don't use infra it is confusing.
There was a problem hiding this comment.
Pull request overview
Adds a --testnet-config-dir option to tx-generator json_highlevel to auto-discover infrastructure settings from a cardano-testnet output directory (using Cardano.Node.Testnet.Paths), and merges those discovered infrastructure fields over user-provided JSON config.
Changes:
- Introduces
Cardano.TxGenerator.Setup.TestnetDiscoveryto discover socket path, signing key, node config, and target nodes from a testnet directory and merge them into user config (infra wins). - Extends
json_highlevelcommand parsing/execution to optionally perform testnet discovery before decodingNixServiceOptions. - Adds a new test module covering JSON round-tripping and a property test ensuring infra fields override user config.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| bench/tx-generator/tx-generator.cabal | Adds new module/deps and wires in new test module/dependencies. |
| bench/tx-generator/src/Cardano/TxGenerator/Setup/TestnetDiscovery.hs | Implements testnet directory discovery + JSON-level merge for infra fields. |
| bench/tx-generator/src/Cardano/Benchmarking/Command.hs | Adds --testnet-config-dir plumbing for json_highlevel. |
| bench/tx-generator/test/TestnetDiscoveryTest.hs | Adds round-trip + property tests for discovery/merge semantics. |
| bench/tx-generator/test/Main.hs | Registers the new test group. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| -- | Validate that a file exists, dying with a clear message if not. | ||
| validateFileExists :: FilePath -> String -> IO () | ||
| validateFileExists path description = do | ||
| exists <- doesFileExist path | ||
| unless exists $ die $ "Required " ++ description ++ " file not found: " ++ path |
There was a problem hiding this comment.
validateFileExists uses doesFileExist for localNodeSocketPath. The node socket is a Unix domain socket (not a regular file), so doesFileExist can return False even when the socket exists, causing discoverTestnetConfig to fail on real testnets. Use an existence check that works for sockets (e.g. doesPathExist/getFileStatus without isRegularFile), or special-case socket validation.
| acquire = do | ||
| saved <- hDuplicate stderr | ||
| devNull <- openFile "/dev/null" WriteMode | ||
| hDuplicateTo devNull stderr | ||
| pure (saved, devNull) |
There was a problem hiding this comment.
withSilentStderr redirects stderr to /dev/null, which will fail on Windows (CI builds include Windows). Consider using System.IO.nullDevice (when available) or redirect to a temporary file/handle (you already depend on temporary) to keep the test portable.
Description
Adds a
--testnet-config-dirflag totx-generator json_highlevelthat auto-discovers infrastructure config (socket path, signing key, node config, target nodes) from acardano-testnetoutput directory, using the shared path conventions fromCardano.Node.Testnet.Paths.Discovered infrastructure always overrides any user-provided values for those fields. All other config fields must be supplied by the user.
Closes #6513 (part 2 of #6510). Depends on #6518 (part 1).
What's new:
Cardano.TxGenerator.Setup.TestnetDiscoverymodule — scans testnet dir for infrastructure config, merges with user config at JSON level (infrastructure always wins)json_highlevelparser now accepts either a full config file (existing behaviour preserved) or--testnet-config-dirwith an optional partial config overlayChecklist
See Running tests for more details
CHANGELOG.mdfor affected package.cabalfiles are updatedhlint. See.github/workflows/check-hlint.ymlto get thehlintversionstylish-haskell. See.github/workflows/stylish-haskell.ymlto get thestylish-haskellversionghc-9.6andghc-9.12