feat: Implement code review improvements from gemini-2.5-pro analysis
✨ Key improvements: • Added public reset_for_testing() method to registry for clean test state management • Updated test setup/teardown to use new public API instead of private attributes • Enhanced inject_transport helper to ensure OpenAI provider registration • Migrated additional test files to use inject_transport pattern • Reduced code duplication by ~30 lines across test files 🔧 Technical details: • transport_helpers.py: Always register OpenAI provider for transport tests • test_o3_pro_output_text_fix.py: Use reset_for_testing() API, remove redundant registration • test_o3_pro_fixture_bisect.py: Migrate all 4 test methods to inject_transport • test_o3_pro_simplified.py: Migrate both test methods to inject_transport • providers/registry.py: Add reset_for_testing() public method ✅ Quality assurance: • All 7 o3-pro tests pass with new helper pattern • No regression in test isolation or provider state management • Improved maintainability through centralized transport injection • Follows single responsibility principle with focused helper function 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
106
tests/test_o3_pro_fixture_bisect.py
Normal file
106
tests/test_o3_pro_fixture_bisect.py
Normal file
@@ -0,0 +1,106 @@
|
||||
"""Bisect which operations in allow_all_models fixture are actually needed"""
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from providers import ModelProviderRegistry
|
||||
from tests.transport_helpers import inject_transport
|
||||
from tools.chat import ChatTool
|
||||
|
||||
cassette_dir = Path(__file__).parent / "openai_cassettes"
|
||||
|
||||
|
||||
class TestO3ProFixtureBisect:
|
||||
"""Test different combinations of fixture operations"""
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.no_mock_provider
|
||||
async def test_minimal_just_api_key(self, monkeypatch):
|
||||
"""Test 1: Only set API key, no other operations"""
|
||||
cassette_path = cassette_dir / "o3_pro_basic_math.json"
|
||||
if not cassette_path.exists():
|
||||
pytest.skip("Cassette not found")
|
||||
|
||||
# Only set API key
|
||||
monkeypatch.setenv("OPENAI_API_KEY", "dummy-key-for-replay")
|
||||
|
||||
# Simplified transport injection - just one line!
|
||||
inject_transport(monkeypatch, cassette_path)
|
||||
|
||||
chat_tool = ChatTool()
|
||||
arguments = {"prompt": "What is 2 + 2?", "model": "o3-pro", "temperature": 1.0}
|
||||
|
||||
result = await chat_tool.execute(arguments)
|
||||
assert result is not None
|
||||
print("Test 1 (API key only) passed!")
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.no_mock_provider
|
||||
async def test_api_key_plus_cache_clear(self, monkeypatch):
|
||||
"""Test 2: API key + cache clear only"""
|
||||
cassette_path = cassette_dir / "o3_pro_basic_math.json"
|
||||
if not cassette_path.exists():
|
||||
pytest.skip("Cassette not found")
|
||||
|
||||
# Set API key and clear cache
|
||||
monkeypatch.setenv("OPENAI_API_KEY", "dummy-key-for-replay")
|
||||
ModelProviderRegistry.clear_cache()
|
||||
|
||||
# Simplified transport injection - just one line!
|
||||
inject_transport(monkeypatch, cassette_path)
|
||||
|
||||
chat_tool = ChatTool()
|
||||
arguments = {"prompt": "What is 2 + 2?", "model": "o3-pro", "temperature": 1.0}
|
||||
|
||||
result = await chat_tool.execute(arguments)
|
||||
assert result is not None
|
||||
print("Test 2 (API key + cache clear) passed!")
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.no_mock_provider
|
||||
async def test_targeted_o3_pro_only(self, monkeypatch):
|
||||
"""Test 3: Allow only o3-pro specifically"""
|
||||
cassette_path = cassette_dir / "o3_pro_basic_math.json"
|
||||
if not cassette_path.exists():
|
||||
pytest.skip("Cassette not found")
|
||||
|
||||
# Set API key and allow only o3-pro
|
||||
monkeypatch.setenv("OPENAI_API_KEY", "dummy-key-for-replay")
|
||||
monkeypatch.setenv("OPENAI_ALLOWED_MODELS", "o3-pro")
|
||||
monkeypatch.setattr("utils.model_restrictions._restriction_service", None)
|
||||
ModelProviderRegistry.clear_cache()
|
||||
|
||||
# Simplified transport injection - just one line!
|
||||
inject_transport(monkeypatch, cassette_path)
|
||||
|
||||
chat_tool = ChatTool()
|
||||
arguments = {"prompt": "What is 2 + 2?", "model": "o3-pro", "temperature": 1.0}
|
||||
|
||||
result = await chat_tool.execute(arguments)
|
||||
assert result is not None
|
||||
print("Test 3 (targeted o3-pro only) passed!")
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.no_mock_provider
|
||||
async def test_full_fixture_operations(self, monkeypatch):
|
||||
"""Test 4: All fixture operations (baseline)"""
|
||||
cassette_path = cassette_dir / "o3_pro_basic_math.json"
|
||||
if not cassette_path.exists():
|
||||
pytest.skip("Cassette not found")
|
||||
|
||||
# Full fixture operations
|
||||
monkeypatch.setattr("utils.model_restrictions._restriction_service", None)
|
||||
monkeypatch.setenv("ALLOWED_MODELS", "")
|
||||
monkeypatch.setenv("OPENAI_API_KEY", "dummy-key-for-replay")
|
||||
ModelProviderRegistry.clear_cache()
|
||||
|
||||
# Simplified transport injection - just one line!
|
||||
inject_transport(monkeypatch, cassette_path)
|
||||
|
||||
chat_tool = ChatTool()
|
||||
arguments = {"prompt": "What is 2 + 2?", "model": "o3-pro", "temperature": 1.0}
|
||||
|
||||
result = await chat_tool.execute(arguments)
|
||||
assert result is not None
|
||||
print("Test 4 (full fixture ops) passed!")
|
||||
Reference in New Issue
Block a user