Merge branch 'main' into summarizer-planner

This commit is contained in:
2025-04-29 14:40:21 -03:00
10 changed files with 331 additions and 15 deletions

View File

@ -0,0 +1,51 @@
"""Test stage for auditing summary."""
import requests
from prometheus_test import Context
async def prepare(context: Context, target_name: str):
"""Prepare for auditing summary."""
staking_key = context.env.get("WORKER_ID")
target_submission = await context.storeGet(f"submission-{target_name}")
return {
"staking_key": staking_key,
"round_number": context.round_number,
"target_submission": target_submission,
"target_name": target_name,
}
async def execute(context: Context, prepare_data: dict):
"""Execute summary audit test."""
staking_key = prepare_data["staking_key"]
round_number = prepare_data["round_number"]
target_submission = prepare_data["target_submission"]
target_name = prepare_data["target_name"]
# Mock response for audit
response = requests.post(
"http://localhost:5000/api/summarizer/audit",
json={
"taskId": context.config.task_id,
"roundNumber": round_number,
"stakingKey": staking_key,
"submitterKey": target_name,
"cid": target_submission.get("cid"),
"prUrl": target_submission.get("pr_url"),
"githubUsername": target_submission.get("github_username"),
},
)
if response.status_code != 200:
raise Exception(f"Failed to audit summary: {response.text}")
result = response.json()
if not result.get("success"):
raise Exception("Failed to audit summary")
# Store audit result
await context.storeSet(f"audit-{staking_key}-{target_name}", result.get("data"))
return True

View File

@ -0,0 +1,39 @@
"""Test stage for fetching summarizer todo."""
import requests
from prometheus_test import Context
async def prepare(context: Context):
"""Prepare for fetching summarizer todo."""
return {
"staking_key": context.env.get("WORKER_ID"),
"round_number": context.round_number,
}
async def execute(context: Context, prepare_data: dict):
"""Execute fetch summarizer todo test."""
staking_key = prepare_data["staking_key"]
round_number = prepare_data["round_number"]
# Mock response for fetching todo
response = requests.post(
"http://localhost:5000/api/summarizer/fetch-summarizer-todo",
json={
"stakingKey": staking_key,
"roundNumber": round_number,
},
)
if response.status_code != 200:
raise Exception(f"Failed to fetch summarizer todo: {response.text}")
result = response.json()
if not result.get("success"):
raise Exception("Failed to fetch summarizer todo")
# Store todo data for next steps
await context.storeSet(f"todo-{staking_key}", result.get("data"))
return True

View File

@ -0,0 +1,47 @@
"""Test stage for generating repository summary."""
import requests
from prometheus_test import Context
async def prepare(context: Context):
"""Prepare for generating summary."""
staking_key = context.env.get("WORKER_ID")
todo = await context.storeGet(f"todo-{staking_key}")
return {
"staking_key": staking_key,
"round_number": context.round_number,
"repo_owner": todo.get("repo_owner"),
"repo_name": todo.get("repo_name"),
}
async def execute(context: Context, prepare_data: dict):
"""Execute summary generation test."""
staking_key = prepare_data["staking_key"]
round_number = prepare_data["round_number"]
repo_owner = prepare_data["repo_owner"]
repo_name = prepare_data["repo_name"]
# Mock response for repo summary generation
response = requests.post(
"http://localhost:5000/api/summarizer/generate-summary",
json={
"taskId": context.config.task_id,
"round_number": str(round_number),
"repo_url": f"https://github.com/{repo_owner}/{repo_name}",
},
)
if response.status_code != 200:
raise Exception(f"Failed to generate summary: {response.text}")
result = response.json()
if not result.get("success"):
raise Exception("Failed to generate summary")
# Store PR URL for next steps
await context.storeSet(f"pr-{staking_key}", result.get("data", {}).get("pr_url"))
return True

View File

@ -0,0 +1,56 @@
"""Test stage for submitting summary."""
import requests
from prometheus_test import Context
async def prepare(context: Context):
"""Prepare for submitting summary."""
staking_key = context.env.get("WORKER_ID")
pr_url = await context.storeGet(f"pr-{staking_key}")
return {
"staking_key": staking_key,
"round_number": context.round_number,
"pr_url": pr_url,
"github_username": context.env.get("GITHUB_USERNAME"),
}
async def execute(context: Context, prepare_data: dict):
"""Execute summary submission test."""
staking_key = prepare_data["staking_key"]
round_number = prepare_data["round_number"]
pr_url = prepare_data["pr_url"]
github_username = prepare_data["github_username"]
# Mock response for submission
response = requests.post(
"http://localhost:5000/api/summarizer/submit",
json={
"taskId": context.config.task_id,
"roundNumber": round_number,
"prUrl": pr_url,
"stakingKey": staking_key,
"githubUsername": github_username,
},
)
if response.status_code != 200:
raise Exception(f"Failed to submit summary: {response.text}")
result = response.json()
if not result.get("success"):
raise Exception("Failed to submit summary")
# Store submission data for audit
await context.storeSet(
f"submission-{staking_key}",
{
"cid": result.get("data", {}).get("cid"),
"pr_url": pr_url,
"github_username": github_username,
},
)
return True

View File

@ -0,0 +1,31 @@
"""Test stage for validating API keys."""
import requests
from prometheus_test import Context
async def prepare(context: Context):
"""Prepare for API key validation test."""
return {
"api_key": context.env.get("ANTHROPIC_API_KEY"),
}
async def execute(context: Context, prepare_data: dict):
"""Execute API key validation test."""
api_key = prepare_data["api_key"]
# Mock response for Anthropic API validation
response = requests.post(
"http://localhost:5000/api/summarizer/validate-api-key",
json={"api_key": api_key},
)
if response.status_code != 200:
raise Exception(f"API key validation failed: {response.text}")
result = response.json()
if not result.get("valid"):
raise Exception("API key is not valid")
return True