diff --git a/.aien/always b/.aien/always new file mode 100644 index 0000000..7bf0586 --- /dev/null +++ b/.aien/always @@ -0,0 +1,4 @@ +# Gates that run on every commit regardless of changed paths (ADR 0033 Decision 12 +# allow-list; inventory contract C6). One gate name per line. Read from the base ref. +CRUMB-VERIFY +RSI-ZERO-DISK-SECRETS diff --git a/.aien/unmapped-ok b/.aien/unmapped-ok new file mode 100644 index 0000000..5a31f94 --- /dev/null +++ b/.aien/unmapped-ok @@ -0,0 +1,7 @@ +# Changed paths matching these globs need only the always-run set (.aien/always). +# Everything else must be covered by a manifest's inputs or the commit is NOT_RUN. +# Conservative: only paths no hosted job compiles or tests. Read from the base ref. +docs/** +*.md +LICENSE +.gitignore diff --git a/.aien/verify.pub b/.aien/verify.pub new file mode 100644 index 0000000..3e65411 --- /dev/null +++ b/.aien/verify.pub @@ -0,0 +1 @@ +01368e0b02dc1113ae7425ad6ab00fdf5aa7dd97e0690745918a52f051d5cf68 diff --git a/.crumb b/.crumb index 9282cba..9353658 100644 --- a/.crumb +++ b/.crumb @@ -79,8 +79,8 @@ "purpose": "Directory src. Purpose not yet described by a human." }, { - "digest": "1266f530a7c210d086c27864b93d3f573431e38ca2883696c0e35a13586a8c17", - "last_commit": "4becebb", + "digest": "7741e691cc295d6dc1a838afb3e73928688143066c0436f89e9cad72bc132110", + "last_commit": "64062d8", "name": "tests", "purpose": "Directory tests. Purpose not yet described by a human." }, @@ -91,15 +91,15 @@ "purpose": "Directory tools. Purpose not yet described by a human." } ], - "children_root": "sha256:4e4db3c70c32a0bcd8dcd5446aa61c0973d754baac400986a6b5b11aff2fdd08", - "compiled_at": "2026-10-08T23:35:13Z", + "children_root": "sha256:5367872f16d5ebf8bab9102115608fb72281eb813237596c63cb56cdeeb4cf65", + "compiled_at": "2026-10-11T17:58:40Z", "compiler": "crumb-compile/1", - "digest": "sha256:586d6df745089efc32175a1d6b20b789ebe08fe5d1883a1084b55ab224c63c80", + "digest": "sha256:750feb8067ade88fcce17edf192a75c8accc450972800f112bbeabef7a440caf", "evidence_files": 2, "evidence_root": "sha256:2af46c9e5c5f639d24acdfd75e5bbc6704616dd36c2d8d18ea4070421f048147", - "files": 105, - "generated_at_commit": "4becebbc9780615c0274753226defd0fb2b5eba1", - "source_tree": "sha256:487564d308d4957b1f9f71f34baa91590aa6534d9d603df9a824b9439e1a9399" + "files": 115, + "generated_at_commit": "f4f01f1e2264c3523e1d79724046af4acfa08321", + "source_tree": "sha256:7f995d61e1c613f8081788b2f981c0ef3a2ad58db06e099e0fad09cdf4ee7534" }, "owner_lane": "", "seed": { diff --git a/.github/workflows/aien-verification.yml b/.github/workflows/aien-verification.yml new file mode 100644 index 0000000..d7b6178 --- /dev/null +++ b/.github/workflows/aien-verification.yml @@ -0,0 +1,186 @@ +# AIEN Verification: the GitHub thin gate (ADR 0033 Decision 11, inventory contract C5). +# +# PHASE 2 DRAFT (2026-10-11, lane REPOS). This workflow is NOT a required check yet. It runs +# beside the existing hosted workflows so that, for N >= 3 commits, the hosted verdict and the +# locally signed bundle verdict can be compared (advisor amendment A7). Nothing here changes +# the repository's required contexts; that switch is phase 3 and needs Drake's agreement. +# +# What it does: checkout; read the trust anchors from the BASE ref (origin/main), never from +# the head under test (amendment A1); crumb verify; fetch //bundle.json from +# aien-dev/aien-receipts; verify the bundle signature and content with the pinned aien-test +# build; run the repository's portable smoke set (gates whose requires is only "portable"). +# +# GitHub-hosted compute: this workflow compiles only the two pinned verifier tools (the crumb +# checker, and aien-test once the repository is enrolled). It never builds or tests this +# repository's own code; the portable smoke set is text scans and format checks only. +# +# PHASE 3 FLIPS (marked "PHASE3" below): a missing bundle becomes NOT_RUN (status pending with +# a retry window) instead of a neutral note, and a trust-surface change becomes a failure +# unless the operator ran it by hand (BLOCKED_OPERATOR). +name: AIEN Verification + +on: + pull_request: + push: + branches: [main] + +permissions: + contents: read + +jobs: + verify: + name: AIEN Verification + runs-on: ubuntu-latest + timeout-minutes: 30 + env: + REPO_SLUG: aien-dev/spark-rsi + AIEN_TEST_PIN: c26f4d7ac3156088469b27462390f5b08ef4f436 + RECEIPTS_RAW: https://raw.githubusercontent.com/aien-dev/aien-receipts/main + steps: + - name: Checkout the head under test + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Resolve the commit under test and the base ref + id: ids + run: | + if [ "${{ github.event_name }}" = pull_request ]; then + sha="${{ github.event.pull_request.head.sha }}" + else + sha="${{ github.sha }}" + fi + git fetch -q origin main + echo "sha=$sha" >> "$GITHUB_OUTPUT" + echo "base=$(git rev-parse origin/main)" >> "$GITHUB_OUTPUT" + echo "commit under test: $sha" + echo "base (trust anchors): $(git rev-parse origin/main)" + + - name: "Trust anchors from the base ref (A1: never from the head under test)" + id: anchors + run: | + mkdir -p "$RUNNER_TEMP/anchors" + base="${{ steps.ids.outputs.base }}" + if git show "$base:.aien/verify.pub" > "$RUNNER_TEMP/anchors/verify.pub" 2>/dev/null; then + echo "enrolled=true" >> "$GITHUB_OUTPUT" + git show "$base:.aien/always" > "$RUNNER_TEMP/anchors/always" 2>/dev/null || : > "$RUNNER_TEMP/anchors/always" + git show "$base:.aien/unmapped-ok" > "$RUNNER_TEMP/anchors/unmapped-ok" 2>/dev/null || : > "$RUNNER_TEMP/anchors/unmapped-ok" + echo "verify.pub (base): $(cat "$RUNNER_TEMP/anchors/verify.pub")" + else + echo "enrolled=false" >> "$GITHUB_OUTPUT" + echo "::notice::.aien/verify.pub is not on the base ref yet: this repository is not enrolled. Phase 2: neutral." + fi + # Trust-surface changes are run by the operator by hand (A1): BLOCKED_OPERATOR. + changed=$(git diff --name-only "$base...${{ steps.ids.outputs.sha }}" -- .aien tests/gates .github/workflows .forgejo tools/aien-test || true) + if [ -n "$changed" ]; then + echo "blocked=true" >> "$GITHUB_OUTPUT" + echo "::notice::BLOCKED_OPERATOR: this head changes the trust surface:"; echo "$changed" + # PHASE3: fail here unless an operator attestation for this sha is present. + else + echo "blocked=false" >> "$GITHUB_OUTPUT" + fi + + - name: Checkout the pinned crumb tool source (aien-architecture @ 94fffbcf88492c5a1c54211b5126c8a6c370a98d) + uses: actions/checkout@v4 + with: + repository: aien-dev/aien-architecture + ref: 94fffbcf88492c5a1c54211b5126c8a6c370a98d + path: .crumb-tool-src + + - name: Build the crumb tool, then remove its source from this tree + run: | + make -C .crumb-tool-src/tools/crumb crumb + mkdir -p "$RUNNER_TEMP/bin" && cp .crumb-tool-src/tools/crumb/crumb "$RUNNER_TEMP/bin/crumb" + rm -rf .crumb-tool-src + echo "$RUNNER_TEMP/bin" >> "$GITHUB_PATH" + + - name: Crumbs must be exactly what the compiler produces now (stays GitHub-hosted, D11) + run: crumb verify . + + - name: Install Stable Rust Toolchain (for the pinned aien-test build and the smoke set) + if: steps.anchors.outputs.enrolled == 'true' + uses: dtolnay/rust-toolchain@stable + with: + components: rustfmt + + - name: Checkout the pinned aien-test source (aien-sovereign-core @ ${{ env.AIEN_TEST_PIN }}) + if: steps.anchors.outputs.enrolled == 'true' + uses: actions/checkout@v4 + with: + repository: aien-dev/aien-sovereign-core + ref: ${{ env.AIEN_TEST_PIN }} + path: .aien-test-src + + - name: Cache the pinned aien-test build + if: steps.anchors.outputs.enrolled == 'true' + uses: actions/cache@v4 + with: + path: | + ~/.cargo/registry + ~/.cargo/git + .aien-test-src/target + key: aien-test-${{ runner.os }}-${{ env.AIEN_TEST_PIN }} + + - name: Build aien-test from the pin (never from the tree under test), then remove the source + if: steps.anchors.outputs.enrolled == 'true' + run: | + cargo build --release -p aien-test --manifest-path .aien-test-src/Cargo.toml + cp .aien-test-src/target/release/aien-test "$RUNNER_TEMP/bin/aien-test" 2>/dev/null || { mkdir -p "$RUNNER_TEMP/bin"; cp .aien-test-src/target/release/aien-test "$RUNNER_TEMP/bin/aien-test"; } + echo "$RUNNER_TEMP/bin" >> "$GITHUB_PATH" + rm -rf .aien-test-src + git status --porcelain --untracked-files=normal + + - name: Fetch the signed verification bundle for this commit + id: bundle + run: | + url="$RECEIPTS_RAW/spark-rsi/${{ steps.ids.outputs.sha }}/bundle.json" + echo "bundle url: $url" + if curl -fsSL "$url" -o "$RUNNER_TEMP/bundle.json"; then + echo "present=true" >> "$GITHUB_OUTPUT" + else + echo "present=false" >> "$GITHUB_OUTPUT" + echo "::notice::bundle not published yet for ${{ steps.ids.outputs.sha }} (phase 2: neutral)." + # PHASE3: exit 2 here (NOT_RUN, status pending with a retry window) instead of a neutral note. + fi + + - name: Verify the bundle with the base-ref public key + if: steps.bundle.outputs.present == 'true' && steps.anchors.outputs.enrolled == 'true' + run: | + required=$(grep -v '^#' "$RUNNER_TEMP/anchors/always" | grep -v '^$' | paste -sd, -) + set +e + aien-test verify-bundle "$RUNNER_TEMP/bundle.json" \ + --repo "github.com/$REPO_SLUG" \ + --commit "${{ steps.ids.outputs.sha }}" \ + --pubkey "$RUNNER_TEMP/anchors/verify.pub" \ + ${required:+--require "$required"} + rc=$? + set -e + echo "verify-bundle exit $rc (0 PASS, 1 FAIL, 2 NOT_RUN, 3 REJECTED)" + [ "$rc" = 0 ] || exit "$rc" + + - name: Portable smoke set (gates whose requires is only portable, named at the base ref) + if: steps.anchors.outputs.enrolled == 'true' && steps.anchors.outputs.blocked == 'false' + run: | + base="${{ steps.ids.outputs.base }}" + names=$(for f in $(git ls-tree -r --name-only "$base" -- tests/gates | grep '\.gate$'); do + git show "$base:$f" | awk ' + /^gate:/ {g=$2} + /^requires:/ {inr=1; next} + inr && /^ - / { if ($2 != "portable") other=1; next } + /^[a-z]/ {inr=0} + END { if (g != "" && !other) print g }' + done) + echo "portable smoke set: $(echo $names)" + mkdir -p "$RUNNER_TEMP/evidence" + fail=0 + for g in $names; do + echo "::group::$g" + if timeout 600 aien-test run "$g" --evidence-dir "$RUNNER_TEMP/evidence"; then echo "$g: PASS"; else echo "::error::$g: not PASS"; fail=1; fi + echo "::endgroup::" + done + exit $fail + + - name: "Not enrolled or blocked: nothing to verify in this phase" + if: steps.anchors.outputs.enrolled != 'true' || steps.anchors.outputs.blocked == 'true' + run: | + echo "AIEN Verification: neutral (enrolled=${{ steps.anchors.outputs.enrolled }}, blocked=${{ steps.anchors.outputs.blocked }}). PHASE3 turns this into a failure." diff --git a/tests/.crumb b/tests/.crumb index 5f5b75c..d3aab3d 100644 --- a/tests/.crumb +++ b/tests/.crumb @@ -14,14 +14,14 @@ } ], "children_root": "sha256:a1e62174b0d03ef0af66ee47476fe3a62ac7075f4c92ad9341ef87beefa3a8f8", - "compiled_at": "2026-10-08T23:18:36Z", + "compiled_at": "2026-10-11T16:52:31Z", "compiler": "crumb-compile/1", - "digest": "sha256:1266f530a7c210d086c27864b93d3f573431e38ca2883696c0e35a13586a8c17", + "digest": "sha256:7741e691cc295d6dc1a838afb3e73928688143066c0436f89e9cad72bc132110", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "files": 17, - "generated_at_commit": "2e5ce1d8c5821dae425274f721ba9ee3dcdf2d03", - "source_tree": "sha256:2ecafefd422ff958a9e8b82f2a62b9d7a4b076b77a8f29db47013b7f62440eb8" + "files": 23, + "generated_at_commit": "64062d8129318208664a96738a9de63dd66e1db6", + "source_tree": "sha256:89e86f0594c6cb2ae8d7813bb196eeba52e109d2da97222d69d9e1abf482f06d" }, "owner_lane": "", "seed": { diff --git a/tests/gates/crumb.gate b/tests/gates/crumb.gate new file mode 100644 index 0000000..531f7b1 --- /dev/null +++ b/tests/gates/crumb.gate @@ -0,0 +1,19 @@ +# tests/gates/crumb.gate +# Mirrors hosted: crumb verify . (ADR 0033 D11; always-run). Inputs cannot list every nested .crumb (literal paths only), so never cached. +gate: CRUMB-VERIFY +manifest_version: 2 +owner: spark-rsi +requires: + - portable +inputs: + - .crumb +run: + exec: tests/gates/run.sh + args: ["crumb-verify"] +expects: + exit: 0 + verdict: PASS +timeout: 2m +exactness: EXACT +cache_scope: portable +cache: never diff --git a/tests/gates/rsi-check.gate b/tests/gates/rsi-check.gate new file mode 100644 index 0000000..08273c7 --- /dev/null +++ b/tests/gates/rsi-check.gate @@ -0,0 +1,23 @@ +# tests/gates/rsi-check.gate +# Mirrors hosted: ci.yml 'Cargo Check': cargo check --locked --all-targets (sibling ../aien-protocols at main) +gate: RSI-CHECK +manifest_version: 2 +owner: spark-rsi +requires: + - host +inputs: + - Cargo.toml + - Cargo.lock + - src/ + - tests/ + - examples/ + - tests/gates/ +run: + exec: tests/gates/run.sh + args: ["check"] +expects: + exit: 0 + verdict: PASS +timeout: 20m +exactness: EXACT +cache_scope: machine diff --git a/tests/gates/rsi-fmt.gate b/tests/gates/rsi-fmt.gate new file mode 100644 index 0000000..8e55733 --- /dev/null +++ b/tests/gates/rsi-fmt.gate @@ -0,0 +1,23 @@ +# tests/gates/rsi-fmt.gate +# Mirrors hosted: ci.yml 'Verify Code Formatting': cargo fmt --all -- --check (host: needs the ../aien-protocols sibling) +gate: RSI-FMT +manifest_version: 2 +owner: spark-rsi +requires: + - host +inputs: + - Cargo.toml + - Cargo.lock + - src/ + - tests/ + - examples/ + - tests/gates/ +run: + exec: tests/gates/run.sh + args: ["fmt"] +expects: + exit: 0 + verdict: PASS +timeout: 5m +exactness: EXACT +cache_scope: portable diff --git a/tests/gates/rsi-test.gate b/tests/gates/rsi-test.gate new file mode 100644 index 0000000..4d83aef --- /dev/null +++ b/tests/gates/rsi-test.gate @@ -0,0 +1,26 @@ +# tests/gates/rsi-test.gate +# Mirrors hosted: ci.yml 'Pre-populate Build Jail Target Cache' + 'Run Tests': release build into /tmp/spark-rsi-target, then cargo test --locked --verbose -- --test-threads=1 (hosted job 223 s total) +# The hosted runner relaxes AppArmor user namespaces and makes bwrap setuid first (root steps); the local state is recorded as observations. +gate: RSI-TEST +manifest_version: 2 +owner: spark-rsi +requires: + - host +inputs: + - Cargo.toml + - Cargo.lock + - src/ + - tests/ + - examples/ + - tools/ + - tests/gates/ +run: + exec: tests/gates/run.sh + args: ["test"] +expects: + exit: 0 + observe: ["prepopulate_rc == 0"] + verdict: PASS +timeout: 40m +exactness: EXACT +cache_scope: machine diff --git a/tests/gates/rsi-zero-disk-secrets.gate b/tests/gates/rsi-zero-disk-secrets.gate new file mode 100644 index 0000000..ca1e058 --- /dev/null +++ b/tests/gates/rsi-zero-disk-secrets.gate @@ -0,0 +1,19 @@ +# tests/gates/rsi-zero-disk-secrets.gate +# Mirrors hosted: no hosted step; the zero-disk-secrets invariant of the sibling repos (always-run) +gate: RSI-ZERO-DISK-SECRETS +manifest_version: 2 +owner: spark-rsi +requires: + - portable +inputs: + - tests/gates/ +run: + exec: tests/gates/run.sh + args: ["zero-disk-secrets"] +expects: + exit: 0 + observe: ["env_files_found == false"] + verdict: PASS +timeout: 2m +exactness: EXACT +cache_scope: portable diff --git a/tests/gates/run.sh b/tests/gates/run.sh new file mode 100755 index 0000000..08a17e6 --- /dev/null +++ b/tests/gates/run.sh @@ -0,0 +1,70 @@ +#!/usr/bin/env bash +# tests/gates/run.sh: the one entry point for the local verification gates of spark-rsi. +# Every step runs the SAME command as the hosted job it mirrors (.github/workflows/ci.yml, +# job "Test & Invariant Verification"). Manifests under tests/gates/ name this script plus +# one step word, so no manifest needs shell expansion (ADR 0028 P6). Observations print as +# "AIEN-OBS ". +# +# Sibling checkout: Cargo.toml depends on ../aien-protocols/crates/* by path. The hosted job +# checks out aien-dev/aien-protocols (main) and copies it to ../aien-protocols; the local +# worker must provide the same sibling. +# +# Hosted runner configuration NOT mirrored here (needs root on the runner): apt-get install +# bubblewrap, sysctl kernel.apparmor_restrict_unprivileged_userns=0, chmod u+s /usr/bin/bwrap. +# The test step records the local state of those knobs as observations so a FAIL caused by +# the sandbox environment is visible as such. +set -euo pipefail +ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)" +cd "$ROOT" +step="${1:?usage: tests/gates/run.sh }" +obs() { printf 'AIEN-OBS %s %s\n' "$1" "$2"; } +need_protocols() { + if [ ! -d ../aien-protocols/crates ]; then + echo "run.sh: ../aien-protocols is missing; the hosted job checks out aien-dev/aien-protocols as a sibling" >&2 + exit 3 + fi + obs sibling_protocols_commit "\"$(git -C ../aien-protocols rev-parse HEAD 2>/dev/null || echo unknown)\"" +} + +case "$step" in + crumb-verify) + "${CRUMB:-crumb}" verify . + ;; + fmt) + need_protocols + cargo fmt --all -- --check + ;; + check) + need_protocols + cargo check --locked --all-targets + ;; + test) + need_protocols + obs bwrap_present "$(command -v bwrap >/dev/null && echo true || echo false)" + obs apparmor_restrict_userns "\"$(sysctl -n kernel.apparmor_restrict_unprivileged_userns 2>/dev/null || echo unknown)\"" + obs bwrap_setuid "$( [ -u /usr/bin/bwrap ] && echo true || echo false)" + # Hosted step "Pre-populate Build Jail Target Cache", then "Run Tests". + CARGO_TARGET_DIR=/tmp/spark-rsi-target cargo build --locked --release + obs prepopulate_rc 0 + # The judge unit tests locate the built binary at target/debug/spark-rsi relative to + # the repo root (hosted layout, no CARGO_TARGET_DIR). A relocated target dir makes + # them panic with "Test executable not found", so the test step always uses the + # in-tree target/ (gitignored) exactly like the hosted runner. + env -u CARGO_TARGET_DIR cargo test --locked --verbose -- --test-threads=1 + ;; + zero-disk-secrets) + # Not a hosted step in this repository; the same invariant the sibling repos enforce. + echo "Auditing repository for prohibited plaintext secret files..." + if find . -maxdepth 4 -name ".env*" -not -path "*/.git/*" -not -path "*/target/*" | grep -q .; then + echo "::error::Prohibited plaintext .env file found. Use an approved AIEN SecretProvider." + obs env_files_found true + exit 1 + fi + obs env_files_found false + echo "Zero plaintext .env files verified." + ;; + *) + echo "run.sh: unknown step '$step'" >&2 + exit 2 + ;; +esac