Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions tests/test_candidate.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
from loopzero.candidate import CandidateError, CandidateRaceError, attest_candidate
from loopzero.types import LoopZeroError

from .conftest import git as isolated_git


@pytest.fixture(autouse=True)
def no_retry_delay(monkeypatch):
Expand Down Expand Up @@ -211,12 +213,9 @@ def tree_candidate(tmp_path, monkeypatch):
remote.mkdir()

def git(*args):
return subprocess.run(["git", *args], cwd=remote, check=True, capture_output=True,
text=True).stdout.strip()
return isolated_git(remote, *args).strip()

git("init", "-b", "main")
git("config", "user.name", "Test")
git("config", "user.email", "test@example.org")

def commit(name, content):
(remote / name).write_text(content)
Expand Down
24 changes: 17 additions & 7 deletions tests/test_sandbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,19 +488,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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Isolation properties from the acceptance criteria are not asserted in the test

The acceptance criteria say the real Bubblewrap run uses a clean home, an empty Python download directory and an unchanged inherited cache sentinel. The test builds isolation into its structure: a tmp_path cache, UV_NO_CONFIG, UV_PYTHON_DOWNLOADS=never, an explicit UV_PYTHON and HOME=tmp_path for uv lock. It never asserts these properties, though. Per the Validation notes, the sentinel was only checked by hand. A later regression could go unnoticed, for example one where uv falls back to ~/.cache/uv because the sandbox drops UV_CACHE_DIR. The smallest fix: after run_checks, assert that uv_cache is non-empty, which shows the disposable cache was the one used. Optionally, also set UV_PYTHON_INSTALL_DIR to an empty tmp directory and assert it stays empty.

assert report.ok, report
Expand Down
Loading