Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 18 additions & 9 deletions src/websitebench/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,25 +102,34 @@ def run_download(args: argparse.Namespace, index: dict, harbor: str | None) -> i
args.parser.error(f"not in the release: {', '.join(unknown)}")

staging_parent = args.output.parent if args.output.parent.exists() else None
installed, failed = [], []
with tempfile.TemporaryDirectory(
prefix=".websitebench-download-", dir=staging_parent
) as tmp:
staging = Path(tmp)
try:
if args.source == "hf":
fetched = fetch_hf(index, tasks, staging, args.revision)
for name in tasks:
try:
if args.source == "hf":
fetched = fetch_hf(index, [name], staging, args.revision)
else:
fetched = fetch_hub(index, [name], staging)
install(index, [name], fetched, args.output, args.force)
except (OSError, subprocess.CalledProcessError, ValueError) as exc:
print(f"error: {name}: {exc}", file=sys.stderr)
failed.append(name)
else:
fetched = fetch_hub(index, tasks, staging)
install(index, tasks, fetched, args.output, args.force)
except (OSError, subprocess.CalledProcessError, ValueError) as exc:
print(f"error: {exc}", file=sys.stderr)
return 1
installed.append(name)

if failed:
print(f"failed: {', '.join(failed)}", file=sys.stderr)
if not installed:
return 1
task = tasks[0] if len(tasks) == 1 else "<task>"
print(
f"Run a task with: {harbor or harbor_command()} run "
f"--path {display_path(args.output)}/{task} --agent oracle"
)
return 0
return 1 if failed else 0


def main(
Expand Down
27 changes: 27 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ def sample_index() -> dict:
return {**INDEX, "tasks": {"sample": entry}}


def two_task_index() -> dict:
index = sample_index()
entry = index["tasks"]["sample"]
return {**index, "tasks": {"sample": entry, "other": entry}}


def fake_hub(index: dict, tasks: list[str], staging: Path) -> Path:
for task in tasks:
write_task(staging / task)
Expand Down Expand Up @@ -148,6 +154,27 @@ def test_missing_command_is_reported(self):
self.assertEqual(code, 1)
self.assertIn("harbor", err)

def test_one_failed_task_does_not_discard_the_rest(self):
failure = subprocess.CalledProcessError(1, ["harbor", "download"])

def fetch_or_fail(index, tasks, staging):
[name] = tasks
if name == "other":
raise failure
return fake_hub(index, tasks, staging)

with (
mock.patch.object(cli, "load_index", return_value=two_task_index()),
mock.patch.object(cli, "fetch_hub", side_effect=fetch_or_fail),
):
code, out, err = run_cli("download", "--output", str(self.output))
self.assertEqual(code, 1)
self.assertIn("OK sample", out)
self.assertIn("error: other:", err)
self.assertIn("failed: other", err)
self.assertTrue((self.output / "sample/task.toml").is_file())
self.assertFalse((self.output / "other").exists())

def test_hf_source_is_selected(self):
def fake_hf(index, tasks, staging, revision):
return fake_hub(index, tasks, staging)
Expand Down