Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 115 additions & 0 deletions .github/scripts/tests/test_rust_ci_workflows.py
Original file line number Diff line number Diff line change
@@ -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
22 changes: 16 additions & 6 deletions .github/workflows/_harness-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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' }}

Expand Down Expand Up @@ -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
Expand All @@ -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 < <(
{
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand Down
40 changes: 30 additions & 10 deletions .github/workflows/_harness-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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' || '' }}

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/_publish-registry.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/_rust-binary.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}

Expand Down Expand Up @@ -334,6 +334,7 @@ jobs:
tar: unix
zip: windows
checksum: sha256
locked: true
manifest-path: ${{ inputs.manifest_path }}
token: ${{ github.token }}
dry-run: false
Loading
Loading