Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 17 additions & 13 deletions agent/services/flow_playwright_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
60 changes: 60 additions & 0 deletions tests/unit/test_flow_playwright_response_capture.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading