Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

fix: fix upload skill zip has an empty directory (#42407)

wangxiaolei7dad80b1f925
diff --git a/api/services/skill_management_service.py b/api/services/skill_management_service.py
index 2c4bbe28060..d89be84067c 100644
--- a/api/services/skill_management_service.py
+++ b/api/services/skill_management_service.py
@@ -3819,7 +3819,8 @@ class SkillManagementService:
return {path: path for path in paths}
root = next(iter(skill_md_roots))
prefix = f"{root}/"
- return {path: path.removeprefix(prefix) for path in paths if path == root or path.startswith(prefix)}
+ # The explicit wrapper directory represents the new root, not a draft item.
+ return {path: path.removeprefix(prefix) for path in paths if path.startswith(prefix)}
def _draft_payload_from_zip(
self,
diff --git a/api/tests/unit_tests/services/test_skill_management_service.py b/api/tests/unit_tests/services/test_skill_management_service.py
index 7e83f39e82e..315e3b6b3b5 100644
--- a/api/tests/unit_tests/services/test_skill_management_service.py
+++ b/api/tests/unit_tests/services/test_skill_management_service.py
@@ -2770,6 +2770,31 @@ def test_import_skill_package_accepts_crlf_skill_md() -> None:
assert skill_md_file["content"].startswith("---\nname: expense-sop\n")
[email protected]("include_empty_directory", [False, True])
+def test_import_skill_package_drops_explicit_wrapper_directory(include_empty_directory: bool) -> None:
+ package = io.BytesIO()
+ with zipfile.ZipFile(package, "w") as archive:
+ archive.writestr("critical-thinking/", "")
+ archive.writestr("__MACOSX/._critical-thinking", b"\x00")
+ archive.writestr(
+ "critical-thinking/SKILL.md",
+ "---\nname: critical-thinking\ndescription: Critical thinking\n---\n# Critical thinking",
+ )
+ archive.writestr("__MACOSX/critical-thinking/._SKILL.md", b"\x00")
+ if include_empty_directory:
+ archive.writestr("critical-thinking/references/", "")
+
+ service = SkillManagementService(tool_file_manager=_FakeToolFileManager())
+ imported = service.import_skill(
+ tenant_id=TENANT,
+ user_id=USER,
+ payload=SkillImportPayload(content=package.getvalue(), filename="critical-thinking.zip"),
+ )
+
+ expected_paths = ["SKILL.md", "references"] if include_empty_directory else ["SKILL.md"]
+ assert [item["path"] for item in imported["files"]] == expected_paths
+
+
def test_import_skill_package_strips_root_alongside_macos_metadata_folder() -> None:
package = io.BytesIO()
with zipfile.ZipFile(package, "w") as archive: