From 058a2145de12466f204d7e4e75a5290f18fa719c Mon Sep 17 00:00:00 2001 From: Bl0ck154 <36800583+Bl0ck154@users.noreply.github.com> Date: Tue, 17 Nov 2026 08:03:43 +0200 Subject: [PATCH] fix(playwright): await Flow radios after asynchronous model selection --- agent/services/flow_playwright_generation.py | 30 ++++++---- .../test_flow_playwright_response_capture.py | 60 +++++++++++++++++++ 2 files changed, 77 insertions(+), 13 deletions(-) diff --git a/agent/services/flow_playwright_generation.py b/agent/services/flow_playwright_generation.py index 6c4cd905..df8ebf9d 100644 --- a/agent/services/flow_playwright_generation.py +++ b/agent/services/flow_playwright_generation.py @@ -118,19 +118,23 @@ async def _click_radio_icon(page: Any, icon: str) -> None: async def _click_radio_text(page: Any, prefix: str) -> None: - buttons = page.locator('button[role="radio"]:visible') - chosen = None - for i in range(await buttons.count()): - item = buttons.nth(i) - text = (await item.inner_text()).strip() - if text.startswith(prefix): - chosen = item - break - if chosen is None: - raise RuntimeError(f"Flow UI radio not found: {prefix}") - if await chosen.get_attribute("aria-checked") != "true": - await chosen.click() - await page.wait_for_timeout(200) + # Changing the Flow model asynchronously replaces the resolution/duration + # radios. An immediate snapshot can incorrectly report "720p not found" + # even though the control appears a moment later. This is entirely before + # the paid Generate click; never retry a submitted generation here. + for poll in range(9): + buttons = page.locator('button[role="radio"]:visible') + for i in range(await buttons.count()): + item = buttons.nth(i) + text = (await item.inner_text()).strip() + if text.startswith(prefix): + if await item.get_attribute("aria-checked") != "true": + await item.click() + await page.wait_for_timeout(200) + return + if poll < 8: + await page.wait_for_timeout(400) + raise RuntimeError(f"Flow UI radio not found: {prefix}") async def _select_model(page: Any, label: str) -> None: diff --git a/tests/unit/test_flow_playwright_response_capture.py b/tests/unit/test_flow_playwright_response_capture.py index f37ff318..fb36ebb0 100644 --- a/tests/unit/test_flow_playwright_response_capture.py +++ b/tests/unit/test_flow_playwright_response_capture.py @@ -44,3 +44,63 @@ async def abort(self): with pytest.raises(RuntimeError,match="upstream cancelled"): await future assert events==["fetch_once","abort"] + +@pytest.mark.asyncio +async def test_radio_waits_for_async_model_options_before_click(): + from agent.services.flow_playwright_generation import _click_radio_text + + class Item: + clicked = 0 + async def inner_text(self): + return "720p" + async def get_attribute(self, name): + return "false" if name == "aria-checked" else None + async def click(self): + self.clicked += 1 + + class Page: + def __init__(self): + self.counts = 0 + self.waits = [] + self.item = Item() + def locator(self, selector): + assert selector == 'button[role="radio"]:visible' + return self + async def count(self): + self.counts += 1 + return 1 if self.counts >= 3 else 0 + def nth(self, index): + assert index == 0 + return self.item + async def wait_for_timeout(self, ms): + self.waits.append(ms) + + page = Page() + await _click_radio_text(page, "720p") + assert page.counts == 3 + assert page.item.clicked == 1 + assert page.waits == [400, 400, 200] + + +@pytest.mark.asyncio +async def test_missing_radio_fails_closed_without_click_or_generate(): + from agent.services.flow_playwright_generation import _click_radio_text + + class Page: + def __init__(self): + self.polls = 0 + self.waits = [] + def locator(self, selector): + assert selector == 'button[role="radio"]:visible' + return self + async def count(self): + self.polls += 1 + return 0 + async def wait_for_timeout(self, ms): + self.waits.append(ms) + + page = Page() + with pytest.raises(RuntimeError, match="Flow UI radio not found: 720p"): + await _click_radio_text(page, "720p") + assert page.polls == 9 + assert page.waits == [400] * 8