Testing

Which kinds of test RegelRecht has, where each one lives, the recipe that runs it locally and the CI job that runs it on a pull request.

The repository has about twenty kinds of test, and the kind decides who acts on a failure. A red engine test is a bug in the engine. A red scenario next to a law means the law or the scenario changed, and someone has to judge which.

Which test goes where

The table lists the tests in this repository and the jobs that run them here. The CI column names the job; what each job does is on CI/CD.

KindWhere it livesRun it locallyIn CI
Law validation (BDD bucket A)corpus/regulation/**/scenarios/*.featureBDD_BUCKET=corpus just bddNo, on purpose
Engine conformance (BDD bucket B)bdd/conformance/*.feature, ruleworks in bdd/conformance/fixtures/BDD_BUCKET=conformance just bddBDD conformance
The cell’s BDD suite and its constructspackages/cel/bdd/just bddBDD conformance
Demo scenarioscorpus/demo/regulation/**/scenarios/just bdd-demoBDD demo
Scenarios of the chronolexografie PoCpackages/poc-chronolexografie/corpus/just bdd-chronoBDD demo
Example caller of the reusable BDD workflowbdd/external-corpus-example/see BDD scenarios from another repositoryExample corpus, Example reports hold only its scenarios
Scenarios of the JavaScript PoCsfrontend-poc-*/tests/scenarios.test.jsnpm test -w frontend-poc-<slug>E2E (mocked)
Rust unit and integration testspackages/*/src/, packages/*/tests/just testRust tests
Golden fixturespackages/engine/tests/golden_tests.rsjust testRust tests
Trace snapshotspackages/engine/tests/trace_integration.rsjust testRust tests
Corpus type checkpackages/engine/tests/typecheck_corpus.rsjust testRust tests
Schema conformancepackages/engine/tests/schema_conformance.rsjust schema-conformanceRust tests
Schema validationthe corporajust validatePre-commit
Script testsscript/*.test.sh, script/*.test.mjsjust checkPre-commit
Frontend unit tests and type checksfrontend/, frontend-lawmaking/, frontend-demo/, packages/frontend-shared/, packages/poc-chronolexografie/frontend/just frontend-testFrontend tests
Unit tests of the JavaScript PoCsfrontend-poc-*/src/npm test -w frontend-poc-<slug>E2E (mocked); wetsgeschiedenis: Frontend tests
PoC tests against the engine or the casusfrontend-poc-*/tests/, packages/poc-chronolexografie/frontend/tests/npm test -w <workspace>E2E (mocked); wetsgeschiedenis and chronolexografie: Frontend tests
Editor end to end, mockedfrontend/e2e/just test-e2eE2E (mocked)
Walkthrough pipelinescript/walkthrough/tests/just walkthrough testFrontend tests
Walkthrough replayfrontend-demo/scripts/verify-walkthrough.mjsjust walkthrough verifyRondleiding speelt terug
Docs source checksdocs/scripts/check-*.mjsnpm run check:source in docs/Docs source checks
Docs accessibilitydocs/scripts/, pa11yjust docs-a11yDocs accessibility gate
Smoketest of a deployed editorfrontend/e2e-smoke/just smoke-preview <pr>No, it needs a deployment
Mutation testingpackages/engine, packages/pipeline, packages/celjust mutants-diffMutation Testing (diff)
Benchmarkspackages/engine/benches/just benchNo

A test of the engine or the law format is named after the construct it tests. That holds for the test file, the feature, the construct directory and the test function: a function says what the construct does (a_grant_revoked_on_objection_does_not_count), not what happens in its case (a refused parking card). The law or case only makes the test concrete, so its name belongs in a fixture or a Background. A large test file is split into a directory, tests/<construct>/main.rs with one module per construct beside it, as packages/cel/tests/submission_lifecycle/ is. Bucket A is the exception, because a scenario next to a rulework tests that rulework. So a test that only checks the values of one rulework belongs there and not in a Rust test.

A test of a construct runs on the smallest rulework that makes the construct possible: fictional, cut down to what the test reads, and a fixture of the test’s own crate. It does not read the corpus, because a change to a law would then turn a test of the engine red. Nor does it read a copy of real legislation, which carries far more than the test exercises. Where a construct builds on a general act such as the Awb, the fixture is a mini-version of that act with only the articles the tests reach. The exception is a test whose subject is the corpus itself, such as the corpus type check.

