mirror of
https://github.com/microsoft/regorus.git
synced 2026-08-05 02:16:11 +00:00
# RVM compiler test cases Coverage: - arithmetic - arrays - chained lookups - comparisons - comprehensions - default rules - destructuring - function rules - loops/quantifiers - multiple entrypoints - objects/sets - variables - negative/edge scenarios such as data/rule conflicts - virtual data lookups - etc # Modify interpreter and compiled policy for RVM Compilation - Interpreter::eval_default_rule_for_compiler: evaluates a named default rule in isolation - allows compiler to emit a constant value instead of instructions for the default value # feat: Rego Compiler Scaffolding - Introduce the rego::compiler module surface and entry point wiring - Add the core compiler concepts: - register allocator - scope tracking - literal/builtin tables - rule worklists - instruction emit helpers - compiler-specific error types - context structs for rules, comprehensions, and loops to support later lowering passes. # feat: Compile Rules/Queries - add compiler::compile_from_policy workflow plus rule worklist, entry-point wiring, and recursion checks - implement query lowering: - scheduling-aware statement ordering - loop hoisting - “every/some” semantics - context yields - literal assertions - finalize Program construction # feat: Expression Lowering - add compile_rego_expr and helpers to translate every AST expression into RVM instructions, - interop with binding plans, comprehensions, and membership checks. - implement collection literal builders (ArrayCreate, SetCreate, ObjectCreate) - dedupe literal keys and handle mixed literal/dynamic fields via instruction data blocks. - operations: - arithmetic/boolean/bin operators - membership - unary minus - set unions/intersections - etc - user-defined and builtin function calls - reference handling - analyse chained refs - distinguishe data/input/local roots - perform rule dispatch or virtual document lookups - emits optimized Index/ChainedIndex instructions. # feat: Comprehensions & Loops - shared comprehension emitter - wraps array/set/object comprehensions with ComprehensionBegin/End - context management - loop lowering utilities - read hoisting metadata - emit LoopStart/LoopNext - some in lowering - every quantifiers - index iteration - propagate binding plans into stored registers so downstream statements see bound variables. # feat: Destructuring Lowering - destructuring planner integration - assignment/parameter/loop bindings use hoisted plans instead of re-walking ASTs. - handle :=, =, wildcard matches, and equality - evaluate RHS - applying destructuring plans - emit assert condition as needed - support nested array/object destructuring, dynamic keys, and some ... in forms # test: Shared Testing + RVM Suites - move YAML test helpers into test_utils.rs and re-export via common.rs for use by interpreter and vm test suites - comprehensive compiler test suite - compiles policies with the new Rego→RVM compiler - runs them through RegoVM - compares against interpreter behavior - supports multiple entry points - provides assembly listings - filterable YAML suites. Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>
146 lines
3.4 KiB
YAML
146 lines
3.4 KiB
YAML
# Copyright (c) Microsoft Corporation.
|
|
# Licensed under the MIT License.
|
|
|
|
# Rule-Data Conflict Detection Test Suite
|
|
# Tests that the RVM properly detects conflicts between rule definitions and data documents
|
|
|
|
cases:
|
|
- note: no_conflict_different_packages
|
|
data:
|
|
users:
|
|
alice:
|
|
role: "guest"
|
|
level: 1
|
|
modules:
|
|
- |
|
|
package test
|
|
result := data.users.alice.role
|
|
query: data.test.result
|
|
want_result: "guest"
|
|
|
|
- note: no_conflict_different_paths
|
|
data:
|
|
config:
|
|
database:
|
|
host: "localhost"
|
|
port: 5432
|
|
modules:
|
|
- |
|
|
package test
|
|
users := {
|
|
"alice": {
|
|
"role": "admin"
|
|
}
|
|
}
|
|
query: data.test.users
|
|
want_result:
|
|
alice:
|
|
role: "admin"
|
|
|
|
- note: conflict_same_path_rule_vs_data
|
|
data:
|
|
test:
|
|
users:
|
|
alice:
|
|
role: "guest"
|
|
modules:
|
|
- |
|
|
package test.users
|
|
alice := {
|
|
"role": "admin",
|
|
"level": 5
|
|
}
|
|
query: data.test.users.alice
|
|
want_error: "Conflict: rule defines path 'test.users.alice' but data also provides this path"
|
|
# RVM detects this conflict, but interpreter may not - that's acceptable
|
|
allow_interpreter_success: true
|
|
|
|
- note: conflict_rule_parent_data_child
|
|
data:
|
|
test:
|
|
config:
|
|
database:
|
|
host: "localhost"
|
|
port: 5432
|
|
modules:
|
|
- |
|
|
package test
|
|
config := {
|
|
"app_name": "myapp",
|
|
"version": "1.0"
|
|
}
|
|
query: data.test.config
|
|
want_error: "Conflict: rule defines path 'test.config' but data also provides this path"
|
|
# RVM detects this conflict, but interpreter may not - that's acceptable
|
|
allow_interpreter_success: true
|
|
|
|
- note: conflict_data_parent_rule_child
|
|
data:
|
|
test:
|
|
users: "not an object"
|
|
modules:
|
|
- |
|
|
package test.users
|
|
alice := {"role": "admin"}
|
|
query: data.test.users.alice
|
|
want_error: "Conflict: rule defines subpaths under 'test.users' but data provides a non-object value at this path"
|
|
# RVM detects this conflict, but interpreter may not - that's acceptable
|
|
allow_interpreter_success: true
|
|
|
|
- note: no_conflict_nested_coexistence
|
|
data:
|
|
static_config:
|
|
database:
|
|
host: "localhost"
|
|
port: 5432
|
|
user_data:
|
|
preferences:
|
|
theme: "dark"
|
|
modules:
|
|
- |
|
|
package dynamic
|
|
users := {
|
|
"alice": {
|
|
"role": "admin"
|
|
}
|
|
}
|
|
computed_stats := {
|
|
"total_users": 42
|
|
}
|
|
query: data.dynamic.users
|
|
want_result:
|
|
alice:
|
|
role: "admin"
|
|
|
|
- note: no_conflict_multiple_rule_levels
|
|
data:
|
|
test:
|
|
api:
|
|
v1:
|
|
endpoints: ["users", "posts"]
|
|
modules:
|
|
- |
|
|
package test.api.v1
|
|
auth := {
|
|
"required": true,
|
|
"methods": ["jwt", "oauth"]
|
|
}
|
|
query: data.test.api.v1.auth
|
|
want_result:
|
|
required: true
|
|
methods: ["jwt", "oauth"]
|
|
|
|
- note: no_conflict_rule_extends_data_object
|
|
data:
|
|
test:
|
|
config:
|
|
database:
|
|
host: "localhost"
|
|
modules:
|
|
- |
|
|
package test.config
|
|
app_name := "myapp"
|
|
version := "1.0"
|
|
query: data.test.config.app_name
|
|
want_result: "myapp"
|