File size: 15,102 Bytes
cb0011e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 | """Build SWE-DockerLess.jsonl from the repos/ fixed/ newtests/ trees.
For every instance this script really does the work:
1. git-init the base repo and record the commit sha (base_commit);
2. overlay the gold fix, capture ``git diff`` as the patch, restore;
3. overlay the new tests, capture ``git diff --cached`` as the test_patch;
4. materialise a clean checkout, apply test_patch, run pytest -> "before";
5. apply patch, run pytest -> "after";
6. derive FAIL_TO_PASS (fail before, pass after) and PASS_TO_PASS
(pass before, pass after) from the observed outcomes, not from guesses.
Run with: python build_dataset.py
"""
import json
import os
import re
import shutil
import subprocess
import sys
import tempfile
from pathlib import Path
ROOT = Path(__file__).resolve().parent
REPOS = ROOT / "repos"
FIXED = ROOT / "fixed"
NEWTESTS = ROOT / "newtests"
OUT = ROOT / "SWE-DockerLess.jsonl"
STAMP = "2026-10-30T12:00:00+0000"
GIT_ENV = {
"GIT_AUTHOR_NAME": "swedl",
"GIT_AUTHOR_EMAIL": "swedl@example.invalid",
"GIT_COMMITTER_NAME": "swedl",
"GIT_COMMITTER_EMAIL": "swedl@example.invalid",
"GIT_AUTHOR_DATE": STAMP,
"GIT_COMMITTER_DATE": STAMP,
"GIT_CONFIG_NOSYSTEM": "1",
}
GIT_FLAGS = [
"-c", "core.autocrlf=false",
"-c", "core.safecrlf=false",
"-c", "user.name=swedl",
"-c", "user.email=swedl@example.invalid",
"-c", "commit.gpgsign=false",
]
PYTEST_CMD = "python -m pytest -v --tb=no -p no:cacheprovider"
RESULT_RE = re.compile(
r"^(tests/[^\s:]+::[^\s]+)\s+(PASSED|FAILED|ERROR|SKIPPED|XFAIL|XPASS)"
)
INSTANCES = [
{
"instance_id": "swedl__miniconf-1",
"repo": "swedl/miniconf",
"name": "miniconf",
"problem_statement": (
"Config interpolation blows up on reference cycles and expands escaped text.\n\n"
"We use miniconf for service configs that are layered from a shared file plus a\n"
"per-environment overlay. Two problems, both reproducible on main:\n\n"
"1. A cycle anywhere in the mapping crashes with `RecursionError` instead of the\n"
" documented error. `Config({'a': '${b}', 'b': '${a}'})['a']` recurses until the\n"
" interpreter gives up, and the traceback is a thousand frames of `_interpolate`.\n"
" The README says this must raise `CircularReferenceError` with a message naming\n"
" the chain, and we rely on that message in our error reporting.\n\n"
"2. `$$` does not escape. Our TLS config has `cert_subject: \"$${cluster}\"`, meaning\n"
" the literal text `${cluster}` to be handed to a downstream templating tool, but\n"
" miniconf substitutes the cluster name into it. The README's escape rule is not\n"
" implemented at all.\n\n"
"Both bugs live in `Config._resolve` / `Config._interpolate` in\n"
"`miniconf/config.py`. `README.md` section \"Interpolation contract\" is the spec we\n"
"want honoured, including the exact wording of the cycle message and the rule that\n"
"substituted text is never rescanned for references. A cycle that is unrelated to\n"
"the key being read must not affect that read, and `as_dict()` must surface cycles\n"
"like any other read.\n\n"
"The existing suite passes; the escape and cycle behaviour was never covered."
),
},
{
"instance_id": "swedl__ttlcache-1",
"name": "ttlcache",
"repo": "swedl/ttlcache",
"problem_statement": (
"LRU eviction ignores reads, and len() counts entries that already expired.\n\n"
"Our request cache is a `TTLCache(maxsize=N, ttl=...)` and it is evicting the wrong\n"
"keys under load:\n\n"
"1. Reading a key does not protect it. With `maxsize=2`, writing `a`, `b`, reading\n"
" `a`, then writing `c` drops `a` and keeps `b` -- the exact opposite of LRU. The\n"
" same happens when a key is overwritten: the new write keeps the old position\n"
" instead of becoming the most recently used entry.\n\n"
"2. `len(cache)` returns the number of stored rows, including rows whose TTL already\n"
" elapsed. Our metrics dashboard reports a cache that never shrinks even though\n"
" every read says the key is gone.\n\n"
"3. `items()` order does not reflect access order for the same reason.\n\n"
"`README.md` documents the intended contract (sections 2-5): reads and overwrites\n"
"mark an entry most-recently-used, expired entries are purged before eviction\n"
"happens, and `len()` counts live entries only. `ttlcache/cache.py` is the file to\n"
"fix; `ttlcache/clock.py` already gives you a deterministic `FakeClock`.\n\n"
"Be careful that expiry still deletes the entry on read and that `get()` keeps\n"
"returning its default for missing keys."
),
},
{
"instance_id": "swedl__cronlite-1",
"name": "cronlite",
"repo": "swedl/cronlite",
"problem_statement": (
"`5/15` in the minute field only fires once an hour, and day-of-week 7 is rejected.\n\n"
"Two field-parsing bugs, both in `cronlite/fields.py`:\n\n"
"1. A single value followed by a step is treated as a one-element set. `5/15`\n"
" parses to `{5}` instead of `{5, 20, 35, 50}`, so a job scheduled at\n"
" `5/20 * * * *` runs at 00:05, 01:05, 02:05 instead of every twenty minutes\n"
" starting at :05. `*/20` and `1-10/3` are correct -- only the `<value>/<step>`\n"
" form is wrong, because the upper bound collapses to the start value.\n\n"
"2. Sunday cannot be written as 7. `0 12 * * 7` raises\n"
" `ValueError: day_of_week value out of range: 7` at construction time, and so do\n"
" `7`, `1,7` and `6-7`. Standard cron accepts 0-7 for that field with both 0 and 7\n"
" meaning Sunday. The README's \"Day of week\" section asks for the 7 alias to be\n"
" accepted everywhere a value is accepted and collapsed onto 0, so that a parsed\n"
" day-of-week set is always expressed on the 0-6 scale (`6-7` -> `{6, 0}`).\n\n"
"Everything else about the field syntax must keep working, including the existing\n"
"range checks and the descending-range rejection."
),
},
{
"instance_id": "swedl__semverlite-1",
"name": "semverlite",
"repo": "swedl/semverlite",
"problem_statement": (
"Prerelease ordering is lexicographic, and prereleases leak into release ranges.\n\n"
"Two spec violations against semver 2.0.0:\n\n"
"1. Prerelease identifiers are compared as strings. `1.0.0-alpha.2` sorts *after*\n"
" `1.0.0-alpha.10` because `\"2\" > \"1\"`, and `1.0.0-beta.2` sorts after\n"
" `1.0.0-beta.11`. Sorting a release train produces a wrong order. Numeric\n"
" identifiers must compare numerically, a numeric identifier must sort below an\n"
" alphanumeric one, and a shorter prerelease must sort below a longer one that\n"
" shares its prefix.\n\n"
"2. A prerelease satisfies ranges that never opted into prereleases.\n"
" `VersionRange('>=1.0.0').allows(Version.parse('1.0.1-alpha'))` returns True, and\n"
" so does `~1.2.3` with `1.2.4-rc.1`. That makes our upgrade tool offer release\n"
" candidates as if they were final releases. A prerelease may only satisfy a range\n"
" when some clause names a prerelease on the same `major.minor.patch` triple, so\n"
" `>=1.0.0-alpha` does allow `1.0.0-beta` but not `1.0.1-beta`.\n\n"
"`semverlite/version.py` holds precedence, `semverlite/range.py` holds range\n"
"matching; `README.md` states both rules precisely. Build metadata must stay\n"
"ignored for precedence, and equality/hashing must stay consistent with the new\n"
"ordering."
),
},
]
def run(cmd, cwd, check=True):
env = os.environ.copy()
env.update(GIT_ENV)
proc = subprocess.run(
cmd, cwd=str(cwd), capture_output=True, text=True, encoding="utf-8", env=env
)
if check and proc.returncode != 0:
raise RuntimeError(
"command failed (%d): %s\n--- stdout ---\n%s\n--- stderr ---\n%s"
% (proc.returncode, " ".join(cmd), proc.stdout, proc.stderr)
)
return proc
def git(args, cwd, check=True):
return run(["git"] + GIT_FLAGS + args, cwd, check=check)
def overlay(src_root, dst_root):
"""Copy every file under src_root into dst_root, preserving relative paths."""
for path in sorted(src_root.rglob("*")):
if path.is_dir() or ".git" in path.parts:
continue
target = dst_root / path.relative_to(src_root)
target.parent.mkdir(parents=True, exist_ok=True)
shutil.copyfile(path, target)
def read_tree(root):
files = {}
for path in sorted(root.rglob("*")):
if path.is_dir() or ".git" in path.parts:
continue
rel = path.relative_to(root).as_posix()
files[rel] = path.read_text(encoding="utf-8")
return files
def write_tree(files, dest):
for rel, content in files.items():
path = dest / rel
path.parent.mkdir(parents=True, exist_ok=True)
with open(path, "w", encoding="utf-8", newline="\n") as handle:
handle.write(content)
def parse_outcomes(stdout):
outcomes = {}
for raw in stdout.splitlines():
match = RESULT_RE.match(raw.strip())
if match:
outcomes[match.group(1)] = match.group(2)
return outcomes
def run_tests(dest, test_files):
proc = run(
[sys.executable, "-m", "pytest", "-v", "--tb=no", "-p", "no:cacheprovider"]
+ list(test_files),
dest,
check=False,
)
return parse_outcomes(proc.stdout), proc
def build_instance(spec):
name = spec["name"]
repo_dir = REPOS / name
git_dir = repo_dir / ".git"
if git_dir.exists():
shutil.rmtree(git_dir)
git(["init", "-q", "-b", "main"], repo_dir)
git(["add", "-A"], repo_dir)
git(["commit", "-q", "-m", "initial import"], repo_dir)
base_commit = git(["rev-parse", "HEAD"], repo_dir).stdout.strip()
# --- gold patch -------------------------------------------------------
overlay(FIXED / name, repo_dir)
patch = git(["diff", "--no-color", "--no-ext-diff"], repo_dir).stdout
git(["checkout", "--", "."], repo_dir)
if not patch.strip():
raise RuntimeError("%s: gold patch is empty" % name)
# --- test patch -------------------------------------------------------
overlay(NEWTESTS / name, repo_dir)
git(["add", "-A"], repo_dir)
test_patch = git(["diff", "--cached", "--no-color", "--no-ext-diff"], repo_dir).stdout
git(["reset", "-q", "--hard", "HEAD"], repo_dir)
git(["clean", "-qfd"], repo_dir)
if not test_patch.strip():
raise RuntimeError("%s: test patch is empty" % name)
base_files = read_tree(repo_dir)
test_files = sorted(
rel for rel in base_files if rel.startswith("tests/") and rel.endswith(".py")
)
test_files += sorted(
rel
for rel in read_tree(NEWTESTS / name)
if rel.startswith("tests/") and rel.endswith(".py")
)
test_files = sorted(set(test_files))
# --- verify by really running pytest ----------------------------------
with tempfile.TemporaryDirectory(prefix="swedl-") as tmp:
work = Path(tmp) / "work"
work.mkdir()
write_tree(base_files, work)
git(["init", "-q", "-b", "main"], work)
git(["add", "-A"], work)
git(["commit", "-q", "-m", "base"], work)
test_patch_file = Path(tmp) / "test.patch"
test_patch_file.write_text(test_patch, encoding="utf-8", newline="\n")
git(["apply", "--check", str(test_patch_file)], work)
git(["apply", str(test_patch_file)], work)
before, before_proc = run_tests(work, test_files)
patch_file = Path(tmp) / "gold.patch"
patch_file.write_text(patch, encoding="utf-8", newline="\n")
git(["apply", str(patch_file)], work)
after, after_proc = run_tests(work, test_files)
if not before:
raise RuntimeError(
"%s: no test outcomes collected\n%s\n%s"
% (name, before_proc.stdout[-3000:], before_proc.stderr[-2000:])
)
missing = set(before) - set(after)
if missing:
raise RuntimeError("%s: tests disappeared after patch: %s" % (name, sorted(missing)))
f2p = sorted(
test
for test, outcome in before.items()
if outcome in ("FAILED", "ERROR") and after.get(test) == "PASSED"
)
p2p = sorted(
test
for test, outcome in before.items()
if outcome == "PASSED" and after.get(test) == "PASSED"
)
broken = sorted(test for test, outcome in after.items() if outcome != "PASSED")
if broken:
raise RuntimeError("%s: gold patch leaves failures: %s" % (name, broken))
if not f2p:
raise RuntimeError("%s: no FAIL_TO_PASS tests" % name)
if not p2p:
raise RuntimeError("%s: no PASS_TO_PASS tests" % name)
row = {
"instance_id": spec["instance_id"],
"repo": spec["repo"],
"base_commit": base_commit,
"patch": patch,
"test_patch": test_patch,
"problem_statement": spec["problem_statement"],
"hints_text": "",
"created_at": "2026-10-30",
"version": "1.0",
"environment_setup_commit": base_commit,
"FAIL_TO_PASS": json.dumps(f2p),
"PASS_TO_PASS": json.dumps(p2p),
"dockerless": {
"language": "python",
"python_requires": ">=3.9",
"install": [],
"run_from": ".",
"test_cmd": PYTEST_CMD + " {tests}",
"test_files": test_files,
"files": base_files,
},
}
return row, f2p, p2p, len(patch.splitlines())
def main():
rows = []
print("%-22s %5s %5s %7s %8s" % ("instance", "F2P", "P2P", "patch", "tests"))
for spec in INSTANCES:
row, f2p, p2p, patch_lines = build_instance(spec)
rows.append(row)
print(
"%-22s %5d %5d %7d %8d"
% (row["instance_id"], len(f2p), len(p2p), patch_lines, len(row["dockerless"]["test_files"]))
)
for test in f2p:
print(" F2P %s" % test)
with open(OUT, "w", encoding="utf-8", newline="\n") as handle:
for row in rows:
handle.write(json.dumps(row, ensure_ascii=False) + "\n")
size = OUT.stat().st_size
print("\nwrote %s (%d rows, %.1f KiB)" % (OUT.name, len(rows), size / 1024.0))
if __name__ == "__main__":
main()
|