Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

Keep the confinement tests off the interpreter walk (#11488)

Daniel Han461f5ab0cb35
diff --git a/studio/backend/tests/test_account_tool_confinement.py b/studio/backend/tests/test_account_tool_confinement.py
index feba693a657..3eb68b4daa3 100644
--- a/studio/backend/tests/test_account_tool_confinement.py
+++ b/studio/backend/tests/test_account_tool_confinement.py
@@ -18,6 +18,31 @@ from .test_account_lifecycle import auth_env, matrix # noqa: F401
ALICE = AccountContext("alice-id", "alice")
BOB = AccountContext("bob-id", "bob")
+
+def _keep_the_interpreter_walk_out_of_the_fixtures(tmp_path, monkeypatch):
+ """Drop the interpreter roots that contain *tmp_path*.
+
+ ``_landlock_rules`` grants an interpreter root child by child, descending
+ past whatever is protected. A checkout whose virtualenv sits above the
+ pytest tmp directory therefore walks straight into the fake /etc and /run
+ these tests build, and grants them on a path that has nothing to do with
+ the system-root split being measured: the fake root lands in the rule list
+ whole, and the whole-list comparison picks up every other worker's tmp
+ directory as it comes and goes. On CI the venv is never an ancestor of the
+ tmp dir, so it does not show there.
+
+ None of these tests is about interpreter roots, which have their own
+ coverage, so take those roots out rather than read a rule list that cannot
+ answer the question being asked.
+ """
+ original = tool_confinement._interpreter_roots
+ monkeypatch.setattr(
+ tool_confinement,
+ "_interpreter_roots",
+ lambda: [r for r in original() if not tool_confinement._contains(r, str(tmp_path))],
+ )
+
+
LANDLOCK = (
sys.platform == "linux"
and tool_confinement.landlock_abi() >= tool_confinement._MIN_LANDLOCK_ABI
@@ -561,11 +586,12 @@ def test_macos_profile_hides_the_hf_cache(tmp_path, monkeypatch):
assert profile.index(f'(allow file-read* (subpath "{prefix.resolve()}"))') < deny
-def test_bases_outside_a_granted_root_leave_the_landlock_rules_unchanged(tmp_path):
+def test_bases_outside_a_granted_root_leave_the_landlock_rules_unchanged(tmp_path, monkeypatch):
if sys.platform != "linux":
pytest.skip("Linux rule builder")
from utils.paths.storage_roots import studio_root
+ _keep_the_interpreter_walk_out_of_the_fixtures(tmp_path, monkeypatch)
run_as(ALICE, tools._get_workdir, "chat")
rules = run_as(ALICE, tool_confinement._landlock_rules, 3, tools._SANDBOX_SITE_DIR)
install_only = tool_confinement._existing((run_as(ALICE, studio_root),))
@@ -777,6 +803,7 @@ def test_runtime_secret_mounts_are_excluded_from_the_system_grant(tmp_path, monk
(run / "secrets" / "db_password").write_text("hunter2")
(run / "credentials" / "svc" / "token").parent.mkdir()
(run / "credentials" / "svc" / "token").write_text("token")
+ _keep_the_interpreter_walk_out_of_the_fixtures(tmp_path, monkeypatch)
monkeypatch.setattr(tool_confinement, "_SYSTEM_READ_ROOTS", (str(run),))
# The shipped list, relocated under the fake /run, so the test reads the real constant.
monkeypatch.setattr(
@@ -819,6 +846,7 @@ def test_privileged_etc_secrets_are_excluded_from_the_system_grant(tmp_path, mon
"ssl/certs/ca.pem",
):
(etc / name).write_text(name)
+ _keep_the_interpreter_walk_out_of_the_fixtures(tmp_path, monkeypatch)
monkeypatch.setattr(tool_confinement, "_SYSTEM_READ_ROOTS", (str(etc),))
monkeypatch.setattr(
tool_confinement,