| #!/usr/bin/env bash | |
| # THE gate. Run this before every commit (DESIGN.md §7, CLAUDE.md). | |
| # | |
| # scripts/gates.sh | |
| # | |
| # Runs, in order, and stops at the first failure: | |
| # 1. cargo build the crate compiles, warning-free | |
| # 2. cargo test the unit tests pass | |
| # 3. scripts/lint-rust-style.sh the Aeneas subset (§3.4), both crates | |
| # scripts/dead-rust.py --check no `pub` Rust item without a caller | |
| # (task #105) | |
| # 4. scripts/provenance.py check every item cites con-leche (§3.7) | |
| # 5. scripts/provenance-selftest.py the gate's Lean parser and the | |
| # bump classifier, on their fixtures | |
| # 6. scripts/twin-lines.py check every `Lean twin:` line names a | |
| # declaration of `proof/ConRon/**` at | |
| # its current lines (§3.7) | |
| # 7. scripts/overview-links.sh OVERVIEW.md/DESIGN.md line anchors | |
| # 8. scripts/holes.sh --check OVERVIEW.md §8.1 == the model's holes | |
| # 9. scripts/gen-pins.sh --check embedded pin text == natOpPinSets | |
| # 10. scripts/gen-prelude.sh --check embedded prelude text == con-leche's | |
| # 11. scripts/gen-prelude-lean.sh --check (B)'s embedded prelude bytes, ditto | |
| # 12. scripts/extract.sh --check committed generated Lean == crate; | |
| # SKIPPED (OK, 0 s) when its inputs match | |
| # a green stamp in `_tmp/extract-green/` | |
| # (task #177; EXTRACT_NO_STAMP=1 forces it) | |
| # 13. cd proof && lake build the default targets elaborate: every | |
| # library of the chain, Theorem 1 | |
| # (`ConRonBridge`), Theorem 2 | |
| # (`ConRonRefine2`), the composition | |
| # (`ConRonMainTheorem`) included; any | |
| # warning from proof/'s own sources fails it (lake-build-wfail.sh, #102) | |
| # (LAKE_JOBS=N caps lake's parallelism through LEAN_NUM_THREADS — Lake 5 | |
| # has no jobs flag; the first con-leche build can exhaust memory, #74). | |
| # The same build also compiles what dead-census needs beyond the | |
| # default targets (its four executables and two index roots), so their | |
| # C compile overlaps the elaboration (task #177). | |
| # 14. lake-seed the green build's artifacts hard- | |
| # linked into the shared Lake cache | |
| # (`_tmp/lake-cache`, CLAUDE.md), for | |
| # the next checkout with the same | |
| # bytes; LAKE_SEED=0 skips it (#177) | |
| # 15. scripts/dead-census-gate.sh no declaration of proof/ConRon/** | |
| # unreachable from the headline | |
| # theorems, Tests and tooling (#105) | |
| # | |
| # One OK/FAIL line per gate; non-zero exit on the first failure. Full output | |
| # of every gate goes to `_tmp/gates-<key>/<n>-<name>.log`, and a full green | |
| # run on a clean tree leaves `_tmp/gates-<key>/green` holding the commit. | |
| set -uo pipefail | |
| # `--only a,b,c` runs just the named steps (the merge queue, task #97-MQ, | |
| # re-gates only what a merge's delta can touch); the rest print SKIP. | |
| only="" | |
| if [ "${1-}" = "--only" ]; then only=",${2-},"; shift 2; fi | |
| # The old per-library steps `lake-refine2`, `lake-bridge`, `lake-capstone` | |
| # (task #98-TIDY folded them into `lake-build`) still select it. | |
| case $only in *,lake-refine2,*|*,lake-bridge,*|*,lake-capstone,*) only="$only,lake-build,";; esac | |
| # The seed belongs to the build it seeds from. | |
| case $only in *,lake-build,*) only="$only,lake-seed,";; esac | |
| root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" | |
| # Per-checkout log dir: `_tmp` is shared between agent worktrees (a symlink), | |
| # and concurrent gate runs must not overwrite each other's logs. | |
| logdir="$root/_tmp/gates-$(printf '%s' "$root" | sha256sum | cut -c1-12)" | |
| rm -rf "$logdir" | |
| mkdir -p "$logdir" | |
| n=0 | |
| skipped=0 | |
| run() { # run <name> <cmd...> | |
| n=$((n + 1)) | |
| local name=$1; shift | |
| if [ -n "$only" ] && [[ "$only" != *",$name,"* ]]; then | |
| skipped=$((skipped + 1)); printf 'SKIP %-22s\n' "$name"; return 0 | |
| fi | |
| local log="$logdir/$n-$name.log" | |
| lastlog=$log | |
| local start end | |
| start=$(date +%s) | |
| if "$@" > "$log" 2>&1; then | |
| end=$(date +%s) | |
| printf 'OK %-22s (%ds)\n' "$name" "$((end - start))" | |
| else | |
| local rc=$? | |
| end=$(date +%s) | |
| printf 'FAIL %-22s (%ds, exit %d) -- %s\n' "$name" "$((end - start))" "$rc" "$log" | |
| echo "--- last 40 lines ---" | |
| tail -40 "$log" | |
| exit 1 | |
| fi | |
| } | |
| # `cargo build`/`cargo test` must be warning-free (§7), which `cargo` does not | |
| # enforce by itself: `-D warnings` does. | |
| run cargo-build env RUSTFLAGS="-D warnings" cargo build --manifest-path "$root/Cargo.toml" | |
| run cargo-test env RUSTFLAGS="-D warnings" cargo test --manifest-path "$root/Cargo.toml" | |
| run lint-rust "$root/scripts/lint-rust-style.sh" "$root/crates/con-ron-core/src" | |
| # Task #105: `-D warnings` catches a private item nothing uses, not a `pub` one. | |
| run dead-rust python3 "$root/scripts/dead-rust.py" --check | |
| run provenance python3 "$root/scripts/provenance.py" check | |
| run provenance-self python3 "$root/scripts/provenance-selftest.py" | |
| # The other half of the same ledger: `provenance` checks what the Rust was | |
| # ported FROM (con-leche, a pinned tree), `twin-lines` what it is a port OF | |
| # (`proof/ConRon/**`, OUR tree, which every task edits — so its ranges rot | |
| # faster). Task #97-TWIN. | |
| run twin-lines python3 "$root/scripts/twin-lines.py" check | |
| run overview-links "$root/scripts/overview-links.sh" | |
| run holes "$root/scripts/holes.sh" --check | |
| run gen-pins "$root/scripts/gen-pins.sh" --check | |
| run gen-prelude "$root/scripts/gen-prelude.sh" --check | |
| run gen-prelude-lean "$root/scripts/gen-prelude-lean.sh" --check | |
| # Charon + Aeneas peak at several GB each; several agents gating at once pushed | |
| # the shared 50 GB cgroup over its cap (peak 53.9 GB, 2026-09-23) and the | |
| # kernel OOM-killed aeneas (exit 137). Serialise this one step machine-wide | |
| # through a lock in the shared `_tmp/` (every worktree sees the same one). | |
| # (the lock is taken inside extract.sh, after its green-stamp check, task #177). | |
| run extract-check "$root/scripts/extract.sh" --check | |
| grep -h -m1 'SKIPPED -- the inputs match' "$lastlog" 2>/dev/null | sed 's/^/ /' || true | |
| # What the build compiles: the default targets (`@con-ron`) and what the | |
| # dead-census step imports beyond them (the list in `dead-census-gate.sh`, whose | |
| # own build is then a no-op). Task #177: one Lake invocation, so the four | |
| # executables' C compile runs beside the elaboration's critical path. | |
| build_targets=(@con-ron ConRon.Bridge ConRon.Refine2 con-ron-lean con-ron-lean-olean-compare | |
| con-ron-arena-bench con-ron-dump-pins) | |
| # Warning-free since task #101; `lake-build-wfail.sh` keeps it so (task #102) | |
| # without failing on the warnings Lake replays from Aeneas's logs. | |
| run lake-build env ${LAKE_JOBS:+LEAN_NUM_THREADS="$LAKE_JOBS"} "$root/scripts/lake-build-wfail.sh" "${build_targets[@]}" | |
| # Task #177: seed the shared Lake cache from the green build (CLAUDE.md, "The | |
| # shared Lake artifact cache"). Elaborates nothing — the tree is up to date — | |
| # it hard-links the artifacts into `_tmp/lake-cache`. Caveat, stated there: | |
| # this also caches the dependency packages of the import closure, which | |
| # chmods their build files read-only and rewrites their `.hash` files. | |
| if [ "${LAKE_SEED:-1}" = 0 ]; then | |
| n=$((n + 1)); skipped=$((skipped + 1)); printf 'SKIP %-22s (LAKE_SEED=0)\n' lake-seed | |
| else | |
| run lake-seed env -C "$root/proof" ${LAKE_JOBS:+LEAN_NUM_THREADS="$LAKE_JOBS"} \ | |
| LAKE_ARTIFACT_CACHE=true LAKE_RESTORE_ARTIFACTS=true lake build "${build_targets[@]}" | |
| fi | |
| # Task #105 (maintainer: "leave no unused code or proofs around"): the census | |
| # over the build the step above left, from the capstone's headline theorems. | |
| run dead-census env ${LAKE_JOBS:+LEAN_NUM_THREADS="$LAKE_JOBS"} "$root/scripts/dead-census-gate.sh" | |
| # Until task #98-TIDY this was followed by three more steps, `lake build | |
| # ConRonRefine2`, `ConRonBridge` and `ConRonMainTheorem`, because those libraries | |
| # were not default targets and a green `lake-build` said nothing about either | |
| # theorem (found by tasks #97-P5-Mut and #97-P3-Ind round 5). They are default | |
| # targets now, so the one step above builds them all. | |
| if [ -n "$only" ]; then | |
| echo "gates: $((n - skipped)) OK, $skipped SKIPPED (--only)" | |
| exit 0 # a partial run is a re-gate, not a landing report | |
| fi | |
| echo "gates: all $n OK" | |
| # The green stamp `scripts/bump-con-leche.sh land` reads (task #108): the | |
| # commit this full run was green at, written only when the tree was clean, so | |
| # that the stamp says exactly which commit passed. The log directory is | |
| # emptied at the start of every run, so a red or partial run leaves none. | |
| if [ -z "$(git -C "$root" status --porcelain --untracked-files=no)" ]; then | |
| git -C "$root" rev-parse HEAD > "$logdir/green" | |
| fi | |
| # The standing progress report (DESIGN.md §7), printed after a green run so | |
| # every landing shows where the port and the proof stand. | |
| echo | |
| python3 "$root/scripts/progress.py" --summary | |
| # The arena's own ledger (task #97-CENSUS): `progress.py` above is the OLD | |
| # tower's report — it credits a con-leche declaration when `Refine/<M>.lean` | |
| # states `f_refines`, and that tree is retired. This one counts the TWINS of | |
| # `proof/ConRon/Arena/**` against Theorem 1 (`Bridge/**`) and Theorem 2 | |
| # (`Refine2/**`). A REPORT, never a FAIL: it runs after the gates and its | |
| # exit code is ignored on purpose. | |
| python3 "$root/scripts/arena-census.py" --summary || true | |
| # The `sorry` FRONTIER of the capstone (task #97-FRONTIER): the declarations | |
| # of `ConRon.MainTheorem.Stages.{model_exists,no_False_declaration}`'s dependency | |
| # closure whose own proof says `sorry`, i.e. what the capstone is actually | |
| # waiting on, and the direct `sorry`s of `Bridge/**`/`Refine2/**` nothing on | |
| # that path needs (dead weight). Also a REPORT: the full list is | |
| # `scripts/frontier.sh ConRon.MainTheorem.Stages.model_exists | |
| # ConRon.MainTheorem.Stages.no_False_declaration`, and every run appends a row to | |
| # `_tmp/frontier-history.tsv` (`scripts/frontier.sh --history`). | |
| "$root/scripts/frontier.sh" --summary --tag capstone \ | |
| ConRon.MainTheorem.Stages.model_exists ConRon.MainTheorem.Stages.no_False_declaration || true | |
| python3 "$root/scripts/loc.py" --summary |