Automate browser based workflows with AI
Python aiapiautomationbrowserbrowser-automationcomputergptllmplaywrightpowerautomatepuppeteerpythonrpaseleniumvisionworkflow
fix(SKY-8795): match workflow_permanent_id and run_id in list search (#5407)
Aaron Perez50021fdb0f7c
diff --git a/skyvern/forge/sdk/db/repositories/workflow_runs.py b/skyvern/forge/sdk/db/repositories/workflow_runs.pyindex 5d230911e..c3088ef20 100644--- a/skyvern/forge/sdk/db/repositories/workflow_runs.py+++ b/skyvern/forge/sdk/db/repositories/workflow_runs.py@@ -437,7 +437,13 @@ class WorkflowRunsRepository(BaseRepository):query = query.filter(effective_status.in_(status))if search_key:- query = query.filter(TaskRunModel.searchable_text.icontains(search_key, autoescape=True))+ query = query.filter(+ or_(+ TaskRunModel.searchable_text.icontains(search_key, autoescape=True),+ TaskRunModel.run_id.icontains(search_key, autoescape=True),+ TaskRunModel.workflow_permanent_id.icontains(search_key, autoescape=True),+ )+ )offset = (page - 1) * page_sizequery = query.order_by(TaskRunModel.created_at.desc()).offset(offset).limit(page_size)diff --git a/skyvern/forge/sdk/db/repositories/workflows.py b/skyvern/forge/sdk/db/repositories/workflows.pyindex fd9cfb9cd..c256f4e9d 100644--- a/skyvern/forge/sdk/db/repositories/workflows.py+++ b/skyvern/forge/sdk/db/repositories/workflows.py@@ -340,7 +340,8 @@ class WorkflowsRepository(BaseRepository):Search semantics:- If `search_key` is provided, its value is used as a unified search term for- `workflows.title`, `folders.title`, and workflow parameter metadata (key, description, and default_value).+ `workflows.title`, `workflows.workflow_permanent_id`, `folders.title`, and+ workflow parameter metadata (key, description, and default_value).- If `search_key` is not provided, no search filtering is applied.- Parameter metadata search excludes soft-deleted parameter rows across parameter tables."""@@ -395,6 +396,7 @@ class WorkflowsRepository(BaseRepository):search_like = f"%{search_key}%"title_like = WorkflowModel.title.ilike(search_like)folder_title_like = FolderModel.title.ilike(search_like)+ workflow_permanent_id_like = WorkflowModel.workflow_permanent_id.icontains(search_key, autoescape=True)parameter_filters = [# WorkflowParameterModel@@ -516,7 +518,9 @@ class WorkflowsRepository(BaseRepository):)),]- main_query = main_query.where(or_(title_like, folder_title_like, or_(*parameter_filters)))+ main_query = main_query.where(+ or_(title_like, folder_title_like, workflow_permanent_id_like, or_(*parameter_filters))+ )main_query = (main_query.order_by(WorkflowModel.created_at.desc()).limit(page_size).offset(db_page * page_size))diff --git a/tests/unit/forge/sdk/db/test_workflow_runs_repository.py b/tests/unit/forge/sdk/db/test_workflow_runs_repository.pyindex 5f185bde8..35594298a 100644--- a/tests/unit/forge/sdk/db/test_workflow_runs_repository.py+++ b/tests/unit/forge/sdk/db/test_workflow_runs_repository.py@@ -3,6 +3,7 @@from __future__ import annotationsfrom datetime import datetime, timezone+from typing import Anyfrom unittest.mock import AsyncMock, MagicMockimport pytest@@ -154,3 +155,38 @@ async def test_batch_create_propagates_sqlalchemy_error_from_commit() -> None:assert exc_info.value is db_errorsession.flush.assert_awaited_once()session.commit.assert_awaited_once()+++async def test_get_all_runs_v2_search_key_matches_run_id_and_workflow_permanent_id() -> None:+ """Regression test for SKY-8795: searching by run_id (wr_*/tsk_*) or wpid_*+ on the global runs page must match the underlying ID columns, not only+ `searchable_text` (which contains only title + url)."""+ captured: dict[str, Any] = {}++ class _Result:+ def mappings(self):+ class _M:+ def all(self_inner):+ return []++ return _M()++ async def _execute(query):+ captured["query"] = query+ return _Result()++ session = MagicMock()+ session.execute = AsyncMock(side_effect=_execute)++ repo = WorkflowRunsRepository(session_factory=lambda: _SessionContext(session), debug_enabled=False)++ await repo.get_all_runs_v2(organization_id="o_test", search_key="wr_abc123")++ # Inspect the WHERE clause specifically — both columns are also in the SELECT+ # list, so a substring check on the full SQL would be a false positive.+ where_clause = str(captured["query"].whereclause.compile(compile_kwargs={"literal_binds": True}))+ assert "task_runs.run_id" in where_clause+ assert "task_runs.workflow_permanent_id" in where_clause+ # autoescape rewrites '_' to e.g. '/_' so check the distinctive suffix.+ assert "abc123" in where_clausediff --git a/tests/unit/forge/sdk/db/test_workflows_repository_search.py b/tests/unit/forge/sdk/db/test_workflows_repository_search.pynew file mode 100644index 000000000..9ced624b1--- /dev/null+++ b/tests/unit/forge/sdk/db/test_workflows_repository_search.py@@ -0,0 +1,60 @@+"""Regression tests for SKY-8795: workflow list search must match workflow_permanent_id.++The /workflows page sends `search_key` to the backend. Before the fix, the search+only matched `workflows.title`, `folders.title`, and parameter metadata — typing a+`wpid_*` into the search box returned no results.+"""++from __future__ import annotations++from typing import Any+from unittest.mock import AsyncMock, MagicMock++import pytest++from skyvern.forge.sdk.db.repositories.workflows import WorkflowsRepository+++class _SessionContext:+ def __init__(self, session: MagicMock) -> None:+ self._session = session++ async def __aenter__(self) -> MagicMock:+ return self._session++ async def __aexit__(self, exc_type, exc, tb) -> bool:+ return False+++async def test_get_workflows_by_organization_id_search_key_matches_workflow_permanent_id() -> None:+ captured: dict[str, Any] = {}++ class _Scalars:+ def all(self):+ return []++ async def _scalars(query):+ captured["query"] = query+ return _Scalars()++ session = MagicMock()+ session.scalars = AsyncMock(side_effect=_scalars)++ repo = WorkflowsRepository(session_factory=lambda: _SessionContext(session), debug_enabled=False)++ await repo.get_workflows_by_organization_id(+ organization_id="o_test",+ search_key="wpid_510867674757598984",+ )++ # Inspect the WHERE clause specifically — workflow_permanent_id is also in the+ # SELECT list, so a substring check on the full SQL would be a false positive.+ whereclause = captured["query"].whereclause+ assert whereclause is not None+ compiled_where = str(whereclause.compile(compile_kwargs={"literal_binds": True}))++ # The search filter must reference the workflow_permanent_id column directly so+ # that pasting a wpid_* into the workflows page search box finds the workflow.+ assert "workflows.workflow_permanent_id" in compiled_where+ assert "wpid_510867674757598984" in compiled_where