mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-08 08:08:37 +00:00
* fix(github-copilot): use GitHub token directly Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * fix(github-copilot): expire API base cache Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * test(github-copilot): restore authenticator coverage Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * fix(github-copilot): update direct token auth tests Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * fix(github-copilot): cover direct-token error paths Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * fix(github-copilot): satisfy type-discipline gate Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
57 lines
2.3 KiB
Python
57 lines
2.3 KiB
Python
from typing import Final
|
|
|
|
import pytest
|
|
|
|
from litellm.llms.github_copilot.github_host import (
|
|
github_host_endpoints,
|
|
normalized_github_host,
|
|
)
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
("raw", "expected"),
|
|
[
|
|
(None, "github.com"),
|
|
("", "github.com"),
|
|
("GitHub.com", "github.com"),
|
|
("OCTO.ghe.com", "octo.ghe.com"),
|
|
("octo-1.ghe.com", "octo-1.ghe.com"),
|
|
("https://octo.ghe.com", None),
|
|
("ghes.example.com", None),
|
|
("octo.ghe.com:443", None),
|
|
("a.b.ghe.com", None),
|
|
("octo.ghe.com.", None),
|
|
(" api.octo.ghe.com", None),
|
|
("octo.ghe.com/path", None),
|
|
],
|
|
)
|
|
def test_normalized_github_host_accepts_only_bare_supported_hosts(raw: object, expected: str | None) -> None:
|
|
assert normalized_github_host(raw) == expected
|
|
|
|
|
|
def test_github_com_endpoints_read_url_overrides_at_call_time(monkeypatch: pytest.MonkeyPatch) -> None:
|
|
monkeypatch.setenv("GITHUB_COPILOT_DEVICE_CODE_URL", "https://device.example/code")
|
|
monkeypatch.setenv("GITHUB_COPILOT_ACCESS_TOKEN_URL", "https://device.example/token")
|
|
monkeypatch.setenv("GITHUB_COPILOT_CLIENT_ID", "custom-client")
|
|
|
|
endpoints: Final = github_host_endpoints("github.com")
|
|
|
|
assert endpoints.device_code_url == "https://device.example/code"
|
|
assert endpoints.access_token_url == "https://device.example/token"
|
|
assert endpoints.copilot_user_url == "https://api.github.com/copilot_internal/user"
|
|
assert endpoints.client_id == "custom-client"
|
|
|
|
|
|
def test_ghe_endpoints_ignore_github_com_url_overrides(monkeypatch: pytest.MonkeyPatch) -> None:
|
|
monkeypatch.setenv("GITHUB_COPILOT_DEVICE_CODE_URL", "https://device.example/code")
|
|
monkeypatch.setenv("GITHUB_COPILOT_ACCESS_TOKEN_URL", "https://device.example/token")
|
|
monkeypatch.setenv("GITHUB_COPILOT_CLIENT_ID", "custom-client")
|
|
|
|
endpoints: Final = github_host_endpoints("octo.ghe.com")
|
|
|
|
assert endpoints.device_code_url == "https://octo.ghe.com/login/device/code"
|
|
assert endpoints.access_token_url == "https://octo.ghe.com/login/oauth/access_token"
|
|
assert endpoints.copilot_user_url == "https://api.octo.ghe.com/copilot_internal/user"
|
|
assert endpoints.user_url == "https://api.octo.ghe.com/user"
|
|
assert endpoints.default_copilot_api_base == "https://copilot-api.octo.ghe.com"
|
|
assert endpoints.client_id == "custom-client"
|