|
| 1 | +"""Tests for GPT-5 Responses API migration: model detection and flag wiring.""" |
| 2 | + |
| 3 | +from unittest.mock import MagicMock, patch |
| 4 | + |
| 5 | +import pytest |
| 6 | + |
| 7 | +from UMLBot.config.config import UMLBotConfig, is_responses_api_model |
| 8 | + |
| 9 | +# --------------------------------------------------------------------------- |
| 10 | +# is_responses_api_model |
| 11 | +# --------------------------------------------------------------------------- |
| 12 | + |
| 13 | + |
| 14 | +class TestIsResponsesApiModel: |
| 15 | + """Tests for the GPT-5 model detection helper.""" |
| 16 | + |
| 17 | + def test_gpt5_matches(self) -> None: |
| 18 | + assert is_responses_api_model("gpt-5") is True |
| 19 | + |
| 20 | + def test_gpt5_mini_matches(self) -> None: |
| 21 | + assert is_responses_api_model("gpt-5-mini") is True |
| 22 | + |
| 23 | + def test_gpt5_nano_matches(self) -> None: |
| 24 | + assert is_responses_api_model("gpt-5-nano") is True |
| 25 | + |
| 26 | + def test_gpt5_no_dash_matches(self) -> None: |
| 27 | + assert is_responses_api_model("gpt5") is True |
| 28 | + |
| 29 | + def test_gpt5_case_insensitive(self) -> None: |
| 30 | + assert is_responses_api_model("GPT-5") is True |
| 31 | + |
| 32 | + def test_gpt5_dot_variant_matches(self) -> None: |
| 33 | + assert is_responses_api_model("gpt-5.2") is True |
| 34 | + |
| 35 | + def test_gpt4o_does_not_match(self) -> None: |
| 36 | + assert is_responses_api_model("gpt-4o") is False |
| 37 | + |
| 38 | + def test_gpt4o_mini_does_not_match(self) -> None: |
| 39 | + assert is_responses_api_model("gpt-4o-mini") is False |
| 40 | + |
| 41 | + def test_empty_string(self) -> None: |
| 42 | + assert is_responses_api_model("") is False |
| 43 | + |
| 44 | + def test_other_model(self) -> None: |
| 45 | + assert is_responses_api_model("claude-3-opus") is False |
| 46 | + |
| 47 | + |
| 48 | +# --------------------------------------------------------------------------- |
| 49 | +# REASONING_EFFORT config |
| 50 | +# --------------------------------------------------------------------------- |
| 51 | + |
| 52 | + |
| 53 | +class TestReasoningEffortConfig: |
| 54 | + """Verify REASONING_EFFORT is present and has a valid default.""" |
| 55 | + |
| 56 | + def test_default_value(self) -> None: |
| 57 | + assert UMLBotConfig.REASONING_EFFORT in ("none", "minimal", "low", "medium", "high", None) |
| 58 | + |
| 59 | + |
| 60 | +# --------------------------------------------------------------------------- |
| 61 | +# _generate_from_description passes Responses API flags |
| 62 | +# --------------------------------------------------------------------------- |
| 63 | + |
| 64 | + |
| 65 | +class TestResponsesApiWiring: |
| 66 | + """Verify that _generate_from_description passes the correct flags to _init_openai.""" |
| 67 | + |
| 68 | + @patch("UMLBot.services.diagram_service._render_plantuml_jar") |
| 69 | + def test_gpt5_model_sets_responses_api_flag(self, mock_render: MagicMock) -> None: |
| 70 | + from UMLBot.services.diagram_service import DiagramService |
| 71 | + |
| 72 | + mock_render.return_value = (None, "rendered") |
| 73 | + service = DiagramService() |
| 74 | + |
| 75 | + handler = MagicMock() |
| 76 | + handler.process.return_value = "@startuml\n@enduml" |
| 77 | + |
| 78 | + service._generate_from_description( |
| 79 | + handler=handler, |
| 80 | + description="test", |
| 81 | + diagram_type="Class", |
| 82 | + theme=None, |
| 83 | + fallback_template="@startuml\n@enduml", |
| 84 | + failure_log="fail", |
| 85 | + openai_compatible_endpoint="https://api.openai.com/v1", |
| 86 | + openai_compatible_key="sk-test", |
| 87 | + openai_compatible_model="gpt-5-mini", |
| 88 | + ) |
| 89 | + |
| 90 | + handler._init_openai.assert_called_once() |
| 91 | + call_kwargs = handler._init_openai.call_args[1] |
| 92 | + assert call_kwargs["use_responses_api"] is True |
| 93 | + assert call_kwargs["reasoning_effort"] is not None |
| 94 | + |
| 95 | + @patch("UMLBot.services.diagram_service._render_plantuml_jar") |
| 96 | + def test_gpt4o_model_does_not_set_responses_api_flag(self, mock_render: MagicMock) -> None: |
| 97 | + from UMLBot.services.diagram_service import DiagramService |
| 98 | + |
| 99 | + mock_render.return_value = (None, "rendered") |
| 100 | + service = DiagramService() |
| 101 | + |
| 102 | + handler = MagicMock() |
| 103 | + handler.process.return_value = "@startuml\n@enduml" |
| 104 | + |
| 105 | + service._generate_from_description( |
| 106 | + handler=handler, |
| 107 | + description="test", |
| 108 | + diagram_type="Class", |
| 109 | + theme=None, |
| 110 | + fallback_template="@startuml\n@enduml", |
| 111 | + failure_log="fail", |
| 112 | + openai_compatible_endpoint="https://api.openai.com/v1", |
| 113 | + openai_compatible_key="sk-test", |
| 114 | + openai_compatible_model="gpt-4o-mini", |
| 115 | + ) |
| 116 | + |
| 117 | + handler._init_openai.assert_called_once() |
| 118 | + call_kwargs = handler._init_openai.call_args[1] |
| 119 | + assert call_kwargs["use_responses_api"] is False |
| 120 | + assert call_kwargs["reasoning_effort"] is None |
0 commit comments