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
26 changes: 26 additions & 0 deletions .github/workflows/tusk-drift-api-tests.yml
Original file line number Diff line number Diff line change
@@ -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 }}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ ENV/
env/
.venv

# Environment variables
.env

# IDE
.vscode/
.idea/
Expand Down
29 changes: 17 additions & 12 deletions .tusk/config.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
23 changes: 23 additions & 0 deletions internal/buggy-branch-diff.diff
Original file line number Diff line number Diff line change
@@ -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:
42 changes: 42 additions & 0 deletions internal/create-buggy-pr.sh
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -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
10 changes: 9 additions & 1 deletion tusk_drift_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)