diff --git a/.github/AGENTS.md b/.github/AGENTS.md index c1e4c4ba46..93bd671609 100644 --- a/.github/AGENTS.md +++ b/.github/AGENTS.md @@ -37,12 +37,20 @@ wheel cache consumed by downstream jobs: enable-cache: false # required for jobs that skip uv sync ``` -Jobs that run `uv sync --locked` may normally omit `enable-cache` (defaults to `auto`, -enabled on GitHub-hosted runners). In `.github/workflows/tests.yml`, however, the `test` -and `cache_prime` jobs deliberately set `enable-cache: false` despite syncing because -explicit `actions/cache` owns their uv-cache I/O. That workflow's matrix jobs restore only; -its schedule-or-`main`-push default-branch primer is the sole saver for the uv dependency -cache. This single-saver rule does not apply to unrelated workflows or non-uv caches. +Jobs that run `uv sync --locked` may normally omit `enable-cache`. In +`.github/workflows/tests.yml`, explicit `actions/cache` owns their uv-cache I/O, +so setup-uv caching stays disabled. `api_simulator_cache` is the sole saver; Linux +matrix jobs restore only and verify imports of the native api-simulator submodules. +The build identity uses the runner image family and toolchain pins, never `uv.lock`, +so package-only version bumps reuse the build. Keep `preflight` independent and +the required `Test (*)` contexts reporting producer failures instead of leaving +the merge queue waiting for missing checks. + +If an entry is unusable, delete it with `gh cache delete ` and rerun. Cached +api-simulator source is readable by pull requests into this public repository; +the owner of both repositories accepted that visibility. + +This single-saver rule applies only to this workflow's uv cache. ## Branch-targeted test policy @@ -61,9 +69,10 @@ shallow without providing a coordinated fallback for merge-base computation. ## Rust toolchain scope -`dtolnay/rust-toolchain` is only needed in jobs that compile native Python extensions -(i.e., jobs that run `uv sync`). Do not add it to preflight, lint, or other utility jobs -that only run `uv lock --check` or similar commands. +`dtolnay/rust-toolchain` is only needed in jobs that compile native Python extensions. In +`.github/workflows/tests.yml` only `api_simulator_cache` compiles, and only on a cache miss; +the test matrix restores that build and must not install Rust. Do not add it to preflight, +lint, or other utility jobs that only run `uv lock --check` or similar commands. ## Lockfile verification diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index c4dfd1af0c..966f3abfe0 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -6,8 +6,6 @@ on: pull_request: branches: [main, develop, stable] merge_group: - schedule: - - cron: "17 3 * * *" permissions: contents: read @@ -15,7 +13,6 @@ permissions: jobs: preflight: name: Preflight checks - if: github.event_name != 'schedule' runs-on: ubuntu-latest outputs: os-matrix: ${{ steps.ci-policy.outputs.os-matrix }} @@ -42,20 +39,30 @@ jobs: echo "uv: $(uv --version)" uv run python --version - cache_metadata: - name: Resolve uv cache identity + api_simulator_cache: + name: Provide api-simulator build runs-on: ubuntu-latest + cache-mode: write outputs: - python_cache_tag: ${{ steps.cache-identity.outputs.python_cache_tag }} - api_simulator_rev: ${{ steps.cache-identity.outputs.api_simulator_rev }} + cache-key: ${{ steps.cache-identity.outputs.key }} steps: - uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4 + - name: Install uv + id: setup-uv + uses: astral-sh/setup-uv@08807647e7069bb48b6ef5acd8ec9567f424441b # v8.1.0 + with: + version: "0.9.21" + enable-cache: false + - name: Resolve cache identity id: cache-identity shell: bash + env: + UV_VERSION: ${{ steps.setup-uv.outputs.uv-version }} run: | python3 <<'PY' >> "$GITHUB_OUTPUT" + import os import re import tomllib from pathlib import Path @@ -70,24 +77,25 @@ jobs: if not isinstance(revision, str) or re.fullmatch(r"[0-9a-fA-F]{40}", revision) is None: raise SystemExit(f"invalid api-simulator revision: {revision!r}") - print(f"python_cache_tag={python_selector.replace('.', '')}") - print(f"api_simulator_rev={revision}") + rust_pin = re.search( + r"^ARG RUST_VERSION=(\S+)$", + Path("scripts/docker/Dockerfile").read_text(encoding="utf-8"), + re.MULTILINE, + ) + if rust_pin is None: + raise SystemExit("missing Dockerfile RUST_VERSION pin") + rust_version = rust_pin.group(1) + + uv_version = os.environ["UV_VERSION"] + if re.fullmatch(r"\d+\.\d+\.\d+", uv_version) is None: + raise SystemExit("invalid resolved uv version") + + # Label the producer's image family; consumers separately verify native imports. + runner = f"{os.environ['RUNNER_OS']}-{os.environ['RUNNER_ARCH']}-{os.environ['ImageOS']}" + python_tag = python_selector.replace(".", "") + print(f"key=uv-api-simulator-{runner}-uv{uv_version}-rust{rust_version}-py{python_tag}-{revision}") PY - cache_prime: - name: Prime uv cache - if: github.event_name == 'schedule' || (github.event_name == 'push' && github.ref == 'refs/heads/main') - needs: cache_metadata - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4 - - - name: Install uv - uses: astral-sh/setup-uv@08807647e7069bb48b6ef5acd8ec9567f424441b # v8.1.0 - with: - version: "0.9.21" - enable-cache: false - - name: Resolve uv cache directory id: uv-cache-dir shell: bash @@ -96,39 +104,52 @@ jobs: echo "UV_CACHE_DIR=$UV_CACHE_DIR" >> "$GITHUB_ENV" echo "path=$UV_CACHE_DIR" >> "$GITHUB_OUTPUT" - - name: Restore uv cache - id: uv-cache-restore + - name: Look up api-simulator build + id: cache-lookup uses: actions/cache/restore@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0 with: path: ${{ steps.uv-cache-dir.outputs.path }} - key: uv-${{ runner.os }}-py${{ needs.cache_metadata.outputs.python_cache_tag }}-${{ needs.cache_metadata.outputs.api_simulator_rev }}-${{ hashFiles('uv.lock') }} - restore-keys: uv-${{ runner.os }}-py${{ needs.cache_metadata.outputs.python_cache_tag }}-${{ needs.cache_metadata.outputs.api_simulator_rev }}- + key: ${{ steps.cache-identity.outputs.key }} + lookup-only: true - name: Configure git auth for private deps - run: git config --global url."https://${{ secrets.GH_USER }}:${{ secrets.GH_PAT }}@github.com/TalonT-Org/".insteadOf "https://github.com/TalonT-Org/" + if: steps.cache-lookup.outputs.cache-hit != 'true' + env: + GH_USER: ${{ secrets.GH_USER }} + GH_PAT: ${{ secrets.GH_PAT }} + run: | + : "${GH_USER:?private-dependency credentials unavailable: GH_USER}" + : "${GH_PAT:?private-dependency credentials unavailable: GH_PAT}" + git config --global url."https://${GH_USER}:${GH_PAT}@github.com/TalonT-Org/".insteadOf "https://github.com/TalonT-Org/" - name: Install Rust toolchain + if: steps.cache-lookup.outputs.cache-hit != 'true' uses: dtolnay/rust-toolchain@29eef336d9b2848a0b548edc03f92a220660cdb8 # stable with: toolchain: "1.98.1" - - name: Install dependencies - run: uv sync --locked --extra dev - - - name: Prune uv cache - run: uv cache prune --ci + - name: Build api-simulator into the uv cache + if: steps.cache-lookup.outputs.cache-hit != 'true' + env: + # Keeps cargo's build output out of uv's Git checkout, which the cached entry includes. + CARGO_TARGET_DIR: ${{ runner.temp }}/api-simulator-target + run: | + uv sync --locked --extra dev + uv cache prune --ci - - name: Save uv cache - if: steps.uv-cache-restore.outputs.cache-hit != 'true' + - name: Save api-simulator build + if: steps.cache-lookup.outputs.cache-hit != 'true' uses: actions/cache/save@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0 with: path: ${{ steps.uv-cache-dir.outputs.path }} - key: ${{ steps.uv-cache-restore.outputs.cache-primary-key }} + key: ${{ steps.cache-identity.outputs.key }} test: name: Test (${{ matrix.shard }}) on ${{ matrix.os }} - if: github.event_name != 'schedule' - needs: [preflight, cache_metadata] + cache-mode: read + # Keep required matrix contexts reporting failure when the cache producer fails. + if: ${{ !cancelled() && needs.preflight.result == 'success' }} + needs: [preflight, api_simulator_cache] runs-on: ${{ matrix.os }} strategy: fail-fast: false @@ -155,13 +176,21 @@ jobs: echo "UV_CACHE_DIR=$UV_CACHE_DIR" >> "$GITHUB_ENV" echo "path=$UV_CACHE_DIR" >> "$GITHUB_OUTPUT" - - name: Restore uv cache + - name: Require api-simulator build + id: require-api-simulator-cache + if: ${{ !cancelled() && runner.os == 'Linux' && needs.api_simulator_cache.result != 'success' }} + run: | + echo 'api-simulator cache producer did not succeed' >&2 + exit 1 + + - name: Restore api-simulator build id: uv-cache-restore + if: runner.os == 'Linux' uses: actions/cache/restore@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0 with: path: ${{ steps.uv-cache-dir.outputs.path }} - key: uv-${{ runner.os }}-py${{ needs.cache_metadata.outputs.python_cache_tag }}-${{ needs.cache_metadata.outputs.api_simulator_rev }}-${{ hashFiles('uv.lock') }} - restore-keys: uv-${{ runner.os }}-py${{ needs.cache_metadata.outputs.python_cache_tag }}-${{ needs.cache_metadata.outputs.api_simulator_rev }}- + key: ${{ needs.api_simulator_cache.outputs.cache-key }} + fail-on-cache-miss: true - name: Install go-task uses: arduino/setup-task@24c5e13bce349197642746563945fcdf9355e8f4 # v2 @@ -176,14 +205,6 @@ jobs: echo "task: $(task --version)" uv run python --version - - name: Configure git auth for private deps - run: git config --global url."https://${{ secrets.GH_USER }}:${{ secrets.GH_PAT }}@github.com/TalonT-Org/".insteadOf "https://github.com/TalonT-Org/" - - - name: Install Rust toolchain - uses: dtolnay/rust-toolchain@29eef336d9b2848a0b548edc03f92a220660cdb8 # stable - with: - toolchain: "1.98.1" - - name: Install ripgrep shell: bash env: @@ -224,6 +245,11 @@ jobs: - name: Install dependencies run: uv sync --locked --extra dev + - name: Verify api-simulator imports + id: verify-api-simulator + if: runner.os == 'Linux' + run: uv run --no-sync python -B -c "import api_simulator.claude, api_simulator.http, api_simulator.mcp" + - name: Generate recipe diagrams run: uv run autoskillit recipes render diff --git a/tests/infra/test_ci_workflow.py b/tests/infra/test_ci_workflow.py index 37fda68479..11f3abb1d4 100644 --- a/tests/infra/test_ci_workflow.py +++ b/tests/infra/test_ci_workflow.py @@ -21,6 +21,9 @@ _BASE_SHA = "0123456789abcdef0123456789abcdef01234567" _POLICY_MODULE_NAME = "_autoskillit_ci_target_policy" +_PRODUCER_MISS = "steps.cache-lookup.outputs.cache-hit != 'true'" +_PRODUCER_KEY = "${{ steps.cache-identity.outputs.key }}" +_CONSUMER_KEY = "${{ needs.api_simulator_cache.outputs.cache-key }}" def _repo_root() -> Path: @@ -648,110 +651,150 @@ def test_complexity_gate_follows_policy_gate() -> None: assert complexity_index == relaxation_index + 1 -def test_workflow_uses_one_explicit_uv_cache_writer() -> None: - workflow = load_yaml(_repo_root() / ".github" / "workflows" / "tests.yml") - triggers = workflow.get("on", workflow.get(True)) - assert {"push", "pull_request", "merge_group", "schedule"} <= set(triggers) - cron = triggers["schedule"][0]["cron"] - assert cron == "17 3 * * *" - assert int(cron.split()[0]) != 0 - - jobs = workflow["jobs"] - preflight = jobs["preflight"] - test_job = jobs["test"] - metadata = jobs["cache_metadata"] - primer = jobs["cache_prime"] - - assert preflight["if"] == "github.event_name != 'schedule'" - assert test_job["if"] == "github.event_name != 'schedule'" - assert test_job["needs"] == ["preflight", "cache_metadata"] - assert "if" not in metadata - assert metadata["runs-on"] == "ubuntu-latest" - assert primer["if"] == ( - "github.event_name == 'schedule' || " - "(github.event_name == 'push' && github.ref == 'refs/heads/main')" - ) - assert primer["needs"] == "cache_metadata" - assert primer["runs-on"] == "ubuntu-latest" - assert "strategy" not in primer - - metadata_step = next(step for step in metadata["steps"] if step.get("id") == "cache-identity") - metadata_script = metadata_step["run"] - project = tomllib.loads((_repo_root() / "pyproject.toml").read_text(encoding="utf-8")) - expected_revision = project["tool"]["uv"]["sources"]["api-simulator"]["rev"] - expected_python_tag = ( - (_repo_root() / ".python-version").read_text(encoding="utf-8").strip().replace(".", "") +@pytest.mark.parametrize("empty_uv_version", [False, True]) +def test_api_simulator_cache_key_is_the_build_identity_not_the_lockfile( + empty_uv_version: bool, +) -> None: + workflow_path = _repo_root() / ".github" / "workflows" / "tests.yml" + producer = load_yaml(workflow_path)["jobs"]["api_simulator_cache"] + identity = next(step for step in producer["steps"] if step.get("id") == "cache-identity") + lines = identity["run"].splitlines() + assert lines[0] == "python3 <<'PY' >> \"$GITHUB_OUTPUT\"" + assert lines[-1] == "PY" + setup_uv = next( + step + for step in producer["steps"] + if step.get("uses", "").startswith("astral-sh/setup-uv@") ) - assert ".python-version" in metadata_script - assert '["tool"]["uv"]["sources"]["api-simulator"]["rev"]' in metadata_script - assert "[0-9a-fA-F]{40}" in metadata_script - assert r"\d+\.\d+" in metadata_script - metadata_lines = metadata_script.splitlines() - assert metadata_lines[0] == "python3 <<'PY' >> \"$GITHUB_OUTPUT\"" - assert metadata_lines[-1] == "PY" - metadata_result = subprocess.run( - [sys.executable, "-B", "-c", "\n".join(metadata_lines[1:-1])], + uv_version = setup_uv["with"]["version"] + rust = next( + step + for step in producer["steps"] + if step.get("uses", "").startswith("dtolnay/rust-toolchain@") + ) + rust_version = rust["with"]["toolchain"] + result = subprocess.run( + [sys.executable, "-B", "-c", "\n".join(lines[1:-1])], cwd=_repo_root(), capture_output=True, text=True, - env=production_interpreter_env(), + env=production_interpreter_env() + | { + "RUNNER_OS": "Linux", + "RUNNER_ARCH": "X64", + "ImageOS": "ubuntu24", + "UV_VERSION": "" if empty_uv_version else uv_version, + }, check=False, ) - assert metadata_result.returncode == 0, metadata_result.stderr - assert metadata_result.stdout.splitlines() == [ - f"python_cache_tag={expected_python_tag}", - f"api_simulator_rev={expected_revision}", + project = tomllib.loads((_repo_root() / "pyproject.toml").read_text(encoding="utf-8")) + revision = project["tool"]["uv"]["sources"]["api-simulator"]["rev"] + python_tag = ( + (_repo_root() / ".python-version").read_text(encoding="utf-8").strip().replace(".", "") + ) + if empty_uv_version: + assert result.returncode != 0 + assert "invalid resolved uv version" in result.stderr + assert not result.stdout + return + assert result.returncode == 0, result.stderr + assert result.stdout.splitlines() == [ + f"key=uv-api-simulator-Linux-X64-ubuntu24-uv{uv_version}-rust{rust_version}-py{python_tag}-{revision}" ] - assert metadata["outputs"] == { - "python_cache_tag": "${{ steps.cache-identity.outputs.python_cache_tag }}", - "api_simulator_rev": "${{ steps.cache-identity.outputs.api_simulator_rev }}", - } + assert identity["env"] == {"UV_VERSION": "${{ steps.setup-uv.outputs.uv-version }}"} - setup_uv_steps = { - job_name: next( - step for step in job["steps"] if "astral-sh/setup-uv@" in step.get("uses", "") - ) - for job_name, job in jobs.items() - if any("astral-sh/setup-uv@" in step.get("uses", "") for step in job.get("steps", [])) - } - assert set(setup_uv_steps) == {"preflight", "test", "cache_prime"} - assert all(step["with"]["version"] == "0.9.21" for step in setup_uv_steps.values()) - assert setup_uv_steps["test"]["with"]["enable-cache"] is False - assert setup_uv_steps["cache_prime"]["with"]["enable-cache"] is False - - restore_pin = "actions/cache/restore@0057852bfaa89a56745cba8c7296529d2fc39830" - save_pin = "actions/cache/save@0057852bfaa89a56745cba8c7296529d2fc39830" - primary_key = ( - "uv-${{ runner.os }}-py${{ needs.cache_metadata.outputs.python_cache_tag }}-" - "${{ needs.cache_metadata.outputs.api_simulator_rev }}-${{ hashFiles('uv.lock') }}" - ) - restore_prefix = ( - "uv-${{ runner.os }}-py${{ needs.cache_metadata.outputs.python_cache_tag }}-" - "${{ needs.cache_metadata.outputs.api_simulator_rev }}-" - ) - for job in (test_job, primer): - cache_dir = next(step for step in job["steps"] if step.get("id") == "uv-cache-dir") - restore = next(step for step in job["steps"] if step.get("id") == "uv-cache-restore") - assert "uv cache dir" in cache_dir["run"] - assert "UV_CACHE_DIR=" in cache_dir["run"] - assert '"$GITHUB_ENV"' in cache_dir["run"] - assert "path=" in cache_dir["run"] - assert '"$GITHUB_OUTPUT"' in cache_dir["run"] - assert restore["uses"] == restore_pin - assert restore["with"] == { - "path": "${{ steps.uv-cache-dir.outputs.path }}", - "key": primary_key, - "restore-keys": restore_prefix, - } - test_restore = next(step for step in test_job["steps"] if step.get("id") == "uv-cache-restore") - test_sync = next(step for step in test_job["steps"] if "uv sync" in step.get("run", "")) - assert test_job["steps"].index(test_restore) < test_job["steps"].index(test_sync) - assert not any( - step.get("uses", "").startswith("actions/cache/save@") for step in test_job["steps"] +@pytest.mark.parametrize("missing_secret", ["GH_USER", "GH_PAT"]) +def test_cache_build_reports_missing_credentials(tmp_path: Path, missing_secret: str) -> None: + workflow = load_yaml(_repo_root() / ".github" / "workflows" / "tests.yml") + auth = next( + step + for step in workflow["jobs"]["api_simulator_cache"]["steps"] + if "git config --global" in step.get("run", "") ) - assert not any(step.get("uses", "").startswith("actions/cache@") for step in test_job["steps"]) + assert auth["env"] == { + "GH_USER": "${{ secrets.GH_USER }}", + "GH_PAT": "${{ secrets.GH_PAT }}", + } + config = tmp_path / "gitconfig" + result = subprocess.run( + ["bash", "-c", auth["run"]], + capture_output=True, + text=True, + check=False, + env=production_interpreter_env() + | { + "GH_USER": "test-user", + "GH_PAT": "test-token", + missing_secret: "", + "GIT_CONFIG_GLOBAL": str(config), + }, + ) + assert result.returncode != 0 + assert f"private-dependency credentials unavailable: {missing_secret}" in result.stderr + assert not config.exists() + +def test_one_producer_builds_api_simulator_and_test_jobs_only_restore_it() -> None: + workflow = load_yaml(_repo_root() / ".github" / "workflows" / "tests.yml") + assert set(workflow.get("on", workflow.get(True))) == {"push", "pull_request", "merge_group"} + jobs = workflow["jobs"] + producer = jobs["api_simulator_cache"] + producer_steps = producer["steps"] + assert "if" not in producer + assert producer["runs-on"] == "ubuntu-latest" + assert "strategy" not in producer + assert producer["cache-mode"] == "write" + assert producer["outputs"] == {"cache-key": _PRODUCER_KEY} + producer_uv = next( + step for step in producer_steps if step.get("uses", "").startswith("astral-sh/setup-uv@") + ) + test_job = jobs["test"] + test_steps = test_job["steps"] + test_uv = next( + step for step in test_steps if step.get("uses", "").startswith("astral-sh/setup-uv@") + ) + for steps in (producer_steps, test_steps): + cache_dir = next(step for step in steps if step.get("id") == "uv-cache-dir") + assert cache_dir["shell"] == "bash" + assert cache_dir["run"].splitlines() == [ + 'UV_CACHE_DIR="$(uv cache dir)"', + 'echo "UV_CACHE_DIR=$UV_CACHE_DIR" >> "$GITHUB_ENV"', + 'echo "path=$UV_CACHE_DIR" >> "$GITHUB_OUTPUT"', + ] + assert producer_uv["id"] == "setup-uv" + for job in jobs.values(): + for step in job.get("steps", []): + if step.get("uses", "").startswith("astral-sh/setup-uv@"): + assert step["with"]["enable-cache"] is False + assert producer_uv["with"]["version"] == test_uv["with"]["version"] + lookup = next(step for step in producer_steps if step.get("id") == "cache-lookup") + assert lookup["uses"] == "actions/cache/restore@0057852bfaa89a56745cba8c7296529d2fc39830" + assert lookup["with"] == { + "lookup-only": True, + "key": _PRODUCER_KEY, + "path": "${{ steps.uv-cache-dir.outputs.path }}", + } + auth = [step for step in producer_steps if "git config --global" in step.get("run", "")] + rust = [ + step + for step in producer_steps + if step.get("uses", "").startswith("dtolnay/rust-toolchain@") + ] + builds = [step for step in producer_steps if "uv sync" in step.get("run", "")] + saves = [ + step for step in producer_steps if step.get("uses", "").startswith("actions/cache/save@") + ] + assert auth and rust and builds and saves + assert all(step["if"] == _PRODUCER_MISS for step in auth + rust + builds + saves) + assert all( + producer_steps.index(lookup) < producer_steps.index(step) + for step in auth + rust + builds + saves + ) + build = builds[0] + assert "uv sync --locked --extra dev" in build["run"] + assert "uv cache prune --ci" in build["run"] + assert build["env"]["CARGO_TARGET_DIR"] == "${{ runner.temp }}/api-simulator-target" save_steps = [ (job_name, step) for job_name, job in jobs.items() @@ -760,50 +803,69 @@ def test_workflow_uses_one_explicit_uv_cache_writer() -> None: ] assert len(save_steps) == 1 save_owner, save = save_steps[0] - assert save_owner == "cache_prime" - assert save["uses"] == save_pin - assert save["if"] == "steps.uv-cache-restore.outputs.cache-hit != 'true'" + assert save_owner == "api_simulator_cache" + assert save["uses"] == "actions/cache/save@0057852bfaa89a56745cba8c7296529d2fc39830" assert save["with"] == { + "key": _PRODUCER_KEY, "path": "${{ steps.uv-cache-dir.outputs.path }}", - "key": "${{ steps.uv-cache-restore.outputs.cache-primary-key }}", } - - primer_steps = primer["steps"] - primer_restore = next(step for step in primer_steps if step.get("id") == "uv-cache-restore") - primer_auth = next( - step for step in primer_steps if "git config --global" in step.get("run", "") + assert producer_steps.index(build) < producer_steps.index(save) + assert not any( + step.get("uses", "").startswith("actions/cache@") + for job in jobs.values() + for step in job.get("steps", []) ) - primer_rust = next( - step for step in primer_steps if "dtolnay/rust-toolchain@" in step.get("uses", "") + preflight = jobs["preflight"] + preflight_steps = preflight["steps"] + assert not preflight.get("needs") + assert any(step.get("run") == "uv lock --check" for step in preflight_steps) + assert not any("uv sync" in step.get("run", "") for step in preflight_steps) + preflight_uv = next( + step for step in preflight_steps if step.get("uses", "").startswith("astral-sh/setup-uv@") ) - primer_sync = next(step for step in primer_steps if "uv sync" in step.get("run", "")) - primer_prune = next( - step for step in primer_steps if "uv cache prune --ci" in step.get("run", "") + assert preflight_uv["with"]["version"] == producer_uv["with"]["version"] + assert test_job["cache-mode"] == "read" + assert {"preflight", "api_simulator_cache"} <= set(test_job["needs"]) + assert test_job["if"] == "${{ !cancelled() && needs.preflight.result == 'success' }}" + require = next(step for step in test_steps if step.get("id") == "require-api-simulator-cache") + assert require["if"] == ( + "${{ !cancelled() && runner.os == 'Linux' && " + "needs.api_simulator_cache.result != 'success' }}" ) - assert primer_steps.index(primer_restore) < primer_steps.index(primer_sync) - assert primer_steps.index(primer_auth) < primer_steps.index(primer_sync) - assert primer_steps.index(primer_rust) < primer_steps.index(primer_sync) - assert primer_steps.index(primer_sync) < primer_steps.index(primer_prune) - assert primer_steps.index(primer_prune) < primer_steps.index(save) - - preflight_runs = [step.get("run", "") for step in preflight["steps"]] - assert any(run == "uv lock --check" for run in preflight_runs) - assert not any("uv sync" in run for run in preflight_runs) - test_checkout = next( - step for step in test_job["steps"] if step.get("uses", "").startswith("actions/checkout@") + failure = subprocess.run( + ["bash", "-c", require["run"]], capture_output=True, text=True, check=False ) - assert test_checkout["with"]["fetch-depth"] == 0 - sync_jobs = { - job_name - for job_name, job in jobs.items() - if any("uv sync" in step.get("run", "") for step in job.get("steps", [])) + assert failure.returncode == 1 + assert failure.stderr.strip() == "api-simulator cache producer did not succeed" + restore = next(step for step in test_steps if step.get("id") == "uv-cache-restore") + assert restore["uses"] == "actions/cache/restore@0057852bfaa89a56745cba8c7296529d2fc39830" + assert restore["if"] == "runner.os == 'Linux'" + assert restore["with"] == { + "path": "${{ steps.uv-cache-dir.outputs.path }}", + "key": _CONSUMER_KEY, + "fail-on-cache-miss": True, } - rust_jobs = { - job_name + install = next(step for step in test_steps if step.get("name") == "Install dependencies") + verify = next(step for step in test_steps if step.get("id") == "verify-api-simulator") + assert test_steps.index(require) < test_steps.index(restore) < test_steps.index(install) + assert verify["if"] == "runner.os == 'Linux'" + assert verify["run"] == ( + 'uv run --no-sync python -B -c "import api_simulator.claude, ' + 'api_simulator.http, api_simulator.mcp"' + ) + assert test_steps.index(verify) == test_steps.index(install) + 1 + project = tomllib.loads((_repo_root() / "pyproject.toml").read_text(encoding="utf-8")) + assert ( + "api-simulator; sys_platform == 'linux'" + in project["project"]["optional-dependencies"]["dev"] + ) + assert not any( + step.get("uses", "").startswith("dtolnay/rust-toolchain@") + or "git config --global" in step.get("run", "") for job_name, job in jobs.items() - if any("dtolnay/rust-toolchain@" in step.get("uses", "") for step in job.get("steps", [])) - } - assert rust_jobs == sync_jobs == {"test", "cache_prime"} + if job_name != "api_simulator_cache" + for step in job.get("steps", []) + ) def test_ci_policy_is_recorded_in_durable_contributor_instructions() -> None: @@ -847,6 +909,8 @@ def test_ci_policy_is_recorded_in_durable_contributor_instructions() -> None: assert "explicit `actions/cache` owns their uv-cache I/O" in agent_rules assert "matrix jobs restore only" in agent_rules assert "sole saver" in agent_rules + assert "never `uv.lock`" in agent_rules + assert "`gh cache delete `" in agent_rules assert "`api-simulator.rev`" in agent_rules assert "regenerated `uv.lock`" in agent_rules assert "`fetch-depth: 0`" in agent_rules