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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: cc-by-4.0
|
| 3 |
+
language:
|
| 4 |
+
- en
|
| 5 |
+
task_categories:
|
| 6 |
+
- text-generation
|
| 7 |
+
tags:
|
| 8 |
+
- code
|
| 9 |
+
- software-engineering
|
| 10 |
+
- test-evolution
|
| 11 |
+
- unit-testing
|
| 12 |
+
- benchmark
|
| 13 |
+
- java
|
| 14 |
+
- coding-agents
|
| 15 |
+
size_categories:
|
| 16 |
+
- n<1K
|
| 17 |
+
pretty_name: TEBench
|
| 18 |
+
configs:
|
| 19 |
+
- config_name: default
|
| 20 |
+
data_files:
|
| 21 |
+
- split: test
|
| 22 |
+
path: data/test.parquet
|
| 23 |
+
---
|
| 24 |
+
|
| 25 |
+
# TEBench: Project-Level Test Evolution Benchmark
|
| 26 |
+
|
| 27 |
+
> **TODO before publishing:** set the final `license:` (see *Licensing*), fill in
|
| 28 |
+
> the BibTeX authors, and add the harness / Docker links.
|
| 29 |
+
|
| 30 |
+
**TEBench** is the first **project-level** benchmark for *test evolution*: given a
|
| 31 |
+
project repository and a commit that changes production code, a system must
|
| 32 |
+
**autonomously** (1) identify which existing tests need to be modified and where
|
| 33 |
+
new tests are needed, and (2) produce the corresponding test patch. Unlike prior
|
| 34 |
+
method-level benchmarks that pre-pair a changed method with its test
|
| 35 |
+
(`⟨m, m', t⟩`), TEBench requires reasoning across the whole project.
|
| 36 |
+
|
| 37 |
+
The benchmark contains **314 task instances from 10 real-world Java/Maven
|
| 38 |
+
projects** in the Defects4J ecosystem, each annotated with one or more of three
|
| 39 |
+
evolution types and accompanied by **developer-written ground-truth test
|
| 40 |
+
patches**.
|
| 41 |
+
|
| 42 |
+
## Evolution Types
|
| 43 |
+
|
| 44 |
+
| Type | Definition |
|
| 45 |
+
|------|------------|
|
| 46 |
+
| **Breaking** | An existing test fails to compile/run after the code change; the developer modifies it to restore correctness. |
|
| 47 |
+
| **Stale** | An existing test still passes after the change but no longer meaningfully validates the new behavior; the developer updates it anyway. |
|
| 48 |
+
| **Missing** | The developer adds a **new** test to cover behavior introduced/exposed by the change. |
|
| 49 |
+
|
| 50 |
+
A task may carry multiple types simultaneously.
|
| 51 |
+
|
| 52 |
+
## The Three-Version Structure
|
| 53 |
+
|
| 54 |
+
Each instance is built around three versions of the project:
|
| 55 |
+
|
| 56 |
+
- **V−1** (`base_commit`) — parent commit, before any change.
|
| 57 |
+
- **V−0.5** — V−1 **plus all non-test changes** from the commit (production code,
|
| 58 |
+
build config, resources), with the **original tests untouched**. This is the
|
| 59 |
+
state given to the system: *the source has moved on, the tests have not.*
|
| 60 |
+
- **V0** (`commit`) — the full commit including the developer's actual test
|
| 61 |
+
changes. This is the **ground truth**.
|
| 62 |
+
|
| 63 |
+
In this dataset:
|
| 64 |
+
|
| 65 |
+
- `source_patch` applies to **V−1** and reconstructs **V−0.5** (the agent's input).
|
| 66 |
+
- `test_patch` is the **gold answer**: the developer's test changes (V−0.5 → V0).
|
| 67 |
+
|
| 68 |
+
Both patches were generated with `git diff --binary --full-index` and are verified
|
| 69 |
+
to apply cleanly to `base_commit` with `git apply` (see `validate_patches.py`):
|
| 70 |
+
**314/314 source patches and 314/314 test patches apply.**
|
| 71 |
+
|
| 72 |
+
## Data Fields
|
| 73 |
+
|
| 74 |
+
| Field | Type | Description |
|
| 75 |
+
|-------|------|-------------|
|
| 76 |
+
| `instance_id` | string | Stable id, `<project>__<short_hash>`. |
|
| 77 |
+
| `project` | string | Project name. |
|
| 78 |
+
| `repo` | string | Upstream GitHub slug (e.g. `apache/commons-lang`). |
|
| 79 |
+
| `base_commit` | string | V−1 commit hash (parent). |
|
| 80 |
+
| `commit` | string | V0 commit hash (ground-truth commit). |
|
| 81 |
+
| `commit_date` | string | V0 commit date. |
|
| 82 |
+
| `commit_message` | string | V0 commit message. |
|
| 83 |
+
| `type` | string | Internal source category (`type 1`/`type 2`). |
|
| 84 |
+
| `difficulty` | string | Curated difficulty label. |
|
| 85 |
+
| `labels` | list[string] | Evolution types: `breaking` / `stale` / `missing`. |
|
| 86 |
+
| `test_change_type` | string | Primary test-change category. |
|
| 87 |
+
| `changed_test_methods` | list[string] | GT modified/added test methods (`Class.method`). |
|
| 88 |
+
| `new_test_files` | list[string] | Test files where GT adds new methods. |
|
| 89 |
+
| `new_test_methods` | string | JSON map `{TestClass: [methods]}` of GT-added methods. |
|
| 90 |
+
| `num_changed_files` | int | Files changed in the commit. |
|
| 91 |
+
| `src_changed_lines` | int | Production lines changed. |
|
| 92 |
+
| `test_changed_lines` | int | Test lines changed. |
|
| 93 |
+
| `source_patch` | string | **V−1 → V−0.5** diff (non-test; given to the system). |
|
| 94 |
+
| `test_patch` | string | **V−0.5 → V0** diff (gold test changes). |
|
| 95 |
+
| `label_reasoning` | string | Rationale for the assigned labels. |
|
| 96 |
+
|
| 97 |
+
There is a single **`test`** split with 314 instances.
|
| 98 |
+
|
| 99 |
+
## Usage
|
| 100 |
+
|
| 101 |
+
```python
|
| 102 |
+
from datasets import load_dataset
|
| 103 |
+
|
| 104 |
+
ds = load_dataset("iSEngLab/TEBench", split="test")
|
| 105 |
+
ex = ds[0]
|
| 106 |
+
print(ex["instance_id"], ex["labels"])
|
| 107 |
+
```
|
| 108 |
+
|
| 109 |
+
Reconstruct the agent input (V−0.5) for an instance:
|
| 110 |
+
|
| 111 |
+
```bash
|
| 112 |
+
git clone https://github.com/<repo>.git && cd <repo>
|
| 113 |
+
git checkout <base_commit>
|
| 114 |
+
git apply source.patch # now at V-0.5: new source, old tests
|
| 115 |
+
# ... system produces test changes ...
|
| 116 |
+
git apply test.patch # gold V0 test changes, for reference/eval
|
| 117 |
+
```
|
| 118 |
+
|
| 119 |
+
## Evaluation
|
| 120 |
+
|
| 121 |
+
TEBench evaluates two dimensions (full harness and Docker image referenced below):
|
| 122 |
+
|
| 123 |
+
- **Identification** — Precision / Recall / F1 of the test methods the system
|
| 124 |
+
modifies/adds vs. the ground truth. Modified/deleted tests are matched at
|
| 125 |
+
**method** granularity; newly added tests at **file** granularity.
|
| 126 |
+
- **Update** — a composite of **executability** (compiles & passes),
|
| 127 |
+
**coverage overlap** with GT on the changed production methods (line + branch),
|
| 128 |
+
and **modification similarity** (token Jaccard vs. GT). Executability gates the
|
| 129 |
+
score: non-compiling updates score 0.
|
| 130 |
+
|
| 131 |
+
## Dataset Statistics
|
| 132 |
+
|
| 133 |
+
| Project | Tasks | Breaking | Stale | Missing |
|
| 134 |
+
|---------|------:|---------:|------:|--------:|
|
| 135 |
+
| commons-cli | 18 | 8 | 12 | 9 |
|
| 136 |
+
| commons-codec | 19 | 12 | 11 | 12 |
|
| 137 |
+
| commons-collections | 23 | 10 | 14 | 15 |
|
| 138 |
+
| commons-compress | 86 | 34 | 58 | 53 |
|
| 139 |
+
| commons-csv | 31 | 22 | 18 | 16 |
|
| 140 |
+
| commons-lang | 69 | 28 | 46 | 40 |
|
| 141 |
+
| commons-math | 8 | 8 | 3 | 2 |
|
| 142 |
+
| gson | 1 | 1 | 0 | 1 |
|
| 143 |
+
| jfreechart | 3 | 1 | 3 | 1 |
|
| 144 |
+
| jsoup | 56 | 48 | 42 | 50 |
|
| 145 |
+
| **Total** | **314** | **172** | **207** | **199** |
|
| 146 |
+
|
| 147 |
+
- **Multi-label:** 219 tasks (69.7%) carry ≥2 types; 45 (14.3%) carry all three;
|
| 148 |
+
95 (30.3%) are single-type.
|
| 149 |
+
- **Complexity (median):** 4 changed files, 34 source lines, ~32 test lines changed.
|
| 150 |
+
|
| 151 |
+
## Construction
|
| 152 |
+
|
| 153 |
+
Built via a four-stage filtering pipeline over the Defects4J ecosystem:
|
| 154 |
+
67,670 commits (14 Maven projects) → static filtering (post-2019, co-modification
|
| 155 |
+
of `src/main` and `src/test`, real method-body changes) → 6,169 → execution-based
|
| 156 |
+
validation (isolated worktrees, Maven Surefire + JaCoCo) → 561 → quality filtering
|
| 157 |
+
(no merges, 5–200 test lines changed, method-level dedup) → **314 instances / 10
|
| 158 |
+
projects**.
|
| 159 |
+
|
| 160 |
+
## Companion Artifacts
|
| 161 |
+
|
| 162 |
+
- **Evaluation harness:** *(GitHub repo — TODO link)* — identification & update
|
| 163 |
+
scoring, baselines.
|
| 164 |
+
- **Reproducible environment:** a Docker image bundling all 10 projects, Maven
|
| 165 |
+
3.6.3, JDK 8/11/17, and the evaluated agents. *(registry — TODO link)*
|
| 166 |
+
|
| 167 |
+
## Licensing
|
| 168 |
+
|
| 169 |
+
- **Annotations / patches metadata in this dataset:** CC-BY-4.0 *(proposed — confirm)*.
|
| 170 |
+
- **Embedded source code** inside `source_patch` / `test_patch` remains under the
|
| 171 |
+
**original license of each upstream project** and must be used accordingly:
|
| 172 |
+
|
| 173 |
+
| Project(s) | License |
|
| 174 |
+
|------------|---------|
|
| 175 |
+
| commons-* (cli, codec, collections, compress, csv, lang, math), gson | Apache-2.0 |
|
| 176 |
+
| jsoup | MIT |
|
| 177 |
+
| jfreechart | LGPL-2.1 *(verify before redistribution)* |
|
| 178 |
+
|
| 179 |
+
Attribution to the original authors is preserved through commit hashes and the
|
| 180 |
+
`repo` field. Redistribution of the Docker image (which contains full source
|
| 181 |
+
trees) must likewise honor these licenses.
|
| 182 |
+
|
| 183 |
+
## Citation
|
| 184 |
+
|
| 185 |
+
```bibtex
|
| 186 |
+
@inproceedings{tebench,
|
| 187 |
+
title = {TEBench: Benchmarking LLM Agents on Project-Level Test Evolution},
|
| 188 |
+
author = {TODO},
|
| 189 |
+
booktitle = {TODO},
|
| 190 |
+
year = {2026}
|
| 191 |
+
}
|
| 192 |
+
```
|
build_dataset.py
ADDED
|
@@ -0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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Export TEBench into a self-contained, SWE-bench-style HuggingFace dataset.
|
| 3 |
+
|
| 4 |
+
Reads the existing task spine and label table plus the local git repositories,
|
| 5 |
+
and materializes one parquet file where every one of the 314 task instances
|
| 6 |
+
carries its own ``source_patch`` (V-1 -> V-0.5, the production/non-test delta
|
| 7 |
+
already applied for the agent) and ``test_patch`` (V-0.5 -> V0, the developer
|
| 8 |
+
ground-truth test changes). Nothing under the existing TEBench tree is modified;
|
| 9 |
+
all output lands in this ``hf_release/`` directory.
|
| 10 |
+
"""
|
| 11 |
+
|
| 12 |
+
import argparse
|
| 13 |
+
import json
|
| 14 |
+
import subprocess
|
| 15 |
+
import sys
|
| 16 |
+
from pathlib import Path
|
| 17 |
+
|
| 18 |
+
import pandas as pd
|
| 19 |
+
import pyarrow as pa
|
| 20 |
+
import pyarrow.parquet as pq
|
| 21 |
+
|
| 22 |
+
# Repo dir -> canonical upstream GitHub slug (for the ``repo`` field).
|
| 23 |
+
REPO_SLUG = {
|
| 24 |
+
"commons-cli": "apache/commons-cli",
|
| 25 |
+
"commons-codec": "apache/commons-codec",
|
| 26 |
+
"commons-collections": "apache/commons-collections",
|
| 27 |
+
"commons-compress": "apache/commons-compress",
|
| 28 |
+
"commons-csv": "apache/commons-csv",
|
| 29 |
+
"commons-lang": "apache/commons-lang",
|
| 30 |
+
"commons-math": "apache/commons-math",
|
| 31 |
+
"gson": "google/gson",
|
| 32 |
+
"jfreechart": "jfree/jfreechart",
|
| 33 |
+
"jsoup": "jhy/jsoup",
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
# new_labels token -> canonical evolution type.
|
| 37 |
+
LABEL_MAP = {
|
| 38 |
+
"test_breaking": "breaking",
|
| 39 |
+
"test_stale": "stale",
|
| 40 |
+
"test_missing": "missing",
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
HERE = Path(__file__).resolve().parent
|
| 44 |
+
TEBENCH = HERE.parent
|
| 45 |
+
TESTUPDATE = TEBENCH.parent
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
def git(repo: Path, *args: str) -> str:
|
| 49 |
+
"""Run a git command in ``repo`` and return stdout.
|
| 50 |
+
|
| 51 |
+
Captured as bytes and decoded without newline translation so that CRLF
|
| 52 |
+
line endings in patches (some repos store files with CRLF) are preserved
|
| 53 |
+
verbatim; otherwise the emitted patch would no longer apply to the blob.
|
| 54 |
+
"""
|
| 55 |
+
out = subprocess.run(
|
| 56 |
+
["git", "-C", str(repo), "--no-pager", *args], capture_output=True,
|
| 57 |
+
)
|
| 58 |
+
if out.returncode != 0:
|
| 59 |
+
raise RuntimeError(
|
| 60 |
+
f"git {' '.join(args)} failed in {repo}: {out.stderr.decode('utf-8', 'replace').strip()}")
|
| 61 |
+
return out.stdout.decode("utf-8", "replace")
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
def is_test_file(path: str) -> bool:
|
| 65 |
+
return "/src/test/" in path or path.startswith("src/test/")
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
def split_patch(repo: Path, base: str, head: str):
|
| 69 |
+
"""Return (source_patch, test_patch, n_src_files, n_test_files)."""
|
| 70 |
+
names = [p for p in git(repo, "diff", "--name-only", base, head).splitlines() if p]
|
| 71 |
+
test_files = [p for p in names if is_test_file(p)]
|
| 72 |
+
src_files = [p for p in names if not is_test_file(p)]
|
| 73 |
+
|
| 74 |
+
def diff(files):
|
| 75 |
+
if not files:
|
| 76 |
+
return ""
|
| 77 |
+
# --binary --full-index keep binary hunks and full blob hashes so the
|
| 78 |
+
# patch applies standalone with `git apply` (no repo objects needed).
|
| 79 |
+
return git(repo, "diff", "--no-color", "--no-ext-diff",
|
| 80 |
+
"--binary", "--full-index", base, head, "--", *files)
|
| 81 |
+
|
| 82 |
+
return diff(src_files), diff(test_files), len(src_files), len(test_files)
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
def to_list(cell) -> list:
|
| 86 |
+
if cell is None or (isinstance(cell, float) and pd.isna(cell)):
|
| 87 |
+
return []
|
| 88 |
+
return [x.strip() for x in str(cell).split("|") if x.strip()]
|
| 89 |
+
|
| 90 |
+
|
| 91 |
+
def load_labels(labels_csv: Path) -> dict:
|
| 92 |
+
"""Map (project, short_hash) -> {labels, reasoning, new_test_methods, new_test_files}."""
|
| 93 |
+
df = pd.read_csv(labels_csv, dtype=str).fillna("")
|
| 94 |
+
out = {}
|
| 95 |
+
for _, r in df.iterrows():
|
| 96 |
+
key = (r["project"], r["v_0_commit"])
|
| 97 |
+
labels = [LABEL_MAP[t] for t in to_list(r.get("new_labels")) if t in LABEL_MAP]
|
| 98 |
+
out[key] = {
|
| 99 |
+
"labels": labels,
|
| 100 |
+
"label_reasoning": r.get("reasoning", ""),
|
| 101 |
+
"new_test_methods": r.get("new_test_methods", ""),
|
| 102 |
+
"new_test_files": to_list(r.get("new_test_files")),
|
| 103 |
+
}
|
| 104 |
+
return out
|
| 105 |
+
|
| 106 |
+
|
| 107 |
+
SCHEMA = pa.schema([
|
| 108 |
+
("instance_id", pa.string()),
|
| 109 |
+
("project", pa.string()),
|
| 110 |
+
("repo", pa.string()),
|
| 111 |
+
("base_commit", pa.string()), # V-1 (parent)
|
| 112 |
+
("commit", pa.string()), # V0 (ground-truth commit)
|
| 113 |
+
("commit_date", pa.string()),
|
| 114 |
+
("commit_message", pa.string()),
|
| 115 |
+
("type", pa.string()),
|
| 116 |
+
("difficulty", pa.string()),
|
| 117 |
+
("labels", pa.list_(pa.string())), # breaking / stale / missing
|
| 118 |
+
("test_change_type", pa.string()),
|
| 119 |
+
("changed_test_methods", pa.list_(pa.string())),
|
| 120 |
+
("new_test_files", pa.list_(pa.string())),
|
| 121 |
+
("new_test_methods", pa.string()), # JSON blob from source table
|
| 122 |
+
("num_changed_files", pa.int64()),
|
| 123 |
+
("src_changed_lines", pa.int64()),
|
| 124 |
+
("test_changed_lines", pa.int64()),
|
| 125 |
+
("source_patch", pa.string()), # V-1 -> V-0.5 (non-test, given to agent)
|
| 126 |
+
("test_patch", pa.string()), # V-0.5 -> V0 (gold test changes)
|
| 127 |
+
("label_reasoning", pa.string()),
|
| 128 |
+
])
|
| 129 |
+
|
| 130 |
+
|
| 131 |
+
def main():
|
| 132 |
+
ap = argparse.ArgumentParser(description=__doc__)
|
| 133 |
+
ap.add_argument("--spine", type=Path,
|
| 134 |
+
default=TEBENCH / "data" / "filtered_commits_step2_full.csv")
|
| 135 |
+
ap.add_argument("--labels", type=Path,
|
| 136 |
+
default=TESTUPDATE / "classification_results_v2.csv")
|
| 137 |
+
ap.add_argument("--repos", type=Path,
|
| 138 |
+
default=TESTUPDATE / "TUDataset" / "defects4j-projects")
|
| 139 |
+
ap.add_argument("--out", type=Path, default=HERE / "data" / "test.parquet")
|
| 140 |
+
args = ap.parse_args()
|
| 141 |
+
|
| 142 |
+
spine = pd.read_excel(args.spine, engine="openpyxl")
|
| 143 |
+
labels = load_labels(args.labels)
|
| 144 |
+
print(f"spine rows={len(spine)} label rows={len(labels)}")
|
| 145 |
+
|
| 146 |
+
records, errors, missing_labels = [], [], 0
|
| 147 |
+
for i, row in enumerate(spine.itertuples(index=False), 1):
|
| 148 |
+
project = row.Project
|
| 149 |
+
short = str(row.CommitID)
|
| 150 |
+
full = str(row.FullHash)
|
| 151 |
+
repo = args.repos / project
|
| 152 |
+
try:
|
| 153 |
+
base = git(repo, "rev-parse", "--verify", f"{full}^").strip()
|
| 154 |
+
msg = git(repo, "log", "-1", "--format=%B", full).strip()
|
| 155 |
+
src_patch, test_patch, n_src, n_test = split_patch(repo, base, full)
|
| 156 |
+
except Exception as e: # noqa: BLE001
|
| 157 |
+
errors.append(f"{project}/{short}: {e}")
|
| 158 |
+
continue
|
| 159 |
+
|
| 160 |
+
lab = labels.get((project, short))
|
| 161 |
+
if lab is None:
|
| 162 |
+
missing_labels += 1
|
| 163 |
+
lab = {"labels": [], "label_reasoning": "", "new_test_methods": "", "new_test_files": []}
|
| 164 |
+
|
| 165 |
+
records.append({
|
| 166 |
+
"instance_id": f"{project}__{short}",
|
| 167 |
+
"project": project,
|
| 168 |
+
"repo": REPO_SLUG.get(project, project),
|
| 169 |
+
"base_commit": base,
|
| 170 |
+
"commit": full,
|
| 171 |
+
"commit_date": str(row.Date),
|
| 172 |
+
"commit_message": msg,
|
| 173 |
+
"type": str(row.Type),
|
| 174 |
+
"difficulty": str(row.Difficulty),
|
| 175 |
+
"labels": lab["labels"],
|
| 176 |
+
"test_change_type": str(row.TestChangeType),
|
| 177 |
+
"changed_test_methods": to_list(row.ChangedTestMethods),
|
| 178 |
+
"new_test_files": lab["new_test_files"],
|
| 179 |
+
"new_test_methods": lab["new_test_methods"],
|
| 180 |
+
"num_changed_files": int(row.ChangedFiles),
|
| 181 |
+
"src_changed_lines": int(row.SrcChangedLines),
|
| 182 |
+
"test_changed_lines": int(row.TestChangedLines),
|
| 183 |
+
"source_patch": src_patch,
|
| 184 |
+
"test_patch": test_patch,
|
| 185 |
+
"label_reasoning": lab["label_reasoning"],
|
| 186 |
+
})
|
| 187 |
+
if i % 50 == 0:
|
| 188 |
+
print(f" ...{i}/{len(spine)}")
|
| 189 |
+
|
| 190 |
+
args.out.parent.mkdir(parents=True, exist_ok=True)
|
| 191 |
+
table = pa.Table.from_pylist(records, schema=SCHEMA)
|
| 192 |
+
pq.write_table(table, args.out)
|
| 193 |
+
|
| 194 |
+
# ---- validation summary ----
|
| 195 |
+
b = sum("breaking" in r["labels"] for r in records)
|
| 196 |
+
s = sum("stale" in r["labels"] for r in records)
|
| 197 |
+
m = sum("missing" in r["labels"] for r in records)
|
| 198 |
+
empty_src = sum(not r["source_patch"] for r in records)
|
| 199 |
+
empty_test = sum(not r["test_patch"] for r in records)
|
| 200 |
+
print("\n==== summary ====")
|
| 201 |
+
print(f"instances written : {len(records)}")
|
| 202 |
+
print(f"errors : {len(errors)}")
|
| 203 |
+
print(f"missing labels : {missing_labels}")
|
| 204 |
+
print(f"labels B/S/M : {b}/{s}/{m} (paper: 172/207/199)")
|
| 205 |
+
print(f"empty source_patch: {empty_src}")
|
| 206 |
+
print(f"empty test_patch : {empty_test}")
|
| 207 |
+
print(f"written to : {args.out}")
|
| 208 |
+
if errors:
|
| 209 |
+
print("\nfirst errors:")
|
| 210 |
+
for e in errors[:10]:
|
| 211 |
+
print(" ", e)
|
| 212 |
+
|
| 213 |
+
|
| 214 |
+
if __name__ == "__main__":
|
| 215 |
+
sys.exit(main())
|
data/test.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:bfd6fbe724bd7a56f6c32fe7f8c1f91603528e6d9dc4d075657f62833a190434
|
| 3 |
+
size 5204033
|
validate_patches.py
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Check that every instance's source_patch + test_patch apply cleanly.
|
| 3 |
+
|
| 4 |
+
For each task we create an isolated detached worktree at ``base_commit``, apply
|
| 5 |
+
``source_patch`` (recreating V-0.5), then apply ``test_patch`` (the gold V0 test
|
| 6 |
+
changes). Failures are reported per instance. Requires the local repos under
|
| 7 |
+
``defects4j-projects``; only used for verification, not for dataset consumption.
|
| 8 |
+
"""
|
| 9 |
+
import argparse, os, shutil, subprocess, tempfile
|
| 10 |
+
from pathlib import Path
|
| 11 |
+
import pandas as pd
|
| 12 |
+
|
| 13 |
+
HERE = Path(__file__).resolve().parent
|
| 14 |
+
REPOS = HERE.parent.parent / "TUDataset" / "defects4j-projects"
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
def apply_check(wt, patch):
|
| 18 |
+
if not patch.strip():
|
| 19 |
+
return True, ""
|
| 20 |
+
p = subprocess.run(["git", "-C", wt, "-c", "core.autocrlf=false",
|
| 21 |
+
"apply", "--check", "-"],
|
| 22 |
+
input=patch, text=True, capture_output=True)
|
| 23 |
+
return p.returncode == 0, p.stderr.strip()
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
def apply(wt, patch):
|
| 27 |
+
if not patch.strip():
|
| 28 |
+
return
|
| 29 |
+
subprocess.run(["git", "-C", wt, "-c", "core.autocrlf=false", "apply", "-"],
|
| 30 |
+
input=patch, text=True, capture_output=True)
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
def main():
|
| 34 |
+
ap = argparse.ArgumentParser()
|
| 35 |
+
ap.add_argument("--parquet", type=Path, default=HERE / "data" / "test.parquet")
|
| 36 |
+
ap.add_argument("--repos", type=Path, default=REPOS)
|
| 37 |
+
ap.add_argument("--limit", type=int, default=0, help="0 = all")
|
| 38 |
+
args = ap.parse_args()
|
| 39 |
+
|
| 40 |
+
df = pd.read_parquet(args.parquet)
|
| 41 |
+
if args.limit:
|
| 42 |
+
df = df.head(args.limit)
|
| 43 |
+
|
| 44 |
+
ok_src = ok_test = 0
|
| 45 |
+
fails = []
|
| 46 |
+
for n, (_, r) in enumerate(df.iterrows(), 1):
|
| 47 |
+
repo = args.repos / r["project"]
|
| 48 |
+
wt = tempfile.mkdtemp(prefix="teb_wt_")
|
| 49 |
+
try:
|
| 50 |
+
subprocess.run(["git", "-C", str(repo), "worktree", "add", "-q",
|
| 51 |
+
"--detach", wt, r["base_commit"]], capture_output=True)
|
| 52 |
+
s_ok, s_err = apply_check(wt, r["source_patch"])
|
| 53 |
+
if s_ok:
|
| 54 |
+
ok_src += 1
|
| 55 |
+
apply(wt, r["source_patch"])
|
| 56 |
+
t_ok, t_err = apply_check(wt, r["test_patch"])
|
| 57 |
+
else:
|
| 58 |
+
t_ok, t_err = False, "(source failed first)"
|
| 59 |
+
if t_ok:
|
| 60 |
+
ok_test += 1
|
| 61 |
+
if not (s_ok and t_ok):
|
| 62 |
+
fails.append((r["instance_id"], s_ok, t_ok,
|
| 63 |
+
(s_err or t_err).splitlines()[-1][:120] if (s_err or t_err) else ""))
|
| 64 |
+
finally:
|
| 65 |
+
subprocess.run(["git", "-C", str(repo), "worktree", "remove",
|
| 66 |
+
"--force", wt], capture_output=True)
|
| 67 |
+
shutil.rmtree(wt, ignore_errors=True)
|
| 68 |
+
if n % 50 == 0:
|
| 69 |
+
print(f" ...{n}/{len(df)}")
|
| 70 |
+
|
| 71 |
+
print(f"\nsource_patch apply ok: {ok_src}/{len(df)}")
|
| 72 |
+
print(f"test_patch apply ok: {ok_test}/{len(df)}")
|
| 73 |
+
if fails:
|
| 74 |
+
print(f"\n{len(fails)} failures:")
|
| 75 |
+
for iid, s, t, msg in fails:
|
| 76 |
+
print(f" {iid:34s} src={s} test={t} {msg}")
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
if __name__ == "__main__":
|
| 80 |
+
main()
|