Skip to content

Add --validate flag to check rules files without harmonizing - #118

Merged
matthewhorridge merged 1 commit into
mainfrom
feat/validate-rules-flag
Jul 9, 2026
Merged

Add --validate flag to check rules files without harmonizing#118
matthewhorridge merged 1 commit into
mainfrom
feat/validate-rules-flag

Conversation

@matthewhorridge

Copy link
Copy Markdown
Contributor

Summary

  • harmonize --validate --rules a.json --rules b.yaml validates 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/--output are not required in this mode (still enforced otherwise)
  • New validate_rules_file in rule_registry.py: unlike RuleSet.load, which raises on the first bad rule, it checks every rule and operation and reports all problems — syntax errors, malformed sources/target/operations, unknown operations, invalid operation settings (validated by actual deserialization, so nested case/coalesce/map_each children are covered), duplicate targets within a file, and empty files
  • Documented in the README under "Validating rules files"

Sample output:

bad_rules.yaml: INVALID
  rule 1 (target 'b'): operation 1 ('frobnicate'): Unknown operation: frobnicate
  rule 2: 'target' must be a non-empty string
  rule 2: operation 1 ('extract_regex'): Invalid regex pattern: '('

Test plan

  • 16 new tests in tests/test_validate.py covering both syntaxes, legacy source key, every error class, multi-file exit codes, and that plain harmonization still requires --input/--output
  • pytest tests — 215 passed
  • Verified from a pipx install: valid file exits 0, broken file exits 1 with all problems listed

🤖 Generated with Claude Code

'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>
@matthewhorridge
matthewhorridge merged commit 782b1ad into main Jul 9, 2026
1 check passed
@matthewhorridge
matthewhorridge deleted the feat/validate-rules-flag branch July 9, 2026 17:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant