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
20 changes: 20 additions & 0 deletions .github/workflows/checks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
19 changes: 17 additions & 2 deletions py/src/braintrust/integrations/temporal/test_temporal.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Unit tests for Braintrust Temporal interceptor."""

import asyncio
import os
import uuid
from dataclasses import dataclass
from datetime import timedelta
Expand Down Expand Up @@ -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


Expand Down