From 765f332e2e178bdfdf5363de2ed141c20c9c1fb0 Mon Sep 17 00:00:00 2001 From: DawnARC Date: Thu, 16 Apr 2026 21:47:28 +0800 Subject: [PATCH] =?UTF-8?q?fix:A=5FMemorix=20=E7=BC=BA=E5=A4=B1=E6=80=BB?= =?UTF-8?q?=E7=BB=93=E6=A8=A1=E5=9E=8B=E9=85=8D=E7=BD=AE=E5=AF=BC=E8=87=B4?= =?UTF-8?q?=E5=AF=BC=E5=85=A5=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复默认值与迁移补写逻辑,并补充回归测试覆盖缺失与旧格式场景。 --- .../test_summary_importer_model_config.py | 48 +++++++++++++++++++ src/A_memorix/core/utils/summary_importer.py | 4 +- .../scripts/release_vnext_migrate.py | 6 ++- 3 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 pytests/A_memorix_test/test_summary_importer_model_config.py diff --git a/pytests/A_memorix_test/test_summary_importer_model_config.py b/pytests/A_memorix_test/test_summary_importer_model_config.py new file mode 100644 index 00000000..845deb08 --- /dev/null +++ b/pytests/A_memorix_test/test_summary_importer_model_config.py @@ -0,0 +1,48 @@ +import pytest + +from src.A_memorix.core.utils.summary_importer import SummaryImporter +from src.config.model_configs import TaskConfig +from src.services import llm_service as llm_api + + +def _fake_available_models() -> dict[str, TaskConfig]: + return { + "replyer": TaskConfig( + model_list=["test-model"], + max_tokens=128, + temperature=0.7, + selection_strategy="priority", + ) + } + + +def test_resolve_summary_model_config_uses_auto_list_when_summarization_missing(monkeypatch): + monkeypatch.setattr(llm_api, "get_available_models", _fake_available_models) + + importer = SummaryImporter( + vector_store=None, + graph_store=None, + metadata_store=None, + embedding_manager=None, + plugin_config={}, + ) + + resolved = importer._resolve_summary_model_config() + + assert resolved is not None + assert resolved.model_list == ["test-model"] + + +def test_resolve_summary_model_config_rejects_legacy_string_selector(monkeypatch): + monkeypatch.setattr(llm_api, "get_available_models", _fake_available_models) + + importer = SummaryImporter( + vector_store=None, + graph_store=None, + metadata_store=None, + embedding_manager=None, + plugin_config={"summarization": {"model_name": "auto"}}, + ) + + with pytest.raises(ValueError, match="List\\[str\\]"): + importer._resolve_summary_model_config() diff --git a/src/A_memorix/core/utils/summary_importer.py b/src/A_memorix/core/utils/summary_importer.py index cea7167c..0728e4dc 100644 --- a/src/A_memorix/core/utils/summary_importer.py +++ b/src/A_memorix/core/utils/summary_importer.py @@ -136,7 +136,9 @@ class SummaryImporter: if not available_tasks: return None - raw_cfg = self.plugin_config.get("summarization", {}).get("model_name", "auto") + # vNext 要求该字段为 List[str];当配置缺失时回退到 ["auto"], + # 避免默认值本身触发类型校验异常。 + raw_cfg = self.plugin_config.get("summarization", {}).get("model_name", ["auto"]) selectors = self._normalize_summary_model_selectors(raw_cfg) default_task_name, default_task_cfg = self._pick_default_summary_task(available_tasks) diff --git a/src/A_memorix/scripts/release_vnext_migrate.py b/src/A_memorix/scripts/release_vnext_migrate.py index d41b755f..49c7517c 100644 --- a/src/A_memorix/scripts/release_vnext_migrate.py +++ b/src/A_memorix/scripts/release_vnext_migrate.py @@ -472,7 +472,11 @@ def _migrate_config(config_doc: Dict[str, Any]) -> Dict[str, Any]: summary = _ensure_table(config_doc, "summarization") summary_model = summary.get("model_name", ["auto"]) - if isinstance(summary_model, str): + if "model_name" not in summary: + normalized = ["auto"] + summary["model_name"] = normalized + changes["summarization.model_name"] = {"old": "", "new": normalized} + elif isinstance(summary_model, str): normalized = [summary_model.strip() or "auto"] summary["model_name"] = normalized changes["summarization.model_name"] = {"old": summary_model, "new": normalized}