mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-12-01 08:26:28 +08:00
fix(plugin): read the runtime compatibility gate from the declared snapshot (#6761)
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -227,6 +227,7 @@ def configure_plugin_system_services():
|
||||
from app.runtime.extensions.service import ServiceConfigHelper
|
||||
from app.startup.initializers.plugins import (
|
||||
_clear_plugin_default_target,
|
||||
_read_plugin_runtime_declaration,
|
||||
_set_plugin_default_target,
|
||||
)
|
||||
|
||||
@@ -262,6 +263,7 @@ def configure_plugin_system_services():
|
||||
logger=plugin_manager_module.logger,
|
||||
set_default_target=_set_plugin_default_target,
|
||||
clear_default_target=_clear_plugin_default_target,
|
||||
runtime_declaration=_read_plugin_runtime_declaration,
|
||||
),
|
||||
tool_build_max_attempts=PluginManager.AGENT_TOOLS_BUILD_MAX_ATTEMPTS,
|
||||
)
|
||||
|
||||
@@ -1084,8 +1084,8 @@
|
||||
"runtime_only": true
|
||||
}
|
||||
},
|
||||
"edge_count": 8865,
|
||||
"edge_sha256": "6641acd38c2aec65ba3f527ce822ef687ed693bc8109c38b375bbd89499cdd68",
|
||||
"edge_count": 8872,
|
||||
"edge_sha256": "6a3f2d8501b1c8dbfc0b4c11f3ba49495ede25a209ffd2a9fee970749d169389",
|
||||
"edges": [
|
||||
"app -> app.foundation",
|
||||
"app -> app.foundation.environment",
|
||||
@@ -3744,6 +3744,8 @@
|
||||
"app.application.plugin.catalog -> app.application.plugin",
|
||||
"app.application.plugin.catalog -> app.application.plugin.identity",
|
||||
"app.application.plugin.catalog -> app.application.plugin.inventory",
|
||||
"app.application.plugin.catalog -> app.domain",
|
||||
"app.application.plugin.catalog -> app.domain.plugin",
|
||||
"app.application.plugin.catalog -> app.schemas",
|
||||
"app.application.plugin.catalog -> app.schemas.plugin",
|
||||
"app.application.plugin.config -> app.schemas",
|
||||
@@ -8482,6 +8484,8 @@
|
||||
"app.runtime.extensions.plugin.lifecycle -> app.runtime.observability",
|
||||
"app.runtime.extensions.plugin.lifecycle -> app.schemas",
|
||||
"app.runtime.extensions.plugin.lifecycle -> app.schemas.plugin",
|
||||
"app.runtime.extensions.plugin.loader -> app.domain",
|
||||
"app.runtime.extensions.plugin.loader -> app.domain.plugin",
|
||||
"app.runtime.extensions.plugin.loader -> app.foundation",
|
||||
"app.runtime.extensions.plugin.loader -> app.foundation.environment",
|
||||
"app.runtime.extensions.plugin.loader -> app.runtime",
|
||||
@@ -9638,6 +9642,8 @@
|
||||
"app.startup.initializers.plugins -> app.application.scheduling",
|
||||
"app.startup.initializers.plugins -> app.application.site",
|
||||
"app.startup.initializers.plugins -> app.db",
|
||||
"app.startup.initializers.plugins -> app.db.adapters",
|
||||
"app.startup.initializers.plugins -> app.db.adapters.pluginidentity",
|
||||
"app.startup.initializers.plugins -> app.db.models",
|
||||
"app.startup.initializers.plugins -> app.db.models.plugininstance",
|
||||
"app.startup.initializers.plugins -> app.db.oper",
|
||||
@@ -9648,6 +9654,7 @@
|
||||
"app.startup.initializers.plugins -> app.db.session",
|
||||
"app.startup.initializers.plugins -> app.db.uow",
|
||||
"app.startup.initializers.plugins -> app.foundation",
|
||||
"app.startup.initializers.plugins -> app.foundation.environment",
|
||||
"app.startup.initializers.plugins -> app.foundation.version",
|
||||
"app.startup.initializers.plugins -> app.runtime",
|
||||
"app.startup.initializers.plugins -> app.runtime.cache",
|
||||
|
||||
@@ -178,6 +178,7 @@ def _build_world(
|
||||
logger=_logger(),
|
||||
set_default_target=lambda _plugin_id, _instance_id: True,
|
||||
clear_default_target=lambda _plugin_id: None,
|
||||
runtime_declaration=lambda _plugin_id: {},
|
||||
)
|
||||
runtime = build_plugin_runtime(
|
||||
SimpleNamespace(
|
||||
|
||||
@@ -205,3 +205,41 @@ def test_declared_metadata_fallback_is_batch_safe_and_preserves_runtime_fields()
|
||||
assert result[1].plugin_version == "loaded-version"
|
||||
assert result[1].runtime_status is PluginRuntimeStatus.READY
|
||||
assert result[2].plugin_name == "MissingPlugin"
|
||||
|
||||
|
||||
def test_installed_card_marks_runtime_incompatibility_from_declared_snapshot() -> None:
|
||||
"""已安装卡片的 v3t 不兼容提示必须能离线得出。
|
||||
|
||||
市场候选那条标注路径要联网才有结果,而切到 v3t 的用户首先看到的是"我的插件"。
|
||||
安装时提交的声明快照是运行目录唯一可离线信任的来源,这里钉住它被消费。
|
||||
"""
|
||||
blocked = _identity(
|
||||
_metadata({"name": "Blocked", "v3": True, "v3t": False}),
|
||||
plugin_id="BlockedPlugin",
|
||||
)
|
||||
allowed = _identity(
|
||||
_metadata({"name": "Allowed", "v3": True}),
|
||||
plugin_id="AllowedPlugin",
|
||||
)
|
||||
plugins = [
|
||||
Plugin(id="BlockedPlugin", plugin_name="Blocked", installed=True),
|
||||
Plugin(id="AllowedPlugin", plugin_name="Allowed", installed=True),
|
||||
]
|
||||
|
||||
on_free_threaded = apply_declared_metadata_fallback(
|
||||
plugins,
|
||||
{"blockedplugin": blocked, "allowedplugin": allowed},
|
||||
free_threaded=True,
|
||||
)
|
||||
assert on_free_threaded[0].runtime_compatible is False
|
||||
assert "v3t" in (on_free_threaded[0].runtime_message or "")
|
||||
assert on_free_threaded[1].runtime_compatible is not False
|
||||
|
||||
# 标准 V3 上同一份声明不得产生任何提示
|
||||
on_standard = apply_declared_metadata_fallback(
|
||||
plugins,
|
||||
{"blockedplugin": blocked, "allowedplugin": allowed},
|
||||
free_threaded=False,
|
||||
)
|
||||
assert on_standard[0].runtime_compatible is not False
|
||||
assert on_standard[0].runtime_message is None
|
||||
|
||||
@@ -96,6 +96,7 @@ def _catalog_query(plugin_manager: MagicMock, persistence: MagicMock) -> PluginC
|
||||
online_candidates=plugin_manager.async_get_online_plugin_candidates,
|
||||
process_plugins=plugin_manager.process_plugins_list,
|
||||
identities=persistence.list_identities,
|
||||
free_threaded=lambda: False,
|
||||
)
|
||||
|
||||
|
||||
@@ -352,6 +353,7 @@ def _release_service(
|
||||
has_release_cache=plugin_helper.async_has_plugin_release_cache,
|
||||
releases=plugin_helper.async_get_plugin_release_versions,
|
||||
refresh_releases=plugin_helper.async_get_plugin_release_versions,
|
||||
free_threaded=lambda: False,
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -95,6 +95,7 @@ def _build_runtime(
|
||||
logger=_logger(),
|
||||
set_default_target=lambda _plugin_id, _instance_id: True,
|
||||
clear_default_target=lambda _plugin_id: None,
|
||||
runtime_declaration=lambda _plugin_id: {},
|
||||
)
|
||||
runtime = build_plugin_runtime(
|
||||
_host(),
|
||||
|
||||
@@ -623,7 +623,11 @@ def test_loader_runtime_gate_only_rejects_explicit_incompatible_declarations(
|
||||
tmp_path,
|
||||
monkeypatch,
|
||||
):
|
||||
"""运行目录缺少声明或 runtime 为空时保持历史插件可加载。"""
|
||||
"""未建立声明或声明为空时保持历史插件可加载,只有显式 false 才拒绝。
|
||||
|
||||
判据来自安装时提交的声明快照。运行目录里的 ``package.json`` 是模块联邦组件的
|
||||
npm manifest,主程序既不写它也不读它,这里一并钉住:它的存在不能影响门禁。
|
||||
"""
|
||||
from app.runtime.extensions.plugin import loader as loader_module
|
||||
|
||||
monkeypatch.setattr(
|
||||
@@ -633,19 +637,34 @@ def test_loader_runtime_gate_only_rejects_explicit_incompatible_declarations(
|
||||
)
|
||||
monkeypatch.setattr(loader_module, "is_free_threaded_runtime", lambda: True)
|
||||
|
||||
missing = tmp_path / "missing"
|
||||
missing.mkdir()
|
||||
assert PluginLoader._is_runtime_compatible(missing)
|
||||
declarations = {
|
||||
"empty": {},
|
||||
"rejected": {"v3": True, "v3t": False},
|
||||
"legacygeneration": {"v3": False},
|
||||
"federated": {},
|
||||
}
|
||||
loader = PluginLoader(
|
||||
plugins_root=tmp_path,
|
||||
import_preparer=lambda **_kwargs: None,
|
||||
import_scanner=lambda **_kwargs: None,
|
||||
runtime_declaration=lambda plugin_id: declarations.get(plugin_id, {}),
|
||||
log=_logger(),
|
||||
)
|
||||
|
||||
empty = tmp_path / "empty"
|
||||
empty.mkdir()
|
||||
(empty / "package.json").write_text('{"runtime": {}}', encoding="utf-8")
|
||||
assert PluginLoader._is_runtime_compatible(empty)
|
||||
# 未建立身份或声明快照的存量安装
|
||||
assert loader.is_runtime_compatible("missing")
|
||||
assert loader.is_runtime_compatible("empty")
|
||||
assert not loader.is_runtime_compatible("rejected")
|
||||
assert not loader.is_runtime_compatible("legacygeneration")
|
||||
|
||||
rejected = tmp_path / "rejected"
|
||||
rejected.mkdir()
|
||||
(rejected / "package.json").write_text('{"v3t": false}', encoding="utf-8")
|
||||
assert not PluginLoader._is_runtime_compatible(rejected)
|
||||
# 插件自带的 npm manifest 不参与判定
|
||||
federated = tmp_path / "federated"
|
||||
federated.mkdir()
|
||||
(federated / "package.json").write_text(
|
||||
'{"name": "moviepilot-federated-plugin", "v3t": false}',
|
||||
encoding="utf-8",
|
||||
)
|
||||
assert loader.is_runtime_compatible("federated")
|
||||
|
||||
|
||||
def test_loader_marks_incompatible_runtime_status_when_skipping(
|
||||
@@ -669,7 +688,6 @@ def test_loader_marks_incompatible_runtime_status_when_skipping(
|
||||
plugin_dir = tmp_path / "rejectedplugin"
|
||||
plugin_dir.mkdir()
|
||||
(plugin_dir / "__init__.py").write_text("", encoding="utf-8")
|
||||
(plugin_dir / "package.json").write_text('{"v3t": false}', encoding="utf-8")
|
||||
|
||||
statuses: dict[str, PluginRuntimeStatus] = {}
|
||||
loader = PluginLoader(
|
||||
@@ -677,6 +695,9 @@ def test_loader_marks_incompatible_runtime_status_when_skipping(
|
||||
import_preparer=lambda **_kwargs: None,
|
||||
import_scanner=lambda **_kwargs: None,
|
||||
runtime_status_writer=statuses.__setitem__,
|
||||
runtime_declaration=lambda plugin_id: (
|
||||
{"v3t": False} if plugin_id == "rejectedplugin" else {}
|
||||
),
|
||||
log=_logger(),
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user