trace-schemas: add namespace-driven schema generation and validation tooling#6527
trace-schemas: add namespace-driven schema generation and validation tooling#6527
Conversation
9b37275 to
8913d02
Compare
mgmeier
left a comment
There was a problem hiding this comment.
Please condense / clean-up commit history for this PR.
mgmeier
left a comment
There was a problem hiding this comment.
Testing feedback: You've already made the various scripts executables in bench/trace-schemas/scripts/schema-gen/trace-schema-gen.cabal. This means, they're part of the nix flake.
So instead of building a full dev shell with all dependencies, and running the script via bash / runghc, you should switch the new Make targets to something like nix run .#schema-gen.
6dd06b1 to
93fa1f5
Compare
| readJsonFile :: FilePath -> IO A.Value | ||
| readJsonFile fp = do | ||
| bs <- BL.readFile fp | ||
| case A.eitherDecode bs of |
There was a problem hiding this comment.
Please use A.eitherDecodeFileStrict'
|
|
||
| parseArgs :: Config -> [String] -> IO Config | ||
| parseArgs = go | ||
| where |
There was a problem hiding this comment.
I'm aware it's a standalone script... but it still could use optparse-applicative for CLI parsing.
Only a suggestion - the approach taken here is sufficient for the scope.
|
|
||
| splitPath :: FilePath -> [FilePath] | ||
| splitPath path = filter (not . null) (go path) | ||
| where |
There was a problem hiding this comment.
Please use splitPath or splitDirectories from System.FilePath.
| (a, []) -> [a] | ||
| (a, _:rest) -> a : go rest | ||
|
|
||
| joinPath :: [FilePath] -> FilePath |
There was a problem hiding this comment.
joinPath is defined in System.FilePath.
| joinPath [] = "" | ||
| joinPath (x:xs) = foldl (</>) x xs | ||
|
|
||
| replaceFileName :: FilePath -> FilePath -> FilePath |
There was a problem hiding this comment.
replaceFileName is defined in System.FilePath.
|
|
||
| -- Read file for quick text parsing; tolerate missing files. | ||
| readFileSafe :: FilePath -> String | ||
| readFileSafe fp = unsafePerformIO (readFile fp `catch` (\(_e :: IOException) -> pure "")) |
There was a problem hiding this comment.
readFileSafe is only ever called inside IO.
There is no need for it to be a pure function using unsafePerformIO - and then naming it "safe" ;)
| collectTargets :: [FilePath] -> IO [FilePath] | ||
| collectTargets roots = do | ||
| files <- concat <$> mapM listHsFiles roots | ||
| catMaybes <$> mapM (\fp -> do |
| (x:_) -> x | ||
|
|
||
| isInfix :: String -> String -> Bool | ||
| isInfix needle hay = T.isInfixOf (T.pack needle) (T.pack hay) |
There was a problem hiding this comment.
Why not just use Data.List.isInfixOf ?
| then pure v | ||
| else do | ||
| bs <- BL.readFile histOut | ||
| case A.decode bs of |
There was a problem hiding this comment.
I first tried A.decodeFile' to match the suggestion, but this repo’s Aeson version does not export it, so A.decodeFileStrict' is the compatible file-based replacement here.
| [] -> s'' | ||
|
|
||
| stripPrefix :: String -> String -> Maybe String | ||
| stripPrefix pre s = if pre `isPrefixOf` s then Just (drop (length pre) s) else Nothing |
Description
Summary
This PR introduces a namespace-driven trace schema workflow and the tooling around it.
It adds support for generating schema files from traced namespaces, validates generated schemas and trace logs, documents how overrides work, and wires the schema scripts into a standalone Cabal package so they can be run consistently from the dev environment. It also updates trace documentation generation to work with optional namespace lists and refreshes the generated trace-schema artifacts.
On the tracing side, it extends the source discovery and inference logic used by schema generation, improves handling of external
trace-dispatcherdefinitions, and tightens warning reporting so schema generation only reports real unresolved cases instead of false positives.Why this is hard
This cannot be solved by deriving JSON Schema directly from Haskell types, because the trace JSON is not determined by the types alone. The emitted payloads are shaped by
forMachineimplementations, helper functions, pattern matches, namespace mapping, verbosity/detail levels, and hand-written rendering logic across multiple packages. In practice, fields may be renamed, omitted, flattened, synthesized, or rendered as strings, so the runtime JSON contract often differs from the source type definition.Main changes
bench/trace-schemasas the home for generated schemas, metadata, documentation, presentations, and helper docs.GhciSchemaGen.hsValidateTraceSchemas.hsValidateTraceLog.hsApplySchemaOverrides.hsCheckOverrideCoverage.hsRegenerateTraceSchemas.shtrace-schema-gen.cabaland wire it intocabal.project.cardano-nodetrace documentation generation to support optional namespace selection.cardano-node,trace-dispatcher, and related tracing modules.newNamespaces.txt,trace-documentation.md, and schema artifacts from the new pipeline.Testing
nix develop.Schema generation problems: 0.