diff --git a/.github/workflows/checks.yaml b/.github/workflows/checks.yaml index b2960cb8..f0baf196 100644 --- a/.github/workflows/checks.yaml +++ b/.github/workflows/checks.yaml @@ -93,6 +93,26 @@ jobs: uses: ./.github/actions/setup-python-env with: python-version: ${{ matrix.python-version }} + - name: Cache Temporal test server binaries + if: runner.os == 'Linux' + uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5 + with: + # The temporalio Python SDK downloads its test-server binary into + # this directory (filename keyed by SDK version), and reuses any + # existing binary on subsequent calls. Caching the directory lets + # CI shards share binaries and avoid temporal.download 429s. + path: ~/.cache/braintrust/temporal-test-server + key: temporal-test-server-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('py/pyproject.toml') }} + restore-keys: | + temporal-test-server-${{ runner.os }}-${{ runner.arch }}- + - name: Configure Temporal test server cache dir + if: runner.os == 'Linux' + shell: bash + run: | + set -euo pipefail + dir="$HOME/.cache/braintrust/temporal-test-server" + mkdir -p "$dir" + echo "BRAINTRUST_TEMPORAL_TEST_SERVER_DIR=$dir" >> "$GITHUB_ENV" - name: Run nox tests (shard ${{ matrix.shard }}/6) shell: bash run: | diff --git a/py/src/braintrust/integrations/temporal/test_temporal.py b/py/src/braintrust/integrations/temporal/test_temporal.py index 5a1a3fbc..671ffd1e 100644 --- a/py/src/braintrust/integrations/temporal/test_temporal.py +++ b/py/src/braintrust/integrations/temporal/test_temporal.py @@ -1,6 +1,7 @@ """Unit tests for Braintrust Temporal interceptor.""" import asyncio +import os import uuid from dataclasses import dataclass from datetime import timedelta @@ -243,8 +244,22 @@ def test_contrib_temporal_compat_import_deprecated(self): @pytest_asyncio.fixture(scope="function") async def temporal_env(): - """Create a Temporal test environment.""" - async with await temporalio.testing.WorkflowEnvironment.start_time_skipping() as env: + """Create a Temporal test environment. + + If ``BRAINTRUST_TEMPORAL_TEST_SERVER_DIR`` is set, point the SDK's binary + download cache at that directory and pin a long TTL so existing binaries + are reused. CI sets this so a cached directory restored from the GitHub + Actions cache shortcuts the download to temporal.download (which rate + limits CI runners). When the var is unset (the local default), the SDK + falls back to its built-in temp-dir download behavior. + """ + kwargs: dict[str, Any] = {} + cache_dir = os.environ.get("BRAINTRUST_TEMPORAL_TEST_SERVER_DIR") + if cache_dir: + os.makedirs(cache_dir, exist_ok=True) + kwargs["download_dest_dir"] = cache_dir + kwargs["test_server_download_ttl"] = timedelta(days=365) + async with await temporalio.testing.WorkflowEnvironment.start_time_skipping(**kwargs) as env: yield env