diff --git a/.github/workflows/bootstrap.yml b/.github/workflows/bootstrap.yml index 39e889c4..cd5c810e 100644 --- a/.github/workflows/bootstrap.yml +++ b/.github/workflows/bootstrap.yml @@ -9,12 +9,24 @@ on: permissions: contents: read + actions: read + +# A newer push to a pull request supersedes its older run. +concurrency: + group: bootstrap-${{ github.event.pull_request.number || github.sha }} + cancel-in-progress: ${{ github.event_name == 'pull_request' }} jobs: # `just vv` runs here as independent legs, each from its own clean checkout, # at once. Together the legs run every recipe of `vv` exactly once on the # normative x86-64 host; the arm host runs the host-dependent `rest` leg. # Wall time is the slowest leg, not the sum. + # + # Every leg but `rest` is a formal obligation: it runs once per content + # identity κ of its inputs (scripts/ci-receipt.sh) and uploads a receipt when + # it passes. A later run with the same κ (a product-only change, a rerun, the + # merge of an up-to-date pull request) finds the receipt and does not repeat + # the work. `rest` checks the product and runs on every revision. template-gate: name: acceptance / ${{ matrix.leg }} / ${{ matrix.runner }} strategy: @@ -24,7 +36,7 @@ jobs: - { leg: rest, runner: ubuntu-24.04, recipes: "lexlean-authority template-check fmt-check model lint test features bdd deny" } - { leg: rest, runner: ubuntu-24.04-arm, recipes: "lexlean-authority template-check fmt-check model lint test features bdd deny" } - { leg: artifacts, runner: ubuntu-24.04, recipes: "lexlean-artifacts" } - - { leg: claims, runner: ubuntu-24.04, recipes: "claim-dispositions" } + - { leg: claims, runner: ubuntu-24.04, recipes: "claim-dispositions formal-tests" } - { leg: varint, runner: ubuntu-24.04, recipes: "varint-proofs" } - { leg: reproducibility, runner: ubuntu-24.04, recipes: "reproducibility" } - { leg: integrity, runner: ubuntu-24.04, recipes: "integrity" } @@ -39,7 +51,16 @@ jobs: with: fetch-depth: 0 persist-credentials: false + - name: Look up a receipt for this leg's inputs + id: receipt + if: matrix.leg != 'rest' + shell: bash + env: + GH_TOKEN: ${{ github.token }} + OBLIGATION: ${{ matrix.leg }}-${{ matrix.runner }} + run: scripts/ci-receipt.sh lookup "$OBLIGATION" >> "$GITHUB_OUTPUT" - name: Run this leg of the template gate through the locked SDK + if: steps.receipt.outputs.proved != 'true' shell: bash env: LEG_RECIPES: ${{ matrix.recipes }} @@ -82,6 +103,20 @@ jobs: devcontainer --version exec just $LEG_RECIPES ' + - name: Record the receipt for this leg's inputs + if: steps.receipt.outputs.proved == 'false' + shell: bash + env: + OBLIGATION: ${{ matrix.leg }}-${{ matrix.runner }} + KAPPA: ${{ steps.receipt.outputs.kappa }} + run: scripts/ci-receipt.sh record "$OBLIGATION" "$KAPPA" + - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a + if: steps.receipt.outputs.proved == 'false' + with: + name: receipt-${{ matrix.leg }}-${{ matrix.runner }}-${{ steps.receipt.outputs.kappa }} + path: .tmp/receipt/receipt.json + if-no-files-found: error + retention-days: 90 # The single required signal per host: it passes only when every leg passed. acceptance: diff --git a/.github/workflows/offline-validation.yml b/.github/workflows/offline-validation.yml index 66fae493..173c9bb3 100644 --- a/.github/workflows/offline-validation.yml +++ b/.github/workflows/offline-validation.yml @@ -8,10 +8,39 @@ on: permissions: contents: read + actions: read + +# A newer push to a pull request supersedes its older run. +concurrency: + group: offline-${{ github.event.pull_request.number || github.sha }} + cancel-in-progress: ${{ github.event_name == 'pull_request' }} jobs: + # The whole workflow is one formal obligation: it runs once per content + # identity κ of its inputs (scripts/ci-receipt.sh). When an earlier run with + # the same κ passed, every job below is skipped. + route: + name: offline formal construction / receipt + runs-on: ubuntu-24.04 + timeout-minutes: 5 + outputs: + proved: ${{ steps.receipt.outputs.proved }} + kappa: ${{ steps.receipt.outputs.kappa }} + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 + with: + fetch-depth: 0 + persist-credentials: false + - name: Look up a receipt for this workflow's inputs + id: receipt + shell: bash + env: + GH_TOKEN: ${{ github.token }} + run: scripts/ci-receipt.sh lookup offline >> "$GITHUB_OUTPUT" regenerate: name: review-only generated projections + needs: route + if: needs.route.outputs.proved != 'true' runs-on: ubuntu-24.04 timeout-minutes: 20 steps: @@ -45,6 +74,8 @@ jobs: include-hidden-files: true offline-setup: name: offline formal construction / dependency setup + needs: route + if: needs.route.outputs.proved != 'true' runs-on: ubuntu-24.04 timeout-minutes: 30 steps: @@ -135,7 +166,7 @@ jobs: include-hidden-files: true offline-compare: name: offline formal construction / two-root comparison - needs: offline + needs: [route, regenerate, offline] runs-on: ubuntu-24.04 timeout-minutes: 10 steps: @@ -157,3 +188,14 @@ jobs: name: offline-comparison path: .prism/uorc/offline-comparison.json if-no-files-found: error + - name: Record the receipt for this workflow's inputs + shell: bash + env: + KAPPA: ${{ needs.route.outputs.kappa }} + run: scripts/ci-receipt.sh record offline "$KAPPA" + - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a + with: + name: receipt-offline-${{ needs.route.outputs.kappa }} + path: .tmp/receipt/receipt.json + if-no-files-found: error + retention-days: 90 diff --git a/Justfile b/Justfile index d21a5374..9b124e38 100644 --- a/Justfile +++ b/Justfile @@ -11,7 +11,7 @@ export LEXLEAN_VERIFY_HINTS := env_var_or_default("LEXLEAN_VERIFY_HINTS", justfi default: vv # The whole gate. -vv: lexlean-authority template-check fmt-check model lint test features bdd deny lexlean-artifacts claim-dispositions varint-proofs reproducibility integrity +vv: lexlean-authority template-check fmt-check model lint test features bdd deny lexlean-artifacts claim-dispositions varint-proofs reproducibility integrity formal-tests @echo "vv: the acceptance gate passed" # The UORC authority files are real LexLean source, not merely files with a @@ -52,8 +52,14 @@ fmt-check: lint: cargo clippy --locked --workspace --all-targets -- -D warnings +# The product and repository crates. The xtask suite drives the formal +# runtimes (tens of minutes) and is its own recipe, `formal-tests`. test: - cargo test --locked --workspace + cargo test --locked --workspace --exclude xtask + +# The xtask suite: product-runtime, integrity, claims and offline harnesses. +formal-tests: + cargo test --locked -p xtask # A feature only its author has built is a feature that does not work: nothing # else in the gate compiles a crate at anything but its default features, so a diff --git a/scripts/ci-receipt.sh b/scripts/ci-receipt.sh new file mode 100755 index 00000000..efc6e7a4 --- /dev/null +++ b/scripts/ci-receipt.sh @@ -0,0 +1,57 @@ +#!/usr/bin/env bash +# Content-addressed CI receipts: each slow obligation runs once per content +# identity of its inputs, and a later run with the same identity reuses that +# result instead of proving it again. +# +# kappa print κ, the SHA-256 of the tracked tree minus the +# paths no formal leg reads (the product client and +# release plumbing below) +# lookup print kappa=…, proved=true|false and run=… for +# $GITHUB_OUTPUT. proved=true when an unexpired +# receipt artifact for this obligation and κ exists +# from a same-repository run +# record <κ> write .tmp/receipt/receipt.json for upload +# +# A receipt artifact is uploaded only after its obligation passed, so its +# existence is the proof. Any lookup failure means "not proved": the work runs. +set -euo pipefail + +# The product client and release plumbing. Product changes are checked by the +# `rest` leg on every run; none of these paths is read by the formal legs. +EXCLUDE='^(client/|crates/uorc/|crates/uorc-wasm/|generated/|web/|Cargo\.toml$|Cargo\.lock$|README\.md$|scripts/bench\.mjs$|scripts/client-export\.mjs$|scripts/ci-receipt\.sh$|\.github/workflows/release\.yml$)' + +kappa() { + git ls-tree -r --full-tree HEAD | awk -F'\t' -v re="$EXCLUDE" '$2 !~ re' | sha256sum | cut -c1-64 +} + +case "${1:-}" in + kappa) + kappa + ;; + lookup) + obligation=${2:?obligation} + k=$(kappa) + echo "kappa=$k" + run=$(gh api "repos/$GITHUB_REPOSITORY/actions/artifacts?name=receipt-$obligation-$k&per_page=100" \ + --jq '[.artifacts[] | select(.expired | not) | select(.workflow_run.head_repository_id == .workflow_run.repository_id)] | first | .workflow_run.id // empty' \ + 2>/dev/null || true) + if [[ $run =~ ^[0-9]+$ ]]; then + echo "proved=true" + echo "run=$run" + echo "::notice title=$obligation proved by receipt::κ $k passed in run $GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$run; its inputs are unchanged, so it is not run again." >&2 + else + echo "proved=false" + fi + ;; + record) + obligation=${2:?obligation} + k=${3:?kappa} + mkdir -p .tmp/receipt + printf '{"schema":"uorc/ci-receipt/1","obligation":"%s","kappa":"%s","sha":"%s","run":"%s","attempt":"%s"}\n' \ + "$obligation" "$k" "$(git rev-parse HEAD)" "${GITHUB_RUN_ID:-}" "${GITHUB_RUN_ATTEMPT:-}" > .tmp/receipt/receipt.json + ;; + *) + echo "usage: $0 kappa | lookup | record " >&2 + exit 64 + ;; +esac diff --git a/template.lock b/template.lock index 6d0af274..9b69b950 100644 --- a/template.lock +++ b/template.lock @@ -1 +1 @@ -{"contract_digest":"sha256:67a3292cfe6e6400bc18718b6a62e8741dec8d6d6b062cb0e4077fc8d9b616f5","policy_files":[{"path":".devcontainer/devcontainer.json","sha256":"sha256:faad010f6e2561877feeac664d30c9b20da5c264de8f0007d485cc3c5a3505f2"},{"path":".github/workflows/bootstrap.yml","sha256":"sha256:d09516af712b34ebdc1685b0cd994ac1414060d40304188005c5eba1827cfb82"},{"path":"AGENTS.md","sha256":"sha256:9a1fe3f73ab2963812c35976909c331292e1ca39ce47c0711ec1aafe8b869d87"},{"path":"VERIFICATION.md","sha256":"sha256:0912821fea354276fff5faa2b6b6ded0cdf4ef86112ad035b41a0a7a0513bd21"},{"path":"prismpm.lock","sha256":"sha256:97f3ca37a1077a7819a6ac6206c9132672a05820d547cc834ade18503e5643bf"},{"path":"template-contract.json","sha256":"sha256:67a3292cfe6e6400bc18718b6a62e8741dec8d6d6b062cb0e4077fc8d9b616f5"}],"policy_tree_sha256":"sha256:45da7b74322771514ca1d5fc3c52e43d43cff349b0d7695cc0a9d9832c515263","schema":"uor/template-lock/1","sdk_image":"ghcr.io/uor-foundation/prismpm-sdk-candidate@sha256:0519fe6e2f1d731fc0d475c70ad21d00396d9089051f0c703d477e1ffe39a11c","template_repository":"https://github.com/UOR-Foundation/template","template_revision":"0f1245367d317d439e6752be277047eef76a9e90"} \ No newline at end of file +{"contract_digest":"sha256:67a3292cfe6e6400bc18718b6a62e8741dec8d6d6b062cb0e4077fc8d9b616f5","policy_files":[{"path":".devcontainer/devcontainer.json","sha256":"sha256:faad010f6e2561877feeac664d30c9b20da5c264de8f0007d485cc3c5a3505f2"},{"path":".github/workflows/bootstrap.yml","sha256":"sha256:ae8b1bba4cb1cba61c258c5a78f73877f5152e85b12b451dc81ba3b5af1b9689"},{"path":"AGENTS.md","sha256":"sha256:9a1fe3f73ab2963812c35976909c331292e1ca39ce47c0711ec1aafe8b869d87"},{"path":"VERIFICATION.md","sha256":"sha256:0912821fea354276fff5faa2b6b6ded0cdf4ef86112ad035b41a0a7a0513bd21"},{"path":"prismpm.lock","sha256":"sha256:97f3ca37a1077a7819a6ac6206c9132672a05820d547cc834ade18503e5643bf"},{"path":"template-contract.json","sha256":"sha256:67a3292cfe6e6400bc18718b6a62e8741dec8d6d6b062cb0e4077fc8d9b616f5"}],"policy_tree_sha256":"sha256:0034c428f0f9a8fa81bf58e845b07a2a31f7de7775170f49a89fb317e399ac5c","schema":"uor/template-lock/1","sdk_image":"ghcr.io/uor-foundation/prismpm-sdk-candidate@sha256:0519fe6e2f1d731fc0d475c70ad21d00396d9089051f0c703d477e1ffe39a11c","template_repository":"https://github.com/UOR-Foundation/template","template_revision":"0f1245367d317d439e6752be277047eef76a9e90"} \ No newline at end of file diff --git a/tests/sdk-preflight/test_source_format.py b/tests/sdk-preflight/test_source_format.py index cf935bbc..b97d8ec9 100644 --- a/tests/sdk-preflight/test_source_format.py +++ b/tests/sdk-preflight/test_source_format.py @@ -232,7 +232,10 @@ def audit_workflow(self, workflow): self.assertIn('name: offline formal construction / ${{ matrix.root }}', workflow) self.assertIn('node scripts/offline-validation.mjs compare-offline .prism/offline/first .prism/offline/second-distinct-root', workflow) self.assertIn('name: review-only generated projections', workflow) - self.assertEqual([line.strip() for line in workflow.splitlines() if 'if:' in line], ['if: always()', 'if: always()']) + self.assertEqual([line.strip() for line in workflow.splitlines() if 'if:' in line], [ + "if: needs.route.outputs.proved != 'true'", "if: needs.route.outputs.proved != 'true'", + 'if: always()', 'if: always()']) + self.assertIn('run: scripts/ci-receipt.sh lookup offline >> "$GITHUB_OUTPUT"', workflow) def test_acceptance_legs_run_every_vv_recipe_exactly_once(self):