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.

Studio: isolate the sandbox traversal test from the real home directory (#11471)

Daniel Han75c5e3efe057
diff --git a/studio/backend/tests/test_sandbox_files_and_storage_roots.py b/studio/backend/tests/test_sandbox_files_and_storage_roots.py
index 1650364f008..74d20d6e801 100644
--- a/studio/backend/tests/test_sandbox_files_and_storage_roots.py
+++ b/studio/backend/tests/test_sandbox_files_and_storage_roots.py
@@ -5140,7 +5140,17 @@ def test_a_traversal_id_stays_inside_the_sandbox_root_and_opens_nothing(tmp_path
from fastapi import HTTPException
- monkeypatch.setenv("UNSLOTH_STUDIO_HOME", str(tmp_path / "home"))
+ # The legacy root is `~/studio_sandbox`, read straight off `expanduser("~")`, and an id the
+ # filesystem cannot hold is looked for in its shared `_invalid` bucket on the way to the 404.
+ # UNSLOTH_STUDIO_HOME does not move that, so without a fake home this test asks about whoever
+ # is running it: on a machine that has ever run Studio with a bad id the bucket is there, the
+ # resolver finds a real directory, and the reveal answers 200 instead. It passed on CI only
+ # because a fresh runner has no such folder.
+ _shared_setup_11(tmp_path / "fake-home", monkeypatch, tmp_path)
+ legacy_bucket = tmp_path / "fake-home" / "studio_sandbox" / "_invalid"
+ assert (
+ not legacy_bucket.exists()
+ ), "the refusals below only hold while the legacy bucket is absent"
from routes import inference
@@ -5171,6 +5181,28 @@ def test_a_traversal_id_stays_inside_the_sandbox_root_and_opens_nothing(tmp_path
assert opened == [], "a refused id must never reach the file manager"
+def test_an_unusable_id_still_reads_the_legacy_shared_bucket(tmp_path, monkeypatch):
+ """The other half of the test above, and the reason it needs a fake home.
+
+ Before the per-id names, every id the filesystem could not hold shared one
+ bucket at the legacy root. `_legacy_session_dir` still reads that bucket, on
+ purpose, so those chats' files stay reachable after the upgrade. So "a
+ traversal id resolves to nothing" is not unconditional: it holds while the
+ bucket is absent, which is a precondition the previous test now states
+ instead of inheriting from whoever runs it. Pinning the read-back here means
+ deleting it cannot quietly turn that test into a tautology.
+ """
+ from core.inference import tools
+
+ _shared_setup_11(tmp_path / "fake-home", monkeypatch, tmp_path)
+ bucket = tmp_path / "fake-home" / "studio_sandbox" / tools._LEGACY_SHARED_BUCKET
+ bucket.mkdir(parents = True)
+
+ assert tools.resolve_sandbox_workdir("../../../../etc") == str(bucket)
+ # A usable id is a chat of its own and never lands in the shared bucket, whatever is in there.
+ assert tools.resolve_sandbox_workdir("thread-1") != str(bucket)
+
+
def test_a_sandbox_file_named_reveal_is_still_served(tmp_path):
"""The POST route shares the path the download route matches with
``{filename:path}``. Being POST-only keeps a file called ``reveal``