use new version of test framework

This commit is contained in:
Laura Abro
2025-04-30 08:06:43 -03:00
parent 68c86bf077
commit e44234a79e
8 changed files with 78 additions and 88 deletions

View File

@ -15,5 +15,6 @@ base58>=2.1.0
tenacity>=9.0.0 tenacity>=9.0.0
sqlmodel>=0.0.22 sqlmodel>=0.0.22
openai>=0.28.0 openai>=0.28.0
colorama>=0.4.67prometheus-swarm>=0.1.7 colorama>=0.4.67
prometheus-test>=0.1.2 prometheus-swarm>=0.1.7
prometheus-test>=0.1.4

View File

@ -7,14 +7,14 @@ def prepare(runner, worker, role: str):
"""Prepare data for worker task""" """Prepare data for worker task"""
return { return {
"taskId": runner.config.task_id, "taskId": runner.get("task_id"),
"round": runner.current_round, "round": runner.get("current_round"),
} }
def execute(runner, worker, data): def execute(runner, worker, data):
"""Execute worker task step""" """Execute worker task step"""
url = f"{runner.config.middle_server_url}/summarizer/worker/update-audit-result" url = f"{runner.get('middle_server_url')}/summarizer/worker/update-audit-result"
response = requests.post( response = requests.post(
url, url,
json=data, json=data,

View File

@ -7,30 +7,22 @@ import requests
def prepare(runner, worker, target_name): def prepare(runner, worker, target_name):
"""Prepare data for worker audit""" """Prepare data for worker audit"""
round_state = runner.state["rounds"].get(str(runner.current_round), {}) pr_url = runner.get(f"pr_urls.{target_name}")
pr_urls = round_state.get("pr_urls", {}) if pr_url is None:
print(f"✓ No pr_urls.{target_name} found - continuing")
if target_name not in pr_urls:
# Return None to indicate this step should be skipped
print(
f"✓ No PR URL found for {target_name}, skipping {worker.name} audit - continuing"
)
return None return None
# Get submission data from state submission_data = runner.get(f"submission_data.{target_name}")
submission_data = round_state.get("submission_data", {}).get(target_name) if submission_data is None:
if not submission_data: print(f"✓ No submission_data.{target_name} found - continuing")
# Return None to indicate this step should be skipped
print(
f"✓ No submission data found for {target_name}, skipping {worker.name} audit - continuing"
)
return None return None
# Note: Commented out code is preserved as it may be needed in future
# Create auditor payload which is used to generate the signature # Create auditor payload which is used to generate the signature
# auditor_payload = { # auditor_payload = {
# "taskId": runner.config.task_id, # "taskId": runner.get("task_id"),
# "roundNumber": runner.current_round, # "roundNumber": runner.get("current_round"),
# "prUrl": pr_urls[target_name], # "prUrl": pr_url,
# "stakingKey": worker.staking_public_key, # "stakingKey": worker.staking_public_key,
# "pubKey": worker.public_key, # "pubKey": worker.public_key,
# } # }
@ -38,9 +30,9 @@ def prepare(runner, worker, target_name):
# Structure the payload according to what the server expects # Structure the payload according to what the server expects
# return { # return {
# "submission": { # "submission": {
# "taskId": runner.config.task_id, # "taskId": runner.get("task_id"),
# "roundNumber": runner.current_round, # "roundNumber": runner.get("current_round"),
# "prUrl": pr_urls[target_name], # "prUrl": pr_url,
# "githubUsername": submission_data.get("githubUsername"), # "githubUsername": submission_data.get("githubUsername"),
# "repoOwner": submission_data.get("repoOwner"), # "repoOwner": submission_data.get("repoOwner"),
# "repoName": submission_data.get("repoName"), # "repoName": submission_data.get("repoName"),
@ -52,7 +44,7 @@ def prepare(runner, worker, target_name):
# "submitterSignature": submission_data.get("signature"), # "submitterSignature": submission_data.get("signature"),
# "submitterStakingKey": submission_data.get("stakingKey"), # "submitterStakingKey": submission_data.get("stakingKey"),
# "submitterPubKey": submission_data.get("pubKey"), # "submitterPubKey": submission_data.get("pubKey"),
# "prUrl": pr_urls[target_name], # "prUrl": pr_url,
# "repoOwner": submission_data.get("repoOwner"), # "repoOwner": submission_data.get("repoOwner"),
# "repoName": submission_data.get("repoName"), # "repoName": submission_data.get("repoName"),
# "githubUsername": worker.env.get("GITHUB_USERNAME"), # "githubUsername": worker.env.get("GITHUB_USERNAME"),
@ -75,7 +67,7 @@ def execute(runner, worker, data):
"message": "Skipped due to missing PR URL or submission data", "message": "Skipped due to missing PR URL or submission data",
} }
url = f"{worker.url}/worker-audit/{runner.current_round}" url = f"{worker.url}/worker-audit/{runner.get('current_round')}"
response = requests.post(url, json=data) response = requests.post(url, json=data)
result = response.json() result = response.json()

