Build and run agents you can see, understand and trust.
Python agentchatbotlarge-language-modelsllmllm-agentmcpmulti-agentmulti-modalreact-agentrealtime-agentvoice-agentvoice-assistant
fix(workspace): resolve case-insensitive skill directory collisions (#3075)
HootRock6423e502369e
diff --git a/src/agentscope/workspace/_local_workspace.py b/src/agentscope/workspace/_local_workspace.pyindex 5aa8c4716..b51bf34ca 100644--- a/src/agentscope/workspace/_local_workspace.py+++ b/src/agentscope/workspace/_local_workspace.py@@ -223,7 +223,9 @@ class LocalWorkspace(WorkspaceBase):base_dir = _sanitize_dir_name(raw_name)dir_name = base_dircounter = 1- while dir_name in existing_dir_names:+ while dir_name in existing_dir_names or os.path.exists(+ os.path.join(skills_dir, dir_name),+ ):dir_name = f"{base_dir}_{counter}"counter += 1@@ -834,7 +836,9 @@ class LocalWorkspace(WorkspaceBase):base_dir = _sanitize_dir_name(raw_name)dir_name = base_dircounter = 1- while dir_name in existing_dir_names:+ while dir_name in existing_dir_names or os.path.exists(+ os.path.join(skills_dir, dir_name),+ ):dir_name = f"{base_dir}_{counter}"counter += 1diff --git a/tests/workspace_local_test.py b/tests/workspace_local_test.pyindex 9f5ee154c..725918a91 100644--- a/tests/workspace_local_test.py+++ b/tests/workspace_local_test.py@@ -8,6 +8,7 @@ import hashlibimport tempfilefrom types import SimpleNamespacefrom typing import Any+from unittest import skipUnlessfrom unittest.async_case import IsolatedAsyncioTestCasefrom unittest.mock import AsyncMock, patchfrom dataclasses import asdict@@ -47,6 +48,9 @@ from agentscope.message import (ToolCallBlock,)+# Probe the temp filesystem rather than assuming case rules from the OS.+_CASE_INSENSITIVE_FS = os.path.exists(tempfile.gettempdir().swapcase())+class _LongResultTool(ToolBase):"""A mock tool that returns a long string result for offload testing."""@@ -1902,6 +1906,43 @@ class TestLocalWorkspaceSkillPartitions(IsolatedAsyncioTestCase):os.path.isdir(os.path.join(self.skills_dir, "A", "a-skill")),)+ @skipUnless(_CASE_INSENSITIVE_FS, "requires case-insensitive FS")+ async def test_add_skill_case_only_directory_collision(self) -> None:+ """Case-only names get distinct paths without renaming the skills."""+ ws = await self._workspace()+ await ws.add_skill(self._make_skill("source-a", "Example"))+ await ws.add_skill(self._make_skill("source-b", "example"))++ self.assertDictEqual(+ {+ s.name: (os.path.basename(s.dir), s.markdown)+ for s in await ws.list_skills()+ },+ {"Example": ("Example", "body"), "example": ("example_1", "body")},+ )++ @skipUnless(_CASE_INSENSITIVE_FS, "requires case-insensitive FS")+ async def test_seed_skill_case_only_directory_collision(self) -> None:+ """Seed population keeps both skills on insensitive filesystems."""+ ws = await self._workspace(+ skill_paths=[+ self._make_skill("source-a", "Example"),+ self._make_skill("source-b", "example"),+ ],+ )++ for agent_id in ("A", "B"):+ self.assertDictEqual(+ {+ s.name: (os.path.basename(s.dir), s.markdown)+ for s in await ws.list_skills(agent_id=agent_id)+ },+ {+ "Example": ("Example", "body"),+ "example": ("example_1", "body"),+ },+ )+async def test_seeds_equip_each_agent_with_its_own_copy(self) -> None:"""``skill_paths`` reach every agent, but as separate copies."""ws = await self._workspace(