Skip to content

Python: Fix CI issues and add comprehensive tests for Azure AI Search Context Provider#2246

Closed
hayato-kishikawa wants to merge 6 commits intomicrosoft:mainfrom
hayato-kishikawa:feature/azure-ai-search-agentic-rag
Closed

Python: Fix CI issues and add comprehensive tests for Azure AI Search Context Provider#2246
hayato-kishikawa wants to merge 6 commits intomicrosoft:mainfrom
hayato-kishikawa:feature/azure-ai-search-agentic-rag

Conversation

@hayato-kishikawa
Copy link
Contributor

@hayato-kishikawa hayato-kishikawa commented Nov 15, 2025

Fix CI issues and add comprehensive tests for Azure AI Search Context Provider

Summary

This PR builds on the excellent work by @farzad528 in PR #1546 and addresses the CI/typing issues blocking the merge.

Changes

🔧 CI/Typing Fixes

  • Mypy error fixed: Removed DEFAULT_CONTEXT_PROMPT override (Line 128) - base class defines this as Final
  • Pre-commit checks: All passing ✅
  • Pyright type errors: All resolved ✅

🧪 Test Coverage Improvements

  • Coverage: 73% → 98% (+25 percentage points)
  • Tests added: 16 new test methods (373 lines)
  • Test results: 41 passed, 0 failed ✅

Farzad Sunavala and others added 6 commits November 2, 2025 15:00
- Fixes mypy error: Cannot assign to final name 'DEFAULT_CONTEXT_PROMPT'
- Base class ContextProvider already defines this as Final
- Instance variable self.context_prompt correctly set in __init__ (Line 197)

Related to microsoft#1546
Added comprehensive test coverage for Azure AI Search provider:
- Agentic mode end-to-end flow (invoking → retrieval)
- Agentic mode empty response fallback handling
- Auto-discovery exception handling for network errors
- Semantic search with semantic_configuration_name parameter

Coverage improved from 73% to 84% (target: 80%+)

Test results: 25 passed, 0 failed

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Added 4 comprehensive tests for vector field auto-discovery (lines 351-384):
- test_single_vector_field_with_embedding_function: Tests successful auto-discovery when embedding function is provided
- test_single_vector_field_warning_without_embedding: Tests warning when vector field found but no embedding function
- test_multiple_vector_fields_warning: Tests warning when multiple vector fields detected
- test_index_client_cleanup_when_not_provided: Tests proper cleanup of internally-created index client

Coverage improved from 84% to 91% (target: 90%+)

Test results: 29 passed, 0 failed

Key fix: Patched Azure SDK classes at source (azure.search.documents.*.aio) instead of module level to handle dynamic imports correctly

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Systematically added comprehensive tests across 4 phases:

**Phase 1 (91%→94%):** Agentic mode validation + resource cleanup
- 7 tests for parameter validation (init-time and runtime)
- Retrieval client cleanup verification

**Phase 2 (94%→95%):** Import error handling
- 1 test for SDK unavailability (ImportError)

**Phase 3 (95%→96%):** Edge cases and alternative paths
- Empty search results handling
- External index client usage
- Early return optimization

**Phase 4 (96%→98%):** Helper functions
- Document text extraction fallback logic

Coverage: 91% → 98% (186 statements, 3 missed)
Tests: 29 → 41 passed (+12 tests)

**Remaining 3 uncovered lines (acceptable):**
- Lines 60-61: Module import exception (impossible to unit test)
- Line 580: Agentic RuntimeError (requires complex SDK mocking)

All tests pass. 98% coverage exceeds industry best practices.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants