test(workflow): pass explicit tenant context

This commit is contained in:
-LAN-
2026-07-28 13:03:28 +08:00
parent 5b4f47e21b
commit 7848fcfd83
2 changed files with 11 additions and 1 deletions
@@ -292,6 +292,7 @@ class TestSQLAlchemyWorkflowExecutionRepository:
):
repo = SQLAlchemyWorkflowExecutionRepository(
session_factory=mock_session_factory,
tenant_id=RESOURCE_TENANT_ID,
user=mock_account,
app_id="test_app",
triggered_from=WorkflowRunTriggeredFrom.APP_RUN,
@@ -314,6 +315,7 @@ class TestSQLAlchemyWorkflowExecutionRepository:
):
repo = SQLAlchemyWorkflowExecutionRepository(
session_factory=mock_session_factory,
tenant_id=RESOURCE_TENANT_ID,
user=mock_account,
app_id="test_app",
triggered_from=WorkflowRunTriggeredFrom.APP_RUN,
@@ -325,7 +327,7 @@ class TestSQLAlchemyWorkflowExecutionRepository:
mock_task.delay.assert_called_once()
call_args = mock_task.delay.call_args.kwargs
assert call_args["execution_data"] == sample_workflow_execution.model_dump()
assert call_args["tenant_id"] == mock_account.current_tenant_id
assert call_args["tenant_id"] == RESOURCE_TENANT_ID
assert call_args["app_id"] == "test_app"
assert call_args["triggered_from"] == WorkflowRunTriggeredFrom.APP_RUN
assert call_args["creator_user_id"] == mock_account.id
@@ -338,6 +340,7 @@ class TestSQLAlchemyWorkflowExecutionRepository:
):
repo = SQLAlchemyWorkflowExecutionRepository(
session_factory=mock_session_factory,
tenant_id=RESOURCE_TENANT_ID,
user=mock_account,
app_id="test_app",
triggered_from=WorkflowRunTriggeredFrom.APP_RUN,
@@ -354,6 +354,7 @@ def test_persist_to_database_rejects_existing_execution_from_other_tenant(monkey
session.get.return_value = SimpleNamespace(tenant_id="other-tenant")
repo = SQLAlchemyWorkflowNodeExecutionRepository(
session_factory=_session_factory(session),
tenant_id=RESOURCE_TENANT_ID,
user=_mock_account(),
app_id=None,
triggered_from=WorkflowNodeExecutionTriggeredFrom.WORKFLOW_RUN,
@@ -689,6 +690,7 @@ def test_save_execution_data_updates_terminal_metadata_without_merging_whole_row
session.execute.return_value.scalars.return_value.first.return_value = existing
repo = SQLAlchemyWorkflowNodeExecutionRepository(
session_factory=_session_factory(session),
tenant_id=RESOURCE_TENANT_ID,
user=_mock_account(),
app_id="app",
triggered_from=WorkflowNodeExecutionTriggeredFrom.WORKFLOW_RUN,
@@ -720,6 +722,7 @@ def test_save_execution_data_ignores_stale_nonterminal_snapshot(monkeypatch: pyt
session.scalar.return_value = existing
repo = SQLAlchemyWorkflowNodeExecutionRepository(
session_factory=_session_factory(session),
tenant_id=RESOURCE_TENANT_ID,
user=_mock_account(),
app_id="app",
triggered_from=WorkflowNodeExecutionTriggeredFrom.WORKFLOW_RUN,
@@ -742,6 +745,7 @@ def test_save_queues_celery_task_when_async_persistence_enabled(mock_task, monke
)
repo = SQLAlchemyWorkflowNodeExecutionRepository(
session_factory=Mock(spec=sessionmaker),
tenant_id=RESOURCE_TENANT_ID,
user=_mock_account(),
app_id="app",
triggered_from=WorkflowNodeExecutionTriggeredFrom.WORKFLOW_RUN,
@@ -778,6 +782,7 @@ def test_save_execution_data_queues_celery_task_when_async_persistence_enabled(
)
repo = SQLAlchemyWorkflowNodeExecutionRepository(
session_factory=Mock(spec=sessionmaker),
tenant_id=RESOURCE_TENANT_ID,
user=_mock_account(),
app_id="app",
triggered_from=WorkflowNodeExecutionTriggeredFrom.WORKFLOW_RUN,
@@ -803,6 +808,7 @@ def test_queue_async_save_requires_context(monkeypatch: pytest.MonkeyPatch) -> N
)
repo = SQLAlchemyWorkflowNodeExecutionRepository(
session_factory=Mock(spec=sessionmaker),
tenant_id=RESOURCE_TENANT_ID,
user=_mock_account(),
app_id="app",
triggered_from=WorkflowNodeExecutionTriggeredFrom.WORKFLOW_RUN,
@@ -831,6 +837,7 @@ def test_queue_async_save_execution_data_requires_context(monkeypatch: pytest.Mo
)
repo = SQLAlchemyWorkflowNodeExecutionRepository(
session_factory=Mock(spec=sessionmaker),
tenant_id=RESOURCE_TENANT_ID,
user=_mock_account(),
app_id="app",
triggered_from=WorkflowNodeExecutionTriggeredFrom.WORKFLOW_RUN,