mirror of
https://github.com/AstrBotDevs/AstrBot
synced 2026-07-15 17:30:13 +08:00
fix: refresh astrbot root path resolution
This commit is contained in:
@@ -96,7 +96,7 @@ class AstrbotPaths:
|
||||
"""Astrbot 项目路径管理类"""
|
||||
|
||||
def __init__(self) -> None:
|
||||
self._root = self._resolve_root()
|
||||
self._root_override: Path | None = None
|
||||
|
||||
def _resolve_root(self) -> Path:
|
||||
if path := os.environ.get("ASTRBOT_ROOT"):
|
||||
@@ -108,11 +108,13 @@ class AstrbotPaths:
|
||||
|
||||
@property
|
||||
def root(self) -> Path:
|
||||
return self._root
|
||||
if self._root_override is not None:
|
||||
return self._root_override
|
||||
return self._resolve_root()
|
||||
|
||||
@root.setter
|
||||
def root(self, value: Path) -> None:
|
||||
self._root = value
|
||||
self._root_override = value
|
||||
|
||||
@property
|
||||
def project_root(self) -> Path:
|
||||
|
||||
33
tests/test_astrbot_paths.py
Normal file
33
tests/test_astrbot_paths.py
Normal file
@@ -0,0 +1,33 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
from astrbot.core.utils.astrbot_path import AstrbotPaths
|
||||
|
||||
|
||||
def test_astrbot_paths_root_tracks_environment_updates(monkeypatch, tmp_path: Path):
|
||||
first_root = tmp_path / "first-root"
|
||||
second_root = tmp_path / "second-root"
|
||||
|
||||
monkeypatch.setenv("ASTRBOT_ROOT", str(first_root))
|
||||
paths = AstrbotPaths()
|
||||
|
||||
assert paths.root == first_root
|
||||
assert paths.skills == first_root / "data" / "skills"
|
||||
|
||||
monkeypatch.setenv("ASTRBOT_ROOT", str(second_root))
|
||||
|
||||
assert paths.root == second_root
|
||||
assert paths.skills == second_root / "data" / "skills"
|
||||
|
||||
|
||||
def test_astrbot_paths_root_override_remains_explicit(monkeypatch, tmp_path: Path):
|
||||
monkeypatch.delenv("ASTRBOT_ROOT", raising=False)
|
||||
paths = AstrbotPaths()
|
||||
override_root = tmp_path / "override-root"
|
||||
|
||||
paths.root = override_root
|
||||
monkeypatch.setenv("ASTRBOT_ROOT", str(tmp_path / "env-root"))
|
||||
|
||||
assert paths.root == override_root
|
||||
assert paths.skills == override_root / "data" / "skills"
|
||||
Reference in New Issue
Block a user