From aab7964ed5e106a71b7521de20c595e71c351af0 Mon Sep 17 00:00:00 2001 From: Ytallo Layon Date: Fri, 14 Aug 2026 22:09:51 -0300 Subject: [PATCH] chore(ci): improve Rust pipeline caching and diagnostics --- .../scripts/tests/test_rust_ci_workflows.py | 115 ++++++++++++++++++ .github/workflows/_harness-e2e.yml | 22 +++- .github/workflows/_harness-integration.yml | 40 ++++-- .github/workflows/_publish-registry.yml | 2 +- .github/workflows/_rust-binary.yml | 3 +- .github/workflows/ci.yml | 53 +++++--- .github/workflows/database-e2e.yml | 2 +- .github/workflows/rbac-proxy-e2e.yml | 2 +- .github/workflows/rust-security-audit.yml | 70 +++++++++++ .github/workflows/shell-e2e.yml | 2 +- .github/workflows/storage-e2e.yml | 6 +- database/tests/e2e/run-tests.sh | 6 +- docs/architecture/testing-and-ci.md | 24 +++- harness/Makefile | 13 +- rbac-proxy/tests/e2e/run-tests.sh | 4 +- rust-toolchain.toml | 4 + shell/tests/e2e/run-tests.sh | 6 +- storage/tests/e2e/run-tests.sh | 4 +- 18 files changed, 316 insertions(+), 62 deletions(-) create mode 100644 .github/scripts/tests/test_rust_ci_workflows.py create mode 100644 .github/workflows/rust-security-audit.yml create mode 100644 rust-toolchain.toml diff --git a/.github/scripts/tests/test_rust_ci_workflows.py b/.github/scripts/tests/test_rust_ci_workflows.py new file mode 100644 index 0000000000..3c6fdc9ebb --- /dev/null +++ b/.github/scripts/tests/test_rust_ci_workflows.py @@ -0,0 +1,115 @@ +from __future__ import annotations + +from pathlib import Path +import tomllib + +import yaml + + +GITHUB = Path(__file__).parents[2] +REPOSITORY = GITHUB.parent +WORKFLOWS = GITHUB / "workflows" + + +def workflow(name: str) -> dict: + value = yaml.load((WORKFLOWS / name).read_text(), Loader=yaml.BaseLoader) + assert isinstance(value, dict) + return value + + +def named_step(steps: list[dict], name: str) -> dict: + return next(step for step in steps if step.get("name") == name) + + +def test_rust_toolchain_is_pinned_to_the_last_verified_stable() -> None: + toolchain = tomllib.loads((REPOSITORY / "rust-toolchain.toml").read_text()) + assert toolchain["toolchain"]["channel"] == "1.97.1" + + bodies = "\n".join(path.read_text() for path in WORKFLOWS.glob("*.yml")) + assert "dtolnay/rust-toolchain@stable" not in bodies + assert bodies.count("dtolnay/rust-toolchain@1.97.1") == 13 + + +def test_prs_restore_rust_caches_and_main_pushes_publish_them() -> None: + ci = workflow("ci.yml") + assert ci["on"]["push"]["branches"] == ["main"] + + rust_cache = next( + step for step in ci["jobs"]["rust"]["steps"] + if step.get("uses") == "Swatinem/rust-cache@v2" + ) + crate_cache = next( + step for step in ci["jobs"]["crates"]["steps"] + if step.get("uses") == "Swatinem/rust-cache@v2" + ) + expected = "${{ github.event_name == 'push' }}" + assert rust_cache["with"]["save-if"] == expected + assert crate_cache["with"]["save-if"] == expected + assert "github.event_name == 'pull_request'" in ci["jobs"]["interface-smoke"]["if"] + assert ci["jobs"]["harness-integration"]["with"]["save-cache"] == expected + + +def test_harness_integration_caches_the_final_engine_and_skips_rebuilds() -> None: + integration = workflow("_harness-integration.yml") + steps = integration["jobs"]["integration"]["steps"] + restore = named_step(steps, "Restore pinned engine binary") + build = named_step(steps, "Build pinned engine") + save = named_step(steps, "Save pinned engine binary") + stack_cache = named_step(steps, "Restore integration Rust cache") + + expected_path = "target/integration-engine-src/${{ steps.lock.outputs.binary }}" + assert restore["with"]["path"] == expected_path + assert "integration-engine-bin-rust-1.97.1" in restore["with"]["key"] + assert "hashFiles('harness/tests/integration/engine.lock')" in restore["with"]["key"] + assert build["if"] == "steps.engine-cache.outputs.cache-hit != 'true'" + assert "--locked --release --timings" in build["run"] + assert save["with"]["path"] == expected_path + assert "database -> target" in stack_cache["with"]["workspaces"] + + +def test_slow_rust_builds_upload_cargo_timing_reports() -> None: + integration = workflow("_harness-integration.yml") + integration_steps = integration["jobs"]["integration"]["steps"] + timing_upload = named_step(integration_steps, "Upload Rust build timings") + assert timing_upload["if"] == "always()" + assert "cargo-timings/*.html" in timing_upload["with"]["path"] + + e2e = workflow("_harness-e2e.yml") + e2e_steps = e2e["jobs"]["build"]["steps"] + e2e_cache = next( + step for step in e2e_steps if step.get("uses") == "Swatinem/rust-cache@v2" + ) + timing_upload = named_step(e2e_steps, "Upload Rust build timings") + assert timing_upload["if"] == "always()" + assert "--timings" in named_step(e2e_steps, "Build source E2E stack")["run"] + assert "fp -> target" in e2e_cache["with"]["workspaces"] + + +def test_ci_cargo_commands_use_committed_lockfiles() -> None: + ci_body = (WORKFLOWS / "ci.yml").read_text() + integration_body = (WORKFLOWS / "_harness-integration.yml").read_text() + release = workflow("_rust-binary.yml") + release_steps = release["jobs"]["build"]["steps"] + upload = named_step(release_steps, "Build and upload binary") + + assert "cargo clippy --locked --all-targets --all-features" in ci_body + assert "cargo test --locked --all-features" in ci_body + assert "cargo build --locked" in ci_body + assert "cargo test --locked --manifest-path harness/Cargo.toml" in integration_body + assert upload["with"]["locked"] == "true" + + +def test_rust_security_audit_is_narrow_on_prs_and_complete_on_schedule() -> None: + audit = workflow("rust-security-audit.yml") + assert "workflow_dispatch" not in audit["on"] + assert audit["on"]["pull_request"]["paths"] == ["**/Cargo.lock"] + assert audit["on"]["schedule"] + + steps = audit["jobs"]["audit"]["steps"] + install = named_step(steps, "Install cargo-audit") + run = named_step(steps, "Audit Rust lockfiles")["run"] + assert install["uses"] == "taiki-e/install-action@v2.79.11" + assert install["with"]["tool"] == "cargo-audit@0.22.2" + assert "git diff --name-only -z" in run + assert "find . -name Cargo.lock" in run + assert "cargo audit --no-fetch --file" in run diff --git a/.github/workflows/_harness-e2e.yml b/.github/workflows/_harness-e2e.yml index 568187c9cc..46670939c1 100644 --- a/.github/workflows/_harness-e2e.yml +++ b/.github/workflows/_harness-e2e.yml @@ -208,7 +208,7 @@ jobs: ;; esac - - uses: dtolnay/rust-toolchain@stable + - uses: dtolnay/rust-toolchain@1.97.1 with: components: ${{ inputs.coverage && 'clippy,llvm-tools' || 'clippy' }} @@ -275,6 +275,7 @@ jobs: iii-directory -> target cron -> target web -> target + fp -> target - name: Test E2E crate run: cargo test --locked --manifest-path harness/Cargo.toml -p harness-e2e @@ -295,7 +296,7 @@ jobs: set -euo pipefail mkdir -p target/coverage/build-profraw for worker in database state queue session-manager llm-router context-manager iii-directory cron web fp; do - cargo build --locked --release --manifest-path "$worker/Cargo.toml" + cargo build --locked --release --timings --manifest-path "$worker/Cargo.toml" done mapfile -t providers < <( { @@ -306,16 +307,25 @@ jobs: for provider in "${providers[@]}"; do worker="provider-$provider" test -f "$worker/Cargo.toml" - cargo build --locked --release --manifest-path "$worker/Cargo.toml" + cargo build --locked --release --timings --manifest-path "$worker/Cargo.toml" done - cargo build --locked --release \ + cargo build --locked --release --timings \ --manifest-path harness/Cargo.toml \ -p harness \ -p harness-e2e - name: Build registry E2E runner if: inputs.stack_mode == 'registry' - run: cargo build --locked --release --manifest-path harness/Cargo.toml -p harness-e2e + run: cargo build --locked --release --timings --manifest-path harness/Cargo.toml -p harness-e2e + + - name: Upload Rust build timings + if: always() + uses: actions/upload-artifact@v6 + with: + name: harness-e2e-rust-timings + path: '*/target/cargo-timings/*.html' + retention-days: 14 + if-no-files-found: ignore - name: Checkout workflow scenario validator uses: actions/checkout@v5 @@ -723,7 +733,7 @@ jobs: with: ref: ${{ inputs.source_ref }} - - uses: dtolnay/rust-toolchain@stable + - uses: dtolnay/rust-toolchain@1.97.1 with: components: llvm-tools diff --git a/.github/workflows/_harness-integration.yml b/.github/workflows/_harness-integration.yml index e12a0f7bfc..2aa174761b 100644 --- a/.github/workflows/_harness-integration.yml +++ b/.github/workflows/_harness-integration.yml @@ -83,7 +83,7 @@ jobs: ref: ${{ steps.lock.outputs.revision }} path: target/integration-engine-src - - uses: dtolnay/rust-toolchain@stable + - uses: dtolnay/rust-toolchain@1.97.1 with: components: ${{ inputs.coverage && 'llvm-tools' || '' }} @@ -98,22 +98,27 @@ jobs: package-manager-cache: false node-version: 22 - - name: Restore engine build + # The engine source is immutable at the locked revision. Cache the final + # executable, not its multi-gigabyte target directory, so a hit can skip + # Cargo entirely instead of merely making the unconditional rebuild less + # cold. + - name: Restore pinned engine binary id: engine-cache uses: actions/cache/restore@v4 with: - path: target/integration-engine-src/target - key: integration-engine-${{ runner.os }}-${{ runner.arch }}-${{ steps.lock.outputs.revision }}-${{ hashFiles('target/integration-engine-src/Cargo.lock') }} + path: target/integration-engine-src/${{ steps.lock.outputs.binary }} + key: integration-engine-bin-rust-1.97.1-${{ runner.os }}-${{ runner.arch }}-${{ steps.lock.outputs.revision }}-${{ hashFiles('harness/tests/integration/engine.lock') }}-${{ hashFiles('target/integration-engine-src/Cargo.lock') }} - name: Build pinned engine + if: steps.engine-cache.outputs.cache-hit != 'true' working-directory: target/integration-engine-src - run: cargo build --locked --release -p ${{ steps.lock.outputs.package }} + run: cargo build --locked --release --timings -p ${{ steps.lock.outputs.package }} - - name: Save engine build + - name: Save pinned engine binary if: inputs.save-cache && steps.engine-cache.outputs.cache-hit != 'true' uses: actions/cache/save@v4 with: - path: target/integration-engine-src/target + path: target/integration-engine-src/${{ steps.lock.outputs.binary }} key: ${{ steps.engine-cache.outputs.cache-primary-key }} - name: Record engine digest @@ -141,9 +146,10 @@ jobs: iii-directory -> target state -> target console -> target + database -> target - name: Integration crate unit tests - run: cargo test --manifest-path harness/Cargo.toml -p harness-integration + run: cargo test --locked --manifest-path harness/Cargo.toml -p harness-integration - name: Validate integration scenarios run: make -C harness integration-validate @@ -156,7 +162,10 @@ jobs: env: RUSTFLAGS: ${{ inputs.coverage && '-Cinstrument-coverage -Cllvm-args=-runtime-counter-relocation' || '' }} LLVM_PROFILE_FILE: ${{ inputs.coverage && format('{0}/target/coverage/profraw/%m_%p%c.profraw', github.workspace) || '' }} - run: make -C harness integration-test III_BIN="${{ steps.engine.outputs.bin }}" + run: >- + make -C harness integration-test + III_BIN="${{ steps.engine.outputs.bin }}" + CARGO_BUILD_FLAGS="--locked --timings" - name: Install Console web dependencies working-directory: console/web @@ -170,7 +179,7 @@ jobs: env: RUSTFLAGS: ${{ inputs.coverage && '-Cinstrument-coverage -Cllvm-args=-runtime-counter-relocation' || '' }} LLVM_PROFILE_FILE: ${{ inputs.coverage && format('{0}/target/coverage/profraw/%m_%p%c.profraw', github.workspace) || '' }} - run: cargo build --release --manifest-path console/Cargo.toml + run: cargo build --locked --release --timings --manifest-path console/Cargo.toml - name: Install Playwright Chromium working-directory: console/web @@ -261,6 +270,17 @@ jobs: echo "| integration Rust | see rust-cache log | $SAVE_CACHE |" } >> "$GITHUB_STEP_SUMMARY" + - name: Upload Rust build timings + if: always() + uses: actions/upload-artifact@v6 + with: + name: harness-integration-rust-timings + path: | + */target/cargo-timings/*.html + target/integration-engine-src/target/cargo-timings/*.html + retention-days: 14 + if-no-files-found: ignore + - name: Upload compact results if: always() uses: actions/upload-artifact@v6 diff --git a/.github/workflows/_publish-registry.yml b/.github/workflows/_publish-registry.yml index b7bc35637a..2e1a24b026 100644 --- a/.github/workflows/_publish-registry.yml +++ b/.github/workflows/_publish-registry.yml @@ -229,7 +229,7 @@ jobs: worker_log="worker-$WORKER.log" pushd "$WORKER" >/dev/null - cargo_args=(run) + cargo_args=(run --locked) if [[ -n "${BIN:-}" ]]; then cargo_args+=(--bin "$BIN") fi diff --git a/.github/workflows/_rust-binary.yml b/.github/workflows/_rust-binary.yml index 4d1d4f127a..7a76701b88 100644 --- a/.github/workflows/_rust-binary.yml +++ b/.github/workflows/_rust-binary.yml @@ -247,7 +247,7 @@ jobs: esac - name: Install Rust toolchain - uses: dtolnay/rust-toolchain@stable + uses: dtolnay/rust-toolchain@1.97.1 with: targets: ${{ matrix.target }} @@ -334,6 +334,7 @@ jobs: tar: unix zip: windows checksum: sha256 + locked: true manifest-path: ${{ inputs.manifest_path }} token: ${{ github.token }} dry-run: false diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 800d2d43ca..af9ce3ae7e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,6 +2,8 @@ name: CI on: pull_request: + push: + branches: [main] concurrency: group: ci-${{ github.ref }} @@ -61,10 +63,20 @@ jobs: - name: Compute base ref id: base env: - BASE_REF: ${{ github.event.pull_request.base.ref || github.event.repository.default_branch || 'main' }} + EVENT_NAME: ${{ github.event_name }} + PR_BASE_REF: ${{ github.event.pull_request.base.ref || '' }} + PUSH_BEFORE: ${{ github.event.before || '' }} run: | - git fetch --no-tags --depth=1 origin "$BASE_REF" || true - echo "ref=origin/$BASE_REF" >> "$GITHUB_OUTPUT" + set -euo pipefail + if [[ "$EVENT_NAME" == "pull_request" ]]; then + base_ref="${PR_BASE_REF:-main}" + git fetch --no-tags --depth=1 origin "$base_ref" + echo "ref=origin/$base_ref" >> "$GITHUB_OUTPUT" + elif [[ "$PUSH_BEFORE" =~ ^[0-9a-f]{40}$ && ! "$PUSH_BEFORE" =~ ^0+$ ]]; then + echo "ref=$PUSH_BEFORE" >> "$GITHUB_OUTPUT" + else + echo "ref=HEAD^" >> "$GITHUB_OUTPUT" + fi - name: Bucket changed workers id: bucket @@ -81,7 +93,7 @@ jobs: pr-checks: name: "${{ matrix.worker }}: PR checks" needs: discover - if: needs.discover.outputs.changed_workers != '[]' + if: github.event_name == 'pull_request' && needs.discover.outputs.changed_workers != '[]' runs-on: ubuntu-latest strategy: fail-fast: false @@ -131,14 +143,16 @@ jobs: - name: Rewrite SSH to HTTPS for public deps run: git config --global url."https://github.com/".insteadOf "ssh://git@github.com/" - - uses: dtolnay/rust-toolchain@stable + - uses: dtolnay/rust-toolchain@1.97.1 with: components: rustfmt, clippy - uses: Swatinem/rust-cache@v2 with: shared-key: worker-${{ matrix.worker }} - save-if: false + # PRs restore the trusted default-branch cache but never publish a + # branch-scoped copy. The push after merge advances the canonical key. + save-if: ${{ github.event_name == 'push' }} workspaces: ${{ matrix.worker }} -> target # Workers and their direct local Rust dependencies can embed a frontend @@ -206,10 +220,10 @@ jobs: run: cargo fmt --all -- --check - name: Run clippy - run: cargo clippy --all-targets --all-features -- -D warnings + run: cargo clippy --locked --all-targets --all-features -- -D warnings - name: Run tests - run: cargo test --all-features + run: cargo test --locked --all-features # ────────────────────────────────────────────────────────────── # Shared Rust crates (crates/*): lint + test. Workers link these by @@ -235,22 +249,23 @@ jobs: - name: Rewrite SSH to HTTPS for public deps run: git config --global url."https://github.com/".insteadOf "ssh://git@github.com/" - - uses: dtolnay/rust-toolchain@stable + - uses: dtolnay/rust-toolchain@1.97.1 with: components: rustfmt, clippy - uses: Swatinem/rust-cache@v2 with: + save-if: ${{ github.event_name == 'push' }} workspaces: crates/${{ matrix.crate }} -> target - name: Check formatting run: cargo fmt --all -- --check - name: Run clippy - run: cargo clippy --all-targets --all-features -- -D warnings + run: cargo clippy --locked --all-targets --all-features -- -D warnings - name: Run tests - run: cargo test --all-features + run: cargo test --locked --all-features # ────────────────────────────────────────────────────────────── # Provider contracts: real engine + real router + selected provider, @@ -274,7 +289,7 @@ jobs: - name: Rewrite SSH to HTTPS for public deps run: git config --global url."https://github.com/".insteadOf "ssh://git@github.com/" - - uses: dtolnay/rust-toolchain@stable + - uses: dtolnay/rust-toolchain@1.97.1 - uses: Swatinem/rust-cache@v2 with: @@ -368,7 +383,7 @@ jobs: interface-smoke: name: "${{ matrix.worker }}: interface boot smoke" needs: discover - if: needs.discover.outputs.rust != '[]' + if: github.event_name == 'pull_request' && needs.discover.outputs.rust != '[]' runs-on: ubuntu-latest timeout-minutes: 30 strategy: @@ -405,7 +420,7 @@ jobs: if: steps.optout.outputs.skip != 'true' run: git config --global url."https://github.com/".insteadOf "ssh://git@github.com/" - - uses: dtolnay/rust-toolchain@stable + - uses: dtolnay/rust-toolchain@1.97.1 if: steps.optout.outputs.skip != 'true' - uses: Swatinem/rust-cache@v2 @@ -449,7 +464,7 @@ jobs: - name: Build worker binary if: steps.optout.outputs.skip != 'true' working-directory: ${{ matrix.worker }} - run: cargo build + run: cargo build --locked - name: Install iii CLI + engine if: steps.optout.outputs.skip != 'true' @@ -584,9 +599,9 @@ jobs: fi # ────────────────────────────────────────────────────────────── - # Harness integration tests (non-required). Pull requests only run - # the complete live stack when an integration input changed. The - # default branch and daily cache warmer run it unconditionally. + # Harness integration tests (non-required). Pull requests and the + # trusted push after merge run the complete live stack only when an + # integration input changed; only the trusted push advances caches. # ────────────────────────────────────────────────────────────── harness-integration: needs: discover @@ -596,7 +611,7 @@ jobs: contents: read uses: ./.github/workflows/_harness-integration.yml with: - save-cache: false + save-cache: ${{ github.event_name == 'push' }} # ────────────────────────────────────────────────────────────── # Node per-worker lint (biome) + test diff --git a/.github/workflows/database-e2e.yml b/.github/workflows/database-e2e.yml index f6478eabf5..8f4d365758 100644 --- a/.github/workflows/database-e2e.yml +++ b/.github/workflows/database-e2e.yml @@ -49,7 +49,7 @@ jobs: run: git config --global url."https://github.com/".insteadOf "ssh://git@github.com/" - name: Install Rust toolchain - uses: dtolnay/rust-toolchain@stable + uses: dtolnay/rust-toolchain@1.97.1 - name: Cache cargo registry & build uses: Swatinem/rust-cache@v2 diff --git a/.github/workflows/rbac-proxy-e2e.yml b/.github/workflows/rbac-proxy-e2e.yml index 65ccb53c71..b8a6af601f 100644 --- a/.github/workflows/rbac-proxy-e2e.yml +++ b/.github/workflows/rbac-proxy-e2e.yml @@ -48,7 +48,7 @@ jobs: run: git config --global url."https://github.com/".insteadOf "ssh://git@github.com/" - name: Install Rust toolchain - uses: dtolnay/rust-toolchain@stable + uses: dtolnay/rust-toolchain@1.97.1 - name: Cache cargo registry & build uses: Swatinem/rust-cache@v2 diff --git a/.github/workflows/rust-security-audit.yml b/.github/workflows/rust-security-audit.yml new file mode 100644 index 0000000000..ed5cad1307 --- /dev/null +++ b/.github/workflows/rust-security-audit.yml @@ -0,0 +1,70 @@ +name: Rust dependency audit + +on: + pull_request: + paths: + - '**/Cargo.lock' + schedule: + - cron: '23 9 * * 1' + +permissions: + contents: read + +concurrency: + group: rust-dependency-audit-${{ github.ref }} + cancel-in-progress: true + +jobs: + audit: + runs-on: ubuntu-latest + timeout-minutes: 20 + steps: + - uses: actions/checkout@v5 + with: + fetch-depth: 0 + + - name: Install cargo-audit + uses: taiki-e/install-action@v2.79.11 + with: + tool: cargo-audit@0.22.2 + fallback: none + + - name: Audit Rust lockfiles + env: + EVENT_NAME: ${{ github.event_name }} + BASE_SHA: ${{ github.event.pull_request.base.sha || '' }} + HEAD_SHA: ${{ github.event.pull_request.head.sha || github.sha }} + run: | + set -euo pipefail + + lockfiles=() + if [[ "$EVENT_NAME" == "pull_request" ]]; then + while IFS= read -r -d '' lockfile; do + [[ -f "$lockfile" ]] && lockfiles+=("$lockfile") + done < <(git diff --name-only -z "$BASE_SHA...$HEAD_SHA" -- '**/Cargo.lock') + else + while IFS= read -r -d '' lockfile; do + lockfiles+=("${lockfile#./}") + done < <(find . -name Cargo.lock -not -path '*/target/*' -print0 | sort -z) + fi + + if (( ${#lockfiles[@]} == 0 )); then + echo "No Rust lockfiles selected." + exit 0 + fi + + status=0 + first=1 + for lockfile in "${lockfiles[@]}"; do + echo "::group::cargo audit --file $lockfile" + if (( first )); then + cargo audit --file "$lockfile" || status=1 + first=0 + else + cargo audit --no-fetch --file "$lockfile" || status=1 + fi + echo "::endgroup::" + done + + echo "Audited ${#lockfiles[@]} lockfile(s)." >> "$GITHUB_STEP_SUMMARY" + exit "$status" diff --git a/.github/workflows/shell-e2e.yml b/.github/workflows/shell-e2e.yml index ea694a00a1..9921359c17 100644 --- a/.github/workflows/shell-e2e.yml +++ b/.github/workflows/shell-e2e.yml @@ -48,7 +48,7 @@ jobs: run: git config --global url."https://github.com/".insteadOf "ssh://git@github.com/" - name: Install Rust toolchain - uses: dtolnay/rust-toolchain@stable + uses: dtolnay/rust-toolchain@1.97.1 - name: Cache cargo registry & build uses: Swatinem/rust-cache@v2 diff --git a/.github/workflows/storage-e2e.yml b/.github/workflows/storage-e2e.yml index 0ea43fbbd1..1b0fe84cd3 100644 --- a/.github/workflows/storage-e2e.yml +++ b/.github/workflows/storage-e2e.yml @@ -47,14 +47,14 @@ jobs: - name: Rewrite SSH to HTTPS for public deps run: git config --global url."https://github.com/".insteadOf "ssh://git@github.com/" - - uses: dtolnay/rust-toolchain@stable + - uses: dtolnay/rust-toolchain@1.97.1 - uses: Swatinem/rust-cache@v2 with: workspaces: storage - name: Build worker - run: cargo build --release --bin storage + run: cargo build --locked --release --bin storage working-directory: storage - name: Install iii engine @@ -92,7 +92,7 @@ jobs: - name: Rewrite SSH to HTTPS for public deps run: git config --global url."https://github.com/".insteadOf "ssh://git@github.com/" - - uses: dtolnay/rust-toolchain@stable + - uses: dtolnay/rust-toolchain@1.97.1 - uses: Swatinem/rust-cache@v2 with: diff --git a/database/tests/e2e/run-tests.sh b/database/tests/e2e/run-tests.sh index 07e100fc07..bb16adf362 100755 --- a/database/tests/e2e/run-tests.sh +++ b/database/tests/e2e/run-tests.sh @@ -109,8 +109,8 @@ fi # 2. Build the worker (unless --no-build) if [[ "$NO_BUILD" -eq 0 ]]; then - echo "[run-tests] cargo build --release (database worker)" - (cd "$WORKER_SRC" && cargo build --release --bin database) + echo "[run-tests] cargo build --locked --release (database worker)" + (cd "$WORKER_SRC" && cargo build --locked --release --bin database) fi if [[ ! -x "$WORKER_BIN_TARGET" ]]; then echo "[run-tests] FATAL: worker binary missing at $WORKER_BIN_TARGET — run without --no-build" >&2 @@ -190,7 +190,7 @@ if [[ "$WITH_CARGO_TEST" -eq 1 ]]; then cd "$WORKER_SRC" && \ TEST_POSTGRES_URL="postgres://iii:iii@127.0.0.1:55432/iii_test" \ TEST_MYSQL_URL="mysql://iii:iii@127.0.0.1:53306/iii_test" \ - cargo test --all-features + cargo test --locked --all-features ) fi diff --git a/docs/architecture/testing-and-ci.md b/docs/architecture/testing-and-ci.md index 9f68dd2747..18a3bd9434 100644 --- a/docs/architecture/testing-and-ci.md +++ b/docs/architecture/testing-and-ci.md @@ -8,7 +8,8 @@ How pull requests are gated for workers in this monorepo. ## Discovery -`discover` job runs `discover_changed_workers.py` comparing the PR to its base. +`discover` runs `discover_changed_workers.py` comparing a PR to its base or a +trusted `main` push to the previous revision. A directory is a **worker** when it contains `iii.worker.yaml` at its root. `docs/` is not discovered (no manifest). @@ -43,13 +44,26 @@ version/tests/README gates downgrade to GitHub notices. | Language | Lint | Test | |---|---|---| -| Rust | `cargo fmt --check`, `clippy -D warnings` | `cargo test --all-features` | +| Rust | `cargo fmt --check`, `cargo clippy --locked -D warnings` | `cargo test --locked --all-features` | | Node | `biome ci` | `npm test` (if `tests/` exists) | | Python | `ruff check`, `ruff format --check` | `pytest` (if `tests/` exists) | Workers with `web/package.json` (e.g. `console`) pre-build the SPA before cargo in both `rust` and `interface-smoke` jobs. +### Rust reproducibility and caches + +- [`rust-toolchain.toml`](../../rust-toolchain.toml) pins the compiler used by + local Cargo commands and every Rust workflow. Update it deliberately after + the replacement version passes the workflow contract and Rust test suite. +- CI compilation and tests use committed lockfiles via `--locked`. +- Pull requests restore Rust caches but do not save branch-scoped copies. The + trusted push after merge advances caches for changed Rust workspaces. +- `rust-version` is a package-level MSRV promise, not an alias for the CI + toolchain. Add or change it only when that package is actually tested on the + claimed minimum compiler; the repository does not infer an MSRV from the + pinned CI version. + ## Interface boot smoke (Rust) **Why it exists:** release publish boots the worker on a clean runner with no @@ -58,7 +72,7 @@ when SQLite parent dirs or sidecars are missing (#104 / `database/v0.2.6`). **Flow:** -1. `cargo build` (default features — same as release binary) +1. `cargo build --locked` (default features — same as release binary) 2. Install `iii` CLI + start engine 3. Start worker from `./target/debug/` (with `--config config.collect.yaml` when shipped) 4. `collect_worker_interface.py` — 120 s wait, assert non-empty interface @@ -74,13 +88,15 @@ Some workers have harness-level e2e beyond unit tests: | `shell-e2e.yml` | `shell` | | `database-e2e.yml` | `database` | | `storage-e2e.yml` | `storage` | +| `rbac-proxy-e2e.yml` | `rbac-proxy` | Add a dedicated workflow when integration with the full harness stack is release-blocking and too slow for the per-PR matrix. ## Script tests -`.github/scripts/tests/` — pytest for release/discovery helpers. Runs on every PR. +`.github/scripts/tests/` — pytest for release/discovery/workflow helpers. Runs +on every PR and trusted `main` push. ## Related diff --git a/harness/Makefile b/harness/Makefile index b946788886..65cc1d238e 100644 --- a/harness/Makefile +++ b/harness/Makefile @@ -375,6 +375,9 @@ where: INTEGRATION_WORKERS := queue iii-directory session-manager context-manager state database INTEGRATION_PROFILE ?= release INTEGRATION_FLAG := $(if $(filter release,$(INTEGRATION_PROFILE)),--release,) +# CI adds --timings here; local runs still use the committed lockfiles by +# default without producing diagnostic artifacts on every build. +CARGO_BUILD_FLAGS ?= --locked INTEGRATION_SCENARIO ?= all INTEGRATION_ARTIFACTS ?= $(REPO_ROOT)/target/integration INTEGRATION_PLAYGROUND_SCENARIO ?= console-streamed-text @@ -388,10 +391,10 @@ integration-test: fi @for w in $(INTEGRATION_WORKERS) harness; do \ echo "building $$w ($(INTEGRATION_PROFILE))"; \ - cargo build $(INTEGRATION_FLAG) --manifest-path "$(REPO_ROOT)/$$w/Cargo.toml" || exit 1; \ + cargo build $(CARGO_BUILD_FLAGS) $(INTEGRATION_FLAG) --manifest-path "$(REPO_ROOT)/$$w/Cargo.toml" || exit 1; \ done @echo "building harness-integration ($(INTEGRATION_PROFILE))" - @cargo build $(INTEGRATION_FLAG) --manifest-path "$(MAKEFILE_DIR)Cargo.toml" -p harness-integration + @cargo build $(CARGO_BUILD_FLAGS) $(INTEGRATION_FLAG) --manifest-path "$(MAKEFILE_DIR)Cargo.toml" -p harness-integration @"$(MAKEFILE_DIR)target/$(INTEGRATION_PROFILE)/harness-integration" \ run \ --engine-bin "$(III_BIN)" \ @@ -434,10 +437,10 @@ integration-playground: fi @for w in $(INTEGRATION_WORKERS) harness console; do \ echo "building $$w ($(INTEGRATION_PROFILE))"; \ - cargo build $(INTEGRATION_FLAG) --manifest-path "$(REPO_ROOT)/$$w/Cargo.toml" || exit 1; \ + cargo build $(CARGO_BUILD_FLAGS) $(INTEGRATION_FLAG) --manifest-path "$(REPO_ROOT)/$$w/Cargo.toml" || exit 1; \ done @echo "building harness-integration ($(INTEGRATION_PROFILE))" - @cargo build $(INTEGRATION_FLAG) --manifest-path "$(MAKEFILE_DIR)Cargo.toml" -p harness-integration + @cargo build $(CARGO_BUILD_FLAGS) $(INTEGRATION_FLAG) --manifest-path "$(MAKEFILE_DIR)Cargo.toml" -p harness-integration @"$(MAKEFILE_DIR)target/$(INTEGRATION_PROFILE)/harness-integration" \ playground \ --engine-bin "$(III_BIN)" \ @@ -453,7 +456,7 @@ integration-playground: --artifacts-dir "$(INTEGRATION_PLAYGROUND_ARTIFACTS)" integration-validate: - @cargo run --quiet --manifest-path "$(MAKEFILE_DIR)Cargo.toml" -p harness-integration -- \ + @cargo run --quiet --locked --manifest-path "$(MAKEFILE_DIR)Cargo.toml" -p harness-integration -- \ validate --scenario all $(STACK): diff --git a/rbac-proxy/tests/e2e/run-tests.sh b/rbac-proxy/tests/e2e/run-tests.sh index dfa2804e50..78c501934e 100755 --- a/rbac-proxy/tests/e2e/run-tests.sh +++ b/rbac-proxy/tests/e2e/run-tests.sh @@ -93,8 +93,8 @@ cd "$ROOT_DIR" # 1. Build the worker (unless --no-build). if [[ "$NO_BUILD" -eq 0 ]]; then - echo "[run-tests] cargo build --release (rbac-proxy worker)" - (cd "$WORKER_SRC" && cargo build --release --bin rbac-proxy) + echo "[run-tests] cargo build --locked --release (rbac-proxy worker)" + (cd "$WORKER_SRC" && cargo build --locked --release --bin rbac-proxy) fi if [[ ! -x "$WORKER_BIN_TARGET" ]]; then echo "[run-tests] FATAL: worker binary missing at $WORKER_BIN_TARGET — run without --no-build" >&2 diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 0000000000..3caff2a7c8 --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,4 @@ +[toolchain] +channel = "1.97.1" +profile = "minimal" +components = ["clippy", "rustfmt"] diff --git a/shell/tests/e2e/run-tests.sh b/shell/tests/e2e/run-tests.sh index 766e546347..3600c5f1ae 100755 --- a/shell/tests/e2e/run-tests.sh +++ b/shell/tests/e2e/run-tests.sh @@ -120,8 +120,8 @@ mkdir -p "$ROOT_DIR/reports" "$RUN_ROOT/data" "$(dirname "$WORKER_BIN_LINK")" # 1. Build the worker (unless --no-build) if [[ "$NO_BUILD" -eq 0 ]]; then - echo "[run-tests] cargo build --release (shell worker)" - (cd "$WORKER_SRC" && cargo build --release --bin shell) + echo "[run-tests] cargo build --locked --release (shell worker)" + (cd "$WORKER_SRC" && cargo build --locked --release --bin shell) fi if [[ ! -x "$WORKER_BIN_TARGET" ]]; then echo "[run-tests] FATAL: worker binary missing at $WORKER_BIN_TARGET — run without --no-build" >&2 @@ -197,7 +197,7 @@ echo "[run-tests] engine listening" if [[ "$SUITE" == jailed ]]; then (cd "$WORKER_SRC" && \ env III_ENGINE_WS_URL=ws://127.0.0.1:49134 \ - cargo test --test bdd -- --tags @live) + cargo test --locked --test bdd -- --tags @live) fi # 8. Launch the harness as a host node process diff --git a/storage/tests/e2e/run-tests.sh b/storage/tests/e2e/run-tests.sh index afa8424dcc..798bf78eb9 100755 --- a/storage/tests/e2e/run-tests.sh +++ b/storage/tests/e2e/run-tests.sh @@ -194,8 +194,8 @@ fi # 2. Build the worker (unless --no-build) if [[ "$NO_BUILD" -eq 0 ]]; then - echo "[run-tests] cargo build --release (storage worker)" - (cd "$WORKER_SRC" && cargo build --release --bin storage) + echo "[run-tests] cargo build --locked --release (storage worker)" + (cd "$WORKER_SRC" && cargo build --locked --release --bin storage) fi if [[ ! -x "$WORKER_BIN_TARGET" ]]; then echo "[run-tests] FATAL: worker binary missing at $WORKER_BIN_TARGET — run without --no-build" >&2