feat: Fix o3-pro response parsing and implement HTTP transport recorder
- Fix o3-pro response parsing to use output_text convenience field - Replace respx with custom httpx transport solution for better reliability - Implement comprehensive PII sanitization to prevent secret exposure - Add HTTP request/response recording with cassette format for testing - Sanitize all existing cassettes to remove exposed API keys - Update documentation to reflect new HTTP transport recorder - Add test suite for PII sanitization and HTTP recording This change: 1. Fixes timeout issues with o3-pro API calls (was 2+ minutes, now ~15-22 seconds) 2. Properly captures response content without httpx.ResponseNotRead exceptions 3. Preserves original HTTP response format including gzip compression 4. Prevents future secret exposure with automatic PII sanitization 5. Enables reliable replay testing for o3-pro interactions Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -15,13 +15,6 @@ parent_dir = Path(__file__).resolve().parent.parent
|
||||
if str(parent_dir) not in sys.path:
|
||||
sys.path.insert(0, str(parent_dir))
|
||||
|
||||
# Set dummy API keys for tests if not already set or if empty
|
||||
if not os.environ.get("GEMINI_API_KEY"):
|
||||
os.environ["GEMINI_API_KEY"] = "dummy-key-for-tests"
|
||||
if not os.environ.get("OPENAI_API_KEY"):
|
||||
os.environ["OPENAI_API_KEY"] = "dummy-key-for-tests"
|
||||
if not os.environ.get("XAI_API_KEY"):
|
||||
os.environ["XAI_API_KEY"] = "dummy-key-for-tests"
|
||||
|
||||
# Set default model to a specific value for tests to avoid auto mode
|
||||
# This prevents all tests from failing due to missing model parameter
|
||||
@@ -77,11 +70,33 @@ def project_path(tmp_path):
|
||||
return test_dir
|
||||
|
||||
|
||||
def _set_dummy_keys_if_missing():
|
||||
"""Set dummy API keys only when they are completely absent."""
|
||||
for var in ("GEMINI_API_KEY", "OPENAI_API_KEY", "XAI_API_KEY"):
|
||||
if not os.environ.get(var):
|
||||
os.environ[var] = "dummy-key-for-tests"
|
||||
|
||||
|
||||
# Pytest configuration
|
||||
def pytest_configure(config):
|
||||
"""Configure pytest with custom markers"""
|
||||
config.addinivalue_line("markers", "asyncio: mark test as async")
|
||||
config.addinivalue_line("markers", "no_mock_provider: disable automatic provider mocking")
|
||||
# Assume we need dummy keys until we learn otherwise
|
||||
config._needs_dummy_keys = True
|
||||
|
||||
|
||||
def pytest_collection_modifyitems(session, config, items):
|
||||
"""Hook that runs after test collection to check for no_mock_provider markers."""
|
||||
# Check if any test has the no_mock_provider marker
|
||||
for item in items:
|
||||
if item.get_closest_marker("no_mock_provider"):
|
||||
config._needs_dummy_keys = False
|
||||
break
|
||||
|
||||
# Set dummy keys only if no test needs real keys
|
||||
if config._needs_dummy_keys:
|
||||
_set_dummy_keys_if_missing()
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
|
||||
Reference in New Issue
Block a user