Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@radugheo
Copy link
Collaborator

No description provided.

@radugheo radugheo requested review from Copilot and ionmincu and removed request for Copilot November 11, 2025 08:51
Copilot AI review requested due to automatic review settings November 11, 2025 08:56
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This WIP PR adds extensive error logging to the ground-to-cloud test file to help diagnose issues during test execution. The changes wrap existing async operations in nested try-except blocks with contextual log messages at different stages of the test workflow.

Key Changes:

  • Added nested try-except blocks around session initialization, tool listing, and tool calling operations
  • Introduced contextual logging tags ([Initialize], [Tools], [Add Tool], [Client Session], [Streamable HTTP Client]) to identify error sources
  • Minor formatting adjustments to multi-line lists

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 66 to 72
except Exception as e:
print(f"[Add Tool] Error calling add tool: {e}")
raise e

if actual_result != expected_result:
raise AssertionError(f"Expected {expected_result}, got {actual_result}")

Copy link

Copilot AI Nov 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable actual_result is used outside the try-except block (line 70) but is only defined inside it (line 65). If an exception occurs in the try block before actual_result is assigned, the code will fail with a NameError when trying to access this undefined variable in the comparison on line 70.

Suggested change
except Exception as e:
print(f"[Add Tool] Error calling add tool: {e}")
raise e
if actual_result != expected_result:
raise AssertionError(f"Expected {expected_result}, got {actual_result}")
if actual_result != expected_result:
raise AssertionError(f"Expected {expected_result}, got {actual_result}")
except Exception as e:
print(f"[Add Tool] Error calling add tool: {e}")
raise e

Copilot uses AI. Check for mistakes.
Comment on lines 36 to 68
try:
await session.initialize()
except Exception as e:
print(f"[Initialize] Error initializing session: {e}")
raise e

# List available tools
try:
tools_result = await session.list_tools()
available_tools = [tool.name for tool in tools_result.tools]
expected_available_tools = [
"add", "subtract", "multiply", "divide", "power", "square_root", "nth_root",
"sin", "cos", "tan", "log10", "natural_log", "log_base", "mean", "median", "standard_deviation",
"complex_add", "complex_multiply", "convert_temperature", "solve_quadratic", "get_constants"
]

print (f"Available tools: {available_tools}")
except Exception as e:
print(f"[Tools] Error listing tools: {e}")
raise e

if set(available_tools) != set(expected_available_tools):
raise AssertionError(f"Tool sets don't match. Expected: {set(expected_available_tools)}, Got: {set(available_tools)}")

# Call the add tool directly
try:
call_tool_result = await session.call_tool(name="add", arguments={"a": 7, "b": 5})

expected_result = "12.0"
actual_result = call_tool_result.content[0].text if call_tool_result.content else None
except Exception as e:
print(f"[Add Tool] Error calling add tool: {e}")
raise e
Copy link

Copilot AI Nov 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These catch-and-re-raise blocks (lines 36-40, 53-55, 66-68) add no value since they simply log and re-raise the same exception without any transformation or recovery logic. The exceptions will propagate naturally and can be logged at a higher level. This pattern creates unnecessary code duplication and increases the indentation depth without providing additional functionality.

Suggested change
try:
await session.initialize()
except Exception as e:
print(f"[Initialize] Error initializing session: {e}")
raise e
# List available tools
try:
tools_result = await session.list_tools()
available_tools = [tool.name for tool in tools_result.tools]
expected_available_tools = [
"add", "subtract", "multiply", "divide", "power", "square_root", "nth_root",
"sin", "cos", "tan", "log10", "natural_log", "log_base", "mean", "median", "standard_deviation",
"complex_add", "complex_multiply", "convert_temperature", "solve_quadratic", "get_constants"
]
print (f"Available tools: {available_tools}")
except Exception as e:
print(f"[Tools] Error listing tools: {e}")
raise e
if set(available_tools) != set(expected_available_tools):
raise AssertionError(f"Tool sets don't match. Expected: {set(expected_available_tools)}, Got: {set(available_tools)}")
# Call the add tool directly
try:
call_tool_result = await session.call_tool(name="add", arguments={"a": 7, "b": 5})
expected_result = "12.0"
actual_result = call_tool_result.content[0].text if call_tool_result.content else None
except Exception as e:
print(f"[Add Tool] Error calling add tool: {e}")
raise e
await session.initialize()
# List available tools
tools_result = await session.list_tools()
available_tools = [tool.name for tool in tools_result.tools]
expected_available_tools = [
"add", "subtract", "multiply", "divide", "power", "square_root", "nth_root",
"sin", "cos", "tan", "log10", "natural_log", "log_base", "mean", "median", "standard_deviation",
"complex_add", "complex_multiply", "convert_temperature", "solve_quadratic", "get_constants"
]
print (f"Available tools: {available_tools}")
if set(available_tools) != set(expected_available_tools):
raise AssertionError(f"Tool sets don't match. Expected: {set(expected_available_tools)}, Got: {set(available_tools)}")
# Call the add tool directly
call_tool_result = await session.call_tool(name="add", arguments={"a": 7, "b": 5})
expected_result = "12.0"
actual_result = call_tool_result.content[0].text if call_tool_result.content else None

