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
Pin the auth mount gate to its behaviour, not one spelling of the guard (#10307)
Daniel Han49dac87ab89a
diff --git a/tests/studio/test_auth_form_input_count.py b/tests/studio/test_auth_form_input_count.pyindex cc5ddbdb7ed..268ed3da9c5 100644--- a/tests/studio/test_auth_form_input_count.py+++ b/tests/studio/test_auth_form_input_count.py@@ -168,12 +168,140 @@ def test_login_jsx_declares_exactly_one_password_input():), f"login JSX must declare exactly one password-typed input; found {pw_ids!r}"+def _at_depth_zero(condition: str):+ """Every character of ``condition`` that sits outside any bracket."""+ depth = 0+ for index, char in enumerate(condition):+ if char in "([{":+ depth += 1+ elif char in ")]}":+ depth -= 1+ elif depth == 0:+ yield index, char+++def _leading_disjunct(condition: str) -> str:+ """The first operand of ``condition`` read as a `||` chain.++ Split at depth zero, so `!active || !(a || b)` yields `!active` and the inner+ `||` is left where it belongs.+ """+ for index, char in _at_depth_zero(condition):+ if char == "|" and condition[index : index + 2] == "||":+ return condition[:index]+ return condition+++def _binds_looser_than_or(condition: str) -> bool:+ """Whether something outside the `||` chain decides what ``condition`` is worth.++ `?:` and `,` both bind looser than `||`, so `!active || mounted ? false : true`+ and `!active || track(), active` each leave the disjunction as a sub-expression+ whose value is then discarded, and both skip the return while inactive. `?.` and+ `??` are neither.+ """+ for index, char in _at_depth_zero(condition):+ if char == ",":+ return True+ if char != "?":+ continue+ if condition[index + 1 : index + 2] in (".", "?") or condition[index - 1 : index] == "?":+ continue+ return True+ return False+++def _blanked(source: str) -> str:+ """A same-length copy of ``source`` with comment and string bodies blanked.++ Bracket depth and token searches only mean anything once prose and literals can+ no longer contribute brackets, or a guard that survives only as a commented-out+ line still reads as the guard.+ """+ out, index, end = list(source), 0, len(source)+ while index < end:+ pair = source[index : index + 2]+ if pair in ("//", "/*"):+ stop = source.find("\n" if pair == "//" else "*/", index + 2)+ stop = end if stop == -1 else stop + (0 if pair == "//" else 2)+ out[index:stop] = " " * (stop - index)+ index = stop+ elif source[index] in "\"'`":+ quote, stop = source[index], index + 1+ while stop < end and source[stop] != quote:+ stop += 2 if source[stop] == "\\" else 1+ out[index + 1 : stop] = " " * max(0, stop - index - 1)+ index = min(stop + 1, end)+ else:+ index += 1+ return "".join(out)+++def _function_body(source: str, name: str) -> str:+ """``name``'s body, from its opening brace to the matching close.++ The parameter list is walked past rather than skipped by eye: the signature is+ `({ active }: { active: boolean })`, so the first brace after the name belongs to+ the destructuring and not to the body.+ """+ index = source.index("(", source.index(f"export function {name}("))+ depth = 0+ while index < len(source):+ depth += (source[index] == "(") - (source[index] == ")")+ index += 1+ if depth == 0:+ break+ opening = source.index("{", index)+ depth = 0+ for index in range(opening, len(source)):+ depth += (source[index] == "{") - (source[index] == "}")+ if depth == 0:+ return source[opening : index + 1]+ return source[opening:]+++def _inactive_returns_null(body: str) -> bool:+ """Whether ``body`` returns null from its OWN top level on every inactive render.++ Read as a parse and not as text. The condition has to be a disjunction whose first+ operand is `!active`, because that is what makes an inactive render short-circuit to+ the return whatever the rest of the guard says. Only statements directly in the+ component body count: `(active) => { if (!active) return null; }` returns from the+ callback and leaves the component mounting.+ """+ for match in re.finditer(r"\bif \(", body):+ before = body[: match.start()]+ if before.count("{") - before.count("}") != 1:+ continue+ start = match.end()+ depth, index = 1, start+ while index < len(body) and depth:+ depth += (body[index] == "(") - (body[index] == ")")+ index += 1+ condition, tail = body[start : index - 1], body[index:]+ # Braced or not: `{ return null; }` is the same guard through a formatter.+ if not re.match(r"\s*\{?\s*return null;", tail):+ continue+ if _binds_looser_than_or(condition):+ continue+ if _leading_disjunct(condition).strip() == "!active":+ return True+ return False++def test_auth_flow_routes_do_not_mount_global_settings():root = (FRONTEND / "app/routes/__root.tsx").read_text(encoding = "utf-8")mount = (FRONTEND / "features/settings/settings-dialog-mount.tsx").read_text(encoding = "utf-8")assert "<SettingsDialogMount active={active && ready} />" in rootassert "<CredentialBootstrapGate active={!isAuthFlowRoute}>" in root- assert "if (!active || !mounted) return null;" in mount+ # The mount must render nothing whenever inactive, which is what keeps the auth routes+ # clear. The rest of the guard is lazy-mount bookkeeping that #10237 changed from one+ # flag to two, so an exact spelling stopped matching.+ mount_body = _function_body(_blanked(mount), "SettingsDialogMount")+ assert _inactive_returns_null(mount_body), (+ "SettingsDialogMount no longer returns null while inactive, so the settings "+ "dialog can mount on the auth routes"+ )assert "useSettingsDialogStore.getState().closeDialog();" in root# The settings chord must stay inert on the auth routes. That used to be an# early return inside a hand-rolled keydown handler; once the chords became