sync: 鍚屾灞€鍩熺綉鏈€鏂颁唬鐮?(source master @ b69568e4)

This commit is contained in:
gozeros committed 2026-10-21 14:51:31 +08:00
1 parent 4f7f07504a
commit 8bc8b0e082
1651 files changed
+278599 -11416

No files matched your search

@@ -136,7 +136,15 @@ def test_validate_rejects_bad_zip(storage: LocalSkillStorage, tmp_path: Path):
def test_validate_rejects_missing_skill_md(storage: LocalSkillStorage, tmp_path: Path):
archive = _write_archive(tmp_path, _make_skill_zip(include_skill_md=False))
archive = _write_archive(
tmp_path,
_make_skill_zip(
include_skill_md=False,
# Keep the archive non-empty so we hit the missing-SKILL.md path
# instead of the empty-archive guard.
extra_files={"notes.txt": "placeholder"},
),
)
with pytest.raises(ValueError, match="SKILL.md"):
storage.validate_skill_archive(archive)
@@ -459,3 +467,103 @@ async def test_direct_upload_rechecks_owner_before_overwrite(
assert exc_info.value.status_code == 409
assert "user 'bob'" in str(exc_info.value.detail)
assert storage.install_calls == 0
# ---------- unattributed (orphaned) custom leftovers are replaceable ----------
@pytest.mark.asyncio
async def test_upload_preflight_allows_replacing_unclaimed_orphan(
monkeypatch: pytest.MonkeyPatch,
) -> None:
# On-disk conflict but NO DB row at all: the leftover is invisible in every
# list, so the uploader may replace it and claim ownership.
store = MemorySkillStore()
monkeypatch.setattr(skills_router, "_attach_owner_usernames", _attach_test_owner_names)
result = await skills_router._preview_install_target(
request=_request("user-a"),
skill_store=store,
skill_name="demo-skill",
target_category=SkillCategory.CUSTOM,
conflict_kind="custom",
)
can_install_as_is, can_overwrite, owned_by_me, owned_by_other, builtin_conflict = result[:5]
assert can_install_as_is is False
assert can_overwrite is True
assert owned_by_me is False
assert owned_by_other is False
assert builtin_conflict is False
assert "no owner record" in result[-1]
@pytest.mark.asyncio
async def test_upload_preflight_allows_replacing_null_owner_row(
monkeypatch: pytest.MonkeyPatch,
) -> None:
# DB row exists but owner_user_id is NULL: same unmanageable leftover case.
store = MemorySkillStore()
await store.create({"name": "demo-skill", "owner_user_id": None})
monkeypatch.setattr(skills_router, "_attach_owner_usernames", _attach_test_owner_names)
result = await skills_router._preview_install_target(
request=_request("user-a"),
skill_store=store,
skill_name="demo-skill",
target_category=SkillCategory.CUSTOM,
conflict_kind="custom",
)
can_install_as_is, can_overwrite, owned_by_me, owned_by_other = result[:4]
assert can_install_as_is is False
assert can_overwrite is True
assert owned_by_me is False
assert owned_by_other is False
@pytest.mark.asyncio
async def test_direct_upload_replaces_unclaimed_orphan(
monkeypatch: pytest.MonkeyPatch,
tmp_path: Path,
) -> None:
store = MemorySkillStore()
storage = _UploadStorage()
upload_path = tmp_path / "orphan-upload.skill"
upload_path.write_bytes(b"placeholder")
async def _persist(_file) -> Path:
return upload_path
async def _refresh() -> None:
return None
monkeypatch.setattr(skills_router, "_persist_uploaded_skill", _persist)
monkeypatch.setattr(
skills_router,
"get_or_new_skill_storage",
lambda **_kwargs: storage,
)
monkeypatch.setattr(
skills_router,
"refresh_skills_system_prompt_cache_async",
_refresh,
)
monkeypatch.setattr("deerflow.skills.usage.mark_uploaded", lambda _name: None)
response = await skills_router.install_skill_upload(
request=_request("user-a"),
file=object(),
overwrite=True,
target_category=SkillCategory.CUSTOM,
config=object(),
skill_store=store,
)
assert response.success is True
assert response.overwritten is True
assert storage.install_calls == 1
# The orphan is adopted: the uploader becomes the registered owner.
record = await store.get_any("demo-skill")
assert record is not None
assert record["owner_user_id"] == "user-a"