fix: preserve legacy plugin catalogs and protect helper token initialization

This commit is contained in:
chenmingxuan committed 2026-10-28 17:53:43 +08:00
1 parent 4dc2057d43
commit e90da727d4
8 files changed
+81 -18

No files matched your search

+1 -1
View File
@@ -87,7 +87,7 @@ class Settings(BaseSettings):
"""Centralized ARTEMIS runtime settings loaded from environment and .env files."""
ARTEMIS_PLUGIN_MARKETPLACE_URL: str = (
"https://git.playones.com/chenmingxuan/Artemis-Plugins/raw/branch/main/catalog-v3.json"
"https://git.playones.com/chenmingxuan/Artemis-Plugins/raw/branch/main/catalog-v4.json"
)
ARTEMIS_PLUGIN_START_TIMEOUT_SECONDS: float = Field(default=30, gt=0, le=300)
ARTEMIS_PLUGIN_TOOL_TIMEOUT_SECONDS: float = Field(default=60, gt=0, le=3600)
+5 -4
View File
@@ -44,10 +44,11 @@ def download(url: str, progress: Callable[[str, int], None]) -> bytes:
def load_catalog() -> PluginCatalog:
url = settings.ARTEMIS_PLUGIN_MARKETPLACE_URL
# Older hosts reject schema-v3 entries before checking version constraints.
# Keep their index intact, and route only the exact former official URL.
if url == "https://git.playones.com/chenmingxuan/Artemis-Plugins/raw/branch/main/catalog.json":
url = url.removesuffix("catalog.json") + "catalog-v3.json"
# Strict older hosts cannot parse newer panel kinds, even if incompatible.
# Preserve their indexes; upgrade only the exact official saved addresses.
official = "https://git.playones.com/chenmingxuan/Artemis-Plugins/raw/branch/main/"
if url in {official + "catalog.json", official + "catalog-v3.json"}:
url = official + "catalog-v4.json"
data = download(url, lambda *_: None)
if len(data) > 2 * 1024 * 1024:
raise ValueError("市场索引过大")
+12 -1
View File
@@ -77,6 +77,8 @@ from typing import Any
import urllib.error
import urllib.request
from filelock import FileLock
from artemis.config.constants import ENV_ARTEMIS_HELPER_AUTO_INSTALL
from artemis.config.paths import get_temp_dir
from artemis.runtime.adb_endpoint import adb_command
@@ -323,7 +325,7 @@ class AccessibilityHelperManager:
if re.fullmatch(r"[0-9a-f]{32,128}", text):
self._token = text
return text
except OSError:
except FileNotFoundError:
pass
token = secrets.token_hex(24)
try:
@@ -550,6 +552,15 @@ class AccessibilityHelperManager:
root.mkdir(parents=True, exist_ok=True)
digest = hashlib.sha256(serial.encode("utf-8")).hexdigest()[:16]
path = root / f"{digest}.mutex"
# An age-based lease alone can be stolen from a live, delayed owner.
# Retain the legacy lease for coexistence with older Artemis processes,
# but serialize current processes with a kernel lock released on exit.
with FileLock(path.with_suffix(".guard"), timeout=_PROVISION_MUTEX_TIMEOUT_SECONDS):
with self._legacy_provision_mutex(path, serial):
yield
@contextmanager
def _legacy_provision_mutex(self, path: Path, serial: str):
started = time.monotonic()
while True:
try: