@@ -295,23 +295,47 @@ async def test_maintains_execution_id_for_concurrent_requests(monkeypatch, capsy
295295
296296
297297def test_async_decorator_with_sync_function ():
298- """Test that the async decorator handles sync functions properly."""
299-
300- # Create a sync function
301298 def sync_func (request ):
302299 return {"status" : "ok" }
303300
304- # Apply the decorator
305301 wrapped = execution_id .set_execution_context_async (enable_id_logging = False )(
306302 sync_func
307303 )
308304
309- # Create mock request
310305 request = Mock ()
311306 request .headers = Mock ()
312307 request .headers .get = Mock (return_value = "" )
313308
314- # Call the wrapped function - it should be sync since the original was sync
315309 result = wrapped (request )
316310
317311 assert result == {"status" : "ok" }
312+
313+
314+ def test_sync_cloudevent_function_has_execution_context (monkeypatch , capsys ):
315+ """Test that sync CloudEvent functions can access execution context."""
316+ monkeypatch .setenv ("LOG_EXECUTION_ID" , "true" )
317+
318+ source = TEST_FUNCTIONS_DIR / "execution_id" / "async_main.py"
319+ target = "sync_cloudevent_with_context"
320+ app = create_asgi_app (target , source , signature_type = "cloudevent" )
321+ client = TestClient (app )
322+
323+ response = client .post (
324+ "/" ,
325+ headers = {
326+ "ce-specversion" : "1.0" ,
327+ "ce-type" : "com.example.test" ,
328+ "ce-source" : "test-source" ,
329+ "ce-id" : "test-id" ,
330+ "Function-Execution-Id" : TEST_EXECUTION_ID ,
331+ "Content-Type" : "application/json" ,
332+ },
333+ json = {"message" : "test" },
334+ )
335+
336+ assert response .status_code == 200
337+ assert response .text == "OK"
338+
339+ record = capsys .readouterr ()
340+ assert f"Execution ID in sync CloudEvent: { TEST_EXECUTION_ID } " in record .err
341+ assert "No execution context in sync CloudEvent function!" not in record .err
0 commit comments