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.

Key the recreated-project delete tests to state, not to a call count (#10571)

Daniel Han0dcea7574cdd
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 4c7be39b493..7cd9c304545 100644
--- a/studio/backend/tests/test_sandbox_files_and_storage_roots.py
+++ b/studio/backend/tests/test_sandbox_files_and_storage_roots.py
@@ -5986,11 +5986,66 @@ def test_a_project_created_during_the_record_write_keeps_its_files(tmp_path, mon
(workspace / "sandbox").mkdir(parents = True)
(workspace / "sandbox" / "fresh.csv").write_text("a,b\n", encoding = "utf-8")
- answers = [None, {"id": project_id}]
+ # Created once the delete has looked, and never removed again. A list popped per call has
+ # it come back and then vanish, which no registry does, and points the scenario at whichever
+ # probe is second: one added ownership read upstream moved it past every surviving check.
+ looked = {"once": False}
+
+ def created_after_the_first_look(pid):
+ if not looked["once"]:
+ looked["once"] = True
+ return None
+ return {"id": pid}
+
+ monkeypatch.setattr(chat_history, "get_chat_project", created_after_the_first_look)
+ monkeypatch.setattr(
+ studio_db,
+ "get_chat_project",
+ lambda pid: {
+ "id": pid,
+ "rootPath": str(workspace),
+ "sandboxPath": str(workspace / "sandbox"),
+ },
+ )
+ monkeypatch.setattr(studio_db, "sandbox_is_referenced_elsewhere", lambda s, e = None: False)
+ _deleted_project(tmp_path, monkeypatch, project_id, workspace)
+
+ assert (workspace / "sandbox" / "fresh.csv").is_file(), "the new project's files went"
+ assert tools.list_orphaned_projects() == [], "a live project was left recorded"
+
+
+def test_a_project_created_inside_the_record_write_itself_keeps_its_files(tmp_path, monkeypatch):
+ """The same rescue, pinned to the window the name describes rather than to a call count.
+
+ The test above is satisfied by the `recreated` probe, well before the record write, so it
+ never reached the last check. Here the project appears during `record_orphaned_project`
+ itself, so only that check can save the files.
+ """
+ monkeypatch.setenv("UNSLOTH_STUDIO_HOME", str(tmp_path / "home"))
+
+ from core.inference import tools
+ from routes import chat_history
+ from storage import studio_db
+
+ _forget_sandbox_state(tools)
+ project_id = "proj14141"
+ workspace = tmp_path / "Notes-proj1414"
+ (workspace / "sandbox").mkdir(parents = True)
+ (workspace / "sandbox" / "fresh.csv").write_text("a,b\n", encoding = "utf-8")
+
+ recreated = {"yet": False}
+ real_record = tools.record_orphaned_project
+
+ def record_then_recreate(*args, **kwargs):
+ result = real_record(*args, **kwargs)
+ recreated["yet"] = True
+ return result
+
+ monkeypatch.setattr(tools, "record_orphaned_project", record_then_recreate)
monkeypatch.setattr(
chat_history,
"get_chat_project",
- lambda pid: answers.pop(0) if answers else None,
+ lambda pid: {"id": pid} if recreated["yet"] else None,
)
monkeypatch.setattr(
studio_db,
@@ -6004,6 +6059,7 @@ def test_a_project_created_during_the_record_write_keeps_its_files(tmp_path, mon
monkeypatch.setattr(studio_db, "sandbox_is_referenced_elsewhere", lambda s, e = None: False)
_deleted_project(tmp_path, monkeypatch, project_id, workspace)
+ assert recreated["yet"], "the record was never written, so this proves nothing"
assert (workspace / "sandbox" / "fresh.csv").is_file(), "the new project's files went"
assert tools.list_orphaned_projects() == [], "a live project was left recorded"