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.

[pre-commit.ci] auto fixes from pre-commit.com hooks

pre-commit-ci[bot]a02024637702
diff --git a/studio/backend/auth/terminal_prompt.py b/studio/backend/auth/terminal_prompt.py
index 4a39b1205fc..14e5b33564b 100644
--- a/studio/backend/auth/terminal_prompt.py
+++ b/studio/backend/auth/terminal_prompt.py
@@ -191,8 +191,12 @@ def _read_password(prompt: str, *, out: "TextIO | None" = None) -> str:
def should_prompt_password_change(
- *, tunnel_will_start: bool, requires_change: bool, stdin_isatty: bool,
- stderr_isatty: bool, bind_is_exposed: bool = False,
+ *,
+ tunnel_will_start: bool,
+ requires_change: bool,
+ stdin_isatty: bool,
+ stderr_isatty: bool,
+ bind_is_exposed: bool = False,
) -> bool:
"""Whether to block startup on an interactive terminal password change.
diff --git a/studio/backend/run.py b/studio/backend/run.py
index c00500cd029..375f2aa3e94 100644
--- a/studio/backend/run.py
+++ b/studio/backend/run.py
@@ -2178,10 +2178,7 @@ def _terminal_password_gate(
# publishes this" with "the socket itself is reachable". Here only the second
# question matters; the first is already tunnel_will_start.
bind_is_exposed = (
- _is_exposed_bind(host, False)
- and frontend_served
- and not api_only
- and not is_colab
+ _is_exposed_bind(host, False) and frontend_served and not api_only and not is_colab
)
if not tunnel_will_start and not bind_is_exposed:
return True, False
@@ -2278,10 +2275,7 @@ def _terminal_password_gate(
is_current_password = _is_current_password,
apply_change = _apply_change,
out = sys.stderr,
- exposure = (
- "on the public internet" if tunnel_will_start
- else "on every network interface"
- ),
+ exposure = ("on the public internet" if tunnel_will_start else "on every network interface"),
)
return (True, True) if changed else (False, False)
diff --git a/studio/backend/tests/test_password_prompt.py b/studio/backend/tests/test_password_prompt.py
index 1b99f1f4c34..52ca94d432a 100644
--- a/studio/backend/tests/test_password_prompt.py
+++ b/studio/backend/tests/test_password_prompt.py
@@ -352,14 +352,16 @@ def test_resolve_supplied_password_off_by_default(monkeypatch):
def test_a_raw_exposed_bind_prompts_when_a_terminal_is_attached():
from auth.terminal_prompt import should_prompt_password_change
-
- assert should_prompt_password_change(
- tunnel_will_start = False,
- bind_is_exposed = True,
- requires_change = True,
- stdin_isatty = True,
- stderr_isatty = True,
- ) is True
+ assert (
+ should_prompt_password_change(
+ tunnel_will_start = False,
+ bind_is_exposed = True,
+ requires_change = True,
+ stdin_isatty = True,
+ stderr_isatty = True,
+ )
+ is True
+ )
def test_a_raw_exposed_bind_stays_silent_without_a_terminal():
@@ -372,52 +374,60 @@ def test_a_raw_exposed_bind_stays_silent_without_a_terminal():
keep the bootstrap deadline as their protection instead.
"""
from auth.terminal_prompt import should_prompt_password_change
-
for stdin_tty, stderr_tty in ((False, False), (True, False), (False, True)):
- assert should_prompt_password_change(
- tunnel_will_start = False,
- bind_is_exposed = True,
- requires_change = True,
- stdin_isatty = stdin_tty,
- stderr_isatty = stderr_tty,
- ) is False
+ assert (
+ should_prompt_password_change(
+ tunnel_will_start = False,
+ bind_is_exposed = True,
+ requires_change = True,
+ stdin_isatty = stdin_tty,
+ stderr_isatty = stderr_tty,
+ )
+ is False
+ )
def test_a_loopback_launch_is_untouched():
"""Plain `unsloth studio` must be completely unaffected."""
from auth.terminal_prompt import should_prompt_password_change
-
- assert should_prompt_password_change(
- tunnel_will_start = False,
- bind_is_exposed = False,
- requires_change = True,
- stdin_isatty = True,
- stderr_isatty = True,
- ) is False
+ assert (
+ should_prompt_password_change(
+ tunnel_will_start = False,
+ bind_is_exposed = False,
+ requires_change = True,
+ stdin_isatty = True,
+ stderr_isatty = True,
+ )
+ is False
+ )
def test_an_already_changed_password_never_prompts():
from auth.terminal_prompt import should_prompt_password_change
-
- assert should_prompt_password_change(
- tunnel_will_start = True,
- bind_is_exposed = True,
- requires_change = False,
- stdin_isatty = True,
- stderr_isatty = True,
- ) is False
+ assert (
+ should_prompt_password_change(
+ tunnel_will_start = True,
+ bind_is_exposed = True,
+ requires_change = False,
+ stdin_isatty = True,
+ stderr_isatty = True,
+ )
+ is False
+ )
def test_the_default_keeps_old_callers_tunnel_only():
"""bind_is_exposed defaults False, so an old caller behaves as before."""
from auth.terminal_prompt import should_prompt_password_change
-
- assert should_prompt_password_change(
- tunnel_will_start = False,
- requires_change = True,
- stdin_isatty = True,
- stderr_isatty = True,
- ) is False
+ assert (
+ should_prompt_password_change(
+ tunnel_will_start = False,
+ requires_change = True,
+ stdin_isatty = True,
+ stderr_isatty = True,
+ )
+ is False
+ )
def test_the_prompt_banner_does_not_claim_the_internet_for_a_lan_bind(monkeypatch):
diff --git a/studio/backend/tests/test_password_prompt_backstop.py b/studio/backend/tests/test_password_prompt_backstop.py
index 07e0771a438..8a79665dde5 100644
--- a/studio/backend/tests/test_password_prompt_backstop.py
+++ b/studio/backend/tests/test_password_prompt_backstop.py
@@ -434,9 +434,7 @@ def test_a_headless_raw_bind_is_byte_for_byte_unchanged(monkeypatch):
"""
_patch_streams(monkeypatch, tty = False)
_patch_seeded_admin(monkeypatch, requires_change = True)
- assert run._terminal_password_gate(
- tunnel_will_start = False, **_RAW_BIND_KWARGS
- ) == (True, False)
+ assert run._terminal_password_gate(tunnel_will_start = False, **_RAW_BIND_KWARGS) == (True, False)
def test_a_raw_bind_with_a_terminal_reaches_the_prompt(monkeypatch):
@@ -452,22 +450,23 @@ def test_a_raw_bind_with_a_terminal_reaches_the_prompt(monkeypatch):
return True
from auth import terminal_prompt
+
monkeypatch.setattr(terminal_prompt, "prompt_for_password_change", _fake_prompt)
- assert run._terminal_password_gate(
- tunnel_will_start = False, **_RAW_BIND_KWARGS
- ) == (True, True)
+ assert run._terminal_password_gate(tunnel_will_start = False, **_RAW_BIND_KWARGS) == (True, True)
# And it must not tell a LAN operator they are on the public internet.
assert seen.get("exposure") == "on every network interface"
def test_a_loopback_launch_still_short_circuits(monkeypatch):
"""Plain `unsloth studio` must not consult storage at all."""
+
def _boom(*_a, **_k):
raise AssertionError("storage must not be consulted for a loopback launch")
monkeypatch.setattr(run, "_stream_isatty", lambda _s: True)
from auth import storage as _storage
+
monkeypatch.setattr(_storage, "ensure_default_admin", _boom)
assert run._terminal_password_gate(
@@ -481,18 +480,27 @@ def test_a_loopback_launch_still_short_circuits(monkeypatch):
def test_api_only_and_colab_raw_binds_do_not_prompt(monkeypatch):
"""Scoped like the bootstrap deadline: web UI only, never api-only or Colab."""
+
def _boom(*_a, **_k):
raise AssertionError("storage must not be consulted")
monkeypatch.setattr(run, "_stream_isatty", lambda _s: True)
from auth import storage as _storage
+
monkeypatch.setattr(_storage, "ensure_default_admin", _boom)
assert run._terminal_password_gate(
- tunnel_will_start = False, host = "0.0.0.0", secure = False,
- api_only = True, frontend_served = True,
+ tunnel_will_start = False,
+ host = "0.0.0.0",
+ secure = False,
+ api_only = True,
+ frontend_served = True,
) == (True, False)
assert run._terminal_password_gate(
- tunnel_will_start = False, host = "0.0.0.0", secure = False,
- api_only = False, frontend_served = True, is_colab = True,
+ tunnel_will_start = False,
+ host = "0.0.0.0",
+ secure = False,
+ api_only = False,
+ frontend_served = True,
+ is_colab = True,
) == (True, False)
diff --git a/unsloth_cli/commands/studio.py b/unsloth_cli/commands/studio.py
index 54c7faf5333..59fe067bc7a 100644
--- a/unsloth_cli/commands/studio.py
+++ b/unsloth_cli/commands/studio.py
@@ -1588,10 +1588,7 @@ def _enforce_password_change_before_exposure(
# the internet on a cloud box. Naming the wrong one in an error trains people
# to ignore it, and would be plainly wrong for `unsloth studio -H 0.0.0.0`.
tunnel_will_start = secure or cloudflare is True
- exposure = (
- "on a public Cloudflare URL" if tunnel_will_start
- else "on every network interface"
- )
+ exposure = "on a public Cloudflare URL" if tunnel_will_start else "on every network interface"
# Before public exposure we must PROVE the admin password is no longer the
# seeded default. If we cannot (auth DB won't open, or a fresh admin cannot be
# seeded + committed below), an old studio-venv child could regenerate a fresh
diff --git a/unsloth_cli/tests/test_studio_password_prompt.py b/unsloth_cli/tests/test_studio_password_prompt.py
index 2c14b036ec9..6783a88f739 100644
--- a/unsloth_cli/tests/test_studio_password_prompt.py
+++ b/unsloth_cli/tests/test_studio_password_prompt.py
@@ -107,9 +107,7 @@ def test_launch_publishes_tunnel_matrix(cloudflare, host, secure, api_only, expe
def test_should_prompt_password_change_matrix(
monkeypatch, cloudflare, host, secure, api_only, interactive, expected
):
- monkeypatch.setattr(
- _studio(), "_prompt_streams_interactive", lambda: interactive
- )
+ monkeypatch.setattr(_studio(), "_prompt_streams_interactive", lambda: interactive)
assert (
_studio()._should_prompt_password_change(
cloudflare = cloudflare, host = host, secure = secure, api_only = api_only