feat: improved config validation#2325
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Greptile SummaryThis PR replaces per-module hand-rolled config validation functions with a declarative
Confidence Score: 5/5Safe to merge; the change is additive and all existing call sites have been updated. The core logic in format_validation_errors, validate_config, and the NoConfig unit struct is straightforward and well-tested. The all schema-key stripping is handled correctly in with_field. The only gap is that the null_config_succeeds_for_unit_type test still exercises () rather than NoConfig, leaving the real generated default type untested for null deserialization — but based on serde semantics for unit structs this path is expected to work correctly. native/rust/dimos-module/src/module.rs — the existing unit-type null deserialization test should be extended or mirrored for NoConfig. Important Files Changed
Sequence DiagramsequenceDiagram
participant Coordinator as Python Coordinator
participant run as run()
participant run_f as run_fallible()
participant parse as parse_config_json()
participant validate as validate_config()
participant module as Module
Coordinator->>run: spawn process, write JSON to stdin
run->>run_f: delegate
run_f->>run_f: init_tracing()
run_f->>parse: read stdin, deserialize
parse-->>run_f: topics + config
run_f->>validate: config.validate()
alt validation fails
validate-->>run_f: Err(ValidationErrors)
run_f-->>run: Err(io::Error)
run->>run: log error, process::exit(1)
else validation passes
validate-->>run_f: Ok(())
run_f->>module: build + setup + handle + teardown
module-->>run_f: done
run_f-->>run: Ok(())
end
Reviews (2): Last reviewed commit: "Merge branch 'main' into andrew/feat/bet..." | Re-trigger Greptile |
Problem
There was a lot of boiler plate for validating config structs in Rust native modules.
Closes DIM-971
Solution
Add ModuleConfig trait and use validator crate to make it easier to add validation to Config structs. Now you can use the validate attribute on struct fields, either the supported ones from the crate or write your own custom ones. Also can do schema level, which I just learned about.
How to Test
cargo testBad configs in the
rust_ping_pong.pycreate error messages like this:Contributor License Agreement