@@ -270,7 +270,7 @@ async def test_compat_rest_transport_subscribe_post_works_no_retry(transport):
270270
271271 async def mock_stream (method , path , context = None , json = None ):
272272 assert method == 'POST'
273- assert json == { 'id' : 'task-123' }
273+ assert json is None
274274 task = Task (id = 'task-123' )
275275 task .status .message .role = Role .ROLE_AGENT
276276 yield StreamResponse (task = task )
@@ -284,8 +284,7 @@ async def mock_stream(method, path, context=None, json=None):
284284 expected_task = Task (id = 'task-123' )
285285 expected_task .status .message .role = Role .ROLE_AGENT
286286 assert events [0 ] == StreamResponse (task = expected_task )
287- assert transport ._subscribe_method == 'POST'
288- assert transport ._subscribe_retry_attempted is False
287+ assert transport ._subscribe_method_override is None
289288
290289
291290@pytest .mark .asyncio
@@ -299,7 +298,7 @@ async def mock_stream(method, path, context=None, json=None):
299298 nonlocal call_count
300299 call_count += 1
301300 if method == 'POST' :
302- assert json == { 'id' : 'task-123' }
301+ assert json is None
303302 create_405_error ()
304303 if method == 'GET' :
305304 assert json is None
@@ -314,29 +313,28 @@ async def mock_stream(method, path, context=None, json=None):
314313
315314 assert len (events ) == 1
316315 assert call_count == 2
317- assert transport ._subscribe_method == 'GET'
318- assert transport ._subscribe_retry_attempted is True
316+ assert transport ._subscribe_method_override == 'GET'
319317
320318 # Second call should use GET directly
321319 call_count = 0
322320 events = [event async for event in transport .subscribe (req )]
323321 assert len (events ) == 1
324322 assert call_count == 1 # Only GET called
325- assert transport ._subscribe_method == 'GET'
323+ assert transport ._subscribe_method_override == 'GET'
326324
327325
328326@pytest .mark .asyncio
329327async def test_compat_rest_transport_subscribe_post_405_get_405_fails (
330328 transport ,
331329):
332330 """Scenario: POST return 405, retry GET, return 405 - error. Second call is just POST."""
333- call_count = 0
331+
332+ method_count = {}
334333
335334 async def mock_stream (method , path , context = None , json = None ):
336- nonlocal call_count
337- call_count += 1
335+ method_count [method ] = method_count .get (method , 0 ) + 1
338336 if method == 'POST' :
339- assert json == { 'id' : 'task-123' }
337+ assert json is None
340338 elif method == 'GET' :
341339 assert json is None
342340 # To make it an async generator even when it raises
@@ -351,16 +349,16 @@ async def mock_stream(method, path, context=None, json=None):
351349 [event async for event in transport .subscribe (req )]
352350
353351 assert '405' in str (exc_info .value )
354- assert call_count == 2 # Tried POST then GET
355- assert transport . _subscribe_method == 'POST'
356- assert transport ._subscribe_retry_attempted is True
352+ assert transport . _subscribe_method_override == ' POST'
353+ assert method_count == { 'POST' : 1 , 'GET' : 1 }
354+ assert transport ._subscribe_auto_method_override is False
357355
358356 # Second call should try POST directly and fail without retry
359- call_count = 0
360357 with pytest .raises (A2AClientError ):
361358 [event async for event in transport .subscribe (req )]
362- assert call_count == 1
363- assert transport ._subscribe_method == 'POST'
359+ assert transport ._subscribe_auto_method_override is False
360+ assert transport ._subscribe_method_override == 'POST'
361+ assert method_count == {'POST' : 2 , 'GET' : 1 }
364362
365363
366364@pytest .mark .asyncio
@@ -372,7 +370,7 @@ async def mock_stream(method, path, context=None, json=None):
372370 nonlocal call_count
373371 call_count += 1
374372 assert method == 'POST'
375- assert json == { 'id' : 'task-123' }
373+ assert json is None
376374 if False :
377375 yield
378376 create_500_error ()
@@ -385,8 +383,71 @@ async def mock_stream(method, path, context=None, json=None):
385383
386384 assert '500' in str (exc_info .value )
387385 assert call_count == 1 # No retry on 500
388- assert transport ._subscribe_method == 'POST'
389- assert transport ._subscribe_retry_attempted is False
386+ assert transport ._subscribe_method_override is None
387+
388+
389+ @pytest .mark .asyncio
390+ async def test_compat_rest_transport_subscribe_method_override_avoids_retry_get (
391+ mock_httpx_client , agent_card
392+ ):
393+ """Scenario: Init with GET override, server returns 405, no automatic retry."""
394+ transport = CompatRestTransport (
395+ httpx_client = mock_httpx_client ,
396+ agent_card = agent_card ,
397+ url = 'http://example.com' ,
398+ subscribe_method_override = 'GET' ,
399+ )
400+ call_count = 0
401+
402+ async def mock_stream (method , path , context = None , json = None ):
403+ nonlocal call_count
404+ call_count += 1
405+ assert method == 'GET'
406+ assert json is None
407+ if False :
408+ yield
409+ create_405_error ()
410+
411+ transport ._send_stream_request = mock_stream
412+
413+ req = SubscribeToTaskRequest (id = 'task-123' )
414+ with pytest .raises (A2AClientError ) as exc_info :
415+ [event async for event in transport .subscribe (req )]
416+
417+ assert '405' in str (exc_info .value )
418+ assert call_count == 1
419+
420+
421+ @pytest .mark .asyncio
422+ async def test_compat_rest_transport_subscribe_method_override_avoids_retry_post (
423+ mock_httpx_client , agent_card
424+ ):
425+ """Scenario: Init with POST override, server returns 405, no automatic retry."""
426+ transport = CompatRestTransport (
427+ httpx_client = mock_httpx_client ,
428+ agent_card = agent_card ,
429+ url = 'http://example.com' ,
430+ subscribe_method_override = 'POST' ,
431+ )
432+ call_count = 0
433+
434+ async def mock_stream (method , path , context = None , json = None ):
435+ nonlocal call_count
436+ call_count += 1
437+ assert method == 'POST'
438+ assert json is None
439+ if False :
440+ yield
441+ create_405_error ()
442+
443+ transport ._send_stream_request = mock_stream
444+
445+ req = SubscribeToTaskRequest (id = 'task-123' )
446+ with pytest .raises (A2AClientError ) as exc_info :
447+ [event async for event in transport .subscribe (req )]
448+
449+ assert '405' in str (exc_info .value )
450+ assert call_count == 1
390451
391452
392453def test_compat_rest_transport_handle_http_error (transport ):
0 commit comments