From 660701494e9f01c7fcd637eea6e1e8a124af046c Mon Sep 17 00:00:00 2001 From: marcel-tan Date: Tue, 6 Jan 2026 16:22:38 -0800 Subject: [PATCH 1/2] feat: add buggy branch script and Tusk Drift GH workflow - Introduced a GitHub Actions workflow for Tusk Drift API tests. - Added script to trigger PR creation for the buggy branch diff --- .github/workflows/tusk-drift-api-tests.yml | 26 ++++++++++++++ internal/buggy-branch-diff.diff | 23 ++++++++++++ internal/create-buggy-pr.sh | 42 ++++++++++++++++++++++ 3 files changed, 91 insertions(+) create mode 100644 .github/workflows/tusk-drift-api-tests.yml create mode 100644 internal/buggy-branch-diff.diff create mode 100644 internal/create-buggy-pr.sh diff --git a/.github/workflows/tusk-drift-api-tests.yml b/.github/workflows/tusk-drift-api-tests.yml new file mode 100644 index 0000000..38d1b30 --- /dev/null +++ b/.github/workflows/tusk-drift-api-tests.yml @@ -0,0 +1,26 @@ +name: Tusk Drift API Tests + +on: + pull_request: + +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.12' + + - name: Install dependencies + run: pip install -r requirements.txt + + - name: Install Tusk CLI + run: curl -fsSL https://cli.usetusk.ai/install.sh | sh + + - name: Run Tusk Drift API tests + env: + TUSK_API_KEY: ${{ secrets.TUSK_DRIFT_API_KEY }} + run: tusk run --cloud --ci --print --commit-sha=${{ github.sha }} --pr-number=${{ github.event.pull_request.number }} --branch=${{ github.event.pull_request.head.ref }} diff --git a/internal/buggy-branch-diff.diff b/internal/buggy-branch-diff.diff new file mode 100644 index 0000000..0aa5139 --- /dev/null +++ b/internal/buggy-branch-diff.diff @@ -0,0 +1,23 @@ +diff --git a/server.py b/server.py +--- a/server.py ++++ b/server.py +@@ -5,6 +5,10 @@ import requests + app = Flask(__name__) + PORT = 3000 + ++ ++def convert_celsius_to_fahrenheit(celsius): ++ return (celsius * 9/5) + 32 ++ + + @app.route('/api/weather-activity', methods=['GET']) + def weather_activity(): +@@ -28,6 +32,8 @@ def weather_activity(): + weather_response.raise_for_status() + weather = weather_response.json()['current_weather'] + ++ weather['temperature'] = convert_celsius_to_fahrenheit(weather['temperature']) ++ + # Business logic: Recommend activity based on weather + recommended_activity = 'Play a board game' + if weather['temperature'] > 40: \ No newline at end of file diff --git a/internal/create-buggy-pr.sh b/internal/create-buggy-pr.sh new file mode 100644 index 0000000..5f64102 --- /dev/null +++ b/internal/create-buggy-pr.sh @@ -0,0 +1,42 @@ +#!/bin/bash + +set -e + +# Generate timestamp +TIMESTAMP=$(date +%s) +BRANCH_NAME="buggy-branch-$TIMESTAMP" + +# Checkout main +git checkout main + +# Create new buggy branch +git checkout -b "$BRANCH_NAME" + +# Apply the buggy diff +git apply internal/buggy-branch-diff.diff + +# Stage all changes +git add . + +# Commit the changes +git commit -m "feat: add Fahrenheit temperature conversion" + +# Push to remote +git push -u origin "$BRANCH_NAME" + +# Create PR non-interactively +gh pr create --title "feat: add Fahrenheit temperature conversion" --body '## Changes +### Temperature Conversion +- Added `convert_celsius_to_fahrenheit` helper function to convert temperatures from Celsius to Fahrenheit +- Updated `/api/weather-activity` endpoint to return temperature in Fahrenheit instead of Celsius +## Motivation +Users in regions using Fahrenheit (e.g., United States) will benefit from having temperatures displayed in their preferred unit. This change makes the weather data more accessible to these users. +## Testing +- [ ] Verify `/api/weather-activity` returns temperature in Fahrenheit +- [ ] Verify activity recommendations still work correctly +- [ ] Test with various temperature ranges' --base main + +# Open PR in web browser +gh pr view --web + +git checkout main \ No newline at end of file From 20758b71caec0cb02d9608f586087970f81ee7a9 Mon Sep 17 00:00:00 2001 From: marcel-tan Date: Tue, 6 Jan 2026 17:24:45 -0800 Subject: [PATCH 2/2] feat: made tusk drift config cloud-ready - Added support for loading environment variables using python-dotenv. - Updated Tusk Drift initialization to use API key from environment variables. - Modified .gitignore to include .env file. - Updated requirements.txt to include python-dotenv. - Enhanced .tusk/config.yaml with Cloud configs --- .gitignore | 3 +++ .tusk/config.yaml | 29 +++++++++++++++++------------ requirements.txt | 1 + tusk_drift_init.py | 10 +++++++++- 4 files changed, 30 insertions(+), 13 deletions(-) diff --git a/.gitignore b/.gitignore index 7c7b727..901951f 100644 --- a/.gitignore +++ b/.gitignore @@ -27,6 +27,9 @@ ENV/ env/ .venv +# Environment variables +.env + # IDE .vscode/ .idea/ diff --git a/.tusk/config.yaml b/.tusk/config.yaml index 75b263a..fcb624d 100644 --- a/.tusk/config.yaml +++ b/.tusk/config.yaml @@ -1,22 +1,27 @@ service: - name: drift-python-demo - port: 3000 - start: - command: python server.py - readiness_check: - command: curl -fsS http://localhost:3000/health - timeout: 30s - interval: 1s + name: drift-python-demo + port: 3000 + start: + command: python server.py + readiness_check: + command: curl -fsS http://localhost:3000/health + timeout: 30s + interval: 1s + id: d02e3f3f-f1f0-4786-b0eb-5159261ee3c8 traces: - dir: .tusk/traces + dir: .tusk/traces test_execution: - timeout: 30s + timeout: 30s recording: - sampling_rate: 1 # Record 100% of requests - export_spans: false # Don't export spans to cloud, export to .tusk/traces instead + sampling_rate: 1 # Record 100% of requests + export_spans: true # Export spans to cloud + enable_env_var_recording: false + +tusk_api: + url: https://use-tusk-dev.uc.r.appspot.com # Only recording traces locally, API url not needed # tusk_api: diff --git a/requirements.txt b/requirements.txt index 51db634..dd052a7 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ flask>=3.0.0 +python-dotenv>=1.0.0 requests>=2.31.0 tusk-drift-python-sdk[flask]>=0.1.4 diff --git a/tusk_drift_init.py b/tusk_drift_init.py index 7564e9a..768faf3 100644 --- a/tusk_drift_init.py +++ b/tusk_drift_init.py @@ -4,7 +4,15 @@ This module initializes the Tusk Drift SDK for recording and replaying API traffic. """ +import os + +from dotenv import load_dotenv from drift import TuskDrift +load_dotenv() + # Initialize Tusk Drift SDK -tusk_drift = TuskDrift.initialize(env="local") +tusk_drift = TuskDrift.initialize( + api_key=os.environ.get("TUSK_API_KEY"), + env="local" +)