from pathlib import Path import subprocess def _run_helper(script_path: Path, *, env: dict[str, str], cwd: Path) -> str: result = subprocess.run( [ "/bin/bash", "-lc", f'source "{script_path}"; _clinic_default_download_dir', ], cwd=str(cwd), env=env, check=True, capture_output=True, text=True, ) return result.stdout.strip() def test_clinic_download_dir_prefers_explicit_env(tmp_path): script_path = ( Path(__file__).resolve().parents[2] / "agentkit/skills/nutshell-skills/platform/clinic-api/scripts/clinic-download-dir.sh" ) explicit_dir = tmp_path / "explicit" env = {"PATH": str(Path("/usr/bin")), "CLINIC_DIAGNOSTIC_DOWNLOAD_DIR": str(explicit_dir)} actual = _run_helper(script_path, env=env, cwd=tmp_path) assert actual == str(explicit_dir) def test_clinic_download_dir_falls_back_to_pwd(tmp_path): script_path = ( Path(__file__).resolve().parents[2] / "agentkit/skills/nutshell-skills/platform/clinic-api/scripts/clinic-download-dir.sh" ) env = {"PATH": str(Path("/usr/bin"))} actual = _run_helper(script_path, env=env, cwd=tmp_path) assert actual == str(tmp_path)