Skip to content

v0.7: equivalence_tests + cve_patches - #10

Merged
adithya-s-k merged 1 commit into
mainfrom
feat/equivalence-tests
May 12, 2026
Merged

v0.7: equivalence_tests + cve_patches#10
adithya-s-k merged 1 commit into
mainfrom
feat/equivalence-tests

Conversation

@adithya-s-k

Copy link
Copy Markdown
Collaborator

Closes #9.

Summary

Two new pipelines + bump 0.6.0 → 0.7.0:

  • equivalence_tests (R2E-style function-level synthesis, ICML '24). Extract a real Python function from the repo as a frozen oracle (reference_<name>), LLM writes equivalence tests comparing it against a <name> candidate, gold patch fills <name> with the original implementation. The LLM only writes the test — we already have the ground truth. Lower-variance than code_instruct; yield scales with the number of qualifying functions.
  • cve_patches (PatchSeeker / CVE-Bench-inspired). OSV public API client (POST /v1/query, no auth needed) → scan references[] for github.com/<owner>/<repo>/commit/<sha> → fetch the fix commit's diff → reuse pr_runtime's F2P/P2P validation harness when test_patch is present, emit-only with validation_status="no_test_patch" otherwise.

Harbor end-to-end

Pipeline Repo Task Mean reward
equivalence_tests pallets/click pallets__click-eqv-a2804cc5 (getchar) 1.000
cve_patches pallets/werkzeug pallets__werkzeug-cve-CVE-2023-25577 (DoS via multipart) 1.000

CI

  • 339/339 unit tests pass
  • ruff lint + format clean
  • Matrix tested on Python 3.12 / 3.13 / 3.14

New files

  • src/repo2rlenv/osv.py — OSV API client + severity helpers (stdlib only)
  • src/repo2rlenv/pipelines/_function_extractor.py — R2E-style AST filters
  • src/repo2rlenv/pipelines/equivalence_tests.py — pipeline class
  • src/repo2rlenv/pipelines/cve_patches.py — pipeline class
  • Tests: test_osv.py, test_function_extractor.py, test_pipeline_{equivalence_tests,cve_patches}.py (~80 new tests)

Notable design decisions

  1. Reference-oracle test pattern. task_module.py ships both reference_<name> (frozen, used by tests) and <name> (stubbed in env, filled by patch). LLM-written tests assert equality. Catches "tautological test" cheats via the Stage-A invariant (test must FAIL when <name> is stubbed).
  2. OSV over NVD. OSV pre-resolves fix-commit URLs in references[], so we don't need a PatchSeeker-style LLM mapper for the common case. No auth required.
  3. No new runtime deps. Both pipelines are pure stdlib + reuse existing pr_runtime helpers (split_patch_and_test_patch, build_environment_dockerfile, build_eval_script, validate_pr).
  4. CVE tasks without test_patch are still emitted with validation_status="no_test_patch". The verifier signal is weak (just "suite passes with fix applied") but the data is useful as training pairs.

Out of scope (v0.8)

  • LLM-judged QA gate (SWE-Bench++ four-layer recipe)
  • Iterative refinement loop for equivalence_tests (R2E's "feedback → fix_error" cycle)
  • LLM-synthesized PoC for cve_patches (security implications gating needed)
  • Polyglot mutation for mutation_bugs (Java/JS/Go via tree-sitter)
  • HF Hub append-mode for pr_stream

🤖 Generated with Claude Code

Closes #9. Adds two new pipelines and bumps 0.6.0 -> 0.7.0.

equivalence_tests (R2E-style, ICML '24):
- Extract module-level Python functions from the target repo using AST
  filters (LOC range, has args + explicit return, no obvious side effects,
  exclude dunder/test/main/private names)
- Single LLM call generates a pytest test importing BOTH `<name>` and
  `reference_<name>` from `task_module`, asserting equality across ≥5
  diverse inputs
- Two-stage in-sandbox verification: stub-must-fail, oracle-must-pass
- Emit a Harbor task whose gold patch adds task_module.py (with
  reference_<name> and <name> set to the original) + a test_r2e_<hash>.py
- Different from code_instruct: seeds are real functions, not LLM-invented
  problems; the LLM only writes the test
- Harbor-verified Mean reward 1.000 on pallets/click

cve_patches (PatchSeeker/CVE-Bench-inspired):
- OSV public API client (no auth, stdlib-only) — POST /v1/query
- For each vuln, scan references[] for github.com/<owner>/<repo>/commit/<sha>
- Fetch commit diff via `gh api`, split into source/test patches
- When test_patch present: full F2P/P2P validation (reuses pr_runtime harness)
- When test_patch absent: emit anyway with validation_status="no_test_patch"
  (still useful as training data; verifier signal is weaker)
- Emit Harbor task with CVE description as instruction, fix diff as oracle
- Severity filter (low/medium/moderate/high/critical) + ecosystem auto-detect
- Harbor-verified Mean reward 1.000 on pallets/werkzeug (CVE-2023-25577)

339 unit tests pass; ruff lint + format clean.

Plans:
- plans/equivalence_tests_plan.md
- (cve_patches: in-flight extension to v0.7; plan was scoped down to MVP)

Files:
- src/repo2rlenv/osv.py (105 LOC) — OSV API client + severity helpers
- src/repo2rlenv/pipelines/_function_extractor.py (216 LOC) — R2E-style filters
- src/repo2rlenv/pipelines/equivalence_tests.py (395 LOC) — pipeline class
- src/repo2rlenv/pipelines/cve_patches.py (294 LOC) — pipeline class
- src/repo2rlenv/github.py: fetch_commit_diff + fetch_commit_parent helpers

Out of scope (v0.8):
- LLM-judged QA gate (SWE-Bench++ four-layer recipe)
- Iterative refinement loop for equivalence_tests
- LLM-synthesized PoC for cve_patches (no public PoC + no test_patch case)
- Polyglot mutation (Java/JS/Go via tree-sitter)
@adithya-s-k
adithya-s-k merged commit 1046987 into main May 12, 2026
5 checks passed
@adithya-s-k
adithya-s-k deleted the feat/equivalence-tests branch May 12, 2026 06:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

v0.7: equivalence_tests pipeline (R2E-style function-level synthesis)

1 participant