Add --validate flag to check rules files without harmonizing - #118
Merged
Conversation
'harmonize --validate --rules ...' validates each rules file (JSON or YAML, chosen by extension like load) and exits non-zero if any file has problems, so it can gate a CI step. Unlike RuleSet.load, which raises on the first bad rule, validate_rules_file checks every rule and operation and reports all problems: syntax errors, malformed sources/target/operations, unknown operations, invalid operation settings (via actual deserialization, so nested case/coalesce/map_each children are covered), duplicate targets within a file, and empty files. --input/--output are no longer required by argparse; they are enforced in main() unless --validate is given. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
Summary
harmonize --validate --rules a.json --rules b.yamlvalidates each rules file (JSON or YAML by extension, same as loading) and exits non-zero if any file has problems, so it can gate a CI step;--input/--outputare not required in this mode (still enforced otherwise)validate_rules_fileinrule_registry.py: unlikeRuleSet.load, which raises on the first bad rule, it checks every rule and operation and reports all problems — syntax errors, malformedsources/target/operations, unknown operations, invalid operation settings (validated by actual deserialization, so nestedcase/coalesce/map_eachchildren are covered), duplicate targets within a file, and empty filesSample output:
Test plan
tests/test_validate.pycovering both syntaxes, legacysourcekey, every error class, multi-file exit codes, and that plain harmonization still requires--input/--outputpytest tests— 215 passed🤖 Generated with Claude Code