fix: Resolve test isolation issues for o3-pro test

- Fixed test_fallback_with_shorthand_restrictions to clear restriction
  service singleton in finally block, preventing state leakage
- Updated o3-pro test to use @patch.dict for OPENAI_ALLOWED_MODELS,
  following standard pattern and allowing both o3-pro and o3-pro-2025-06-10
- Removed invalid cassette file that had wrong request content

The test now passes in both isolated and full suite runs.

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

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Josh Vera
2025-07-13 10:22:03 -06:00
parent 538ac55880
commit 3b1c80865b
4 changed files with 7 additions and 97 deletions

File diff suppressed because one or more lines are too long

View File

@@ -694,3 +694,6 @@ class TestAutoModeWithRestrictions:
registry._initialized_providers.clear()
registry._providers.update(original_providers)
registry._initialized_providers.update(original_initialized)
# Clear the restriction service to prevent state leakage
utils.model_restrictions._restriction_service = None

View File

@@ -10,8 +10,10 @@ the OpenAI SDK to create real response objects that we can test.
RECORDING: To record new responses, delete the cassette file and run with real API keys.
"""
import os
import unittest
from pathlib import Path
from unittest.mock import patch
import pytest
from dotenv import load_dotenv
@@ -34,11 +36,6 @@ class TestO3ProOutputTextFix:
def setup_method(self):
"""Set up the test by ensuring clean registry state."""
# Clear the restriction service singleton to ensure clean state
import utils.model_restrictions
utils.model_restrictions._restriction_service = None
# Use the new public API for registry cleanup
ModelProviderRegistry.reset_for_testing()
# Provider registration is now handled by inject_transport helper
@@ -49,6 +46,7 @@ class TestO3ProOutputTextFix:
ModelProviderRegistry.reset_for_testing()
@pytest.mark.no_mock_provider # Disable provider mocking for this test
@patch.dict(os.environ, {"OPENAI_ALLOWED_MODELS": "o3-pro,o3-pro-2025-06-10"})
async def test_o3_pro_uses_output_text_field(self, monkeypatch):
"""Test that o3-pro parsing uses the output_text convenience field via ChatTool."""
# Set API key inline - helper will handle provider registration

View File

@@ -22,11 +22,10 @@ def inject_transport(monkeypatch, cassette_path: str):
transport = inject_transport(monkeypatch, "path/to/cassette.json")
"""
# Ensure OpenAI provider is registered - always needed for transport injection
import os
from providers.base import ProviderType
from providers.openai_provider import OpenAIModelProvider
from providers.registry import ModelProviderRegistry
# Always register OpenAI provider for transport tests (API key might be dummy)
ModelProviderRegistry.register_provider(ProviderType.OPENAI, OpenAIModelProvider)