fix: detect desktop runtime without frozen python (#5859)
* fix: detect desktop runtime without frozen python * chore: drop planning docs from runtime fix pr
This commit is contained in:
@@ -7,4 +7,4 @@ def is_frozen_runtime() -> bool:
|
||||
|
||||
|
||||
def is_packaged_desktop_runtime() -> bool:
|
||||
return is_frozen_runtime() and os.environ.get("ASTRBOT_DESKTOP_CLIENT") == "1"
|
||||
return os.environ.get("ASTRBOT_DESKTOP_CLIENT") == "1"
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
from unittest.mock import AsyncMock
|
||||
|
||||
import pytest
|
||||
|
||||
from astrbot.core.utils.pip_installer import PipInstaller
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_install_targets_site_packages_for_desktop_client(monkeypatch, tmp_path):
|
||||
monkeypatch.setenv("ASTRBOT_DESKTOP_CLIENT", "1")
|
||||
monkeypatch.delattr("sys.frozen", raising=False)
|
||||
|
||||
site_packages_path = tmp_path / "site-packages"
|
||||
run_pip = AsyncMock(return_value=0)
|
||||
prepend_sys_path_calls = []
|
||||
ensure_preferred_calls = []
|
||||
|
||||
monkeypatch.setattr(PipInstaller, "_run_pip_in_process", run_pip)
|
||||
monkeypatch.setattr(
|
||||
"astrbot.core.utils.pip_installer.get_astrbot_site_packages_path",
|
||||
lambda: str(site_packages_path),
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
"astrbot.core.utils.pip_installer._prepend_sys_path",
|
||||
lambda path: prepend_sys_path_calls.append(path),
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
"astrbot.core.utils.pip_installer._ensure_plugin_dependencies_preferred",
|
||||
lambda path, requirements: ensure_preferred_calls.append((path, requirements)),
|
||||
)
|
||||
|
||||
installer = PipInstaller("")
|
||||
await installer.install(package_name="demo-package")
|
||||
|
||||
run_pip.assert_awaited_once()
|
||||
recorded_args = run_pip.await_args_list[0].args[0]
|
||||
|
||||
assert "--target" in recorded_args
|
||||
assert str(site_packages_path) in recorded_args
|
||||
assert prepend_sys_path_calls == [str(site_packages_path), str(site_packages_path)]
|
||||
assert ensure_preferred_calls == [(str(site_packages_path), {"demo-package"})]
|
||||
@@ -0,0 +1,26 @@
|
||||
from astrbot.core.utils.astrbot_path import get_astrbot_root
|
||||
from astrbot.core.utils.runtime_env import is_packaged_desktop_runtime
|
||||
|
||||
|
||||
def test_desktop_client_env_marks_desktop_runtime_without_frozen(monkeypatch):
|
||||
monkeypatch.setenv("ASTRBOT_DESKTOP_CLIENT", "1")
|
||||
monkeypatch.delattr("sys.frozen", raising=False)
|
||||
|
||||
assert is_packaged_desktop_runtime() is True
|
||||
|
||||
|
||||
def test_desktop_client_uses_home_root_without_explicit_astrbot_root(monkeypatch):
|
||||
monkeypatch.setenv("ASTRBOT_DESKTOP_CLIENT", "1")
|
||||
monkeypatch.delenv("ASTRBOT_ROOT", raising=False)
|
||||
monkeypatch.delattr("sys.frozen", raising=False)
|
||||
|
||||
assert get_astrbot_root().endswith(".astrbot")
|
||||
|
||||
|
||||
def test_explicit_astrbot_root_overrides_desktop_default(monkeypatch, tmp_path):
|
||||
explicit_root = tmp_path / "astrbot-root"
|
||||
monkeypatch.setenv("ASTRBOT_DESKTOP_CLIENT", "1")
|
||||
monkeypatch.setenv("ASTRBOT_ROOT", str(explicit_root))
|
||||
monkeypatch.delattr("sys.frozen", raising=False)
|
||||
|
||||
assert get_astrbot_root() == str(explicit_root.resolve())
|
||||
Reference in New Issue
Block a user