Copilot uses AI. Check for mistakes.
"complex_add", "complex_multiply", "convert_temperature", "solve_quadratic", "get_constants"
]

print (f"Available tools: {available_tools}")
Copy link

Copilot AI Nov 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's an extra space between print and the opening parenthesis. This is inconsistent with Python style conventions (PEP 8) which recommend no space between a function name and its opening parenthesis.

Suggested change
print (f"Available tools: {available_tools}")
print(f"Available tools: {available_tools}")

Copilot uses AI. Check for mistakes.
Comment on lines 31 to 82
try:
async with streamablehttp_client(mcp_url, headers={ 'Authorization': f'Bearer {token}' }) as (read_stream, write_stream, _):
try:
async with ClientSession(read_stream, write_stream) as session:
# Initialize the session
try:
await session.initialize()
except Exception as e:
print(f"[Initialize] Error initializing session: {e}")
raise e

# List available tools
try:
tools_result = await session.list_tools()
available_tools = [tool.name for tool in tools_result.tools]
expected_available_tools = [
"add", "subtract", "multiply", "divide", "power", "square_root", "nth_root",
"sin", "cos", "tan", "log10", "natural_log", "log_base", "mean", "median", "standard_deviation",
"complex_add", "complex_multiply", "convert_temperature", "solve_quadratic", "get_constants"
]

print (f"Available tools: {available_tools}")
except Exception as e:
print(f"[Tools] Error listing tools: {e}")
raise e

if set(available_tools) != set(expected_available_tools):
raise AssertionError(f"Tool sets don't match. Expected: {set(expected_available_tools)}, Got: {set(available_tools)}")

# Call the add tool directly
try:
call_tool_result = await session.call_tool(name="add", arguments={"a": 7, "b": 5})

expected_result = "12.0"
actual_result = call_tool_result.content[0].text if call_tool_result.content else None
except Exception as e:
print(f"[Add Tool] Error calling add tool: {e}")
raise e

if actual_result != expected_result:
raise AssertionError(f"Expected {expected_result}, got {actual_result}")

print("Test completed successfully")
except Exception as e:
print(f"[Client Session] Error during MCP session: {e}")
raise e
except Exception as e:
print(f"[Streamable HTTP Client] Error connecting to MCP server: {e}")
raise e
except Exception as e:
print(f"Unexpected error connecting to MCP server: {e}")
raise AssertionError(f"Connection error, {e}") from e
Copy link

Copilot AI Nov 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These nested try-except blocks create unnecessary complexity and redundancy. Each block catches exceptions, logs them with a contextual tag, and re-raises them. However, this creates multiple layers of exception handling where:

  1. Inner exceptions are caught, logged, and re-raised
  2. Outer exceptions catch the same exception, log it again with a different tag, and re-raise
  3. The outermost handler (line 80-82) catches everything and logs it a third time

This results in duplicate error logging and makes the code harder to maintain. Consider using a single try-except block around the main operations with appropriate logging at that level, or use a logging decorator if you need contextual information at different stages.

