-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
fix: 修复了国内配置一些模型不可用问题 #7685
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: 修复了国内配置一些模型不可用问题 #7685
Changes from all commits
616e9ac
f26aeb2
260fd26
7fa4421
269ec30
c2443a8
e9a4eed
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| import ssl | ||
|
|
||
| import pytest | ||
|
|
||
| from astrbot.core.utils import network_utils | ||
|
|
||
|
|
||
| def test_create_proxy_client_reuses_shared_ssl_context( | ||
| monkeypatch: pytest.MonkeyPatch, | ||
| ): | ||
| captured_calls: list[dict] = [] | ||
| headers = {"X-Test-Header": "value"} | ||
|
|
||
| class _FakeAsyncClient: | ||
| def __init__(self, **kwargs): | ||
| captured_calls.append(kwargs) | ||
|
|
||
| monkeypatch.setattr(network_utils.httpx, "AsyncClient", _FakeAsyncClient) | ||
|
|
||
| network_utils.create_proxy_client("OpenAI") | ||
| network_utils.create_proxy_client("OpenAI", proxy="http://127.0.0.1:7890") | ||
| network_utils.create_proxy_client("OpenAI", headers=headers) | ||
|
Comment on lines
+20
to
+22
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion (testing): Add an explicit test for an empty proxy string to match how Since |
||
| network_utils.create_proxy_client("OpenAI", proxy="") | ||
|
|
||
| assert len(captured_calls) == 4 | ||
| assert "proxy" not in captured_calls[0] | ||
| assert captured_calls[1]["proxy"] == "http://127.0.0.1:7890" | ||
| assert captured_calls[2]["headers"] is headers | ||
| assert "proxy" not in captured_calls[3] | ||
| assert isinstance(captured_calls[0]["verify"], ssl.SSLContext) | ||
| assert captured_calls[0]["verify"] is captured_calls[1]["verify"] | ||
| assert captured_calls[1]["verify"] is captured_calls[2]["verify"] | ||
| assert captured_calls[2]["verify"] is captured_calls[3]["verify"] | ||
|
|
||
|
|
||
| def test_create_proxy_client_allows_verify_override( | ||
| monkeypatch: pytest.MonkeyPatch, | ||
| ): | ||
| captured_calls: list[dict] = [] | ||
| custom_verify = ssl.create_default_context() | ||
|
|
||
| class _FakeAsyncClient: | ||
| def __init__(self, **kwargs): | ||
| captured_calls.append(kwargs) | ||
|
|
||
| monkeypatch.setattr(network_utils.httpx, "AsyncClient", _FakeAsyncClient) | ||
|
|
||
| network_utils.create_proxy_client("OpenAI", verify=custom_verify) | ||
|
|
||
| assert len(captured_calls) == 1 | ||
| assert captured_calls[0]["verify"] is custom_verify | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion (testing): Add assertions to verify that
proxyandheadersarguments are correctly forwarded tohttpx.AsyncClient.This test covers SSL context reuse but doesn’t yet validate that
headersandproxyare forwarded correctly. Please extend it (or add a new test) to assert that:proxyis omitted,AsyncClientis called without aproxykwarg.proxyis provided,AsyncClientreceives the expectedproxyvalue.headersis provided tocreate_proxy_client, it is forwarded as theheaderskwarg.You can keep using
_FakeAsyncClientand checkcaptured_calls[i]["proxy"]andcaptured_calls[i]["headers"].