Repository navigation
test: add shared explanation corpus - #885
Merged
Anand Krishnamoorthi (anakrish) merged 1 commit intoOct 30, 2026
Merged
Anand Krishnamoorthi (anakrish) merged 1 commit into
Anand Krishnamoorthi (anakrish) merged 1 commit into
Conversation
Add tests/explanation_corpus, a data-driven set of Rego policies and inputs that explanation (causality) and partial-evaluation tests can reuse. Each case is a policy, a query and examples with at least two distinct expected outcomes, so every match has a non-match twin. The values are checked on the interpreter and on the RVM in run-to-completion and suspendable modes. With REGORUS_OPA set to an OPA binary, corpus_matches_opa checks every expected value against OPA. Where regorus differs from OPA today, the expected value is OPA's and a `divergence` entry pins the current regorus result, so a fix makes the test fail until the entry is removed. Fields for expected explanations and partial-evaluation results are reserved and rejected until a checker exists. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Anand Krishnamoorthi (anakrish)
approved these changes
Oct 30, 2026
Anand Krishnamoorthi (anakrish)
left a comment
Collaborator
There was a problem hiding this comment.
LGTM!
Thanks for focusing on tests for such a complex feature!
Anand Krishnamoorthi (anakrish)
merged commit Oct 30, 2026
652bdf3
into
microsoft:main
60 checks passed
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
Adds
tests/explanation_corpus, a data-driven set of Rego policies and inputsfor explanation (causality) and partial-evaluation tests to share. Later PRs
can add expected explanations or partial-evaluation results to existing cases
instead of writing new ones. The value each case expects is fixed now, checked
on every regorus evaluator and against OPA.
The change is test-only: no production code, no new dependencies. It is built
with the
rvmfeature, which is on by default.Details
tests/explanation_corpus/README.md. A case is one policy and query; itsexamples are inputs with an expected value or error. Each case needs at least
two distinct expected outcomes, so every matching input has a non-matching
twin.
elsechains; defaults; multiple definitions;not;some ... in;every;membership; comprehensions; helper rules and cross-package calls;
with;builtins; Undefined vs
falsevs empty vsnull; an absent input document;conflicts; runtime errors; and Rego v0 syntax.
corpus_is_well_formedfails if any construct has no caseand prints the coverage counts.
corpus_valuesruns every example on the interpreter and onthe RVM in run-to-completion and suspendable modes.
REGORUS_OPApoints to an OPA binary,corpus_matches_oparunsopa evalon every example and compares the resultwith the expected value. An expected error must be an OPA evaluation error;
a parse, compile or usage error from OPA fails the test. Without the
variable the test does nothing.
want_erroris a substring of the regorus error message. Itmust not occur in the policy source, because error messages quote the
failing line.
strict_builtin_errors. It isapplied to both regorus evaluators and passed to OPA as
--strict-builtin-errors.unknownslists the input paths partial evaluation should treat asunknown.
secretslists values that a report must not show unredacted. Each onemust appear in the case's input or data.
explanation(per example) andpartial_eval(per case) are reserved andrejected for now. The PR that adds a feature replaces the field with its
typed expectation and a check.
Known divergences
Where regorus differs from OPA today, the expected value is OPA's, and a
divergenceentry pins what regorus currently returns. The test checks thepinned value. Once the behaviour is fixed, the test fails, and the fix PR must
remove the entry. Pinned today:
x in coll) on an Undefined collection returnsfalseinsteadof Undefined, so
not x in collsucceeds. This affects both evaluators.withyet.complete-rule or function definitions produce different values.
raising an error (RVM: partial object codegen gaps (constant-key, multi-level, duplicate-key) #719).
every k, v in input.limits { v <= data.max[k] }when the check fails for the current key, or when the key is missing from
data.max.call, such as
count(5)or division by zero, instead of an error.Compatibility
None. This change adds test code only.
Testing
cargo test --test mod explanation_corpuspasses with default features andwith
--features explanations, withREGORUS_OPAset to OPA 1.2.0. OPAagrees with all 150 expected values.
cargo test --test mod(all 182 tests) passes with default features and with--features rego-extensions. With--no-default-featuresthe corpus compilesout and the remaining tests pass.
cargo xtask pre-commit: build, fmt and clippy, includingbindings).
corpus_valuesandcorpus_matches_opa.corpus_values.occurs in the policy, fails
corpus_is_well_formed.corpus_matches_opa.nullon the RVM failscorpus_values.cargo fmt --check;cargo clippy --all-features --all-targets -D warnings;cargo clippy --no-default-features --lib --tests -D warnings.