From 93c6e22f8f3215f3edd645633a1d3b381cde5f11 Mon Sep 17 00:00:00 2001 From: bluzername Date: Fri, 27 Nov 2026 07:22:01 +0200 Subject: [PATCH] fix: download install each task as it is fetched, not all or nothing run_download fetched every task into one staging dir then installed all of them together. If one task failed partway (network error, hub rate limit, a hash mismatch), the except block returned before install ever ran, and the TemporaryDirectory then deleted everything already fetched. For a full download that throw away gigabytes of good work for one bad task, closes #4. Now each task is fetched and installed on its own, right after the other. A failed task is printed and skipped, the rest keep going, and the command exit 1 at the end with the list of what failed. --- src/websitebench/cli.py | 27 ++++++++++++++++++--------- tests/test_cli.py | 27 +++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 9 deletions(-) diff --git a/src/websitebench/cli.py b/src/websitebench/cli.py index 6f8278ed..cb687e35 100644 --- a/src/websitebench/cli.py +++ b/src/websitebench/cli.py @@ -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 "" 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( diff --git a/tests/test_cli.py b/tests/test_cli.py index 09e3422f..90ca9154 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -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) @@ -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)