cardano-testnet: Replace Defaults.defaultXxxDir path-building with typed EnvLayout
## Problem
File paths within a testnet environment are constructed by concatenating strings at each call site, using functions like `Defaults.defaultNodeDataDir`, `Defaults.defaultSpoKeysDir`, `Defaults.defaultGenesisFilepath`, etc. The same path patterns are repeated independently in `Testnet/Start/Cardano.hs`, `Testnet/Components/Configuration.hs`, and `Testnet/Defaults.hs`.
This means:
- Renaming a directory requires finding and updating every string concatenation site.
- Typos in path construction (e.g., `"nodedata"` vs `"node-data"`) are not caught by the compiler.
- There is no way to validate that all expected paths exist when loading an env.
## Proposed fix
Define a typed `EnvLayout` data structure that represents the full directory structure:
```haskell
data EnvLayout = EnvLayout
{ elRoot :: FilePath
, elConfigFile :: FilePath
, elGenesisFile :: forall era. CardanoEra era -> FilePath
, elNodeLayout :: Int -> NodeLayout
, elPoolKeys :: Int -> PoolKeysLayout
, elUtxoKeys :: Int -> UtxoKeysLayout
}
data NodeLayout = NodeLayout
{ nlDataDir :: FilePath
, nlTopology :: FilePath
, nlDbDir :: FilePath
, nlPortFile :: FilePath
}
```
Construct this once from the root path (replacing scattered `Defaults.*` calls), then thread it through both phases.
Benefits:
- Rename a directory = change one function (`mkEnvLayout`).
- Path existence can be validated structurally when loading an env.
- All path references are typed accessors, not string concatenations.
## Depends on
- #6463 (opaque TestnetEnv — EnvLayout naturally lives inside TestnetEnv)
## Type: Refactoring
## Effort: Medium-high (~200 lines: new types, mkEnvLayout, update ~20 call sites)
## Risk: Medium (many call sites to update, but each change is mechanical and compiler-guided)
0 条评论