View File

@ -5,16 +5,16 @@ import requests
def prepare(runner, worker): def prepare(runner, worker):
"""Prepare data for worker task""" """Prepare data for worker task"""
# Create fetch-todo payload for stakingSignature and publicSignature pr_url = runner.get(f"pr_urls.{worker.name}")
round_state = runner.state["rounds"].get(str(runner.current_round), {}) if pr_url is None:
if not round_state.get("pr_urls"): print(f"✓ No pr_urls.{worker.name} found - continuing")
print(f"✓ No PR URLs found for {worker.name} - continuing") return None
return
return { return {
"stakingKey": worker.staking_public_key, "stakingKey": worker.staking_public_key,
"roundNumber": runner.current_round, "roundNumber": runner.get("current_round"),
"githubUsername": worker.env.get("GITHUB_USERNAME"), "githubUsername": worker.env.get("GITHUB_USERNAME"),
"prUrl": round_state.get("pr_urls", {}).get(worker.name), "prUrl": pr_url,
} }
@ -22,7 +22,7 @@ def execute(runner, worker, data):
"""Execute worker task step""" """Execute worker task step"""
if not data: if not data:
return {"success": True, "message": "No PR URL found"} return {"success": True, "message": "No PR URL found"}
url = f"{runner.config.middle_server_url}/summarizer/worker/check-todo" url = f"{runner.get('middle_server_url')}/summarizer/worker/check-todo"
response = requests.post( response = requests.post(
url, url,
json=data, json=data,

View File

@ -8,8 +8,8 @@ def prepare(runner, worker):
"""Prepare data for worker task""" """Prepare data for worker task"""
# Create fetch-todo payload for stakingSignature and publicSignature # Create fetch-todo payload for stakingSignature and publicSignature
payload = { payload = {
"taskId": runner.config.task_id, "taskId": runner.get("task_id"),
"roundNumber": runner.current_round, "roundNumber": runner.get("current_round"),
"action": "fetch-todo", "action": "fetch-todo",
"githubUsername": worker.env.get("GITHUB_USERNAME"), "githubUsername": worker.env.get("GITHUB_USERNAME"),
"stakingKey": worker.staking_public_key, "stakingKey": worker.staking_public_key,
@ -17,8 +17,8 @@ def prepare(runner, worker):
} }
return { return {
"taskId": runner.config.task_id, "taskId": runner.get("task_id"),
"roundNumber": runner.current_round, "roundNumber": runner.get("current_round"),
"stakingKey": worker.staking_public_key, "stakingKey": worker.staking_public_key,
"pubKey": worker.public_key, "pubKey": worker.public_key,
"stakingSignature": create_signature(worker.staking_signing_key, payload), "stakingSignature": create_signature(worker.staking_signing_key, payload),
@ -28,7 +28,7 @@ def prepare(runner, worker):
def execute(runner, worker, data): def execute(runner, worker, data):
"""Execute worker task step""" """Execute worker task step"""
url = f"{runner.config.middle_server_url}/summarizer/worker/fetch-todo" url = f"{runner.get('middle_server_url')}/summarizer/worker/fetch-todo"
response = requests.post( response = requests.post(
url, url,
json={"signature": data["stakingSignature"], "stakingKey": data["stakingKey"]}, json={"signature": data["stakingSignature"], "stakingKey": data["stakingKey"]},
@ -45,10 +45,7 @@ def execute(runner, worker, data):
response.raise_for_status() response.raise_for_status()
if result.get("success"): if result.get("success"):
round_key = str(runner.current_round) repo_url = f"https://github.com/{result['data']['repo_owner']}/{result['data']['repo_name']}"
round_state = runner.state["rounds"].setdefault(round_key, {}) runner.set("repo_url", repo_url, scope="round")
round_state["repo_url"] = (
f"https://github.com/{result['data']['repo_owner']}/{result['data']['repo_name']}"
)
return result return result

View File

@ -3,17 +3,16 @@ from prometheus_test.utils import create_signature
def prepare(runner, worker): def prepare(runner, worker):
round_state = runner.state["rounds"].get(str(runner.current_round), {}) pr_url = runner.get(f"pr_urls.{worker.name}")
if pr_url is None:
if worker.name not in round_state.get("pr_urls", {}): print(f"✓ No pr_urls.{worker.name} found - continuing")
print(f"✓ No PR URL found for {worker.name} - continuing")
return None return None
payload = { payload = {
"taskId": runner.config.task_id, "taskId": runner.get("task_id"),
"action": "add-todo-pr", "action": "add-todo-pr",
"roundNumber": runner.current_round, "roundNumber": runner.get("current_round"),
"prUrl": round_state["pr_urls"][worker.name], "prUrl": pr_url,
"stakingKey": worker.staking_public_key, "stakingKey": worker.staking_public_key,
"pubKey": worker.public_key, "pubKey": worker.public_key,
} }
@ -29,7 +28,7 @@ def execute(runner, worker, data):
if data is None: if data is None:
return {"success": True, "message": "Skipped due to missing PR URL"} return {"success": True, "message": "Skipped due to missing PR URL"}
url = f"{runner.config.middle_server_url}/summarizer/worker/add-todo-pr" url = f"{runner.get('middle_server_url')}/summarizer/worker/add-todo-pr"
response = requests.post( response = requests.post(
url, url,
json={"signature": data["signature"], "stakingKey": data["stakingKey"]}, json={"signature": data["signature"], "stakingKey": data["stakingKey"]},

View File

@ -6,25 +6,21 @@ from prometheus_test.utils import create_signature
def prepare(runner, worker): def prepare(runner, worker):
"""Prepare data for worker submission""" """Prepare data for worker submission"""
# Get the current round's state pr_url = runner.get(f"pr_urls.{worker.name}")
round_state = runner.state.get("rounds", {}).get(str(runner.current_round), {}) if pr_url is None:
pr_urls = round_state.get("pr_urls", {}) print(f"✓ No pr_urls.{worker.name} found - continuing")
if worker.name not in pr_urls:
# Return None to indicate this step should be skipped
print(f"✓ No PR URL found for {worker.name} - continuing")
return None return None
# Get submission data from worker # Get submission data from worker
url = f"{worker.url}/submission/{runner.current_round}" url = f"{worker.url}/submission/{runner.get('current_round')}"
response = requests.get(url) response = requests.get(url)
response.raise_for_status() response.raise_for_status()
submission_data = response.json() submission_data = response.json()
# Create signature for the submission # Create signature for the submission
submitter_payload = { submitter_payload = {
"taskId": runner.config.task_id, "taskId": runner.get("task_id"),
"roundNumber": runner.current_round, "roundNumber": runner.get("current_round"),
"stakingKey": worker.staking_public_key, "stakingKey": worker.staking_public_key,
"pubKey": worker.public_key, "pubKey": worker.public_key,
"action": "audit", "action": "audit",
@ -46,15 +42,7 @@ def execute(runner, worker, data):
return {"success": True, "message": "Skipped due to missing PR URL"} return {"success": True, "message": "Skipped due to missing PR URL"}
# Store submission data in state # Store submission data in state
round_key = str(runner.current_round) runner.set(f"submission_data.{worker.name}", data, scope="round")
round_state = runner.state["rounds"].setdefault(round_key, {})
# Initialize submission_data if not exists
if "submission_data" not in round_state:
round_state["submission_data"] = {}
# Store or update submission data
round_state["submission_data"][worker.name] = data
# Return success result # Return success result
return {"success": True, "data": data} return {"success": True, "data": data}

View File

@ -1,18 +1,34 @@
"""Stage for executing worker tasks.""" """Stage for executing worker tasks."""
import requests import requests
from uuid import uuid4
from prometheus_test.utils import create_signature
def prepare(runner, worker): def prepare(runner, worker):
"""Prepare data for worker task""" """Prepare data for worker task"""
round_state = runner.state["rounds"].get(str(runner.current_round), {}) repo_url = runner.get("repo_url")
if not round_state.get("repo_url"): if repo_url is None:
print(f"✓ No repo url found for {worker.name} - continuing") print("✓ No repo_url found - continuing")
return return None
# Generate UUID for this round
uuid = str(uuid4())
runner.set(f"uuid.{worker.name}", uuid, scope="round")
# Create podcall payload and signature
podcall_payload = {
"taskId": runner.get("task_id"),
"roundNumber": runner.get("current_round"),
"uuid": uuid,
}
podcall_signature = create_signature(worker.staking_signing_key, podcall_payload)
return { return {
"taskId": runner.config.task_id, "task_id": runner.get("task_id"),
"round_number": str(runner.current_round), "round_number": str(runner.get("current_round")),
"repo_url": round_state["repo_url"], "repo_url": repo_url,
"podcall_signature": podcall_signature,
} }
@ -20,7 +36,7 @@ def execute(runner, worker, data):
"""Execute worker task step""" """Execute worker task step"""
if not data: if not data:
return {"success": True, "message": "No repo url found"} return {"success": True, "message": "No repo url found"}
url = f"{worker.url}/worker-task/{runner.current_round}" url = f"{worker.url}/worker-task/{runner.get('current_round')}"
response = requests.post(url, json=data) response = requests.post(url, json=data)
result = response.json() result = response.json()
@ -32,12 +48,9 @@ def execute(runner, worker, data):
return {"success": True, "message": result.get("message")} return {"success": True, "message": result.get("message")}
if result.get("success") and "pr_url" in result["result"]["data"]: if result.get("success") and "pr_url" in result["result"]["data"]:
round_key = str(runner.current_round) # Store PR URL in state
round_state = runner.state["rounds"].setdefault(round_key, {}) runner.set(
f"pr_urls.{worker.name}", result["result"]["data"]["pr_url"], scope="round"
# Initialize pr_urls if not exists )
if "pr_urls" not in round_state:
round_state["pr_urls"] = {}
round_state["pr_urls"][worker.name] = result["result"]["data"]["pr_url"]
return result return result