"""Tests for backup.py -- target resolution and dry-run behavior without network.""" import pytest import backup def test_resolve_targets_expands_all_without_uploading_unknowns(): assert backup._resolve_targets("A") == ["A"] assert backup._resolve_targets("all") == list(backup.TARGETS) with pytest.raises(ValueError, match="unknown target"): backup._resolve_targets("missing") def test_local_paths_keep_results_under_results_host(monkeypatch, tmp_path): workspace = tmp_path / "workspace" host = tmp_path / "host" monkeypatch.setattr(backup, "WORKSPACE_ROOT", workspace) monkeypatch.setattr(backup, "RESULTS_HOST_ROOT", host) assert backup._local_path("results/A") == host / "results/A" assert backup._local_path("harness") == workspace / "harness" def test_backup_dry_run_skips_empty_targets_and_never_imports_hub( monkeypatch, tmp_path, capsys ): workspace = tmp_path / "workspace" host = tmp_path / "host" (workspace / "harness").mkdir(parents=True) (workspace / "harness" / "run.py").write_text("# source\n") monkeypatch.setattr(backup, "WORKSPACE_ROOT", workspace) monkeypatch.setattr(backup, "RESULTS_HOST_ROOT", host) monkeypatch.setattr(backup, "TARGETS", {"code": ["harness"], "A": ["results/A"]}) uploaded = backup.backup("owner/dataset", "all", dry_run=True) assert uploaded == ["code"] output = capsys.readouterr().out assert "[A] skipped" in output assert "would upload" in output assert str(workspace / "harness") in output def test_target_root_rejects_mixed_workspace_and_results_roots(): with pytest.raises(ValueError, match="mixes incompatible"): backup._target_root(["results/A", "tests"])