-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_pr_review.py
More file actions
68 lines (62 loc) · 2.03 KB
/
test_pr_review.py
File metadata and controls
68 lines (62 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import os
from dotenv import load_dotenv
# Load environment variables from .env file
load_dotenv()
# Set required environment variables if not already set
if not os.getenv("REGION_ID"):
os.environ["REGION_ID"] = "us-west-2"
if not os.getenv("MEMORY_ID"):
os.environ["MEMORY_ID"] = "agentcore_starter_strands_mem-Aq6zOCGjAL"
if not os.getenv("MODEL_ID"):
os.environ["MODEL_ID"] = "anthropic.claude-3-5-haiku-20241022-v1:0"
from agentcore_starter_strands import invoke
# Sample PR data for testing
sample_pr = {
"pr_data": {
"title": "Add user authentication endpoint",
"author": "developer123",
"description": "Implements JWT-based authentication for the API",
"files": [
{
"filename": "auth.py",
"patch": """@@ -0,0 +1,25 @@
+import jwt
+from flask import request, jsonify
+
+def authenticate_user():
+ token = request.headers.get('Authorization')
+ if not token:
+ return jsonify({'error': 'No token provided'}), 401
+
+ try:
+ # Decode JWT token
+ payload = jwt.decode(token, 'secret_key', algorithms=['HS256'])
+ user_id = payload['user_id']
+ return jsonify({'user_id': user_id}), 200
+ except jwt.ExpiredSignatureError:
+ return jsonify({'error': 'Token expired'}), 401
+ except jwt.InvalidTokenError:
+ return jsonify({'error': 'Invalid token'}), 401
+
+def login():
+ username = request.json.get('username')
+ password = request.json.get('password')
+
+ # TODO: Add proper password validation
+ if username == 'admin' and password == 'password':
+ token = jwt.encode({'user_id': 1}, 'secret_key', algorithm='HS256')
+ return jsonify({'token': token}), 200
+
+ return jsonify({'error': 'Invalid credentials'}), 401"""
}
]
}
}
class Context:
session_id = "pr-review-test-session"
print("Testing PR Review Assistant...")
result = invoke(sample_pr, Context())
print("\n" + "="*50)
print("REVIEW RESULT:")
print("="*50)
print(result['review'])