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.

studiobench: carry on with image_upload when the click opened the menu but timed out (#13377)

Daniel Han501482abaf6b
diff --git a/tests/studio/studiobench/scene/actions.py b/tests/studio/studiobench/scene/actions.py
index 12dfe27119d..289330ab943 100644
--- a/tests/studio/studiobench/scene/actions.py
+++ b/tests/studio/studiobench/scene/actions.py
@@ -1752,17 +1752,23 @@ def image_upload(ctx: ActionContext) -> ActionResult:
_ev(ctx, _MARK_MENUS_BEFORE_JS)
started = time.monotonic()
# Bounded by what is left of the slot, never by Playwright's 30s default.
+ click_overran = False
try:
plus.click(timeout = max(500, min(ctx.budget_ms // 3, 5000)))
except Exception as exc: # noqa: BLE001
- # A click can open the menu and still time out: Radix opens it on pointerdown. Left open, it
- # blocked the next action's New chat button (thread_reopen NOT RUN, "no point on the control
- # hit-tests to it") on a run that allowed only this action not to run.
- closed = _close_open_menu(ctx)
- return not_run(
- f"the attachments button could not be clicked: {type(exc).__name__}"
- + _left_menu_note(closed)
- )
+ # Radix opens the menu on pointerdown, so the click can time out on the modal open after it
+ # took effect (that open grows with DOM size). The menu this attempt opened is the click's
+ # effect: carry on with it.
+ if _ev(ctx, _NEW_MENU_OPEN_JS) is True:
+ click_overran = True
+ else:
+ # Left open, a menu blocked the next action's New chat button (thread_reopen NOT RUN, "no
+ # point on the control hit-tests to it") on a run that allowed only this action not to run.
+ closed = _close_open_menu(ctx)
+ return not_run(
+ f"the attachments button could not be clicked: {type(exc).__name__}"
+ + _left_menu_note(closed)
+ )
ctx.page.wait_for_timeout(200)
try:
with ctx.page.expect_file_chooser(timeout = 6000) as fc:
@@ -1805,6 +1811,8 @@ def image_upload(ctx: ActionContext) -> ActionResult:
"attachments_before": before,
"attachments_after": after,
"attachment_containers": containers,
+ # The click opened the menu but Playwright's bounded click timed out on the open.
+ "click_overran": click_overran,
},
timings = {"upload_ms": round(elapsed, 1)},
reason = reason,
diff --git a/tests/studio/studiobench/scene/selftest/test_studiobench_image_upload_leaves_no_menu.py b/tests/studio/studiobench/scene/selftest/test_studiobench_image_upload_leaves_no_menu.py
index b6cdbef5f1f..2b850d91f08 100644
--- a/tests/studio/studiobench/scene/selftest/test_studiobench_image_upload_leaves_no_menu.py
+++ b/tests/studio/studiobench/scene/selftest/test_studiobench_image_upload_leaves_no_menu.py
@@ -15,6 +15,7 @@ for turned into one it was not: thread_reopen NOT RUN, and the job red.
from __future__ import annotations
+import contextlib
import sys
from pathlib import Path
@@ -46,6 +47,18 @@ class _Button:
raise TimeoutError(f"Timeout {timeout}ms exceeded.")
+class _Chooser:
+ def __init__(self, page: "_Page") -> None:
+ self._page = page
+
+ @property
+ def value(self) -> "_Chooser":
+ return self
+
+ def set_files(self, _path) -> None:
+ self._page.attachments += 1
+
+
class _Locator:
def __init__(self, page: "_Page") -> None:
self._page = page
@@ -71,7 +84,10 @@ class _Page:
menu_closes_on_escape: bool = True,
already_open: tuple = (),
click_dismisses_open_menu: bool = False,
+ chooser_opens: bool = False,
) -> None:
+ self.chooser_opens = chooser_opens
+ self.attachments = 0
self.click_opens_menu = click_opens_menu
self.menu_closes_on_escape = menu_closes_on_escape
self.click_dismisses_open_menu = click_dismisses_open_menu
@@ -82,6 +98,16 @@ class _Page:
def locator(self, _selector: str) -> _Locator:
return _Locator(self)
+ @contextlib.contextmanager
+ def expect_file_chooser(self, timeout = None):
+ chooser = _Chooser(self)
+ yield chooser
+ if not (self.chooser_opens and "attachments" in self.menus):
+ raise TimeoutError(
+ f'Timeout {timeout}ms exceeded while waiting for event "filechooser"'
+ )
+ self.menus.remove("attachments") # picking "Add photos" closes the menu
+
def evaluate(
self,
script,
@@ -94,7 +120,9 @@ class _Page:
return any(menu not in self._before for menu in self.menus)
if '[role="menu"]' in script:
return bool(self.menus) # a presence-only query
- return 0 # the attachment count
+ if "menuItemByText" in script:
+ return None
+ return self.attachments # the attachment count
def wait_for_timeout(self, _ms) -> None:
return None
@@ -117,12 +145,25 @@ def _upload(page: _Page):
return image_upload(ctx)
+def test_a_click_that_opened_the_menu_and_timed_out_still_uploads():
+ """The menu opened on pointerdown and the bounded click timed out on the modal open."""
+ page = _Page(click_opens_menu = True, chooser_opens = True)
+ result = _upload(page)
+
+ assert result.ran is True, result.reason
+ assert result.expect_ok is True
+ assert result.expect["click_overran"] is True
+ assert page.attachments == 1
+ assert page.menus == []
+ assert page.keyboard.pressed == []
+
+
def test_a_click_that_opened_the_menu_and_timed_out_closes_it():
page = _Page(click_opens_menu = True)
result = _upload(page)
assert result.ran is False
- assert "could not be clicked: TimeoutError" in result.reason
+ assert "the file chooser never opened" in result.reason
assert page.menus == [], "the modal menu was left open over the next action"
assert page.keyboard.pressed == ["Escape"]
assert "closed the menu it opened" in result.reason