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.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
Studio tests: skip the real-prepare sandbox tests on a host without bubblewrap (#16371)
Daniel Han227693109ccf
diff --git a/studio/backend/tests/test_sandbox_linux.py b/studio/backend/tests/test_sandbox_linux.pyindex 1e276b99070..bda8d5169eb 100644--- a/studio/backend/tests/test_sandbox_linux.py+++ b/studio/backend/tests/test_sandbox_linux.py@@ -52,6 +52,13 @@ def _plan(return ToolLaunchPlan(argv = argv, workdir = str(workdir), env = {"PATH": "/usr/bin"}, **kwargs)+def bwrap():+ """Skip without bubblewrap, as ``prepared`` does: the test calls the real ``prepare()``, which resolves bwrap first."""+ if sandbox_linux.shutil.which("bwrap") is None:+ pytest.skip("bubblewrap is not installed on this host")++@pytest.fixturedef prepared(tmp_path):if sandbox_linux.shutil.which("bwrap") is None:@@ -150,7 +157,7 @@ def test_the_writable_workdir_bind_lands_after_the_root_goes_read_only(prepared,assert argv[argv.index("--chdir") + 1] == workdir-def test_both_spellings_of_a_symlinked_workdir_get_a_mount_point(tmp_path):+def test_both_spellings_of_a_symlinked_workdir_get_a_mount_point(bwrap, tmp_path):real = tmp_path / "real"real.mkdir()link = tmp_path / "link"@@ -432,7 +439,7 @@ def test_nothing_binds_or_creates_the_filesystem_root(prepared):assert "/" not in directories-def test_a_launch_with_no_command_is_refused_rather_than_handed_to_bwrap(tmp_path):+def test_a_launch_with_no_command_is_refused_rather_than_handed_to_bwrap(bwrap, tmp_path):with pytest.raises(SandboxUnavailableError, match = "needs a command"):sandbox_linux.prepare(_plan(tmp_path, argv = ()))@@ -596,7 +603,9 @@ def test_the_workdir_is_the_only_writable_bind(prepared, tmp_path):assert _pairs(prepared.argv, "--bind") == [(workdir, workdir)]-def test_the_model_cache_shares_its_data_subdirectories_and_nothing_else(tmp_path, monkeypatch):+def test_the_model_cache_shares_its_data_subdirectories_and_nothing_else(+ bwrap, tmp_path, monkeypatch+):cache = tmp_path / "hostcache"for name in ("hub", "datasets", "modules", "xet", "assets"):(cache / name).mkdir(parents = True)@@ -622,7 +631,7 @@ def test_the_model_cache_shares_its_data_subdirectories_and_nothing_else(tmp_patlaunch.cleanup()-def test_the_cache_mount_points_are_made_here_and_left(tmp_path, cache):+def test_the_cache_mount_points_are_made_here_and_left(bwrap, tmp_path, cache):workdir = tmp_path / "session"workdir.mkdir()@@ -634,7 +643,7 @@ def test_the_cache_mount_points_are_made_here_and_left(tmp_path, cache):assert (workdir / ".cache" / "huggingface" / "hub").is_dir()-def test_a_cache_directory_the_tool_call_wrote_is_left_alone(tmp_path, cache):+def test_a_cache_directory_the_tool_call_wrote_is_left_alone(bwrap, tmp_path, cache):workdir = tmp_path / "session"(workdir / ".cache" / "huggingface").mkdir(parents = True)(workdir / ".cache" / "notes.txt").write_text("the user's")@@ -644,7 +653,7 @@ def test_a_cache_directory_the_tool_call_wrote_is_left_alone(tmp_path, cache):assert (workdir / ".cache" / "notes.txt").read_text() == "the user's"-def test_the_model_cache_bind_is_absent_when_the_host_has_no_cache(tmp_path, monkeypatch):+def test_the_model_cache_bind_is_absent_when_the_host_has_no_cache(bwrap, tmp_path, monkeypatch):monkeypatch.setattr(sandbox_linux, "_model_cache_binds", lambda workdir: {})launch = sandbox_linux.prepare(_plan(tmp_path))try:@@ -663,7 +672,7 @@ def test_the_inner_home_and_tmpdir_are_set_by_bwrap_not_by_the_caller_environmenassert prepared.env == {"PATH": "/usr/bin"}-def test_a_tmpdir_inside_the_workdir_survives_into_the_jail(tmp_path):+def test_a_tmpdir_inside_the_workdir_survives_into_the_jail(bwrap, tmp_path):scratch = tmp_path / "unsloth-tmp"scratch.mkdir()plan = ToolLaunchPlan(@@ -678,7 +687,7 @@ def test_a_tmpdir_inside_the_workdir_survives_into_the_jail(tmp_path):launch.cleanup()-def test_a_tmpdir_outside_the_workdir_is_replaced_by_the_private_tmpfs(tmp_path):+def test_a_tmpdir_outside_the_workdir_is_replaced_by_the_private_tmpfs(bwrap, tmp_path):plan = ToolLaunchPlan(argv = ("/bin/true",),workdir = str(tmp_path),@@ -691,7 +700,7 @@ def test_a_tmpdir_outside_the_workdir_is_replaced_by_the_private_tmpfs(tmp_path)launch.cleanup()-def test_the_outer_setsid_preexec_is_preserved(tmp_path):+def test_the_outer_setsid_preexec_is_preserved(bwrap, tmp_path):ran = []launch = sandbox_linux.prepare(_plan(tmp_path, preexec_fn = lambda: ran.append("plan")))try:@@ -702,7 +711,7 @@ def test_the_outer_setsid_preexec_is_preserved(tmp_path):launch.cleanup()-def test_the_plan_policy_fields_survive_preparation(tmp_path):+def test_the_plan_policy_fields_survive_preparation(bwrap, tmp_path):launch = sandbox_linux.prepare(_plan(tmp_path, timeout_seconds = 42, terminate_descendants = False))try:assert launch.timeout_seconds == 42@@ -712,7 +721,7 @@ def test_the_plan_policy_fields_survive_preparation(tmp_path):launch.cleanup()-def test_cleanup_releases_the_descriptor_and_the_private_identity_directory(tmp_path):+def test_cleanup_releases_the_descriptor_and_the_private_identity_directory(bwrap, tmp_path):launch = sandbox_linux.prepare(_plan(tmp_path))identity_dir = launch.cleanup_paths[0]handle = launch.owned_files[0]@@ -801,7 +810,7 @@ def test_an_overrun_does_not_stop_a_real_finding_from_refusing(tmp_path, monkeypsandbox_linux._validate_workdir(str(tmp_path))-def test_an_incomplete_scan_reaches_the_execution_record(tmp_path, monkeypatch):+def test_an_incomplete_scan_reaches_the_execution_record(bwrap, tmp_path, monkeypatch):monkeypatch.setattr(os_sandbox, "WORKDIR_SCAN_ENTRIES", 2)for name in ("a", "b", "c", "d"):(tmp_path / name).write_text("")@@ -1150,7 +1159,7 @@ def test_a_runtime_path_symlinked_out_of_the_workdir_is_not_bound(tmp_path, monkassert not any(sandbox_linux._within(str(secret), path) for path in paths)-def test_a_symlinked_cache_ancestor_is_refused_rather_than_written_through(tmp_path, cache):+def test_a_symlinked_cache_ancestor_is_refused_rather_than_written_through(bwrap, tmp_path, cache):"""Refused rather than unlinked: symlinking a cache leaf at another volume is a legitimate layout."""workdir = tmp_path / "session"workdir.mkdir()@@ -1279,7 +1288,9 @@ def test_the_plan_pre_exec_still_runs_before_the_scope():assert ran == ["plan"]-def test_a_standalone_interpreter_in_the_workdir_is_re_bound_read_only(tmp_path, monkeypatch):+def test_a_standalone_interpreter_in_the_workdir_is_re_bound_read_only(+ bwrap, tmp_path, monkeypatch+):workdir = tmp_path / "session"workdir.mkdir()executable = workdir / "python"@@ -1319,7 +1330,7 @@ def _within_for_test(path: str, root: str) -> bool:return path == root or path.startswith(root.rstrip("/") + "/")-def test_a_runtime_origin_is_excluded_under_the_workdir_alias_too(tmp_path, monkeypatch):+def test_a_runtime_origin_is_excluded_under_the_workdir_alias_too(bwrap, tmp_path, monkeypatch):real = tmp_path / "real"real.mkdir()alias = tmp_path / "alias"@@ -1597,7 +1608,9 @@ def test_a_runtime_prefix_contributes_its_certificate_store(tmp_path, monkeypatcassert str(prefix / "ssl") in paths-def test_a_workdir_reached_through_a_symlink_is_bound_at_the_spelling_the_caller_used(tmp_path):+def test_a_workdir_reached_through_a_symlink_is_bound_at_the_spelling_the_caller_used(+ bwrap, tmp_path+):real = tmp_path / "real"real.mkdir()link = tmp_path / "link"@@ -1613,7 +1626,7 @@ def test_a_workdir_reached_through_a_symlink_is_bound_at_the_spelling_the_callerlaunch.cleanup()-def test_a_cache_leaf_left_behind_as_a_file_is_refused_at_preparation(tmp_path, cache):+def test_a_cache_leaf_left_behind_as_a_file_is_refused_at_preparation(bwrap, tmp_path, cache):workdir = tmp_path / "session"(workdir / ".cache" / "huggingface").mkdir(parents = True)(workdir / ".cache" / "huggingface" / "hub").write_text("not a directory")@@ -1714,7 +1727,7 @@ def test_a_clean_cache_component_is_still_shared(tmp_path, monkeypatch):def test_a_hazardous_cache_drops_the_component_rather_than_failing_the_launch(- tmp_path, monkeypatch+ bwrap, tmp_path, monkeypatch):host = tmp_path / "hostcache"(host / "hub").mkdir(parents = True)@@ -1740,7 +1753,7 @@ def test_a_trusted_system_gitconfig_is_bound_and_an_untrusted_one_is_not(tmp_patassert sandbox_linux._trusted_system_file(str(good)) is False, "world-writable accepted"-def test_a_runtime_under_the_workdir_is_re_bound_read_only(tmp_path, monkeypatch):+def test_a_runtime_under_the_workdir_is_re_bound_read_only(bwrap, tmp_path, monkeypatch):workdir = tmp_path / "session"venv = workdir / "venv"(venv / "lib").mkdir(parents = True)@@ -1763,7 +1776,7 @@ def test_a_runtime_under_the_workdir_is_re_bound_read_only(tmp_path, monkeypatchlaunch.cleanup()-def test_a_runtime_symlinked_out_of_the_workdir_is_not_re_bound(tmp_path, monkeypatch):+def test_a_runtime_symlinked_out_of_the_workdir_is_not_re_bound(bwrap, tmp_path, monkeypatch):"""The negative control for the rule above."""workdir = tmp_path / "session"(workdir / "venv").mkdir(parents = True)@@ -1901,7 +1914,7 @@ def test_an_editable_root_at_the_filesystem_root_is_refused(tmp_path, monkeypatcdef test_a_runtime_under_a_symlinked_workdir_is_read_only_through_both_spellings(- tmp_path, monkeypatch+ bwrap, tmp_path, monkeypatch):real = tmp_path / "real"venv = real / "venv"@@ -1932,7 +1945,9 @@ def test_a_runtime_under_a_symlinked_workdir_is_read_only_through_both_spellingslaunch.cleanup()-def test_a_runtime_is_protected_when_sys_prefix_carries_the_workdir_alias(tmp_path, monkeypatch):+def test_a_runtime_is_protected_when_sys_prefix_carries_the_workdir_alias(+ bwrap, tmp_path, monkeypatch+):real = tmp_path / "real"(real / "venv" / "lib").mkdir(parents = True)(real / "venv" / "bin").mkdir()@@ -3130,3 +3145,47 @@ def test_a_launch_finding_a_check_in_progress_waits_for_its_answer(threading.Timer(0.05, release.set).start()assert sandbox_linux._cache_hazard_within_deadline("hub", str(component)) is Noneassert walks == [str(component)]+++def test_every_real_prepare_call_skips_without_bubblewrap():+ """A test that runs the real prepare() errors on a host without bwrap unless it asks for the skip or fakes which()."""+ import ast++ tree = ast.parse(open(__file__, encoding = "utf-8").read())+ unguarded = []+ for node in tree.body:+ if not (isinstance(node, ast.FunctionDef) and node.name.startswith("test_")):+ continue+ if {"bwrap", "prepared"} & {a.arg for a in node.args.args}:+ continue+ calls = [+ c+ for c in ast.walk(node)+ if isinstance(c, ast.Call)+ and isinstance(c.func, ast.Attribute)+ and c.func.attr == "prepare"+ and isinstance(c.func.value, ast.Name)+ and c.func.value.id == "sandbox_linux"+ ]+ # Guarded too: an inline skip, a faked which(), or a PATH the test sets to its own bwrap.+ guarded = any(+ isinstance(c, ast.Call)+ and isinstance(c.func, ast.Attribute)+ and (+ (+ c.func.attr == "skip"+ and isinstance(c.func.value, ast.Name)+ and c.func.value.id == "pytest"+ )+ or (+ c.func.attr in ("setattr", "setenv")+ and any(+ isinstance(a, ast.Constant) and a.value in ("which", "PATH") for a in c.args+ )+ )+ )+ for c in ast.walk(node)+ )+ if calls and not guarded:+ unguarded.append(node.name)+ assert not unguarded, unguarded