|
| 1 | +"""Minimal end-to-end episode runner for the deployed code review environment.""" |
| 2 | + |
| 3 | +from __future__ import annotations |
| 4 | + |
| 5 | +import asyncio |
| 6 | +import os |
| 7 | + |
| 8 | +try: |
| 9 | + from code_review_env import CodeReviewAction, CodeReviewEnv, ReviewFinding |
| 10 | +except ImportError: # pragma: no cover |
| 11 | + from client import CodeReviewEnv |
| 12 | + from models import CodeReviewAction, ReviewFinding |
| 13 | + |
| 14 | + |
| 15 | +DEFAULT_BASE_URL = "https://rohan556-openenv-code-review-arena.hf.space" |
| 16 | + |
| 17 | + |
| 18 | +async def main() -> None: |
| 19 | + base_url = os.getenv("CODE_REVIEW_ENV_URL", DEFAULT_BASE_URL) |
| 20 | + |
| 21 | + async with CodeReviewEnv(base_url=base_url) as env: |
| 22 | + result = await env.reset(task_id="sql_injection_report_filters") |
| 23 | + print(f"task={result.observation.task_id}") |
| 24 | + print(f"pr={result.observation.pr_title}") |
| 25 | + |
| 26 | + await env.step( |
| 27 | + CodeReviewAction( |
| 28 | + action_type="inspect_file", |
| 29 | + file_path="analytics/reporting.py", |
| 30 | + view_mode="full", |
| 31 | + start_line=1, |
| 32 | + end_line=80, |
| 33 | + ) |
| 34 | + ) |
| 35 | + |
| 36 | + graded = await env.step( |
| 37 | + CodeReviewAction( |
| 38 | + action_type="submit_review", |
| 39 | + findings=[ |
| 40 | + ReviewFinding( |
| 41 | + file_path="analytics/reporting.py", |
| 42 | + line_start=9, |
| 43 | + line_end=15, |
| 44 | + severity="critical", |
| 45 | + category="sql_injection", |
| 46 | + title="Unsafe string interpolation in SQL report query", |
| 47 | + explanation=( |
| 48 | + "customer_id and period are interpolated directly into raw SQL " |
| 49 | + "instead of being passed as bound parameters, so an attacker can " |
| 50 | + "inject arbitrary predicates or SQL fragments." |
| 51 | + ), |
| 52 | + confidence=0.98, |
| 53 | + ) |
| 54 | + ], |
| 55 | + ) |
| 56 | + ) |
| 57 | + |
| 58 | + scorecard = graded.observation.scorecard |
| 59 | + print(f"done={graded.done}") |
| 60 | + if scorecard is None: |
| 61 | + raise RuntimeError("Expected a scorecard after submit_review") |
| 62 | + print(f"score={scorecard.overall_score}") |
| 63 | + print(f"grade_band={scorecard.grade_band}") |
| 64 | + print(scorecard.summary) |
| 65 | + |
| 66 | + |
| 67 | +if __name__ == "__main__": |
| 68 | + asyncio.run(main()) |
0 commit comments