Skip to content
Projetos

Sobre

Review benchmark for model-generated code patches: six tasks across Python, JavaScript, Go and Java with hidden tests, a fixed rubric and a Docker runner.

Sistemas e infraestrutura

Como estes números são medidos

Crescimento medido de estrelas

em 24 h
-1
em 7 dias
-1
em 15 dias
Coletando histórico
em 1 mês
Coletando histórico

Variações líquidas em períodos sobrepostos, não totais diários. Medições ausentes ficam em branco. Estrelas indicam interesse, não qualidade.

README.md

Original

code-review-bench

crbench is a small, self-contained benchmark for reviewing model-generated code patches. Each task provides a compact base repository, a candidate diff, and a hidden test suite. A reviewer reads the task spec and the diff, then reports defects as JSON. crbench grade matches those findings against the task's reference findings and applies a fixed rubric. crbench validate proves the planted defects are real: the hidden tests fail on the patched tree and pass on the unpatched base.

The benchmark measures review coverage on these six tasks. It does not measure general model quality, coding ability, or the quality of a reviewer on other codebases.

Tasks

Task Language Planted defect
py-mutable-default Python A mutable default dictionary shares index state across calls.
py-boundary-check Python An off-by-one end bound drops the final row of a page.
ts-missing-await JavaScript A missing await turns an unknown-token check into an authentication bypass.
go-ignored-error Go Discarded write errors make a truncated export look successful.
java-resource-leak Java A reader opened during config loading is never closed.
py-sql-injection Python A username is interpolated into SQL instead of bound as a parameter.

Python tasks use pytest hidden tests, the Node task uses node --test, the Go task uses go test, and the Java task uses a single-file javac/java check.

Why review benchmarks are hard

A review benchmark is not just a set of diffs with opinions attached. The defects have to be real, the reviewer has to be able to find them from the material provided, and the scoring has to survive different wording.

  • Planted defects need proof. A diff can look wrong without being wrong. Every expected finding here names a hidden test that fails on the patched tree. crbench validate checks the counterfactual by reverting the patch and running the same suite.
  • Small diffs hide the signal. The candidate patches are 5-25 lines. The useful review often depends on a boundary, an ownership rule, or an async control-flow detail outside the changed lines, so a reviewer has to read the base code rather than pattern-match on the diff.
  • Free-form reviews need stable matching. Two reviewers can describe the same defect in different words. The matcher uses file, category, a line tolerance, and concept keywords; the rubric makes those rules explicit so a score is reproducible.
  • Severity is part of the task. Calling every issue a blocker is easy and unhelpful. The rubric separates security bypasses and cross-call corruption from localized wrong output, resource leaks, and style.
  • Review artifacts are untrusted input. Patches, comments, test names, and task text can contain instructions or insecure suggestions. The red-team checklist documents the expected behavior.

Quick start

Requires Python 3.10 or newer. The CLI uses only the standard library; the dev extra adds pytest and ruff.

uv venv --python 3.12 .venv
uv pip install --python .venv/bin/python -e '.[dev]'

.venv/bin/python -m pytest -q
.venv/bin/ruff check .
.venv/bin/python -m crbench list

Example task listing:

TASK                LANGUAGE  FINDINGS  REQUIRED
------------------  --------  --------  --------
go-ignored-error    go        1         1
java-resource-leak  java      1         1
py-boundary-check   python    1         1
py-mutable-default  python    1         1
py-sql-injection    python    1         1
ts-missing-await    node      1         1

Assign a review:

.venv/bin/python -m crbench show py-mutable-default
.venv/bin/python -m crbench grade \
  --task py-mutable-default \
  --findings tasks/py-mutable-default/reference_review.md

The reference review scores 100:

Task: py-mutable-default
Submitted findings: 1

Findings:
  ID                     REQ  EXPECTED       RESULT    SUBMITTED
  mutable-default-index  yes  blocker / bug  matched   inventory.py:20 (blocker)

Score: 100/100 (Excellent)
  Required coverage: 70.0/70  (1/1)
  Precision:         20.0/20  (0 false blocker(s), 0 other unmatched)
  Severity:          10.0/10  (1/1 exact)

The full CLI surface:

Command Purpose
crbench list Table of task ids, languages, and finding counts.
crbench show <task> Print task.md followed by patch.diff.
crbench validate [--task ID ...] [--keep] Apply each patch, run its hidden tests, revert, and run them again.
crbench grade --task ID --findings FILE Parse findings and print the per-finding table, score, and band.

--keep preserves the temporary work directory and prints its path. Repeated --task flags select several tasks; omitting them selects all six.

Task format

tasks/<id>/
  task.md                 repository context, model task, review instructions
  patch.diff              candidate diff in unified format
  base/                   small repository before the candidate change
  hidden_tests/           tests that fail on the patched tree, pass on base
  expected_findings.json  1-3 reference findings with evidence
  reference_review.md     example review covering every required finding
  task.json               harness metadata (language, hidden tests, main class)

Each expected finding has:

  • id, a stable name;
  • file and line in the patched tree (grading accepts plus or minus three);
  • category and severity;
  • required, which controls coverage points;
  • summary and keywords, used to match submitted wording;
  • evidence, naming the hidden test that fails on the patched code.

The patch must apply cleanly with git apply; the runner falls back to patch -p1 when git is unavailable. Hidden tests are copied into the temporary root next to the base files. The harness looks for the tasks directory under ./tasks, the repository root, or the path named by CRBENCH_TASKS.

The JSON a reviewer submits is:

{
  "findings": [
    {
      "file": "inventory.py",
      "line": 20,
      "category": "bug",
      "severity": "blocker",
      "summary": "One sentence describing the defect.",
      "why": "One or two sentences explaining the failure and impact."
    }
  ]
}

