feat: add Azure Policy constraint parser#658
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds an Azure Policy constraint parser to the languages::azure_policy::parser module, exposing a public parse_constraint() API that parses the JSON under a policy rule’s "if" into span-annotated AST nodes. It also introduces a YAML-driven integration test suite to validate that a wide variety of constraint shapes can be parsed (and that invalid shapes are rejected).
Changes:
- Added
constraint.rswith parsing for logical combinators (allOf/anyOf/not), leaf conditions (field/value+ operator), andcountblocks (includingwhere). - Exposed
parser::parse_constraint()as a public API and addedParseError::DuplicateKey. - Added YAML-driven parser integration tests plus duplicate-key regression tests.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
src/languages/azure_policy/parser/mod.rs |
Updates module docs and adds the public parse_constraint() entrypoint. |
src/languages/azure_policy/parser/constraint.rs |
New constraint parsing implementation (combinators, leaf conditions, count/where). |
src/languages/azure_policy/parser/error.rs |
Adds ParseError::DuplicateKey and display formatting. |
tests/azure_policy/mod.rs |
Wires the new parser_tests integration test module. |
tests/azure_policy/parser_tests/mod.rs |
New YAML-driven test runner that extracts "if" and calls parse_constraint(). |
tests/azure_policy/parser_tests/cases/operators.yaml |
Adds operator-focused parsing cases. |
tests/azure_policy/parser_tests/cases/logical_combinators.yaml |
Adds parsing cases for allOf/anyOf/not nesting. |
tests/azure_policy/parser_tests/cases/fields.yaml |
Adds parsing cases for built-in fields and field-path patterns. |
tests/azure_policy/parser_tests/cases/expressions.yaml |
Adds parsing cases for ARM template expressions in constraint positions. |
tests/azure_policy/parser_tests/cases/count.yaml |
Adds parsing cases for count (field/value) and nested where constraints. |
tests/azure_policy/parser_tests/cases/parse_errors.yaml |
Adds malformed/invalid JSON/constraint shapes expected to fail parsing. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
4f5ea92 to
54e9aca
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
54e9aca to
ed4d5c2
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 11 out of 11 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
ed4d5c2 to
2f7fac1
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Add constraint.rs module that parses Azure Policy JSON constraints into span-annotated AST nodes: - Logical combinators: allOf, anyOf, not - Leaf conditions: field/value with all 19 operators - Count blocks: field-count and value-count with where clauses Public API: parse_constraint() parses a standalone constraint from JSON. Includes YAML-driven test suite with 6 test files covering operators, fields, expressions, logical combinators, count, and parse errors.
2f7fac1 to
8fc36d6
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 11 out of 11 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Add constraint.rs module that parses Azure Policy JSON constraints into span-annotated AST nodes:
Public API: parse_constraint() parses a standalone constraint from JSON.
Includes YAML-driven test suite with 6 test files covering operators, fields, expressions, logical combinators, count, and parse errors.