JiuwenSwarm is an intelligent AI Agent built on openJiuwen. It extends the powerful capabilities of large language models directly to your fingertips through various communication apps you use daily.
Python
fix(skill): 网页卸载兼容 origin 只写在 local_skills 的旧 skillhub 记录
meizi661314c758d9d
diff --git a/jiuwenswarm/server/runtime/skill/skill_manager.py b/jiuwenswarm/server/runtime/skill/skill_manager.pyindex d16027dff3..24a318c80a 100644--- a/jiuwenswarm/server/runtime/skill/skill_manager.py+++ b/jiuwenswarm/server/runtime/skill/skill_manager.py@@ -3970,14 +3970,7 @@ class SkillManager:}origin = str(params.get("origin") or "").strip()- if origin:- matches = [- record for record in self.list_skill_installations()- if str(record.get("origin") or "").strip() == origin- ]- installation = matches[0] if len(matches) == 1 else None- else:- installation = self._find_skill_installation(name=name)+ installation = self._find_web_uninstall_installation(name=name, origin=origin)if installation is None:return {"success": False,@@ -6181,6 +6174,50 @@ class SkillManager:if source:payload["source"] = source+ def _find_web_uninstall_installation(+ self,+ *,+ name: str,+ origin: str,+ ) -> dict[str, Any] | None:+ """定位网页卸载要删的安装记录。++ ``installed_plugins.origin`` 精确命中优先。旧 skillhub 记录把 origin+ 只写在 ``local_skills`` 上,插件行没有 origin;这时仅当本地记录的 name+ 与请求一致、且插件行 origin 为空时才认领,并带上本地 origin 供后续按身份删除。+ 插件行已有别的 origin,或 origin 在两本账里都不存在时,不按 name 回退。+ """+ if not origin:+ return self._find_skill_installation(name=name)+ matches = [+ record for record in self.list_skill_installations()+ if str(record.get("origin") or "").strip() == origin+ ]+ if len(matches) == 1:+ return matches[0]+ if matches:+ return None+ local_matches = [+ record for record in self.get_local_skills()+ if isinstance(record, dict) and str(record.get("origin") or "").strip() == origin+ ]+ if len(local_matches) != 1:+ return None+ if str(local_matches[0].get("name") or "").strip() != name:+ return None+ # G.EXP.04: 多条件过滤不用跨行推导式,改为显式循环。+ candidates = []+ for record in self.list_skill_installations():+ record_name = str(record.get("name") or "").strip()+ record_origin = str(record.get("origin") or "").strip()+ if record_name == name and not record_origin:+ candidates.append(record)+ if len(candidates) != 1:+ return None+ resolved = dict(candidates[0])+ resolved["origin"] = origin+ return resolved+def _find_skill_installation(self,*,diff --git a/tests/unit_tests/agentserver/test_skill_manager_enterprise_state.py b/tests/unit_tests/agentserver/test_skill_manager_enterprise_state.pyindex ac1fe44d19..34ee70c5ff 100644--- a/tests/unit_tests/agentserver/test_skill_manager_enterprise_state.py+++ b/tests/unit_tests/agentserver/test_skill_manager_enterprise_state.py@@ -219,6 +219,41 @@ def test_enterprise_uninstall_does_not_fall_back_from_unknown_origin(tmp_path: Passert skill_dir.exists()+def test_enterprise_uninstall_resolves_origin_kept_only_on_local_skills(tmp_path: Path) -> None:+ """旧 skillhub 把 origin 只写在 local_skills,网页仍按该 origin 卸载。"""+ manager = SkillManager(workspace_dir=str(tmp_path), service_id="svc", agent_id="agent")+ skill_dir = _write_skill(tmp_path, "employment-rights-team")+ manager.record_skill_installation(+ name="employment-rights-team",+ source_type="user",+ origin="skillhub:8",+ source="skillhub",+ )+ state_file = tmp_path / "skills" / "skills_state.json"+ state = json.loads(state_file.read_text(encoding="utf-8"))+ plugin = state["installed_plugins"][0]+ plugin.pop("origin", None)+ plugin.pop("source_type", None)+ plugin["marketplace"] = "skillhub"+ state["local_skills"] = [{+ "name": "employment-rights-team",+ "origin": "skillhub:8",+ "source": "skillhub",+ }]+ state_file.write_text(json.dumps(state), encoding="utf-8")++ restored = SkillManager(workspace_dir=str(tmp_path), service_id="svc", agent_id="agent")+ result = asyncio.run(restored.handle_skills_web_uninstall({+ "name": "employment-rights-team",+ "origin": "skillhub:8",+ }))++ assert result == {"success": True, "name": "employment-rights-team"}+ assert not skill_dir.exists()+ assert restored.list_skill_installations() == []+ assert restored.get_local_skills() == []++def test_enterprise_skills_list_does_not_wait_for_marketplace_sync(tmp_path: Path,monkeypatch: pytest.MonkeyPatch,