MCPcopy Create free account
hub / github.com/1rgs/claude-code-proxy / test_streaming

Function test_streaming

tests.py:568–630  ·  view source on GitHub ↗

Run a streaming test with the given request data.

(test_name, request_data)

Source from the content-addressed store, hash-verified

566 len(proxy_stats.text_content) > 0 or proxy_stats.has_tool_use)
567
568async def test_streaming(test_name, request_data):
569 """Run a streaming test with the given request data."""
570 print(f"\n{'='*20} RUNNING STREAMING TEST: {test_name} {'='*20}")
571
572 # Log the request data
573 print(f"\nRequest data:\n{json.dumps({k: v for k, v in request_data.items() if k != 'messages'}, indent=2)}")
574
575 # Make copies of the request data to avoid modifying the original
576 anthropic_data = request_data.copy()
577 proxy_data = request_data.copy()
578
579 if not anthropic_data.get("stream"):
580 anthropic_data["stream"] = True
581 if not proxy_data.get("stream"):
582 proxy_data["stream"] = True
583
584 check_tools = "tools" in request_data
585
586 try:
587 # Send streaming requests
588 anthropic_stats, anthropic_error = await stream_response(
589 ANTHROPIC_API_URL, anthropic_headers, anthropic_data, "Anthropic"
590 )
591
592 proxy_stats, proxy_error = await stream_response(
593 PROXY_API_URL, proxy_headers, proxy_data, "Proxy"
594 )
595
596 # Print statistics
597 print("\n--- Anthropic Stream Statistics ---")
598 anthropic_stats.summarize()
599
600 print("\n--- Proxy Stream Statistics ---")
601 proxy_stats.summarize()
602
603 # Compare the responses
604 if anthropic_error:
605 print(f"\n⚠️ Anthropic stream had an error: {anthropic_error}")
606 # If Anthropic errors, the test passes if proxy does anything useful
607 if not proxy_error and proxy_stats.total_chunks > 0:
608 print(f"\n✅ Test {test_name} passed! (Proxy worked even though Anthropic failed)")
609 return True
610 else:
611 print(f"\n❌ Test {test_name} failed! Both streams had errors.")
612 return False
613
614 if proxy_error:
615 print(f"\n❌ Test {test_name} failed! Proxy had an error: {proxy_error}")
616 return False
617
618 result = compare_stream_stats(anthropic_stats, proxy_stats)
619 if result:
620 print(f"\n✅ Test {test_name} passed!")
621 return True
622 else:
623 print(f"\n❌ Test {test_name} failed!")
624 return False
625

Callers 1

run_testsFunction · 0.85

Calls 3

stream_responseFunction · 0.85
compare_stream_statsFunction · 0.85
summarizeMethod · 0.80

Tested by

no test coverage detected