Testing and verification
Performance
The benchmark times the cases of
OPA's v1 conformance suite that
expect a result: a set of solutions (want_result). The benchmark README
explains how to run it.
- Skipped: a case that expects an error (
want_errororwant_error_code), and a case with no expected result. Such a case has no result to compare and time. - Checked: before the benchmark times an engine on a case, it checks that the engine gives the
want_result. - Count: the last full run timed 1135 of the 2538 cases.
The benchmark times each case on three engines:
The benchmark interleaves the engines over the same span of time. It repeats each case, for statistical confidence.
In the last full run (1135 cases, 4 passes), these were the geometric means of the time, as a ratio of native OPA's time:
- rego4k: 0.27 (95% CI 0.265–0.281).
- Native OPA with
opa build -O=1andGOGC=400: 0.38. - The WebAssembly build: 0.33, over the 732 cases that it supports without builtins from the host.
That run was before commit 4e0921c (2026-11-30). This commit made rego4k approximately 2.5 times slower: it built
the rule index again for each evaluation.
On 2026-12-02, after the fixes, three runs of benchGate gave a ratio of 0.23 to 0.25 for rego4k on HotSpot
(rego4k 3.4 µs to 3.6 µs, native OPA 13.6 µs to 15.7 µs): rego4k is about 4 times as fast. Before the fixes, the ratio
was 0.67. See "Finding" in HANDOFF.md.
These policies are small (microseconds for each evaluation), so the fixed cost of each evaluation is the largest part of the time. The results do not show the performance of large policies.
See verification/benchmark/README.md for the method.
Verification
Coding agents wrote most of the engine code of rego4k. If you doubt code that an agent wrote, we agree: do not trust it because it passes its own tests.
Trust it only as far as independent evidence shows. The oracle for each layer below is the OPA 1.23.0 binary, or a published specification, not a test that the same agent wrote.
The layers
-
OPA's conformance suite. All 2538 cases of OPA's v1 suite pass, with OPA's expected results and error codes.
checkruns the suite again with a tracer on each evaluation. It also runs the suite with each case shaken to only its reachable rules and builtins. The results must not change. -
Cases from the OPA binary. About 2400 more cases in 72 YAML files, in the format of OPA's suite. Each expected result or error comes from a run of the OPA binary, not from rego4k. They cover each fault that the other layers found.
checkalso runs them with the RE2 engine. -
Differential fuzzing against the OPA binary. The fuzzer generates programs from the types of the builtins, with adversarial values. It runs each program in rego4k and in OPA. It also runs each program after transformations that must not change its result:
- the same program with different line breaks,
- the
withmodifiers in the opposite order, - the program in the body of a rule,
- the program with strict builtin errors.
It compares the raw JSON, the solutions as a multiset, the error codes and the messages.
- The fuzz gate (4500 programs, about 25000 cases) runs before each commit. It fails for a new difference, and also when a known difference disappears. Each of the 18 known differences has a reason: the exact arithmetic of rego4k, or a fault in OPA (see Divergences from OPA).
- The gate uses
Re2Engine, the regex engine of OPA. - Each night, a run of 50000 programs uses a new seed.
- A separate mode (
-Pmode=index) shows which rules each engine evaluates, to compare the rule index with OPA's.
-
Ports compared on many inputs. When rego4k copies a Go library (for example gqlparser, jwx,
crypto/x509,encoding/jsonor gojsonschema), the port is compared with the OPA binary on many inputs. For example, about 4000 GraphQL schemas, and 193 JSON texts forjson.unmarshal. -
Old against new. A large refactor of the parser, the compiler or the evaluator must give the same results as the code before it. The comparison uses tens of thousands of inputs, including inputs that fail. For example, the trampolined evaluator ran about 68000 fuzz cases on both versions, and the parser changes ran up to 192000 inputs.
-
External tools. OPA loads, runs and verifies the bundles that rego4k writes and signs. cosign, the signing tool of the Sigstore project, verifies the decisions that
rego4k-signing-signersigns. -
Long and large inputs. Tests run these inputs on a 512 KB stack:
- bodies of 20000 expressions,
- chains of 10000 rules,
- 10000 nested brackets,
- collections of 100000 elements.
A test fails if the time of size n is more than 30 times the time of size n / 10. Thus a quadratic or exponential step fails it on any machine.
-
Mutation testing. PIT, a mutation testing tool for the JVM, changes the code on purpose. Then it checks that a test finds each change. The survivors show the gaps in the tests.
-
Benchmark thresholds. rego4k must not get much slower than native OPA, measured in the same run.
-
Static checks.
checkfails for each of these faults:- a warning of the compiler,
- a declaration that nothing uses,
- an unused import,
- a package with more than 7 files,
- a dependency between packages that the layers do not allow (ArchUnit, a library that tests the architecture of Java code).
These checks keep the code small enough for a person to read.
Each divergence from OPA that is on purpose is in Divergences from OPA, with its reason.
Humans design the API
Agents built the engine: the parser, the compiler, the evaluator and the ports of the builtins. Their correctness comes from the layers above.
A person designs the API that a user calls, because only a person can judge if an API is easy for a person to use. Examples of these decisions:
- A document is a
Value, and JSON is only at the edge. - A module has the types
RegoFileNameandRegoFile, not two strings that a caller can exchange by mistake. - Each builtin is
Builtin.PureorBuiltin.Impure, and an application adds sets of builtins with+. RevisionHashTreatmentandMetadataBlocksare enums, so each call shows its choice.- Package names are plural, and the file system shows the concepts of the domain.
When the layers run
rego4k must give the same results as OPA, and it must not get much slower without a decision. These layers run:
| Layer | Command | When |
|---|---|---|
| The unit tests, the 2538 cases of OPA's conformance suite and the cases of rego4k | ./gradlew check |
each commit (pre-commit hook), each push |
| The fuzz gate: 4500 generated programs, compared with native OPA | ./gradlew fuzzGate |
each commit (pre-commit hook), each push |
| The benchmark thresholds on every 10th case | ./gradlew benchGate |
each push |
| The benchmark thresholds on all the cases | ./gradlew benchNightly |
each night |
| The long fuzz run: 50000 programs with the date as the seed | ./gradlew fuzzNightly |
each night |
| The mutation testing of core and stdlib, against the tests and the fuzz gate | ./gradlew pitest |
each night |
| The tests and the fuzz gate against the latest release of OPA, if it is not the pinned version | the workflow opa-latest |
each day |
The soak run: new seeds against opa eval and opa run --server, and PIT on every package of the library |
./gradlew soak -Phours=48 |
by hand, on a machine with no other work |
Benchmark thresholds
The thresholds in verification/benchmark/thresholds.txt give the
maximum ratio of the time of rego4k to the time of native OPA. One threshold is for all the cases, and one is for
each group of categories, for example strings or crypto.
The two engines run interleaved on the same machine. Thus the ratio changes much less than the times when the machine is slower.
The margins find large changes only: on a machine with a low load, benchGate fails if rego4k becomes
approximately 1.6 times slower. See "Thresholds" in verification/benchmark/README.md.
Mutation testing
./gradlew pitest runs PIT on the main code of rego4k-core and
rego4k-builtins-stdlib-pure.
PIT makes small changes (mutants) to the bytecode, for example a changed operator or a removed call. Then it runs the tests against each mutant. A mutant that no test finds (a survivor) shows a gap in the tests.
The report is in verification/mutation/build/reports/pitest/. -Pmutate=rego4k.values.* mutates only the
classes of one package. check does not run PIT, because it is slow.
All the classes take too long for one night. rego4k.values has 322 mutants and 2% of the bytecode, and PIT took
2 h 27 min for it with 2 threads.
Thus -Pshard=k/50 divides the classes, sorted by name, into 50 shards with about the same size of bytecode.
Each night mutates one shard, by the day of the year. Thus the nightly build mutates all the classes in 50 nights.
The first run, on rego4k.values, killed 292 of the 322 mutants (91%). These are the scores of the runs of
2026-12-03 (PIT counts a mutant that it stops at the time limit as killed), and the scores after the tests of the gaps:
| package | mutants | killed | killed after the new tests |
|---|---|---|---|
rego4k.values |
322 | 303 (94%) | 305 (95%) |
rego4k.caches |
61 | 51 (84%) | 55 (90%) |
rego4k.builtins.contexts |
16 | 8 (50%) | 13 (81%) |
All the mutants that stay are equivalent: the change does not change the behaviour. Most of them remove a null
check of the Kotlin compiler on a value that is never null. HANDOFF.md gives the reason for each mutant.
PIT runs these layers against each mutant:
- the tests of core, stdlib and impure. The tests of
rego4k-builtins-stdlib-impurehave the conformance suite and the cases of rego4k, because only that module has the full library, - the fuzz gate, as the JUnit test
FuzzGateTestinverification/mutation.
PIT runs the tests that cover a mutant from the fastest to the slowest, and it stops at the first test that fails. The fuzz gate takes about 30 s, so it runs only for the mutants that the faster tests do not find.
A JUnit test is the simplest way to add this layer: PIT gives it this order with no plugin. The module
verification/mutation holds the test, so that check does not need the opa binary.
PIT does not run the benchmark against a mutant, for these reasons:
- PIT changes a class only in its own JVM. The benchmark runs rego4k in a separate JVM, interleaved with native OPA.
- A benchmark of one mutant takes minutes, and core and stdlib have thousands of mutants.
- PIT stops a mutant that makes a test much slower. The mutant gets
TIMED_OUT, and PIT counts it as found. The time limit of a test is 1.25 times its normal time, plus 4 s.
Thus a mutant that makes rego4k slower but not wrong, and that stays in this time limit, is not found.
benchNightly finds such a change when somebody commits it.
PIT has no support for Kotlin of its own. The Kotlin plugin of Arcmutate, the commercial extensions of PIT, needs a paid licence. Thus the build uses plain PIT.
PIT removes some mutants in the code that the Kotlin compiler generates, but not all. Thus some survivors are in
generated code, for example in the equals of a data class.
The GitHub Actions build
These workflows run on GitHub Actions:
build: .github/workflows/build.yml runs for each push and pull request. It has three jobs that run in parallel, each on its own runner:check,fuzz-gateandbenchmark(benchPrepare, thenbenchGate). Thus the benchmark does not share its runner with the other jobs.nightly: .github/workflows/nightly.yml runs each night at 02:00 UTC, and when you start it ("Run workflow"). Its jobs arebenchmark(benchNightly),fuzz(fuzzNightly) andmutation(pitest). A new difference in the long fuzz run does not fail the job. Examine its report.opa-latest: .github/workflows/opa-latest.yml runs each day the checks against the latest release of OPA. See The latest release of OPA.demo: .github/workflows/demo.yml deploys the demo to Heroku on each push tomain. Its comments give the secret and the variable that it needs.
The jobs get the tools with ./gradlew fetchBenchTools (pinned versions, with checksums). They keep the
Gradle caches and .bench-tools between runs.
To see the results, do these steps:
- Open the "Actions" tab of the repository on GitHub, and select the workflow
build,nightlyoropa-latest. - Select a run. The page shows each job with a mark for success or failure.
- Select a job to see its log. The log of
benchGateandbenchNightlyhas the table of the ratios and the maximums. - Download the files from the "Artifacts" part at the bottom of the page of the run:
benchmark:report.htmland the results of the benchmark.fuzz-nightly: the report of the long fuzz run, with one YAML file for each group of differences.mutation-report: the report of PIT. Openindex.html.conformance-report: the result of each conformance case. Thecheckjob keeps it only if it fails.opa-latest: the page and the reports of the checks against the latest release of OPA.
The latest release of OPA
The build uses the pinned version of OPA (opaVersion in gradle.properties). A new release of OPA can add cases
to the conformance suite, change a builtin or add a builtin.
.github/workflows/opa-latest.yml runs each day at 04:00 UTC, and when you start it. It does not change the pinned version. It has two jobs:
latestgets the tag of the latest release from the GitHub API. If the tag is the pinned version, the job summary says so, and the workflow passes.compatibilityruns only if the latest release is not the pinned version. It does these steps:-
fetchOpa -PopaVersion=<tag>downloads the opa binary of the release, and examines its published checksum.OPA_BINis this binary in all the later steps. -
tests:./gradlew test -PopaVersion=<tag>runs the conformance suite of the release, and all the other tests. These tests also compare rego4k with the new binary, for example:OpaContractTest(opa run --server),- the contract tests of
verification/capabilities, OpaFormatTest(opa fmt),ParseModuleMessagesTest,BuiltinDescriptionsTest(opa capabilities),HttpSendOpaTest.
-
fuzz-gate: the fuzz gate with the new binary. It compares the differences withknown-differences.txtof the pinned version. A known difference does not fail it. A new difference, a changed difference and a difference that is gone fail it. -
fuzz:fuzzNightly, with the date as the seed. A difference does not fail it. -
report: verification/opa-latest/report.py finds each difference of the release from the pinned version. Each difference has a stable key, for example:builtin:<name>for a new builtin,conformance:<file>#<note>for a failed conformance case,test:<class>#<test>for another failed test,fuzz-gate:<case>for a new, changed or gone difference of the fuzz gate.
The script writes the line of the release in verification/opa-latest/tested-versions.tsv, and the page The latest release of OPA. The page gives each difference with its detail and the command that shows it. The page is also the job summary.
-
commit: if the record or the page changed, the step commits them tomainasgithub-actions[bot]. Then it starts the workflowsite, which publishes the page. The comment of the step explains why this cannot make a loop. -
verdict: the job fails if a difference is not in verification/opa-latest/documented-differences.tsv, or if a key of that file does not occur.
-
Thus the workflow fails each day until each difference of the release is fixed or documented.
A documented difference has a line <key><tab><reason>. A documented difference that does not occur also fails
the workflow, so that the list stays correct.
To fix the differences, give the page to a coding agent. See verification/opa-latest/README.md.
The artifact opa-latest holds the page, the conformance report, the JUnit results, the output of the fuzz gate
and the report of the fuzz run.
To run the same checks locally against a release, do these steps:
- Download the binary of the release into a directory of your own, and examine its checksum.
- Set
OPA_BINto the binary. - Run
./gradlew test fuzzGate -PopaVersion=<tag> --continue.
Update the pinned version of OPA
When the workflow opa-latest fails for a new release, do these steps:
- Set
opaVersioningradle.propertiesto the tag of the release. - Set
OPA_VERSIONin.devcontainer/Dockerfileto the same tag. Then build the devcontainer again. - Run
./gradlew fetchOpa, or setOPA_BINto the new binary. The repository has no checksum of the opa binary to change:fetchOpaand the Dockerfile examine the checksum that OPA publishes with each release. The cache key of.bench-toolsholdsgradle.properties, so the GitHub Actions build gets the new binary. - Run
./gradlew check. Correct rego4k for each conformance case and each test that fails. - Run
./gradlew fuzzGate. Examine each new, changed and gone difference. Correct rego4k, or document the difference in Divergences from OPA. Then run./gradlew fuzzGate -Pupdate. - Run
./gradlew benchGate. A new release of OPA can be faster or slower. - Change the version in the text of
README.md, the pages and the home page ofsite, andHANDOFF.md, for example "2538 cases (OPA v1.23.0)". - Remove the lines of verification/opa-latest/documented-differences.tsv. Each key there compares a release with the old pinned version. The record of the tested versions stays.
- Add a note about the update to the status in
HANDOFF.md: the version, and what changed for rego4k.