|
4 | 4 | from typing import Union, cast, Optional
|
5 | 5 |
|
6 | 6 | from commit0.harness.constants import (
|
| 7 | + ABSOLUTE_REPO_DIR, |
| 8 | + RELATIVE_REPO_DIR, |
7 | 9 | RepoInstance,
|
8 | 10 | SimpleInstance,
|
9 | 11 | )
|
|
17 | 19 | class Spec(ABC):
|
18 | 20 | """A dataclass that represents a test specification for a single instance of SWE-bench."""
|
19 | 21 |
|
| 22 | + absolute: bool |
20 | 23 | repo: str
|
21 | 24 | # repo dir on docker
|
22 | 25 | repo_directory: str
|
@@ -164,11 +167,12 @@ def make_repo_script_list(self) -> list[str]:
|
164 | 167 |
|
165 | 168 | def make_eval_script_list(self) -> list[str]:
|
166 | 169 | """Run the tests."""
|
| 170 | + diff_path = "/patch.diff" if self.absolute else "../patch.diff" |
167 | 171 | eval_script_list = [
|
168 | 172 | f"cd {self.repo_directory}",
|
169 | 173 | "source .venv/bin/activate",
|
170 | 174 | f"git reset --hard {self.instance['base_commit']}",
|
171 |
| - "git apply --allow-empty -v /patch.diff", |
| 175 | + f"git apply --allow-empty -v {diff_path}", |
172 | 176 | "git status",
|
173 | 177 | f"{self.instance['test']['test_cmd']} --json-report --json-report-file=report.json --continue-on-collection-errors{{coverage}} {{test_ids}} > test_output.txt 2>&1",
|
174 | 178 | "echo $? > pytest_exit_code.txt",
|
@@ -306,39 +310,45 @@ def make_eval_script_list(self) -> list[str]:
|
306 | 310 | def get_specs_from_dataset(
|
307 | 311 | dataset: Union[list[Union[RepoInstance, SimpleInstance]], list[Spec]],
|
308 | 312 | dataset_type: str,
|
| 313 | + absolute: bool, |
309 | 314 | ) -> list[Spec]:
|
310 | 315 | """Idempotent function that converts a list of RepoInstance objects to a list of Spec objects."""
|
311 | 316 | if isinstance(dataset[0], Spec):
|
312 | 317 | return cast(list[Spec], dataset)
|
313 | 318 | return list(
|
314 | 319 | map(
|
315 |
| - lambda instance: make_spec(instance, dataset_type), |
| 320 | + lambda instance: make_spec(instance, dataset_type, absolute), |
316 | 321 | cast(list["RepoInstance"], dataset),
|
317 | 322 | )
|
318 | 323 | )
|
319 | 324 |
|
320 | 325 |
|
321 |
| -def make_spec(instance: Union[RepoInstance, SimpleInstance], dataset_type: str) -> Spec: |
| 326 | +def make_spec( |
| 327 | + instance: Union[RepoInstance, SimpleInstance], dataset_type: str, absolute: bool |
| 328 | +) -> Spec: |
| 329 | + repo_directory = ABSOLUTE_REPO_DIR if absolute else RELATIVE_REPO_DIR |
322 | 330 | if isinstance(instance, Spec):
|
323 | 331 | return instance
|
324 |
| - repo_directory = "/testbed" |
325 | 332 | if dataset_type == "commit0":
|
326 | 333 | return Commit0Spec(
|
327 | 334 | repo=instance["instance_id"],
|
328 | 335 | repo_directory=repo_directory,
|
329 | 336 | instance=instance,
|
| 337 | + absolute=absolute, |
330 | 338 | )
|
331 | 339 | elif dataset_type == "swebench":
|
332 | 340 | return SWEBenchSpec(
|
333 | 341 | repo=instance["instance_id"],
|
334 | 342 | repo_directory=repo_directory,
|
335 | 343 | instance=instance,
|
| 344 | + absolute=absolute, |
336 | 345 | )
|
337 | 346 | elif dataset_type == "simple":
|
338 | 347 | return SimpleSpec(
|
339 | 348 | repo="simple", # all benchmarks with mere function writing will share the simple docker image
|
340 | 349 | repo_directory=repo_directory,
|
341 | 350 | instance=instance,
|
| 351 | + absolute=absolute, |
342 | 352 | )
|
343 | 353 | else:
|
344 | 354 | raise NotImplementedError(
|
|
0 commit comments