Suggested change
try:
async with streamablehttp_client(mcp_url, headers={ 'Authorization': f'Bearer {token}' }) as (read_stream, write_stream, _):
try:
async with ClientSession(read_stream, write_stream) as session:
# Initialize the session
try:
await session.initialize()
except Exception as e:
print(f"[Initialize] Error initializing session: {e}")
raise e
# List available tools
try:
tools_result = await session.list_tools()
available_tools = [tool.name for tool in tools_result.tools]
expected_available_tools = [
"add", "subtract", "multiply", "divide", "power", "square_root", "nth_root",
"sin", "cos", "tan", "log10", "natural_log", "log_base", "mean", "median", "standard_deviation",
"complex_add", "complex_multiply", "convert_temperature", "solve_quadratic", "get_constants"
]
print (f"Available tools: {available_tools}")
except Exception as e:
print(f"[Tools] Error listing tools: {e}")
raise e
if set(available_tools) != set(expected_available_tools):
raise AssertionError(f"Tool sets don't match. Expected: {set(expected_available_tools)}, Got: {set(available_tools)}")
# Call the add tool directly
try:
call_tool_result = await session.call_tool(name="add", arguments={"a": 7, "b": 5})
expected_result = "12.0"
actual_result = call_tool_result.content[0].text if call_tool_result.content else None
except Exception as e:
print(f"[Add Tool] Error calling add tool: {e}")
raise e
if actual_result != expected_result:
raise AssertionError(f"Expected {expected_result}, got {actual_result}")
print("Test completed successfully")
except Exception as e:
print(f"[Client Session] Error during MCP session: {e}")
raise e
except Exception as e:
print(f"[Streamable HTTP Client] Error connecting to MCP server: {e}")
raise e
except Exception as e:
print(f"Unexpected error connecting to MCP server: {e}")
raise AssertionError(f"Connection error, {e}") from e
async with streamablehttp_client(mcp_url, headers={ 'Authorization': f'Bearer {token}' }) as (read_stream, write_stream, _):
async with ClientSession(read_stream, write_stream) as session:
# Initialize the session
await session.initialize()
# List available tools
tools_result = await session.list_tools()
available_tools = [tool.name for tool in tools_result.tools]
expected_available_tools = [
"add", "subtract", "multiply", "divide", "power", "square_root", "nth_root",
"sin", "cos", "tan", "log10", "natural_log", "log_base", "mean", "median", "standard_deviation",
"complex_add", "complex_multiply", "convert_temperature", "solve_quadratic", "get_constants"
]
print (f"Available tools: {available_tools}")
if set(available_tools) != set(expected_available_tools):
raise AssertionError(f"Tool sets don't match. Expected: {set(expected_available_tools)}, Got: {set(available_tools)}")
# Call the add tool directly
call_tool_result = await session.call_tool(name="add", arguments={"a": 7, "b": 5})
expected_result = "12.0"
actual_result = call_tool_result.content[0].text if call_tool_result.content else None
if actual_result != expected_result:
raise AssertionError(f"Expected {expected_result}, got {actual_result}")
print("Test completed successfully")
except Exception as e:
print(f"Error during MCP server test: {e}")
raise AssertionError(f"Test failed: {e}") from e

Copilot uses AI. Check for mistakes.
Comment on lines 53 to 59
except Exception as e:
print(f"[Tools] Error listing tools: {e}")
raise e

if set(available_tools) != set(expected_available_tools):
raise AssertionError(f"Tool sets don't match. Expected: {set(expected_available_tools)}, Got: {set(available_tools)}")

Copy link

Copilot AI Nov 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable available_tools is used outside the try-except block (line 57) but is only defined inside it (line 45). If an exception occurs in the try block before available_tools is assigned, the code will fail with a NameError when trying to access this undefined variable in the comparison on line 57.

Suggested change
except Exception as e:
print(f"[Tools] Error listing tools: {e}")
raise e
if set(available_tools) != set(expected_available_tools):
raise AssertionError(f"Tool sets don't match. Expected: {set(expected_available_tools)}, Got: {set(available_tools)}")
if set(available_tools) != set(expected_available_tools):
raise AssertionError(f"Tool sets don't match. Expected: {set(expected_available_tools)}, Got: {set(available_tools)}")
except Exception as e:
print(f"[Tools] Error listing tools: {e}")
raise e

Copilot uses AI. Check for mistakes.
@radugheo radugheo changed the title [WIP] test: add logs [WIP] Add cloud to integration tests Nov 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant