From 9b4e6b98d60612c1636033ca59ff71b476ab981e Mon Sep 17 00:00:00 2001 From: alexcastgonz <82875882+pcbeingused333@users.noreply.github.com> Date: Sun, 22 Nov 2026 01:37:32 -0400 Subject: [PATCH] fix(plugin): normalize nested history values from third-party market indexes (#7534) --- app/runtime/extensions/plugin/metadata.py | 25 ++++++++++++++++++++++- tests/test_plugin_documentation.py | 22 ++++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/app/runtime/extensions/plugin/metadata.py b/app/runtime/extensions/plugin/metadata.py index ee2ed2b09..f7b75ee81 100644 --- a/app/runtime/extensions/plugin/metadata.py +++ b/app/runtime/extensions/plugin/metadata.py @@ -107,7 +107,7 @@ class PluginMetadataMapper: ), None, ) - plugin.history = info.get("history") or {} + plugin.history = self.normalize_history(info.get("history")) plugin.release = bool(info.get("release")) plugin.repo_url = market plugin.package_version = package_version @@ -128,6 +128,29 @@ class PluginMetadataMapper: self._logger.error(f"获取插件 {plugin_id} 状态出错:{error}") return False + @staticmethod + def normalize_history(history: Any) -> dict[str, str]: + """ + 把市场索引的更新记录归一化为版本到文本的映射。 + + 第三方索引可能把版本说明写成含 ``content`` 的嵌套对象,这里取其正文拼接为文本, + 无法得到正文的条目直接丢弃,避免错误类型进入响应模型。 + + :param history: 索引中的原始 history 字段 + :return: 仅包含字符串值的更新记录 + """ + if not isinstance(history, dict): + return {} + normalized: dict[str, str] = {} + for version, note in history.items(): + if isinstance(note, dict): + note = note.get("content") + if isinstance(note, list): + note = "\n".join(str(item) for item in note) + if isinstance(note, str): + normalized[str(version)] = note + return normalized + @staticmethod def normalize_label(labels: Any) -> Optional[str]: """ diff --git a/tests/test_plugin_documentation.py b/tests/test_plugin_documentation.py index 894c1c7eb..af9ee36d4 100644 --- a/tests/test_plugin_documentation.py +++ b/tests/test_plugin_documentation.py @@ -3,6 +3,7 @@ """ import asyncio +import warnings from contextlib import asynccontextmanager from types import SimpleNamespace from typing import Optional @@ -364,3 +365,24 @@ async def test_readme_probe_falls_back_after_proxy_error(monkeypatch: pytest.Mon assert len(calls) == 2 finally: await transport.async_get_plugin_readme_url.cache_clear() + + +def test_nested_history_is_normalized_to_text() -> None: + """ + 第三方索引把 history 值写成嵌套对象时,应归一化为字符串且不触发序列化警告。 + """ + info = { + "name": "Demo", + "version": "1.7.3", + "history": { + "v1.7.3": {"version": "1.7.3", "date": "2026-01-01", "content": ["修复A", "修复B"]}, + "v1.18.4": {"version": "1.18.4"}, + "v1.0.0": "初始版本", + }, + } + plugin = _mapper().map("Demo", info, REPO, [], 0, "v3") + assert plugin is not None + assert plugin.history == {"v1.7.3": "修复A\n修复B", "v1.0.0": "初始版本"} + with warnings.catch_warnings(): + warnings.simplefilter("error") + plugin.model_dump_json()