From 343e10cc7a620d7581057d38778a82cf7a96e82c Mon Sep 17 00:00:00 2001 From: Sokwhan Huh Date: Tue, 2 Jun 2026 10:00:29 -0700 Subject: [PATCH] Add conformance test cases for policy variable scoping fixes PiperOrigin-RevId: 925421169 --- .../config.yaml | 18 ++++++ .../policy.yaml | 34 +++++++++++ .../tests.yaml | 36 ++++++++++++ .../testdata/unconditional_rules/config.yaml | 8 +++ .../testdata/unconditional_rules/policy.yaml | 30 ++++++++++ .../testdata/unconditional_rules/tests.yaml | 58 +++++++++++++++++++ .../variable_type_propagation/config.yaml | 18 ++++++ .../variable_type_propagation/policy.yaml | 23 ++++++++ .../variable_type_propagation/tests.yaml | 21 +++++++ 9 files changed, 246 insertions(+) create mode 100644 conformance/testdata/nested_rules_variable_shadowing/config.yaml create mode 100644 conformance/testdata/nested_rules_variable_shadowing/policy.yaml create mode 100644 conformance/testdata/nested_rules_variable_shadowing/tests.yaml create mode 100644 conformance/testdata/unconditional_rules/config.yaml create mode 100644 conformance/testdata/unconditional_rules/policy.yaml create mode 100644 conformance/testdata/unconditional_rules/tests.yaml create mode 100644 conformance/testdata/variable_type_propagation/config.yaml create mode 100644 conformance/testdata/variable_type_propagation/policy.yaml create mode 100644 conformance/testdata/variable_type_propagation/tests.yaml diff --git a/conformance/testdata/nested_rules_variable_shadowing/config.yaml b/conformance/testdata/nested_rules_variable_shadowing/config.yaml new file mode 100644 index 0000000..9ea46ef --- /dev/null +++ b/conformance/testdata/nested_rules_variable_shadowing/config.yaml @@ -0,0 +1,18 @@ +# Copyright 2026 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +name: nested_rules_variable_shadowing +variables: + - name: x + type_name: int diff --git a/conformance/testdata/nested_rules_variable_shadowing/policy.yaml b/conformance/testdata/nested_rules_variable_shadowing/policy.yaml new file mode 100644 index 0000000..47d2b22 --- /dev/null +++ b/conformance/testdata/nested_rules_variable_shadowing/policy.yaml @@ -0,0 +1,34 @@ +# Copyright 2026 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +name: nested_rules_variable_shadowing +rule: + variables: + - name: i + expression: '1' + - name: j + expression: '2' + match: + - condition: "x == 1" + rule: + variables: + - name: i + expression: "5" + match: + - output: "variables.i + variables.j" + - condition: "x == 2" + rule: + match: + - output: "variables.i + variables.j" + - output: "variables.i + variables.j" diff --git a/conformance/testdata/nested_rules_variable_shadowing/tests.yaml b/conformance/testdata/nested_rules_variable_shadowing/tests.yaml new file mode 100644 index 0000000..76c693b --- /dev/null +++ b/conformance/testdata/nested_rules_variable_shadowing/tests.yaml @@ -0,0 +1,36 @@ +# Copyright 2026 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +description: "Nested rule tests for rule variable shadowing" +section: + - name: "shadowing" + tests: + - name: "shadowed" + input: + x: + expr: "1" + output: + expr: "7" + - name: "neighbor_rule" + input: + x: + expr: "2" + output: + expr: "3" + - name: "parent_rule" + input: + x: + expr: "3" + output: + expr: "3" diff --git a/conformance/testdata/unconditional_rules/config.yaml b/conformance/testdata/unconditional_rules/config.yaml new file mode 100644 index 0000000..087179d --- /dev/null +++ b/conformance/testdata/unconditional_rules/config.yaml @@ -0,0 +1,8 @@ +name: unconditional_rules +variables: + - name: a + type_name: bool + - name: b + type_name: bool + - name: c + type_name: bool diff --git a/conformance/testdata/unconditional_rules/policy.yaml b/conformance/testdata/unconditional_rules/policy.yaml new file mode 100644 index 0000000..66d149d --- /dev/null +++ b/conformance/testdata/unconditional_rules/policy.yaml @@ -0,0 +1,30 @@ +# Copyright 2026 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +name: unconditional_rules +rule: + match: + - condition: "a" + rule: + match: + - rule: + match: + - condition: "b" + output: "1" + - output: "2" + - rule: + match: + - condition: "c" + output: "3" + - output: "4" diff --git a/conformance/testdata/unconditional_rules/tests.yaml b/conformance/testdata/unconditional_rules/tests.yaml new file mode 100644 index 0000000..729d971 --- /dev/null +++ b/conformance/testdata/unconditional_rules/tests.yaml @@ -0,0 +1,58 @@ +# Copyright 2026 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +description: Unconditional rules propagation conformance tests +section: + - name: "composition" + tests: + - name: "case_a_true_b_true" + input: + a: + expr: "true" + b: + expr: "true" + c: + expr: "true" + output: + expr: "1" + - name: "case_a_true_b_false" + input: + a: + expr: "true" + b: + expr: "false" + c: + expr: "true" + output: + expr: "2" + - name: "case_a_false_c_true" + input: + a: + expr: "false" + b: + expr: "false" + c: + expr: "true" + output: + expr: "3" + - name: "case_a_false_c_false" + input: + a: + expr: "false" + b: + expr: "false" + c: + expr: "false" + output: + expr: "4" diff --git a/conformance/testdata/variable_type_propagation/config.yaml b/conformance/testdata/variable_type_propagation/config.yaml new file mode 100644 index 0000000..ebf2b68 --- /dev/null +++ b/conformance/testdata/variable_type_propagation/config.yaml @@ -0,0 +1,18 @@ +# Copyright 2026 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +name: variable_type_propagation +variables: + - name: x + type_name: int diff --git a/conformance/testdata/variable_type_propagation/policy.yaml b/conformance/testdata/variable_type_propagation/policy.yaml new file mode 100644 index 0000000..4967b32 --- /dev/null +++ b/conformance/testdata/variable_type_propagation/policy.yaml @@ -0,0 +1,23 @@ +# Copyright 2026 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +name: variable_type_propagation +rule: + variables: + - name: empty_list + expression: '[]' + - name: string_list + expression: '["foo"]' + match: + - output: "variables.empty_list + [1]" diff --git a/conformance/testdata/variable_type_propagation/tests.yaml b/conformance/testdata/variable_type_propagation/tests.yaml new file mode 100644 index 0000000..b32b2fc --- /dev/null +++ b/conformance/testdata/variable_type_propagation/tests.yaml @@ -0,0 +1,21 @@ +# Copyright 2026 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +description: "Rule demonstrating variable types propagate independently" +section: + - name: "test" + tests: + - name: "types_agree" + output: + expr: "[1]"