Spaces:
Runtime error
Runtime error
Commit ·
a4ea2be
1
Parent(s): db7afce
testing changes
Browse files- .dockerignore +16 -1
- __init__.py +7 -0
- tests/test_multi_domain_platform.py +52 -0
.dockerignore
CHANGED
|
@@ -5,16 +5,31 @@
|
|
| 5 |
!client.py
|
| 6 |
!compat.py
|
| 7 |
!inference.py
|
| 8 |
-
!
|
| 9 |
!openenv.yaml
|
| 10 |
!pyproject.toml
|
| 11 |
!DEMO_SCRIPT.md
|
|
|
|
| 12 |
!triage.py
|
| 13 |
!triage_catalog.py
|
| 14 |
!triage_models.py
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
!server/
|
| 16 |
!server/**
|
|
|
|
|
|
|
| 17 |
!tasks/
|
| 18 |
!tasks/**
|
|
|
|
|
|
|
| 19 |
!graders/
|
| 20 |
!graders/**
|
|
|
|
| 5 |
!client.py
|
| 6 |
!compat.py
|
| 7 |
!inference.py
|
| 8 |
+
!openenv_models.py
|
| 9 |
!openenv.yaml
|
| 10 |
!pyproject.toml
|
| 11 |
!DEMO_SCRIPT.md
|
| 12 |
+
!launch.py
|
| 13 |
!triage.py
|
| 14 |
!triage_catalog.py
|
| 15 |
!triage_models.py
|
| 16 |
+
!api/
|
| 17 |
+
!api/**
|
| 18 |
+
!app/
|
| 19 |
+
!app/**
|
| 20 |
+
!analyzers/
|
| 21 |
+
!analyzers/**
|
| 22 |
+
!models/
|
| 23 |
+
!models/**
|
| 24 |
+
!schemas/
|
| 25 |
+
!schemas/**
|
| 26 |
!server/
|
| 27 |
!server/**
|
| 28 |
+
!services/
|
| 29 |
+
!services/**
|
| 30 |
!tasks/
|
| 31 |
!tasks/**
|
| 32 |
+
!utils/
|
| 33 |
+
!utils/**
|
| 34 |
!graders/
|
| 35 |
!graders/**
|
__init__.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
"""Public package exports for python_code_review_env."""
|
| 2 |
|
| 3 |
from .client import PythonCodeReviewEnv, PythonEnv
|
|
|
|
| 4 |
from .openenv_models import (
|
| 5 |
PythonAction,
|
| 6 |
PythonCodeReviewAction,
|
|
@@ -9,6 +10,8 @@ from .openenv_models import (
|
|
| 9 |
PythonObservation,
|
| 10 |
PythonState,
|
| 11 |
)
|
|
|
|
|
|
|
| 12 |
from .triage import CodeTriageEngine, HashingEmbeddingBackend, TransformersEmbeddingBackend, get_default_engine
|
| 13 |
from .triage_models import TriageResult
|
| 14 |
|
|
@@ -21,8 +24,12 @@ __all__ = [
|
|
| 21 |
"PythonCodeReviewState",
|
| 22 |
"PythonCodeReviewEnv",
|
| 23 |
"PythonEnv",
|
|
|
|
|
|
|
|
|
|
| 24 |
"CodeTriageEngine",
|
| 25 |
"HashingEmbeddingBackend",
|
|
|
|
| 26 |
"TransformersEmbeddingBackend",
|
| 27 |
"TriageResult",
|
| 28 |
"get_default_engine",
|
|
|
|
| 1 |
"""Public package exports for python_code_review_env."""
|
| 2 |
|
| 3 |
from .client import PythonCodeReviewEnv, PythonEnv
|
| 4 |
+
from .models import PyTorchCodeAnalyzerModel
|
| 5 |
from .openenv_models import (
|
| 6 |
PythonAction,
|
| 7 |
PythonCodeReviewAction,
|
|
|
|
| 10 |
PythonObservation,
|
| 11 |
PythonState,
|
| 12 |
)
|
| 13 |
+
from .schemas import AnalyzeCodeRequest, AnalyzeCodeResponse
|
| 14 |
+
from .services import AnalysisService
|
| 15 |
from .triage import CodeTriageEngine, HashingEmbeddingBackend, TransformersEmbeddingBackend, get_default_engine
|
| 16 |
from .triage_models import TriageResult
|
| 17 |
|
|
|
|
| 24 |
"PythonCodeReviewState",
|
| 25 |
"PythonCodeReviewEnv",
|
| 26 |
"PythonEnv",
|
| 27 |
+
"AnalyzeCodeRequest",
|
| 28 |
+
"AnalyzeCodeResponse",
|
| 29 |
+
"AnalysisService",
|
| 30 |
"CodeTriageEngine",
|
| 31 |
"HashingEmbeddingBackend",
|
| 32 |
+
"PyTorchCodeAnalyzerModel",
|
| 33 |
"TransformersEmbeddingBackend",
|
| 34 |
"TriageResult",
|
| 35 |
"get_default_engine",
|
tests/test_multi_domain_platform.py
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
from fastapi.testclient import TestClient
|
| 4 |
+
|
| 5 |
+
from api.main import app
|
| 6 |
+
from schemas.request import AnalyzeCodeRequest
|
| 7 |
+
from services.analysis_service import AnalysisService
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def test_analysis_service_detects_web_code() -> None:
|
| 11 |
+
service = AnalysisService()
|
| 12 |
+
request = AnalyzeCodeRequest(
|
| 13 |
+
code="from fastapi import FastAPI\napp = FastAPI()\n\n@app.get('/health')\ndef health():\n return {'status': 'ok'}\n",
|
| 14 |
+
domain_hint="auto",
|
| 15 |
+
)
|
| 16 |
+
|
| 17 |
+
result = service.analyze(request)
|
| 18 |
+
|
| 19 |
+
assert result.detected_domain == "web"
|
| 20 |
+
assert 0.0 <= result.score_breakdown.reward <= 1.0
|
| 21 |
+
assert len(result.improvement_plan) == 3
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
def test_analysis_service_detects_dsa_code() -> None:
|
| 25 |
+
service = AnalysisService()
|
| 26 |
+
request = AnalyzeCodeRequest(
|
| 27 |
+
code="def has_pair(nums, target):\n for i in range(len(nums)):\n for j in range(i + 1, len(nums)):\n if nums[i] + nums[j] == target:\n return True\n return False\n",
|
| 28 |
+
domain_hint="auto",
|
| 29 |
+
)
|
| 30 |
+
|
| 31 |
+
result = service.analyze(request)
|
| 32 |
+
|
| 33 |
+
assert result.detected_domain == "dsa"
|
| 34 |
+
assert result.static_analysis.time_complexity in {"O(n^2)", "O(n^3)"}
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
def test_api_analyze_endpoint_returns_valid_payload() -> None:
|
| 38 |
+
client = TestClient(app)
|
| 39 |
+
response = client.post(
|
| 40 |
+
"/analyze",
|
| 41 |
+
json={
|
| 42 |
+
"code": "import torch\n\ndef predict(model, x):\n return model(x)\n",
|
| 43 |
+
"context_window": "Inference helper for a classifier",
|
| 44 |
+
"traceback_text": "",
|
| 45 |
+
"domain_hint": "auto",
|
| 46 |
+
},
|
| 47 |
+
)
|
| 48 |
+
|
| 49 |
+
assert response.status_code == 200
|
| 50 |
+
payload = response.json()
|
| 51 |
+
assert "detected_domain" in payload
|
| 52 |
+
assert "score_breakdown" in payload
|