Repository navigation
Give the offline uv sandbox test a disposable cache #1774
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -507,19 +507,29 @@ def test_real_sandbox_tmp_subpath_bind_stays_visible(git_repo, tmp_path): | |
| @pytest.mark.skipif( | ||
| not _real_bwrap_works() or shutil.which("uv") is None, reason="needs real bwrap and uv" | ||
| ) | ||
| def test_real_sandbox_uv_run_offline(git_repo): | ||
| home = Path.home() # the sandbox home inside `loopzero check`: bind the real toolchain | ||
| uv_cache = os.environ.get("UV_CACHE_DIR", f"{home}/.cache/uv") | ||
| uv_pythons = os.environ.get("UV_PYTHON_INSTALL_DIR", f"{home}/.local/share/uv/python") | ||
| def test_real_sandbox_uv_run_offline(git_repo, tmp_path): | ||
| uv_cache = tmp_path / "uv-cache" | ||
| uv_cache.mkdir() | ||
| uv = shutil.which("uv") | ||
| assert uv is not None | ||
| env = { | ||
| "UV_CACHE_DIR": str(uv_cache), | ||
| "UV_NO_CONFIG": "1", | ||
| "UV_OFFLINE": "1", | ||
| "UV_PYTHON": str(Path(sys._base_executable).resolve()), | ||
| "UV_PYTHON_DOWNLOADS": "never", | ||
| } | ||
| pyproject = '[project]\nname = "t"\nversion = "0"\nrequires-python = ">=3.12"\n' | ||
| (git_repo / "pyproject.toml").write_text(pyproject + "[dependency-groups]\ndev = []\n") | ||
| subprocess.run(["uv", "lock", "-q"], cwd=git_repo, check=True) # projects commit uv.lock | ||
| lock_env = {"HOME": str(tmp_path), "PATH": os.defpath, **env} | ||
| subprocess.run([uv, "lock", "-q"], cwd=git_repo, env=lock_env, check=True) | ||
| git(git_repo, "add", "-A") | ||
| git(git_repo, "commit", "-q", "-m", "uv project") | ||
| cfg = make_config( | ||
| checks=("uv run --group dev python -c 1", ".venv/bin/python -c 1", "test ! -w ."), | ||
| env=(("UV_CACHE_DIR", uv_cache), ("UV_PYTHON_INSTALL_DIR", uv_pythons)), | ||
| sandbox_ro=(str(Path(shutil.which("uv")).parent), uv_pythons), writable=(uv_cache,), | ||
| env=tuple(env.items()), | ||
| sandbox_ro=(str(Path(uv).parent), sys.base_prefix), | ||
| writable=(str(uv_cache),), | ||
| ) | ||
| report = sandbox.run_checks(cfg, git_repo) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion: Cache isolation is not asserted by the test The acceptance criteria say the inherited cache and sentinel stay unchanged. That was only checked by hand. In the test, isolation follows from overriding |
||
| assert report.ok, report | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: Bound interpreter prefix is not resolved, but UV_PYTHON is
UV_PYTHONis set toPath(sys._base_executable).resolve(), but the sandbox read-only bind uses the unresolvedsys.base_prefix. The two can point to different trees. One case is a uv-managed interpreter under~/.local/share/uv/python, where newer uv versions use a minor-version symlink directory (cpython-3.12-…→cpython-3.12.N-…) as the venv home.bwrap --ro-bind-trywould mount that content at the symlink path, while the resolved executable path points into the patch directory, and the sandbox does not expose that directory because/homeis hidden.uv runwould then fail to find the interpreter inside the sandbox. This is a host-dependent false failure, not a leak. The smallest fix is to derive both values from the same resolved path, for examplepy = Path(sys._base_executable).resolve()and then bindstr(py.parent.parent), or bindstr(Path(sys.base_prefix).resolve()).