async def test_workflow_handles_cancellation(self, mock_dicts):
        """Test that workflow handles cancellation and updates sync job status."""
        async with WorkflowEnvironment() as env:
            # Mock the activities
            async def mock_run_sync_activity(*args, **kwargs):
                # Simulate a long-running activity that gets cancelled
                raise CancelledError("Activity was cancelled")

            status_updated = False

            async def mock_update_status_activity(*args, **kwargs):
                nonlocal status_updated
                # Verify the correct parameters are passed
                sync_job_id, status, user_dict, error, failed_at = args
                assert sync_job_id == mock_dicts["sync_job_dict"]["id"]
                assert status == "CANCELLED"
                assert "cancelled" in error.lower()
                assert failed_at is not None
                # failed_at should be an ISO format string from workflow.now()
                datetime.fromisoformat(failed_at)
                status_updated = True

            # Register mocked activities
            env.set_activity_implementation(run_sync_activity, mock_run_sync_activity)
            env.set_activity_implementation(
                update_sync_job_status_activity, mock_update_status_activity
            )

            # Run the workflow and expect it to raise CancelledError
            with pytest.raises(CancelledError):
                await env.client.execute_workflow(
                    RunSourceConnectionWorkflow.run,
                    args=[
                        mock_dicts["sync_dict"],
                        mock_dicts["sync_job_dict"],
                        mock_dicts["sync_dag_dict"],
                        mock_dicts["collection_dict"],
                        mock_dicts["source_connection_dict"],
                        mock_dicts["user_dict"],
                        None,
                    ],
                    id=f"test-workflow-{uuid4()}",
                    task_queue="test-queue",
                )

            # Verify that the status update activity was called
            assert status_updated, "Status update activity should have been called"
Test that workflow handles cancellation and updates sync job status.
backend/tests/unit/platform/temporal/test_error_handling.py