Modify WorkflowRunNodeExecutionListApi and keep paused records as is (vibe-kanban 05b90412)

The current implementation filters out all node executions whose status is `paused`. Please remove this logic, add unit / integration tests and execute relevant tests.
This commit is contained in:
QuantumGhost
2026-01-27 18:11:24 +08:00
parent f3eb342883
commit d289cf4824
6 changed files with 51 additions and 15 deletions

View File

@ -2,8 +2,7 @@ import enum
class HumanInputFormStatus(enum.StrEnum):
"""Status of a human input form.
"""
"""Status of a human input form."""
# Awaiting submission from any recipient. Forms stay in this state until
# submitted or a timeout rule applies.

View File

@ -114,7 +114,6 @@ class DifyAPISQLAlchemyWorkflowNodeExecutionRepository(DifyAPIWorkflowNodeExecut
WorkflowNodeExecutionModel.tenant_id == tenant_id,
WorkflowNodeExecutionModel.app_id == app_id,
WorkflowNodeExecutionModel.workflow_run_id == workflow_run_id,
WorkflowNodeExecutionModel.status != WorkflowNodeExecutionStatus.PAUSED,
).order_by(asc(WorkflowNodeExecutionModel.created_at))
with self._session_maker() as session:

View File

@ -494,17 +494,19 @@ class TestWorkflowRunService:
# Assert: Verify the expected outcomes
assert result is not None
assert len(result) == 3
assert len(result) == 4
# Verify node execution properties
statuses = [node_execution.status for node_execution in result]
assert "paused" in statuses
assert statuses.count("succeeded") == 3
assert statuses.count("paused") == 1
for node_execution in result:
assert node_execution.status != "paused"
assert node_execution.tenant_id == app.tenant_id
assert node_execution.app_id == app.id
assert node_execution.workflow_run_id == workflow_run.id
assert node_execution.index in [0, 1, 2] # Check that index is one of the expected values
assert node_execution.node_id.startswith("node_") # Check that node_id starts with "node_"
assert node_execution.status == "succeeded"
assert node_execution.node_id.startswith("node_")
def test_get_workflow_run_node_executions_empty(
self, db_session_with_containers, mock_external_service_dependencies

View File

@ -34,9 +34,6 @@ def _patch_console_guards(monkeypatch: pytest.MonkeyPatch, account: Account) ->
monkeypatch.setattr(login_lib, "current_account_with_tenant", lambda: (account, account.current_tenant_id))
monkeypatch.setattr(login_lib, "check_csrf_token", lambda *_, **__: None)
monkeypatch.setattr(console_wraps, "current_account_with_tenant", lambda: (account, account.current_tenant_id))
monkeypatch.setattr(
workflow_run_module, "current_account_with_tenant", lambda: (account, account.current_tenant_id)
)
monkeypatch.setattr(workflow_run_module, "current_user", account)
monkeypatch.setattr(console_wraps.dify_config, "EDITION", "CLOUD")
@ -58,7 +55,8 @@ def test_pause_details_returns_backstage_input_url(app: Flask, monkeypatch: pyte
workflow_run = Mock(spec=WorkflowRun)
workflow_run.status = WorkflowExecutionStatus.PAUSED
workflow_run.created_at = datetime(2024, 1, 1, 12, 0, 0)
monkeypatch.setattr(workflow_run_module.db.session, "get", lambda *_: workflow_run)
fake_db = SimpleNamespace(engine=Mock(), session=SimpleNamespace(get=lambda *_: workflow_run))
monkeypatch.setattr(workflow_run_module, "db", fake_db)
reason = HumanInputRequired(
form_id="form-1",

View File

@ -0,0 +1,40 @@
"""Unit tests for DifyAPISQLAlchemyWorkflowNodeExecutionRepository implementation."""
from unittest.mock import Mock
from sqlalchemy.orm import Session, sessionmaker
from repositories.sqlalchemy_api_workflow_node_execution_repository import (
DifyAPISQLAlchemyWorkflowNodeExecutionRepository,
)
class TestDifyAPISQLAlchemyWorkflowNodeExecutionRepository:
def test_get_executions_by_workflow_run_keeps_paused_records(self):
mock_session = Mock(spec=Session)
execute_result = Mock()
execute_result.scalars.return_value.all.return_value = []
mock_session.execute.return_value = execute_result
session_maker = Mock(spec=sessionmaker)
context_manager = Mock()
context_manager.__enter__ = Mock(return_value=mock_session)
context_manager.__exit__ = Mock(return_value=None)
session_maker.return_value = context_manager
repository = DifyAPISQLAlchemyWorkflowNodeExecutionRepository(session_maker)
repository.get_executions_by_workflow_run(
tenant_id="tenant-123",
app_id="app-123",
workflow_run_id="workflow-run-123",
)
stmt = mock_session.execute.call_args[0][0]
where_clauses = list(getattr(stmt, "_where_criteria", []) or [])
where_strs = [str(clause).lower() for clause in where_clauses]
assert any("tenant_id" in clause for clause in where_strs)
assert any("app_id" in clause for clause in where_strs)
assert any("workflow_run_id" in clause for clause in where_strs)
assert not any("paused" in clause for clause in where_strs)

View File

@ -167,9 +167,7 @@ def test_check_and_handle_human_input_timeouts_marks_and_routes(monkeypatch: pyt
task_module.check_and_handle_human_input_timeouts(limit=100)
assert {
(call["form_id"], call["timeout_status"], call["reason"]) for call in repo.calls
} == {
assert {(call["form_id"], call["timeout_status"], call["reason"]) for call in repo.calls} == {
("form-global", HumanInputFormStatus.EXPIRED, "global_timeout"),
("form-node", HumanInputFormStatus.TIMEOUT, "node_timeout"),
("form-delivery", HumanInputFormStatus.TIMEOUT, "delivery_test_timeout"),