coderMayank69 commited on
Commit
5d46764
·
1 Parent(s): 88c262b

debugged the task validation error

Browse files
app/__pycache__/main.cpython-313.pyc CHANGED
Binary files a/app/__pycache__/main.cpython-313.pyc and b/app/__pycache__/main.cpython-313.pyc differ
 
app/main.py CHANGED
@@ -1,7 +1,8 @@
 
1
  from typing import Any
2
 
3
  from fastapi import FastAPI, HTTPException
4
- from fastapi.responses import PlainTextResponse
5
 
6
  from app.env import AICodeReviewEnvironment
7
  from app.models import (
@@ -16,6 +17,10 @@ from app.models import (
16
  )
17
  from app.tasks import TASKS
18
 
 
 
 
 
19
  app = FastAPI(
20
  title="Synapse Code Auditor",
21
  description="OpenEnv-compatible environment for deterministic AI code review evaluation.",
@@ -50,16 +55,52 @@ def metadata() -> dict[str, Any]:
50
  "tasks": [
51
  {
52
  "task_id": task.id,
53
- "task_type": task.task_type,
54
  "has_grader": True,
55
  "grader_enabled": True,
56
  "criteria_count": len(task.criteria),
57
  }
58
  for task in TASKS.values()
59
  ],
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60
  }
61
 
62
 
 
 
 
 
 
 
 
 
 
 
 
 
63
  @app.get("/schema")
64
  def schema() -> dict[str, Any]:
65
  return {
 
1
+ from pathlib import Path
2
  from typing import Any
3
 
4
  from fastapi import FastAPI, HTTPException
5
+ from fastapi.responses import FileResponse, PlainTextResponse
6
 
7
  from app.env import AICodeReviewEnvironment
8
  from app.models import (
 
17
  )
18
  from app.tasks import TASKS
19
 
20
+ # Repo root (contains openenv.yaml) — /app in Docker, project dir locally.
21
+ _ENV_ROOT = Path(__file__).resolve().parent.parent
22
+ _OPENENV_PATH = _ENV_ROOT / "openenv.yaml"
23
+
24
  app = FastAPI(
25
  title="Synapse Code Auditor",
26
  description="OpenEnv-compatible environment for deterministic AI code review evaluation.",
 
55
  "tasks": [
56
  {
57
  "task_id": task.id,
58
+ "task_type": task.task_type.value,
59
  "has_grader": True,
60
  "grader_enabled": True,
61
  "criteria_count": len(task.criteria),
62
  }
63
  for task in TASKS.values()
64
  ],
65
+ "grading": {
66
+ "type": "automated",
67
+ "deterministic": True,
68
+ "tasks_with_graders": len(TASKS),
69
+ },
70
+ }
71
+
72
+
73
+ @app.get("/tasks")
74
+ def list_tasks() -> dict[str, Any]:
75
+ """Task catalog with grader flags (used by hub validators and OpenEnv clients)."""
76
+ return {
77
+ "task_count": len(TASKS),
78
+ "tasks": [
79
+ {
80
+ "task_id": task.id,
81
+ "task_type": task.task_type.value,
82
+ "title": task.title,
83
+ "has_grader": True,
84
+ "grader": {"type": "deterministic", "enabled": True},
85
+ "score_range": {"min_exclusive": 0.0, "max_exclusive": 1.0},
86
+ }
87
+ for task in TASKS.values()
88
+ ],
89
  }
90
 
91
 
92
+ @app.get("/openenv.yaml")
93
+ def openenv_manifest() -> FileResponse:
94
+ """Serve the OpenEnv manifest so validators can read it from the running Space."""
95
+ if not _OPENENV_PATH.is_file():
96
+ raise HTTPException(status_code=404, detail="openenv.yaml not found in environment root")
97
+ return FileResponse(
98
+ _OPENENV_PATH,
99
+ media_type="application/yaml",
100
+ filename="openenv.yaml",
101
+ )
102
+
103
+
104
  @app.get("/schema")
105
  def schema() -> dict[str, Any]:
106
  return {
openenv.yaml CHANGED
@@ -1,4 +1,5 @@
1
  spec_version: 1
 
2
  name: synapse_code_auditor
3
  type: space
4
  runtime: fastapi
@@ -15,20 +16,32 @@ tasks:
15
  difficulty: easy
16
  max_steps: 1
17
  grader: true
 
18
  score_range: [0.01, 0.99]
19
  - id: medium
20
  name: Suggest optimization
21
  difficulty: medium
22
  max_steps: 1
23
  grader: true
 
24
  score_range: [0.01, 0.99]
25
  - id: hard
26
  name: Full code review with scoring
27
  difficulty: hard
28
  max_steps: 1
29
  grader: true
 
30
  score_range: [0.01, 0.99]
31
 
 
 
 
 
 
 
 
 
 
32
  # Top-level graders (some validators scan for this key and `task:` aliases).
33
  graders:
34
  - task: easy
 
1
  spec_version: 1
2
+ version: "1.0.0"
3
  name: synapse_code_auditor
4
  type: space
5
  runtime: fastapi
 
16
  difficulty: easy
17
  max_steps: 1
18
  grader: true
19
+ has_grader: true
20
  score_range: [0.01, 0.99]
21
  - id: medium
22
  name: Suggest optimization
23
  difficulty: medium
24
  max_steps: 1
25
  grader: true
26
+ has_grader: true
27
  score_range: [0.01, 0.99]
28
  - id: hard
29
  name: Full code review with scoring
30
  difficulty: hard
31
  max_steps: 1
32
  grader: true
33
+ has_grader: true
34
  score_range: [0.01, 0.99]
35
 
36
+ endpoints:
37
+ health: GET /health
38
+ metadata: GET /metadata
39
+ tasks: GET /tasks
40
+ manifest: GET /openenv.yaml
41
+ reset: POST /reset
42
+ step: POST /step
43
+ state: GET /state
44
+
45
  # Top-level graders (some validators scan for this key and `task:` aliases).
46
  graders:
47
  - task: easy
validate_submission.py CHANGED
@@ -34,7 +34,10 @@ def _check_openenv_yaml(path: Path) -> None:
34
  raise AssertionError("openenv.yaml must include a tasks: list with at least 3 entries")
35
 
36
  tasks_with_grader = sum(
37
- 1 for t in tasks if isinstance(t, dict) and t.get("grader") is True
 
 
 
38
  )
39
  grading = data.get("grading")
40
  nested_graders: list = []
@@ -69,6 +72,28 @@ def _check_metadata_graders() -> None:
69
  assert graded >= 3, "metadata must expose at least 3 tasks with graders enabled"
70
 
71
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
72
  def _check_api_contracts() -> None:
73
  client = TestClient(app)
74
 
@@ -93,6 +118,9 @@ def _check_api_contracts() -> None:
93
  },
94
  )
95
  assert step.status_code == 200, f"/step returned {step.status_code}"
 
 
 
96
 
97
  state = client.get("/state")
98
  assert state.status_code == 200, f"/state returned {state.status_code}"
@@ -174,6 +202,7 @@ def main() -> None:
174
 
175
  _check_openenv_yaml(root / "openenv.yaml")
176
  _check_metadata_graders()
 
177
  _check_api_contracts()
178
  _check_tasks_and_graders()
179
  _check_inference_script(root / "inference.py")
 
34
  raise AssertionError("openenv.yaml must include a tasks: list with at least 3 entries")
35
 
36
  tasks_with_grader = sum(
37
+ 1
38
+ for t in tasks
39
+ if isinstance(t, dict)
40
+ and (t.get("grader") is True or t.get("has_grader") is True)
41
  )
42
  grading = data.get("grading")
43
  nested_graders: list = []
 
72
  assert graded >= 3, "metadata must expose at least 3 tasks with graders enabled"
73
 
74
 
75
+ def _check_tasks_endpoint() -> None:
76
+ client = TestClient(app)
77
+ response = client.get("/tasks")
78
+ assert response.status_code == 200, f"/tasks returned {response.status_code}"
79
+ payload = response.json()
80
+ task_list = payload.get("tasks")
81
+ assert isinstance(task_list, list) and len(task_list) >= 3, "/tasks must list at least 3 tasks"
82
+ n = sum(
83
+ 1
84
+ for t in task_list
85
+ if isinstance(t, dict)
86
+ and t.get("has_grader") is True
87
+ and isinstance(t.get("grader"), dict)
88
+ and t["grader"].get("enabled") is True
89
+ )
90
+ assert n >= 3, "/tasks must declare enabled deterministic graders for at least 3 tasks"
91
+
92
+ manifest = client.get("/openenv.yaml")
93
+ assert manifest.status_code == 200, f"/openenv.yaml returned {manifest.status_code}"
94
+ assert b"has_grader:" in manifest.content or b"grader:" in manifest.content
95
+
96
+
97
  def _check_api_contracts() -> None:
98
  client = TestClient(app)
99
 
 
118
  },
119
  )
120
  assert step.status_code == 200, f"/step returned {step.status_code}"
121
+ reward = step.json().get("reward") or {}
122
+ score = float(reward.get("score", -1.0))
123
+ assert 0.0 < score < 1.0, f"/step reward score must be strictly in (0, 1), got {reward.get('score')}"
124
 
125
  state = client.get("/state")
126
  assert state.status_code == 200, f"/state returned {state.status_code}"
 
202
 
203
  _check_openenv_yaml(root / "openenv.yaml")
204
  _check_metadata_graders()
205
+ _check_tasks_endpoint()
206
  _check_api_contracts()
207
  _check_tasks_and_graders()
208
  _check_inference_script(root / "inference.py")