| |
| """Validate generated cve-bench-nova-coding v2 repositories.""" |
|
|
| from __future__ import annotations |
|
|
| import json |
| import sys |
| from pathlib import Path |
|
|
|
|
| ROOT = Path(__file__).resolve().parents[1] |
| IGNORED_DIRS = {"node_modules", "playwright-report", "test-results", "__pycache__"} |
| FORBIDDEN_TEXT = [ |
| "cvebench_prompt", |
| "target:9091", |
| "/api/done", |
| "proof_uploading_url", |
| "Exploit CVE", |
| ] |
|
|
|
|
| def fail(message: str) -> None: |
| print(f"ERROR: {message}", file=sys.stderr) |
| raise SystemExit(1) |
|
|
|
|
| def read_json(path: Path) -> dict: |
| return json.loads(path.read_text(encoding="utf-8")) |
|
|
|
|
| def validate() -> None: |
| manifest_path = ROOT / "manifest.json" |
| if not manifest_path.exists(): |
| fail("manifest.json is missing; run generate_coding_v2_repos.py first") |
|
|
| manifest = read_json(manifest_path) |
| repos = manifest.get("repos", []) |
| if manifest.get("format") != "cve-bench-nova-coding-v2": |
| fail("unexpected manifest format") |
| if len(repos) != 10: |
| fail(f"expected 10 repos, found {len(repos)}") |
| if manifest.get("task_count") != 100: |
| fail(f"expected 100 tasks, found {manifest.get('task_count')}") |
| if manifest.get("intentional_vulnerabilities") is not False: |
| fail("intentional_vulnerabilities must be false") |
|
|
| all_text_paths: list[Path] = [] |
| for repo_info in repos: |
| repo = Path(repo_info["path"]) |
| if not repo.exists(): |
| fail(f"repo path missing: {repo}") |
|
|
| package = read_json(repo / "package.json") |
| if package["devDependencies"].get("@playwright/test") != "1.58.2": |
| fail(f"{repo.name} must pin @playwright/test to 1.58.2") |
| frontend_package = read_json(repo / "src/frontend/package.json") |
| for section_name in ("dependencies", "devDependencies"): |
| for dependency, version in frontend_package.get(section_name, {}).items(): |
| if version == "latest" or version.startswith(("^", "~", ">=", "<=", ">", "<", "*")): |
| fail(f"{repo.name} frontend dependency {dependency} must be pinned, found {version!r}") |
|
|
| task_files = sorted((repo / "tasks").glob("*.json")) |
| if len(task_files) != 10: |
| fail(f"{repo.name} expected 10 task files, found {len(task_files)}") |
|
|
| public_specs = sorted((repo / "tests/public").glob("*.spec.ts")) |
| if len(public_specs) != 11: |
| fail(f"{repo.name} expected 10 public task specs plus base.spec.ts, found {len(public_specs)}") |
|
|
| private_specs = sorted((repo / "evaluation/private-test-cases").glob("*.private.spec.ts")) |
| security_specs = sorted((repo / "evaluation/security-test-cases").glob("*.security.spec.ts")) |
| if len(private_specs) != 10: |
| fail(f"{repo.name} expected 10 private specs, found {len(private_specs)}") |
| if len(security_specs) != 10: |
| fail(f"{repo.name} expected 10 security specs, found {len(security_specs)}") |
| for spec_path in [*public_specs, *private_specs, *security_specs]: |
| spec_text = spec_path.read_text(encoding="utf-8") |
| if "test(" in spec_text and "import { test, expect } from '@playwright/test';" not in spec_text: |
| fail(f"{spec_path} uses test() without importing test from @playwright/test") |
|
|
| scope = read_json(repo / "evaluation/security_scope.json") |
| if scope.get("intentional_vulnerabilities") is not False: |
| fail(f"{repo.name} security_scope must set intentional_vulnerabilities=false") |
|
|
| for task_path in task_files: |
| task = read_json(task_path) |
| for key in ("task_id", "difficulty", "description", "acceptance_criteria", "test_case_location", "private_test_case_location", "security_case_location", "complexity_vectors"): |
| if key not in task: |
| fail(f"{task_path} missing {key}") |
| if task["difficulty"] not in {"easy", "medium", "hard"}: |
| fail(f"{task_path} has invalid difficulty") |
| if "Exploit" in task["description"] or "CVE" in task["description"]: |
| fail(f"{task_path} still looks like an attack task") |
|
|
| for path in repo.rglob("*"): |
| if IGNORED_DIRS.intersection(path.parts): |
| continue |
| if path.is_file() and path.suffix in {".json", ".md", ".ts", ".tsx", ".py", ".yml", ".yaml", ".conf", ".sh"}: |
| all_text_paths.append(path) |
|
|
| for path in [manifest_path, ROOT / "README.md", *all_text_paths]: |
| text = path.read_text(encoding="utf-8", errors="ignore") |
| for forbidden in FORBIDDEN_TEXT: |
| if forbidden in text: |
| fail(f"forbidden legacy attack text {forbidden!r} found in {path}") |
|
|
| print("cve-bench-nova-coding-v2 validation passed") |
|
|
|
|
| if __name__ == "__main__": |
| validate() |
|
|