from gpu_rent.config import load_config from gpu_rent.paths import env_path, migrate_legacy_if_needed, models_manifest_path, runtime_dir from gpu_rent.ssh_keys import ensure_ed25519, public_path def test_load_config_missing_auth(monkeypatch, tmp_path): monkeypatch.setenv("HOME", str(tmp_path)) monkeypatch.setenv("USERPROFILE", str(tmp_path)) for key in ( "OS_AUTH_URL", "OS_USER_DOMAIN_NAME", "OS_USERNAME", "OS_PASSWORD", "OS_PROJECT_ID", "OS_REGION_NAME", "GPU_RENT_AZ", ): monkeypatch.delenv(key, raising=False) cfg = load_config(require_auth=False) assert not cfg.auth_ok assert "OS_USERNAME" in cfg.missing assert cfg.data_volume_size_gb == 100 assert cfg.models_manifest == models_manifest_path() assert runtime_dir() == tmp_path / ".gpu-rent" assert env_path() == tmp_path / ".env" def test_migrate_legacy_user_home(tmp_path, monkeypatch): monkeypatch.setenv("HOME", str(tmp_path / "user")) monkeypatch.setenv("USERPROFILE", str(tmp_path / "user")) proj = tmp_path / "proj" proj.mkdir() monkeypatch.chdir(proj) legacy = tmp_path / "user" / ".gpu-rent" legacy.mkdir(parents=True) (legacy / "models.yaml").write_text("checkpoint:\n - version_id: 1\n", encoding="utf-8") (legacy / ".env").write_text("OS_USERNAME=x\n", encoding="utf-8") notes = migrate_legacy_if_needed() assert notes assert (proj / "models.yaml").is_file() assert (proj / ".env").is_file() def test_ssh_key_generate(tmp_path): private = tmp_path / "id_ed25519" got, pub = ensure_ed25519(private) assert got == private assert pub == public_path(private) assert private.is_file() assert pub.is_file() text = pub.read_text(encoding="utf-8") assert text.startswith("ssh-ed25519") ensure_ed25519(private) assert private.read_bytes()