BDD scenarios

Most behavior is tested with Gherkin feature files, which the Rust engine runs through cucumber-rs.

Two buckets, one language

Feature files live in two places, and the difference decides who fixes a failure:

  • Bucket A, law validation: corpus/regulation/**/scenarios/*.feature, run against the real corpus. A failure means a law changed or the scenario went stale, and a human decides which. Scenarios tagged @wip are skipped.
  • Bucket B, engine conformance: bdd/conformance/*.feature, tagged by tier, proving an engine speaks the whole language. CI blocks on this bucket. Its features run against the fictional test_* ruleworks in bdd/conformance/fixtures/regulation alone, a mini Awb among them, whatever REGULATION_PATH says. Those ruleworks are not part of the corpus, so the editor and the demo never show them, and a change to a real law cannot turn this bucket red.

The cell has a BDD suite of its own in packages/cel/bdd/, outside both buckets. Its steps record submissions, decisions and facts in a cell’s chronicle, evaluate a reduction that plays the chronicle forward, and check what the engine did. A well-founded objection, for example, makes the engine play the chronicle again without the decision it revokes, while an unfounded one leaves the decision standing. They stay out of bdd/grammar.yaml, which is the contract every engine (Rust and JS) executes, because recording a chronicle is the cell’s job and only the Rust engine plays one forward; the JS engines do not implement projection. The features in packages/cel/bdd/features run against the ruleworks in packages/cel/bdd/fixtures alone, a mini Awb among them. Each construct set under packages/cel/bdd/constructs/ runs against its own. Neither reads the corpus. bdd/README.md explains how that suite reuses the canonical steps and the generator, and why its runner sits in packages/cel.

Trying out a construct

A construct of the law format that is hard to get right gets a directory of its own under packages/cel/bdd/constructs/. The first, hook_open_term_host_fill, is an open term of a hook that the law the hook fires on fills, with the decision term of Awb 4:13 as its case. A construct’s features load only the ruleworks in its regulation/ directory. For hooks that matters. A hook fires on every decision or submission its applies_to matches, in every loaded rulework, so loading the whole corpus would bring in hooks the construct is not about.

packages/cel/bdd/constructs/hook_open_term_host_fill/ regulation/nl/wet/test_general_administrative_act/2026-01-01.yaml regulation/nl/wet/test_permit_act/2026-01-01.yaml regulation/nl/wet/test_permit_act_implements/2026-01-01.yaml regulation/nl/wet/test_permit_act_short_term/2026-01-01.yaml scenarios/hook_open_term_host_fill.feature

In the hook_open_term_host_fill construct, a mini-Awb (test_general_administrative_act, after Awb 4:2 and 4:13) meets three fictional permit acts. An application is recorded on the day it arrives, which is the moment Awb 4:13 counts from, and the decision follows on a later day. The scenarios check what the application holds, the last day of the term, and whether the decision came on or before it: well within the term, on the last day, one day late, and counted from receipt rather than from the date on the application. Two permit acts set a term of their own, and between them they show both routes to the last day, decision_deadline. test_permit_act_short_term sets two weeks with an override on decision_deadline. test_permit_act_implements sets one week by filling the open term statutory_decision_term of 4:13 with implements. Under the hook on its application, only that act fills it (RFC-058). In both cases the fallback of lid 2, reasonable_decision_term_end, stays eight weeks.

To add a construct:

  1. Make packages/cel/bdd/constructs/<construct>/ with a regulation/ and a scenarios/ directory. The runner fails when either is missing or when scenarios/ holds no feature.
  2. Put the fictional ruleworks in regulation/, in the layout of the corpus. Give each an $id starting with test_, mark the text FICTIEF, and invent the content: no real case, no real person. A general law the construct builds on, such as the Awb, is a mini-version holding only what the scenarios need. The construct then does not change when the corpus does. just validate and the pre-commit hook check the ruleworks against the schema.
  3. Write the features in scenarios/, in English. A feature may use the canonical steps and the cell’s own. A decision the cell takes (the cell decides ...) sets the result, so Then output ... equals ... reads what the decision and the hooks on it gave.
  4. A scenario the engine cannot run yet gets @wip and a comment above it that names the missing piece and the branch or issue that builds it.

just bdd and the CI job “BDD conformance” run the constructs with the rest of the cell’s suite; no recipe or workflow changes.

The runner reads the set from where a feature sits, whichever directory <set> is. BDD_CONSTRUCT_SETS names sets from outside the crate: a :-separated list of set directories. When it is set, the runner plays those sets alone and leaves out its own suite, which runs in regelrecht’s CI. A directory in it that is not a set, or that holds no feature, fails the run as a construct would. The engine’s own runner does not look at where a feature sits and always loads the corpus.

The step vocabulary is generated, not hand-written

bdd/grammar.yaml is the single source of truth for the step phrasings. The bindings for every engine are generated from it: Rust through packages/engine/build.rs, the editor and demo JavaScript through bdd/codegen/gen-js.mjs, which writes packages/frontend-shared/src/gherkin/grammar.generated.js (re-exported for the editor by frontend/src/gherkin/). Never hand-edit a generated file. Change grammar.yaml and run just bdd-codegen.

A step that is not in grammar.yaml does not exist. A minimal scenario:

Feature: Healthcare allowance Scenario: An adult with an active policy is entitled to zorgtoeslag Given the calculation date is "2025-01-01" Given law "zorgverzekeringswet" is loaded Given parameter "bsn" is "999993653" When I evaluate "heeft_recht_op_zorgtoeslag" of "wet_op_de_zorgtoeslag" Then the execution succeeds Then output "heeft_recht_op_zorgtoeslag" is true Then output "hoogte_zorgtoeslag" equals 157731

Laws that need source data (BRP, Belastingdienst, and the like) provide it with a data-table step keyed on the identifier the law looks up:

Given the following "personal_data" data with key "bsn": | bsn | geboortedatum | verblijfsadres | | 999993653 | 2005-01-01 | Amsterdam |

See corpus/regulation/nl/wet/wet_op_de_zorgtoeslag/scenarios/eligibility.feature for a complete, data-driven example.

Running the scenarios

just bdd # Both buckets, then the cell's own suite BDD_BUCKET=conformance just bdd # Engine conformance, then the cell's suite BDD_BUCKET=corpus just bdd # Law validation, then the cell's suite just bdd-demo # Bucket A over the demo corpus just bdd-chrono # Bucket A over the corpus of the chronolexografie PoC just bdd-trace # With execution traces in trace_output/

When a rulework in a directory of REGULATION_PATH cannot be loaded, the run fails and names the file; the loader does not skip it.

just bdd-chrono runs bucket A over the corpus of the chronolexografie PoC, which keeps its own copies of the real ruleworks it uses so that work on the PoC leaves corpus/regulation/ alone. Their scenarios went along with them. Two of those features are still identical to the originals in the corpus: criteria.feature of the Regeling gehandicaptenparkeerkaart and regio_en_vakanties.feature of the Regeling vaststelling schoolvakanties. Both copies stay. The PoC’s copy of the parking card regulation already makes a choice of its own on article 2, so that feature tests a different version. The PoC’s ruleworks change only when someone works on the PoC, so a red scenario there is a real error and runs in CI. The originals are bucket A and stay out.

Two other PoCs run their scenarios against the engine built to WASM instead, through tests/scenarios.test.js in their frontend. They are listed in BDD_RUNNERS in script/orphan-tests.mjs, which is how the orphan check knows their features are read.

Deriving scenarios from legislative intent

Test scenarios are derived from the Memorie van Toelichting (MvT), the explanatory memorandum that accompanies Dutch legislation. The MvT contains examples and reasoning from the legislature that serve as ground truth for expected behavior.

BDD scenarios from another repository

A corpus kept in another repository runs its scenarios in its own CI by calling the reusable workflow .github/workflows/corpus-bdd.yml. The workflow checks out the caller and regelrecht side by side and builds the engine. It then runs bucket A over the caller’s ruleworks, the construct sets in a directory of the caller, or both:

# .github/workflows/bdd.yml in example-org/regelrecht-corpus-example name: BDD on: pull_request: push: branches: [main] jobs: bdd: uses: NederlandseDigitaleDienst/regelrecht/.github/workflows/corpus-bdd.yml@<commit> with: regulation-path: regulation # holds nl/ and the scenarios/ directories include-central-corpus: true # load corpus/regulation beside it buckets: all # corpus, constructs or all constructs-path: constructs # one construct set per subdirectory

The commit after @ fixes the workflow and the engine together: with regelrecht-ref left empty, the workflow checks out regelrecht at the commit it was read from. Pin a commit, not a branch: a change in regelrecht then reaches the corpus as an update someone reviews. Set regelrecht-ref only to try another engine under the same workflow.

With include-central-corpus, the ruleworks of corpus/regulation load beside the caller’s but their scenarios do not run: BDD_SCENARIO_PATH keeps bucket A to the caller’s directory. A $id that both directories hold fails every scenario, with a file from each in the message. A corpus with its own version of a central rulework therefore leaves include-central-corpus off, and keeps every central rulework its scenarios read in its own directory. The engine keeps one version per $id and valid_from. Without the check, a file with the same valid_from would replace the other, and the order of REGULATION_PATH would decide which one stays; a file with another valid_from would quietly join it as an extra version.

Within one directory, the versions of a rulework load side by side.

Each construct set of the caller is named after the construct it tests, as the sets here are. The construct sets run through the cell’s runner, without its own suite. Each run writes a JUnit report through BDD_JUNIT, so both reports hold only the caller’s scenarios. The workflow uploads them as one artifact, named by artifact-name (default bdd-reports), and lists the counts and every failed scenario in the step summary. The job fails when either run fails. .github/workflows/corpus-bdd-example.yml calls it against the fictional corpus in bdd/external-corpus-example whenever the workflow, a runner or the example corpus changes.

To run the example locally, from packages/engine and then from packages/cel:

BDD_BUCKET=corpus REGULATION_PATH=$PWD/../../bdd/external-corpus-example/regulation:$PWD/../../corpus/regulation \ BDD_SCENARIO_PATH=$PWD/../../bdd/external-corpus-example/regulation cargo test --test bdd BDD_CONSTRUCT_SETS=$PWD/../../bdd/external-corpus-example/constructs/decision_on_submission cargo test --test bdd

Rust tests

The Rust unit and integration tests, across every crate in the workspace:

just test # Whole workspace (needs Docker) just test-no-docker # Everything that needs no external services just test-db # Only the container-backed crates

A few crates also have a recipe of their own, such as just pipeline-test and just pipeline-integration-test (the second needs Docker); just lists them.

Each crate’s tests read their own fixtures. Those of packages/cel are in packages/cel/tests/fixtures/corpus/, and the reduction tests of the engine (packages/engine/tests/reduction.rs) have theirs in packages/engine/tests/fixtures/reduction/. A fixture is YAML made for its tests and holds only what they read: the cells, and fictional rulework and reductions cut down to the articles and outputs a test exercises. The real laws these tests build on are replaced by fictional mini-versions in the same fixtures, each after a real act (test_general_administrative_act after the Awb, test_school_leave_act after article 13a of the Leerplichtwet 1969, test_traffic_decree after the BABW). They keep the article numbers of that act, so a test can still say which article it exercises.

Golden fixtures and trace snapshots

packages/engine/tests/golden_tests.rs runs the JSON cases in packages/engine/tests/fixtures/*.json, each a law as YAML text with parameters and an expected result. Conformance describes their format and where they came from.

packages/engine/tests/trace_integration.rs evaluates a decision across laws, compares each rendered trace with its snapshot (expected_allowance_trace.txt, expected_premium_trace.txt), and checks what each step of the trace carries. It reads a fictional chain in packages/engine/tests/fixtures/trace/: an allowance act that reads a register, calls an income act and leaves an open term to a regulation, and a mini general act whose two hooks fire on the decision. That is what a trace across laws shows. A rulework added to the chain can fire a hook and change the expected trace. A few unit tests in packages/engine/src (article.rs, resolver.rs, service.rs) read the same chain, and one of them counts its ruleworks.

The corpus type check

packages/engine/tests/typecheck_corpus.rs runs the static type check over the corpus, the demo corpus and the corpus of the chronolexografie PoC, and fails on any finding. Unlike the trace test it reads the live corpora on purpose, because it guards the corpus.

Schema conformance

just schema-conformance

Checks that the Rust law-model accepts exactly what the JSON schema accepts. It is a different suite from engine conformance, BDD bucket B: that one runs scenarios, this one compares the model with the schema. just test includes it. What it covers, and what conformance does not cover yet, is on Conformance; adding a fixture is described in packages/engine/tests/schema_conformance/README.md.

Schema validation

Every rulework is validated against the JSON schema. Without arguments, just validate checks the corpus (corpus/regulation), the ruleworks and reductions of the chronolexografie PoC, and the fixtures of the cell’s BDD suite (packages/cel/bdd/fixtures: its regulation/ directory and the reductions of its cell), the regulation/ directory of each construct in packages/cel/bdd/constructs, the fictional ruleworks of bucket B in bdd/conformance/fixtures/regulation, and the fictional outside corpus in bdd/external-corpus-example. It leaves the demo corpus out; just validate-demo covers that. The pre-commit hook runs the same recipe on the changed files in all of these directories, the demo corpus included, and CI runs the hooks over the whole tree.

just validate # Validate all just validate path/to/law.yaml # Validate a specific file just validate-annotations # Validate stand-off notes just validate-demo # Validate the demo corpus

Frontend tests

just frontend-test runs the unit tests and type checks of the editor, lawmaking, the demo, the shared package and the chronolexografie PoC. just test-e2e builds the engine to WASM and drives the editor with Playwright against mocked backends. Where frontend code and its tests go is on Frontend code.

just smoke-preview is the one test that runs against a deployed editor: a preview by its pull request number, or a URL. It logs in through the real Keycloak and needs the test user’s credentials, so CI does not run it. Deployment covers previews and waking one up first.

The demo

just demo-check checks the demo end to end: the laws, their scenarios, the frontend tests, and the WASM build. Run it before pushing anything demo-related.

The recorded walkthrough has two checks. just walkthrough test runs the pytest suite of the pipeline that cuts and subtitles the takes, in script/walkthrough/tests/. just walkthrough verify replays every chapter headless and names each recorded action that finds nothing on the page, which is the CI job “Rondleiding speelt terug”. The route from recording to release is on Demo.

Script tests

The scripts in script/ that decide something in CI, such as a merge gate or the orphan check, have a test suite next to them: script/<name>.test.sh or script/<name>.test.mjs. A pre-commit hook runs each suite when the script or the workflow it guards changes, and a just recipe runs it by hand (just ci-gate-test, just orphan-tests-test). just check runs most of them; CI runs every hook in the Pre-commit job. Change a script that decides green or red together with its suite.

Docs checks

npm run check:source in docs/ checks the docs without building them. Among other things it checks that cited paths exist, that Gherkin steps are in the grammar, the prose style, and the RFC numbering and coverage. just docs-a11y builds the site and runs the accessibility gate, pa11y included. The writing rules behind the prose check are in the docs-writing skill.

Mutation testing

cargo-mutants checks whether the tests actually pin behavior or merely execute it. CI runs the diff variant as a gate on changed code. The weekly full run (mutation-testing.yml) mutates the engine and the cell and opens an issue with what survived.

just mutants # Full run just mutants-diff # Only what this branch changed

Line coverage is no measure of this. A line counts as covered when a test runs it, whether or not an assertion depends on what it computed. Read a coverage percentage as context next to the mutation results, never on its own.

Construct mutation

cargo-mutants breaks the Rust code and runs the Rust tests. It does not run the BDD suites, which are test = false, so it says nothing about whether the language suites pin a construct. Bucket B is the contract every engine has to meet, and an engine other than the Rust one has none of the Rust unit tests behind it.

Construct mutation asks that question of the law format. just construct-mutants breaks one construct at a time in every synthetic test_* rulework. ADD becomes SUBTRACT, GREATER_THAN becomes GREATER_THAN_OR_EQUAL, an EQUALS gets wrapped in a NOT, the hooks of an article are dropped. Real ruleworks in the corpus are left alone.

With one construct broken, the run executes bucket B and the cell’s suite. A construct is pinned when either suite turns red. The mutations keep the rulework valid against the schema, so a red suite usually means an assertion noticed. It can also be a run-time error the mutation caused, such as a division by zero after MULTIPLY became DIVIDE; the run counts that as pinned too. The same holds for a mutant the engine’s type check refuses when it loads. Removing nullable, an implements or the defaults of open_terms can do that, and then every scenario turns red without an assertion having noticed.

just construct-mutants # Every construct just construct-mutants --only ADD,IF # A few just construct-mutants --check bdd/construct-gaps.txt

The mutations are in packages/engine/tests/common/construct_mutation.rs, and the driver and its report in script/construct-mutants.mjs. A construct the run has no mutation for is listed in NOT_MUTATED in the same file, with the reason. packages/engine/tests/construct_coverage.rs runs with the other Rust tests and fails when the schema has an operation or a property in neither list, so a new construct arrives with a decision about how its tests are measured.

bdd/construct-gaps.txt lists the constructs that no scenario pins yet. The workflow Construct mutation runs the check on a pull request that changes the scenarios, the synthetic ruleworks, the schema or the mutations. It turns red when a construct that is not on the list is not pinned. It also turns red when a listed gap gets pinned, so a gap leaves the list as soon as a scenario covers it. In CI it runs in four shards of about six minutes each. It also runs weekly, and the issue of the weekly mutation run carries its report.

Benchmarks

Performance benchmarks using Criterion:

just bench # Run all benchmarks just bench-save baseline-name # Save a baseline just bench-compare baseline-name # Compare against baseline

Everything at once

just check runs formatting, lints, a build check, schema and annotation validation, the script test suites, and the full Rust test suite. It needs no npm dependencies. Run it before pushing, and after a frontend change also just frontend-test: the frontend unit tests and type checks, as CI runs them. The Playwright suite is just test-e2e.

The first three also run on their own, and the pre-commit hooks call them the same way:

just format # rustfmt check (cargo fmt --check) just lint # clippy over all packages and targets, with the validate and annotation-validation features just build-check # cargo check over the whole workspace

Does the new test run?

A test that no CI job starts never fails, so a missing hook or step goes unnoticed for months. An audit of the repository in October 2026 found seventeen. just orphan-tests (script/check-orphan-tests.mjs) reads what CI runs: the steps in .github/workflows/, the pre-commit hooks, and every Justfile recipe and npm script those reach. It fails on any of these:

  • a *.test.ts, *.test.js or *.test.mjs file that no command names and that no vitest run in CI picks up through its config’s include and exclude
  • a *.test.sh or test-*.sh script that no hook or step runs, directly or through a recipe that one of them calls
  • a workspace crate that no cargo test in CI covers
  • a .feature file that no BDD runner in CI reads. The engine reads the directories that BDD_BUCKET and REGULATION_PATH select per step; the PoC runners are listed in BDD_RUNNERS in script/orphan-tests.mjs
  • a @wip tag or an #[ignore] without a comment that says why, above it or on the same line (#[ignore = "..."] counts too)

The guard skips two directories. Bucket A over the live laws in corpus/regulation stays out of CI on purpose. bdd/external-corpus-example does run, but through the inputs of the reusable workflow, which the guard cannot read. EXCEPTIONS in script/orphan-tests.mjs records both reasons. The guard runs as a pre-commit hook and therefore in the Pre-commit check. Its own suite is just orphan-tests-test, with a passing and a failing case for each rule.

It reads YAML and shell line by line and leans towards counting a test as run. A recipe with a case counts as running every branch, and a file counts as run once it is the command or an argument of an interpreter such as node or bash. The vitest include and exclude lists and the cargo flags that narrow a run (--no-run, --lib, --test) decide what a run covers. Beyond those, a test drops out only through a literal if: false on its step or job, a leg under a matrix exclude, or a hook that CI never runs. Any other condition still counts as a run. So does a workflow that only runs on a schedule, and so does a step with continue-on-error. Playwright *.spec.* files and the pytest suites are outside its scope. Whether a test that runs also tests something is still a question for review.

RegelRecht

An exploration into transparent, executable legislation, and one of the three projects in the starting selection of the Nederlandse Digitale Dienst.

Links

GitHub repository
How it works
Demo walkthrough
Stay informed
Roadmap (Dutch)
Documentation
Research
Basiswerk recht (Dutch)

Contact

regelrecht@minbzk.nl

Part of

Nederlandse Digitale Dienst
Ministry of Economic Affairs and Climate Policy