These are the helper scripts that AGENTS.md points to. Each _test.sh file tests the script of the same name.
spec/check_rules_test.py tests the length and example-value check of spec/check_rules.py and its allow-list, spec/rule_examples_test.py tests spec/rule_examples.py, which writes the examples under each rule of the spec from the cases marked "shown": [rules], and checks.sh and CI run python3 spec/rule_examples.py --check; spec/README.md explains both.
.github/dump-diff_test.sh tests .github/dump-diff.sh, which lists the files that differ between two folders.
.github/pr-facts_test.sh tests .github/pr-facts.sh, which prints how many Rust case reports a change moved, which known failures it added or removed, and whether a case that passed now fails or is gone; put its output in the body of a pull request that changes Rust reports.
.github/pairs-facts_test.sh tests .github/pairs-facts.sh, which runs the pairs in .github/sweep-pairs.json through both engines and prints how many the engines differ on, how many say their want, and which pairs the Rust output of a change moved, first and in capitals any that moved away from Rego or from their want; it only informs, and the pairs-facts job writes it in the summary of a pull request.
.github/mutants-facts_test.sh tests .github/mutants-facts.sh, which runs cargo-mutants on the lines of Rust source a change touches, stops at a time limit (MUTANTS_FACTS_TIMEOUT, 900 seconds by default) and prints how many mutants were caught, missed, unviable or timed out, and the missed ones; it only informs, and the mutants-facts job writes it in the summary of a pull request.
.github/body-facts_test.sh tests .github/body-facts.sh, which reads the output of pr-facts.sh and pairs-facts.sh and the pull request body, prints the counts of reports and pairs a change moved in a line to paste after Changes the report:, and warns when something moved and the body has no line starting with that, or notes the line when nothing moved; it also fails, and lists each one, when the body repeats a sentence of those facts with other numbers (N case reports changed, Rust output changed on N pairs, known-failures.txt had X lines and has Y now, N of M pairs differ between Rego and Rust, Pairs that say their want message: Rego N of M, Rust N of M), and when the facts for such a line can't be read, while other prose is never checked, and it checks every such sentence when a line holds more than one; a fenced code block is the way to write prose that looks like one of those sentences without it being checked; the body-facts job writes it in the summary of a pull request, and its last step is the one that goes red, so a job that fails on the numbers means the body is wrong. The job reads the body when it runs on a push, so after editing the body push or re-run the job. When cargo test failed, it says the report count is unknown and warns.
.github/matrix-facts_test.sh tests .github/matrix-facts.sh, which runs one of the generators in .github/matrix (matrix-a by default) on a base and on the working tree and prints the pairs that got worse than the base and the Rust causes that are lower than ergo.rego's; it only informs, and the matrix-facts job writes it in the summary of a pull request. .github/matrix/README.md says what each generator makes and how to run one by hand.
.github/property-check.py is the second probe for the same changes. It builds one random policy, input and params from a fixed seed, runs about 600 rows through ergo.rego and through the Rust CLI built from main and from your branch, and prints how many rows raise each flag, like a pass where ergo.rego fails, a cause that got milder, a problem said twice or dropped, or problems in a different order. Build dist/ergo.rego and both CLIs natively first, and run it under nice -n 19, one run at a time: nice -n 19 python3 .github/property-check.py run --main-bin <main target>/release/ergo --main-tree <main worktree> --branch-bin <target>/release/ergo. It refuses a binary built from another commit than its tree, and it never fails on a flag. property-check.py --help explains each flag and the show, new, cover and order commands that read what a run left in dist/property-check. .github/property-check_test.sh tests it on a fake engine.
.github/sync-facts.sh [BASE] prints how far the engines are from the spec, one block for your branch and one for BASE (default origin/main, read with git show), then the change: the lines in engines/rust/known-failures.txt by case folder, the known_differences rows in engines/rego/tests/spec_test.rego, the entries in each "differ" section of spec/OPEN.md, and the number of spec cases with the failing share. It never fails on what it finds, and only a bad argument or an unknown base exits non-zero. CI runs it in the rust-report-facts job summary. .github/sync-facts_test.sh tests it.
.github/diff-types.py sorts every case in engines/rust/known-failures.txt and every known_differences row by what differs from the case's expected report: type 1 when a verdict differs (a row passes in one and fails in the other, compliant or a requirement's status differs, or a row is missing or extra), type 2 when the verdicts agree and a row's cause differs, or its inputs differ (a name, a value or a locations list, compared only when the case pins inputs), and type 3 for anything else, like a message or failures, a cause or inputs inside a nested entry included. It reads the Rust reports that the cases test writes when ERGO_DUMP=<folder> is set (--dump <folder> to reuse them, or it runs the test itself) and runs opa eval once for the known_differences names with --rego, after .github/build-ergo.sh. It prints the counts by type and by family, then the case names of types 1 and 2, or only the counts with --summary. The dump has no violations, so a case that differs only there counts as type 3. It exits non-zero on a bad argument, and with --require-no-type-1 when a type 1 is left. CI runs only its test, because the classification needs a Rust test run of its own; run it on demand. .github/diff-types_test.sh tests it.
.github/workflows/nightly.yml runs once a day on main (and by hand): it builds both engines, runs the whole grid of spec/sweep.py and its pairs, and .github/diff-types.py --rego, each with --require-no-type-1, so the run fails when a verdict differs between the engines or from a spec case. Its status job, the only one that may write to issues, puts .github/status-intro.md and the block that .github/status-block.sh prints (the date in UTC, the run's result and the counts by type) in the body of issue #573, replacing the whole body each time. .github/status-block_test.sh tests the script.
engines/rust/known-failures.txt merges with its own driver, so two branches that add or delete lines in it merge without a conflict (the result is the base minus every deleted line plus every added line, sorted). Git's own merge=union would bring deleted lines back. The driver is set once per clone (its worktrees share it) with .github/setup-merge-drivers.sh; CI doesn't need it, because it never merges, and without it git reports the conflict as usual. The changelogs have no driver, because two entries under the same heading need a person to order them.
To have CI run an example, put a line like <!-- ergo-run: NAME role=file path=policy.yaml --> right before the code block (readers don't see it). The roles are file (written to path; normalise=ergo_spec swaps its ergo_spec: line for the version of dist/ergo.rego), command (a shell command that can call opa or ergo; an ergo command runs the binary in ERGO_BIN, or the ergo on PATH, and fails, naming ERGO_BIN, when there is none; it is run in that folder with dist/ergo.rego copied to ergo.rego, or to ergo=PATH) and output (what it prints, compared word for word). Blocks with the same NAME are one group, and may be in different files. Run .github/docs-run.sh [FILE...] after .github/build-ergo.sh; it lists every group that differs, with a diff. README.md follows the latest release, so CI checks its example against the ergo.rego of the latest rego-v* release, with .github/docs-run-release.sh. To mark such a group, add use=release to its command marker, and when the group has no command block that readers see, put the command in the marker as run=`COMMAND` , which runs in that folder and is allowed only when the group has no command block. A run= command, like any command block marked this way, runs as shell in CI, like any script in a pull request, and run= cannot contain a backtick. While a release is being prepared (_spec or version in basics.rego has no -dev), docs-run-release.sh checks against dist/ergo.rego and not the latest release, because README.md has already moved. Without DOCS_RUN_RELEASE_ERGO_REGO set, docs-run.sh prints skip for these groups, and DOCS_RUN_REQUIRE_RELEASE=1 makes a skip fail.
.github/release-version-check.sh VERSION reads the output of ergo --version on its input and fails unless it starts with ergo and the first word after that is VERSION, so a trailing (commit ...) or a Windows line end does not matter. The build-rust job of release.yml runs it on each built binary, and .github/release-version-check_test.sh tests it.