test: enhance elicitation callback logging and error handling
Improve debugging capabilities for OAuth flow in elicitation callback: - Add detailed logging for consent screen handling - Capture screenshots when consent screen not detected or fails - Replace networkidle wait with explicit callback URL polling - Add 2-second grace period for server-side callback processing - Log page title and current URL for debugging This helps diagnose issues like expired OAuth clients or authorization failures during real elicitation testing. Test results: All 4 elicitation integration tests passing - test_check_logged_in_with_real_elicitation_callback ✓ - test_elicitation_callback_url_extraction ✓ - test_elicitation_stores_refresh_token ✓ - test_second_check_logged_in_does_not_elicit ✓ 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
+34
-3
@@ -339,15 +339,46 @@ async def nc_mcp_oauth_client_with_elicitation(
|
||||
|
||||
# Handle consent screen if present
|
||||
try:
|
||||
logger.info(f" Current URL before consent: {page.url}")
|
||||
consent_handled = await _handle_oauth_consent_screen(page, username)
|
||||
if consent_handled:
|
||||
logger.info(" ✓ Consent granted")
|
||||
else:
|
||||
logger.warning(" ⚠ No consent screen detected")
|
||||
# Take screenshot for debugging
|
||||
screenshot_path = f"/tmp/elicitation_no_consent_{uuid.uuid4()}.png"
|
||||
await page.screenshot(path=screenshot_path)
|
||||
logger.info(f" Screenshot saved: {screenshot_path}")
|
||||
# Log page title for debugging
|
||||
page_title = await page.title()
|
||||
logger.info(f" Page title: {page_title}")
|
||||
except Exception as e:
|
||||
logger.debug(f" No consent screen: {e}")
|
||||
logger.warning(f" ⚠ Consent screen handling failed: {e}")
|
||||
# Take screenshot for debugging
|
||||
screenshot_path = f"/tmp/elicitation_consent_error_{uuid.uuid4()}.png"
|
||||
await page.screenshot(path=screenshot_path)
|
||||
logger.info(f" Screenshot saved: {screenshot_path}")
|
||||
|
||||
# Wait for OAuth callback completion (redirect to success page or callback URL)
|
||||
# Wait for OAuth callback URL to be reached
|
||||
# The MCP server's callback endpoint will handle token exchange
|
||||
await page.wait_for_load_state("networkidle", timeout=30000)
|
||||
logger.info("⏳ Waiting for OAuth callback to complete...")
|
||||
|
||||
# Wait for URL to contain /oauth/callback or a success page
|
||||
# Give it up to 30 seconds for the redirect and token exchange
|
||||
for _ in range(60): # 60 * 0.5s = 30s max wait
|
||||
await anyio.sleep(0.5)
|
||||
current_url = page.url
|
||||
if "/oauth/callback" in current_url or "/user" in current_url:
|
||||
logger.info(f" ✓ Callback URL reached: {current_url}")
|
||||
break
|
||||
else:
|
||||
logger.warning(
|
||||
f" ⚠ Timeout waiting for callback, final URL: {page.url}"
|
||||
)
|
||||
|
||||
# Wait a bit more to ensure the server processed the callback
|
||||
await anyio.sleep(2)
|
||||
|
||||
final_url = page.url
|
||||
logger.info(f" Final URL: {final_url}")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user