Skip to content

Automate browser based workflows with AI

SKY-11208 collapse normal select fanout (#6878)

Marc Kelechavadb2d3736bbd3
diff --git a/skyvern/core/script_generations/fuzzy_matcher.py b/skyvern/core/script_generations/fuzzy_matcher.py
index d4754ebd2..63286f4d4 100644
--- a/skyvern/core/script_generations/fuzzy_matcher.py
+++ b/skyvern/core/script_generations/fuzzy_matcher.py
@@ -97,3 +97,35 @@ def match_option(candidate: str, options: list[str], *, min_substring_len: int =
return best_overlap_idx
return None
+
+
+def match_option_exact_or_stem(candidate: str, options: list[str], *, min_stem_len: int = 3) -> int | None:
+ """Find an exact or singular/plural stem option match.
+
+ This deliberately excludes substring and word-overlap matches. Returning
+ None is the safe fallback signal for option matches that need the LLM path.
+ """
+ if not candidate or not options:
+ return None
+
+ candidate_norm = _normalize(candidate)
+ exact_matches = [i for i, opt in enumerate(options) if _normalize(opt) == candidate_norm]
+ if len(exact_matches) == 1:
+ return exact_matches[0]
+ if len(exact_matches) > 1:
+ return None
+
+ # Simple trailing-s stripping is intentionally precision-first; min_stem_len keeps non-linguistic stems safe.
+ candidate_stem = candidate_norm.rstrip("s")
+ if len(candidate_stem) < min_stem_len:
+ return None
+
+ stem_matches = [
+ i
+ for i, opt in enumerate(options)
+ if len(opt_stem := _normalize(opt).rstrip("s")) >= min_stem_len and opt_stem == candidate_stem
+ ]
+ if len(stem_matches) == 1:
+ return stem_matches[0]
+
+ return None
diff --git a/skyvern/forge/agent_functions.py b/skyvern/forge/agent_functions.py
index 977fde902..a7f5bf0d2 100644
--- a/skyvern/forge/agent_functions.py
+++ b/skyvern/forge/agent_functions.py
@@ -18,6 +18,7 @@ from playwright.async_api import Frame, Page
from skyvern.config import settings
from skyvern.constants import CUSTOMER_STORAGE_UPLOAD_MAX_BYTES, SKYVERN_ID_ATTR
+from skyvern.core.script_generations.fuzzy_matcher import match_option_exact_or_stem
from skyvern.exceptions import (
AzureConfigurationError,
DisabledBlockExecutionError,
@@ -101,6 +102,15 @@ class CopilotAliasResolution:
kind: str = "canonical_alias"
+@dataclass(frozen=True)
+class FieldOptionResolution:
+ matched_index: int | None
+ matched_label: str | None
+ matched_value: str | None
+ confidence: float
+ fallback_to_llm: bool
+
+
def _remove_rect(element: dict) -> None:
if "rect" in element:
del element["rect"]
@@ -1572,6 +1582,41 @@ class AgentFunction:
"""
return None
+ async def resolve_field_option(
+ self,
+ *,
+ target_value: str,
+ option_labels: list[str],
+ option_values: list[str | None],
+ field_context: Any,
+ url: str | None,
+ organization_id: str | None,
+ ) -> FieldOptionResolution:
+ """Resolve a requested field value against option labels.
+
+ Only high-precision exact or whole-stem singular/plural matches are
+ resolvable. A ``None`` match or ``fallback_to_llm=True`` means the
+ caller must defer to the LLM path.
+ """
+ matched_index = match_option_exact_or_stem(target_value, option_labels)
+ if matched_index is None:
+ return FieldOptionResolution(
+ matched_index=None,
+ matched_label=None,
+ matched_value=None,
+ confidence=0.0,
+ fallback_to_llm=True,
+ )
+
+ matched_value = option_values[matched_index] if matched_index < len(option_values) else None
+ return FieldOptionResolution(
+ matched_index=matched_index,
+ matched_label=option_labels[matched_index],
+ matched_value=matched_value,
+ confidence=1.0,
+ fallback_to_llm=False,
+ )
+
async def fill_custom_widget(
self,
page: Any,
diff --git a/skyvern/webeye/actions/handler.py b/skyvern/webeye/actions/handler.py
index 69ec43306..17ff708d6 100644
--- a/skyvern/webeye/actions/handler.py
+++ b/skyvern/webeye/actions/handler.py
@@ -146,6 +146,7 @@ from skyvern.webeye.utils.dom import (
DomUtil,
InteractiveElement,
SkyvernElement,
+ SkyvernOptionType,
is_post_dispatch_click_timeout,
)
from skyvern.webeye.utils.page import SkyvernFrame
@@ -155,6 +156,7 @@ LOG = structlog.get_logger()
UPLOAD_PENDING_FOLLOWUP_MESSAGE = "Upload is not complete yet. Continue the upload flow."
FIX_TEL_INPUT_DIGIT_DROP_FLAG = "FIX_TEL_INPUT_DIGIT_DROP"
+COLLAPSE_SELECT_FANOUT_FLAG = "COLLAPSE_SELECT_FANOUT"
DOWNLOAD_EVENT_ACTIVE_DIR_GRACE_SECONDS = 60
DOWNLOAD_DUPLICATE_STEM_SUFFIX_RE = re.compile(r"(?:\s+\(\d{1,3}\)|_\d{1,3})$")
@@ -612,6 +614,30 @@ async def _is_tel_digit_fix_enabled(task: Task) -> bool:
return False
+async def _is_collapse_select_fanout_enabled(task: Task) -> bool:
+ organization_id = task.organization_id
+ if not organization_id:
+ return False
+ experimentation_provider = getattr(app, "EXPERIMENTATION_PROVIDER", None)
+ if not experimentation_provider:
+ return False
+ try:
+ return bool(
+ await experimentation_provider.is_feature_enabled_cached(
+ COLLAPSE_SELECT_FANOUT_FLAG,
+ organization_id,
+ properties={"organization_id": organization_id},
+ )
+ )
+ except Exception:
+ LOG.warning(
+ "Failed to evaluate collapse-select-fanout flag; defaulting to disabled",
+ organization_id=organization_id,
+ exc_info=True,
+ )
+ return False
+
+
async def verify_phone_input_digits(*, tag_name: str, locator: Locator, expected_value: str) -> None:
# Compare digit counts only — never the raw value, which may be a secret.
actual_value = await get_input_value(tag_name=tag_name, locator=locator)
@@ -632,6 +658,191 @@ async def _verify_tel_input_after_fill(*, skyvern_element: SkyvernElement, tag_n
)
+def _select_option_target_value(option: SelectOption) -> str | None:
+ if option.label:
+ return option.label
+ if option.value:
+ return option.value
+ return None
+
+
+def _select_option_labels_and_values(options: list[SkyvernOptionType]) -> tuple[list[str], list[str | None]]:
+ labels: list[str] = []
+ values: list[str | None] = []
+ for option in options:
+ labels.append(option.get("text") or option.get("value") or "")
+ values.append(option.get("value"))
+ return labels, values
+
+
+def _normal_select_successful(action_results: list[ActionResult]) -> bool:
+ return any(isinstance(action_result, ActionSuccess) for action_result in action_results)
+
+
+def _select_value_is_ambiguous(options: list[SkyvernOptionType], value: str | None) -> bool:
+ if value is None:
+ return False
+ return sum(1 for option in options if option.get("value") == value) > 1
+
+
+async def _select_deterministic_normal_option(
+ *,
+ action: actions.SelectOptionAction,
+ skyvern_element: SkyvernElement,
+ locator: Locator,
+ matched_label: str | None,
+ matched_value: str | None,
+ matched_index: int | None,
+) -> list[ActionResult]:
+ action_result: list[ActionResult] = []
+ is_success = False
+
+ try:
+ await locator.click(
+ timeout=settings.BROWSER_ACTION_TIMEOUT_MS,
+ )
+ except Exception as e:
+ LOG.info(
+ "Failed to click before select action",
+ exc_info=True,
+ action=action,
+ locator=locator,
+ )
+ action_result.append(ActionFailure(e))
+ return action_result
+
+ value = matched_value if matched_value is not None else matched_label
+ if value is not None and not _select_value_is_ambiguous(skyvern_element.get_options(), value):
+ try:
+ await locator.select_option(
+ value=value,
+ timeout=settings.BROWSER_ACTION_TIMEOUT_MS,
+ )
+ is_success = True
+ action_result.append(ActionSuccess())
+ except Exception:
+ action_result.append(ActionFailure(FailToSelectByValue(action.element_id)))
+ LOG.info(
+ "Failed to take select action by value",
+ exc_info=True,
+ action=action,
+ locator=locator,
+ )
+
+ if not is_success and matched_label is not None and matched_label != value:
+ try:
+ await locator.select_option(
+ label=matched_label,
+ timeout=settings.BROWSER_ACTION_TIMEOUT_MS,
+ )
+ is_success = True
+ action_result.append(ActionSuccess())
+ except Exception:
+ action_result.append(ActionFailure(FailToSelectByLabel(action.element_id)))
+ LOG.info(
+ "Failed to take select action by label",
+ exc_info=True,
+ action=action,
+ locator=locator,
+ )
+
+ if not is_success and matched_index is not None:
+ if matched_index >= len(skyvern_element.get_options()):
+ action_result.append(ActionFailure(OptionIndexOutOfBound(action.element_id)))
+ LOG.info(
+ "option index is out of bound",
+ action=action,
+ locator=locator,
+ )
+ else:
+ try:
+ await locator.select_option(
+ index=matched_index,
+ timeout=settings.BROWSER_ACTION_TIMEOUT_MS,
+ )
+ is_success = True
+ action_result.append(ActionSuccess())
+ except Exception:
+ action_result.append(ActionFailure(FailToSelectByIndex(action.element_id)))
+ LOG.info(
+ "Failed to click on the option by index",
+ exc_info=True,
+ action=action,
+ locator=locator,
+ )
+
+ if len(action_result) == 0:
+ action_result.append(ActionFailure(EmptySelect(element_id=action.element_id)))
+
+ return action_result
+
+
+async def _verify_normal_select_option(
+ *,
+ locator: Locator,
+ matched_index: int,
+ matched_label: str | None,
+ matched_value: str | None,
+) -> bool:
+ try:
+ selection = await locator.evaluate(
+ r"""
+ (select) => {
+ const normalize = (value) => (value ?? "").replace(/\s+/g, " ").trim();
+ if (!(select instanceof HTMLSelectElement)) {
+ return { index: null, label: null, value: normalize(select?.value) };
+ }
+ const option = select.options[select.selectedIndex] ?? null;
+ return {
+ index: select.selectedIndex,
+ label: option ? normalize(option.textContent) : null,
+ value: option ? normalize(option.value) : normalize(select.value),
+ };
+ }
+ """
+ )
+ except Exception:
+ LOG.info(
+ "Failed to read normal select option after deterministic selection",
+ expected_index=matched_index,
+ expected_label=matched_label,
+ expected_value=matched_value,
+ exc_info=True,
+ )
+ return False
+
+ if not isinstance(selection, dict):
+ LOG.info(
+ "Normal select read-back returned unexpected payload",
+ expected_index=matched_index,
+ expected_label=matched_label,
+ expected_value=matched_value,
+ actual_selection=selection,
+ )
+ return False
+
+ actual_index = selection.get("index")
+ actual_value = selection.get("value")
+ actual_label = selection.get("label") or actual_value
+ if (
+ actual_index == matched_index
+ and actual_label == matched_label
+ and (matched_value is None or actual_value == matched_value)
+ ):
+ return True
+
+ LOG.info(
+ "Normal select read-back did not match deterministic option",
+ expected_index=matched_index,
+ expected_label=matched_label,
+ expected_value=matched_value,
+ actual_index=actual_index,
+ actual_label=actual_label,
+ actual_value=actual_value,
+ )
+ return False
+
+
async def check_date_format(
value: str,
action: actions.InputTextAction,
@@ -5487,7 +5698,10 @@ async def normal_select(
step: Step,
builder: ElementTreeBuilder,
) -> List[ActionResult]:
- action.set_has_mini_agent()
+ collapse_select_fanout_enabled = await _is_collapse_select_fanout_enabled(task)
+ if not collapse_select_fanout_enabled:
+ action.set_has_mini_agent()
+
try:
current_text = await skyvern_element.get_attr("selected")
if current_text and (current_text == action.option.label or current_text == action.option.value):
@@ -5510,7 +5724,46 @@ async def normal_select(
context=input_or_select_context,
)
- await skyvern_element.refresh_select_options()
+ select_options_result = await skyvern_element.refresh_select_options()
+ select_options = select_options_result[0] if select_options_result else skyvern_element.get_options()
+ target_value = _select_option_target_value(action.option)
+ if target_value and select_options and collapse_select_fanout_enabled:
+ option_labels, option_values = _select_option_labels_and_values(select_options)
+ resolution = await app.AGENT_FUNCTION.resolve_field_option(
+ target_value=target_value,
+ option_labels=option_labels,
+ option_values=option_values,
+ field_context=input_or_select_context.model_dump(),
+ url=task.url,
+ organization_id=task.organization_id,
+ )
+ if not resolution.fallback_to_llm and resolution.matched_index is not None:
+ deterministic_result = await _select_deterministic_normal_option(
+ action=action,
+ skyvern_element=skyvern_element,
+ locator=locator,
+ matched_label=resolution.matched_label,
+ matched_value=resolution.matched_value,
+ matched_index=resolution.matched_index,
+ )
+ if _normal_select_successful(deterministic_result) and await _verify_normal_select_option(
+ locator=locator,
+ matched_index=resolution.matched_index,
+ matched_label=resolution.matched_label,
+ matched_value=resolution.matched_value,
+ ):
+ return deterministic_result
+
+ LOG.info(
+ "Deterministic normal-select failed; falling back to LLM path",
+ action=action,
+ target_value=target_value,
+ matched_index=resolution.matched_index,
+ matched_label=resolution.matched_label,
+ )
+
+ if collapse_select_fanout_enabled:
+ action.set_has_mini_agent()
options_html = skyvern_element.build_HTML()
field_information = (
input_or_select_context.field if not input_or_select_context.intention else input_or_select_context.intention
diff --git a/tests/unit/test_fuzzy_matcher_exact_or_stem.py b/tests/unit/test_fuzzy_matcher_exact_or_stem.py
new file mode 100644
index 000000000..ea4731ed2
--- /dev/null
+++ b/tests/unit/test_fuzzy_matcher_exact_or_stem.py
@@ -0,0 +1,35 @@
+from __future__ import annotations
+
+import pytest
+
+from skyvern.core.script_generations.fuzzy_matcher import match_option_exact_or_stem
+
+
+ ("candidate", "options", "expected"),
+ [
+ ("United States", ["Canada", "United States"], 1),
+ ("united states", ["Canada", "United States"], 1),
+ ("O'Reilly", ["O'Reilly Auto", "OReilly"], 1),
+ ("Departments", ["Department", "Role"], 0),
+ ("bachelors", ["Bachelor", "Master"], 0),
+ ],
+)
+def test_returns_index_on_exact_or_clean_stem(candidate: str, options: list[str], expected: int) -> None:
+ assert match_option_exact_or_stem(candidate, options) == expected
+
+
+ ("candidate", "options"),
+ [
+ ("", ["United States"]),
+ ("United States", []),
+ ("United States", ["United States", "United States"]),
+ ("Senior", ["Senior Vice President", "Associate"]),
+ ("New York", ["New York City", "New Hampshire"]),
+ ("us", ["use", "user"]),
+ ("offices", ["office", "Office"]),
+ ],
+)
+def test_returns_none_when_not_safely_resolvable(candidate: str, options: list[str]) -> None:
+ assert match_option_exact_or_stem(candidate, options) is None
diff --git a/tests/unit/test_normal_select_deterministic.py b/tests/unit/test_normal_select_deterministic.py
new file mode 100644
index 000000000..b7961e018
--- /dev/null
+++ b/tests/unit/test_normal_select_deterministic.py
@@ -0,0 +1,321 @@
+from __future__ import annotations
+
+from datetime import UTC, datetime
+from types import SimpleNamespace
+from unittest.mock import AsyncMock, MagicMock, call
+
+import pytest
+
+from skyvern.forge.agent_functions import AgentFunction
+from skyvern.webeye.actions import handler
+from skyvern.webeye.actions.actions import InputOrSelectContext, SelectOption, SelectOptionAction
+from tests.unit.helpers import make_organization, make_task
+
+
+class _FakeSelectElement:
+ def __init__(self, options: list[dict], locator: MagicMock, selected_attr: str | None = None) -> None:
+ self._options = options
+ self._locator = locator
+ self.get_attr = AsyncMock(return_value=selected_attr)
+ self.refresh_select_options = AsyncMock(return_value=(options, ""))
+
+ def get_locator(self) -> MagicMock:
+ return self._locator
+
+ def get_options(self) -> list[dict]:
+ return self._options
+
+ def build_HTML(self) -> str:
+ return "<select></select>"
+
+
+def _select_action(label: str) -> SelectOptionAction:
+ return SelectOptionAction(
+ element_id="select-1",
+ option=SelectOption(label=label),
+ input_or_select_context=InputOrSelectContext(field="Department", is_required=True),
+ )
+
+
+def _task() -> object:
+ now = datetime.now(UTC)
+ organization = make_organization(now)
+ return make_task(now, organization)
+
+
+def _selected_option_readback(
+ options: list[dict],
+ selected_value: str,
+ *,
+ selected_label: str | None = None,
+ selected_index: int | None = None,
+) -> dict:
+ for index, option in enumerate(options):
+ if option.get("value") == selected_value:
+ return {
+ "index": option.get("optionIndex", index) if selected_index is None else selected_index,
+ "label": option.get("text") if selected_label is None else selected_label,
+ "value": selected_value,
+ }
+ return {"index": selected_index, "label": selected_label or selected_value, "value": selected_value}
+
+
+def _locator(
+ options: list[dict],
+ selected_value: str,
+ *,
+ selected_label: str | None = None,
+ selected_index: int | None = None,
+) -> MagicMock:
+ locator = MagicMock()
+ locator.click = AsyncMock()
+ locator.select_option = AsyncMock()
+ locator.input_value = AsyncMock(return_value=selected_value)
+ locator.evaluate = AsyncMock(
+ return_value=_selected_option_readback(
+ options,
+ selected_value,
+ selected_label=selected_label,
+ selected_index=selected_index,
+ )
+ )
+ return locator
+
+
+async def _run_normal_select(
+ monkeypatch: pytest.MonkeyPatch,
+ *,
+ feature_enabled: bool,
+ action: SelectOptionAction,
+ options: list[dict],
+ selected_value: str,
+ selected_attr: str | None = None,
+ selected_label: str | None = None,
+ selected_index: int | None = None,
+ llm_response: dict | None = None,
+) -> tuple[list, MagicMock, AsyncMock]:
+ provider = SimpleNamespace(is_feature_enabled_cached=AsyncMock(return_value=feature_enabled))
+ normal_select_llm = AsyncMock(return_value=llm_response or {"value": "fallback", "index": None})
+
+ monkeypatch.setattr(handler.app, "EXPERIMENTATION_PROVIDER", provider)
+ monkeypatch.setattr(handler.app, "AGENT_FUNCTION", AgentFunction())
+ monkeypatch.setattr(handler.app, "NORMAL_SELECT_AGENT_LLM_API_HANDLER", normal_select_llm)
+ monkeypatch.setattr(handler.prompt_engine, "load_prompt", MagicMock(return_value="prompt"))
+ monkeypatch.setattr(handler.skyvern_context, "ensure_context", MagicMock(return_value=SimpleNamespace(tz_info=UTC)))
+
+ locator = _locator(options, selected_value, selected_label=selected_label, selected_index=selected_index)
+ result = await handler.normal_select(
+ action=action,
+ skyvern_element=_FakeSelectElement(options, locator, selected_attr), # type: ignore[arg-type]
+ task=_task(), # type: ignore[arg-type]
+ step=MagicMock(),
+ builder=MagicMock(),
+ )
+ return result, locator, normal_select_llm
+
+
+ ("target", "options", "selected_value"),
+ [
+ (
+ "United States",
+ [
+ {"optionIndex": 0, "text": "Canada", "value": "CA"},
+ {"optionIndex": 1, "text": "United States", "value": "US"},
+ ],
+ "US",
+ ),
+ (
+ "Departments",
+ [
+ {"optionIndex": 0, "text": "Department", "value": "department"},
+ {"optionIndex": 1, "text": "Role", "value": "role"},
+ ],
+ "department",
+ ),
+ ],
+)
+async def test_normal_select_exact_or_stem_match_skips_llm(
+ monkeypatch: pytest.MonkeyPatch,
+ target: str,
+ options: list[dict],
+ selected_value: str,
+) -> None:
+ result, locator, normal_select_llm = await _run_normal_select(
+ monkeypatch,
+ feature_enabled=True,
+ action=_select_action(target),
+ options=options,
+ selected_value=selected_value,
+ )
+
+ assert handler._normal_select_successful(result)
+ locator.select_option.assert_awaited_once_with(
+ value=selected_value,
+ timeout=handler.settings.BROWSER_ACTION_TIMEOUT_MS,
+ )
+ normal_select_llm.assert_not_awaited()
+
+
+async def test_normal_select_duplicate_value_selects_matched_label(monkeypatch: pytest.MonkeyPatch) -> None:
+ action = _select_action("Target Department")
+ result, locator, normal_select_llm = await _run_normal_select(
+ monkeypatch,
+ feature_enabled=True,
+ action=action,
+ options=[
+ {"optionIndex": 0, "text": "Wrong Department", "value": "shared"},
+ {"optionIndex": 1, "text": "Target Department", "value": "shared"},
+ ],
+ selected_value="shared",
+ selected_label="Target Department",
+ selected_index=1,
+ )
+
+ assert handler._normal_select_successful(result)
+ locator.select_option.assert_awaited_once_with(
+ label="Target Department",
+ timeout=handler.settings.BROWSER_ACTION_TIMEOUT_MS,
+ )
+ locator.evaluate.assert_awaited_once()
+ normal_select_llm.assert_not_awaited()
+
+
+async def test_normal_select_duplicate_value_wrong_label_falls_back_to_llm(
+ monkeypatch: pytest.MonkeyPatch,
+) -> None:
+ action = _select_action("Target Department")
+ result, locator, normal_select_llm = await _run_normal_select(
+ monkeypatch,
+ feature_enabled=True,
+ action=action,
+ options=[
+ {"optionIndex": 0, "text": "Wrong Department", "value": "shared"},
+ {"optionIndex": 1, "text": "Target Department", "value": "shared"},
+ ],
+ selected_value="shared",
+ selected_label="Wrong Department",
+ selected_index=0,
+ llm_response={"value": "Target Department", "index": 1},
+ )
+
+ assert handler._normal_select_successful(result)
+ assert action.has_mini_agent is True
+ assert locator.select_option.await_args_list[0] == call(
+ label="Target Department",
+ timeout=handler.settings.BROWSER_ACTION_TIMEOUT_MS,
+ )
+ locator.evaluate.assert_awaited_once()
+ normal_select_llm.assert_awaited_once()
+
+
+ ("target", "options", "llm_value"),
+ [
+ (
+ "Senior",
+ [
+ {"optionIndex": 0, "text": "Senior Vice President", "value": "svp"},
+ {"optionIndex": 1, "text": "Associate", "value": "associate"},
+ ],
+ "svp",
+ ),
+ (
+ "United States",
+ [
+ {"optionIndex": 0, "text": "United States", "value": "US"},
+ {"optionIndex": 1, "text": "United States", "value": "USA"},
+ ],
+ "USA",
+ ),
+ ],
+)
+async def test_normal_select_unsafe_match_falls_back_to_llm(
+ monkeypatch: pytest.MonkeyPatch,
+ target: str,
+ options: list[dict],
+ llm_value: str,
+) -> None:
+ action = _select_action(target)
+ result, locator, normal_select_llm = await _run_normal_select(
+ monkeypatch,
+ feature_enabled=True,
+ action=action,
+ options=options,
+ selected_value=llm_value,
+ llm_response={"value": llm_value, "index": None},
+ )
+
+ assert handler._normal_select_successful(result)
+ assert action.has_mini_agent is True
+ locator.select_option.assert_awaited_once_with(value=llm_value, timeout=handler.settings.BROWSER_ACTION_TIMEOUT_MS)
+ normal_select_llm.assert_awaited_once()
+
+
+async def test_normal_select_readback_failure_falls_back_to_llm(monkeypatch: pytest.MonkeyPatch) -> None:
+ action = _select_action("United States")
+ result, locator, normal_select_llm = await _run_normal_select(
+ monkeypatch,
+ feature_enabled=True,
+ action=action,
+ options=[
+ {"optionIndex": 0, "text": "Canada", "value": "CA"},
+ {"optionIndex": 1, "text": "United States", "value": "US"},
+ ],
+ selected_value="CA",
+ llm_response={"value": "US", "index": None},
+ )
+
+ assert handler._normal_select_successful(result)
+ assert action.has_mini_agent is True
+ locator.select_option.assert_has_awaits(
+ [
+ call(value="US", timeout=handler.settings.BROWSER_ACTION_TIMEOUT_MS),
+ call(value="US", timeout=handler.settings.BROWSER_ACTION_TIMEOUT_MS),
+ ]
+ )
+ normal_select_llm.assert_awaited_once()
+
+
+async def test_normal_select_flag_off_uses_llm_path(monkeypatch: pytest.MonkeyPatch) -> None:
+ action = _select_action("United States")
+ result, locator, normal_select_llm = await _run_normal_select(
+ monkeypatch,
+ feature_enabled=False,
+ action=action,
+ options=[{"optionIndex": 0, "text": "United States", "value": "US"}],
+ selected_value="US",
+ llm_response={"value": "US", "index": None},
+ )
+
+ assert handler._normal_select_successful(result)
+ assert action.has_mini_agent is True
+ locator.select_option.assert_awaited_once_with(value="US", timeout=handler.settings.BROWSER_ACTION_TIMEOUT_MS)
+ normal_select_llm.assert_awaited_once()
+
+
+async def test_normal_select_flag_off_marks_mini_agent_before_already_selected_return(
+ monkeypatch: pytest.MonkeyPatch,
+) -> None:
+ action = _select_action("United States")
+ result, locator, normal_select_llm = await _run_normal_select(
+ monkeypatch,
+ feature_enabled=False,
+ action=action,
+ options=[{"optionIndex": 0, "text": "United States", "value": "US"}],
+ selected_attr="United States",
+ selected_value="US",
+ llm_response={"value": "US", "index": None},
+ )
+
+ assert handler._normal_select_successful(result)
+ assert action.has_mini_agent is True
+ locator.select_option.assert_not_awaited()
+ normal_select_llm.assert_not_awaited()