Findings may be a bare JSON document or a JSON fence inside Markdown. Categories are bug, security, performance, style, and test-gap. Severities are blocker, major, minor, and nit.

Grading

The score is built from three parts:

  • Coverage (70 points). Fraction of required expected findings matched.
  • Precision / no false blockers (20 points). Starts at 20. Each unmatched submitted blocker costs 10 points; each other unmatched submitted finding costs 2. The component floors at zero.
  • Severity (10 points). Fraction of matched findings whose severity exactly matches the reference severity.

A submitted finding is eligible to match an expected finding when the file path agrees after normalization, the category is identical, the line is within three lines, and at least one third of the expected keywords appear in its summary and why. Eligible pairs are assigned greedily by keyword overlap and then by line distance, one-to-one.

Bands: 90-100 Excellent, 75-89 Solid, 60-74 Partial, 40-59 Weak, 0-39 Inadequate. See rubric.md for category definitions, severity definitions, and band anchors.

Reference reviews are not special-cased. Every reference review in this repository is scored by the same parser and matcher as a submitted review.

Validation

.venv/bin/python -m crbench validate \
  --task py-mutable-default \
  --task py-boundary-check \
  --task py-sql-injection
PASS py-mutable-default (python): patched code fails the hidden tests; base code passes
PASS py-boundary-check (python): patched code fails the hidden tests; base code passes
PASS py-sql-injection (python): patched code fails the hidden tests; base code passes

Summary: 3 passed, 0 skipped, 0 failed

For each task, validate copies base/ into a temporary directory, copies the hidden tests, applies patch.diff, runs the language-specific test command, and expects a non-zero exit. It then reverses the patch and expects a zero exit on the base. A task fails validation when the patched suite passes, the base suite fails, or the patch cannot be applied or reverted.

If a toolchain is missing, the task is skipped with a message such as toolchain not found: go or toolchain not found: javac. Skips do not fail the run. Python validation needs pytest, which is in the dev extra; the Docker image installs it as well.

Full validation of all six tasks therefore needs Python with pytest, Node, Go, and javac plus java. In an environment without Go or a JDK, the run is:

SKIP go-ignored-error (go): toolchain not found: go
SKIP java-resource-leak (java): toolchain not found: javac
PASS py-boundary-check (python): patched code fails the hidden tests; base code passes
PASS py-mutable-default (python): patched code fails the hidden tests; base code passes
PASS py-sql-injection (python): patched code fails the hidden tests; base code passes
PASS ts-missing-await (node): patched code fails the hidden tests; base code passes

Summary: 4 passed, 2 skipped, 0 failed

Inside the Docker image, where Go and the JDK are installed, the same command covers all six:

PASS go-ignored-error (go): patched code fails the hidden tests; base code passes
PASS java-resource-leak (java): patched code fails the hidden tests; base code passes
PASS py-boundary-check (python): patched code fails the hidden tests; base code passes
PASS py-mutable-default (python): patched code fails the hidden tests; base code passes
PASS py-sql-injection (python): patched code fails the hidden tests; base code passes
PASS ts-missing-await (node): patched code fails the hidden tests; base code passes

Summary: 6 passed, 0 skipped, 0 failed

Validation runs task code in a temporary directory, not in a sandbox. Only run tasks you trust. Use the Docker image for cross-language runs or for a disposable environment.

Docker

The image starts from the Python 3.12 slim Bookworm image and installs Node.js, Go, the JDK 17, git, and patch from apt. It installs the package editable together with pytest, then uses python -m crbench as the entrypoint.

docker compose build
docker compose run --rm crbench validate

docker-compose.yml already passes validate as the command, so docker compose up --build runs the same full validation. The image is intended for validation, not for serving untrusted tasks.

Adding a task

  1. Create tasks/<new-id>/base/ with a small, self-contained repository. Keep the base correct and runnable.
  2. Write patch.diff against that base in unified format. Keep it deterministic and small. Apply it once by hand to confirm the line numbers.
  3. Write hidden_tests/ that fail on the patched code and pass on the base.
  4. Write expected_findings.json with 1-3 findings. Point evidence at the hidden test that proves each defect. Mark only findings that a complete review should contain as required.
  5. Write task.md with repository context, the task the model was given, and the submission schema. Write reference_review.md with a finding for every required defect and a one-sentence rationale.
  6. Add task.json with the language and hidden test entry points. Java tasks also need main_class.
  7. Run crbench validate --task <new-id> and crbench grade --task <new-id> --findings tasks/<new-id>/reference_review.md. The second command must score 100.

The task id must be lowercase words separated by single hyphens. Paths in hidden_tests are relative to that directory; the harness rejects absolute paths and ...

Limitations

  • Six small synthetic tasks with one required finding each. They exercise specific review skills; they are not a representative sample of code review, and scores here should not be presented as general model quality.
  • Expected findings and hidden tests are part of this repository. A reviewer with filesystem access can read the answers. For an honest holdout run, give the reviewer only task.md, patch.diff, and base/, then score outside their environment.
  • Matching is heuristic. A correct finding can lose points if it uses different keywords, a different category, or a line outside the tolerance. Category is exact by design; the rubric gives priority rules.
  • Severity is a judgment call. The taxonomy is explicit, but reasonable reviewers can still disagree at the margin.
  • Hidden tests prove the named defects. They do not prove that the diff is otherwise correct, and they are not a substitute for a full test suite.
  • The Java check verifies the injected reader's close flag. It does not inspect operating-system file descriptors.
  • CI runs pytest, ruff, and validation of the three Python tasks only. The Node, Go, and Java tasks are validated through the Docker image or a local run with those toolchains installed.

License

MIT. See LICENSE.

Explore projetos relacionados

Carregando…