|
| 1 | +# SPDX-FileCopyrightText: GitHub, Inc. |
| 2 | +# SPDX-License-Identifier: MIT |
| 3 | + |
| 4 | +"""Extended tests for capi module.""" |
| 5 | + |
| 6 | +from __future__ import annotations |
| 7 | + |
| 8 | +from seclab_taskflow_agent.capi import AI_API_ENDPOINT_ENUM, supports_tool_calls |
| 9 | + |
| 10 | + |
| 11 | +class TestSupportsToolCalls: |
| 12 | + """Tests for supports_tool_calls with unknown endpoints.""" |
| 13 | + |
| 14 | + def test_unknown_endpoint_known_model(self, monkeypatch): |
| 15 | + """Unknown endpoint returns True when model is in the catalog.""" |
| 16 | + monkeypatch.setenv("AI_API_ENDPOINT", "https://custom.api.example.com/v1") |
| 17 | + models = {"my-model": {"id": "my-model"}} |
| 18 | + assert supports_tool_calls("my-model", models) is True |
| 19 | + |
| 20 | + def test_unknown_endpoint_unknown_model(self, monkeypatch): |
| 21 | + """Unknown endpoint returns False when model is NOT in the catalog.""" |
| 22 | + monkeypatch.setenv("AI_API_ENDPOINT", "https://custom.api.example.com/v1") |
| 23 | + models = {"other-model": {"id": "other-model"}} |
| 24 | + assert supports_tool_calls("missing-model", models) is False |
| 25 | + |
| 26 | + def test_copilot_endpoint_with_capabilities(self, monkeypatch): |
| 27 | + """Copilot endpoint checks capabilities.supports.tool_calls.""" |
| 28 | + monkeypatch.setenv("AI_API_ENDPOINT", "https://api.githubcopilot.com") |
| 29 | + models = { |
| 30 | + "gpt-4o": { |
| 31 | + "id": "gpt-4o", |
| 32 | + "capabilities": {"supports": {"tool_calls": True}}, |
| 33 | + } |
| 34 | + } |
| 35 | + assert supports_tool_calls("gpt-4o", models) is True |
| 36 | + |
| 37 | + def test_copilot_endpoint_without_capabilities(self, monkeypatch): |
| 38 | + """Copilot endpoint returns False when tool_calls not in capabilities.""" |
| 39 | + monkeypatch.setenv("AI_API_ENDPOINT", "https://api.githubcopilot.com") |
| 40 | + models = { |
| 41 | + "text-only": { |
| 42 | + "id": "text-only", |
| 43 | + "capabilities": {"supports": {}}, |
| 44 | + } |
| 45 | + } |
| 46 | + assert supports_tool_calls("text-only", models) is False |
| 47 | + |
| 48 | + def test_models_github_endpoint(self, monkeypatch): |
| 49 | + """models.github.ai checks for 'tool-calling' in capabilities list.""" |
| 50 | + monkeypatch.setenv("AI_API_ENDPOINT", "https://models.github.ai/inference") |
| 51 | + models = { |
| 52 | + "openai/gpt-4o": { |
| 53 | + "id": "openai/gpt-4o", |
| 54 | + "capabilities": ["tool-calling", "chat"], |
| 55 | + } |
| 56 | + } |
| 57 | + assert supports_tool_calls("openai/gpt-4o", models) is True |
| 58 | + |
| 59 | + def test_models_github_endpoint_no_tool_calling(self, monkeypatch): |
| 60 | + """models.github.ai returns False when 'tool-calling' not in list.""" |
| 61 | + monkeypatch.setenv("AI_API_ENDPOINT", "https://models.github.ai/inference") |
| 62 | + models = { |
| 63 | + "some-model": { |
| 64 | + "id": "some-model", |
| 65 | + "capabilities": ["chat"], |
| 66 | + } |
| 67 | + } |
| 68 | + assert supports_tool_calls("some-model", models) is False |
| 69 | + |
| 70 | + def test_openai_endpoint_gpt_model(self, monkeypatch): |
| 71 | + """OpenAI endpoint returns True for models containing 'gpt-'.""" |
| 72 | + monkeypatch.setenv("AI_API_ENDPOINT", "https://api.openai.com/v1") |
| 73 | + assert supports_tool_calls("gpt-4o", {}) is True |
| 74 | + |
| 75 | + def test_openai_endpoint_non_gpt_model(self, monkeypatch): |
| 76 | + """OpenAI endpoint returns False for non-GPT models.""" |
| 77 | + monkeypatch.setenv("AI_API_ENDPOINT", "https://api.openai.com/v1") |
| 78 | + assert supports_tool_calls("claude-3-opus", {}) is False |
| 79 | + |
| 80 | + |
| 81 | +class TestAIAPIEndpointEnum: |
| 82 | + """Tests for the AI_API_ENDPOINT_ENUM StrEnum.""" |
| 83 | + |
| 84 | + def test_enum_values(self): |
| 85 | + """All expected endpoint values exist.""" |
| 86 | + assert AI_API_ENDPOINT_ENUM.AI_API_MODELS_GITHUB == "models.github.ai" |
| 87 | + assert AI_API_ENDPOINT_ENUM.AI_API_GITHUBCOPILOT == "api.githubcopilot.com" |
| 88 | + assert AI_API_ENDPOINT_ENUM.AI_API_OPENAI == "api.openai.com" |
| 89 | + |
| 90 | + def test_to_url_models_github(self): |
| 91 | + assert AI_API_ENDPOINT_ENUM.AI_API_MODELS_GITHUB.to_url() == "https://models.github.ai/inference" |
| 92 | + |
| 93 | + def test_to_url_copilot(self): |
| 94 | + assert AI_API_ENDPOINT_ENUM.AI_API_GITHUBCOPILOT.to_url() == "https://api.githubcopilot.com" |
| 95 | + |
| 96 | + def test_to_url_openai(self): |
| 97 | + assert AI_API_ENDPOINT_ENUM.AI_API_OPENAI.to_url() == "https://api.openai.com/v1" |
0 commit comments