From 91ea3ae4b2e5214390f0865329648f9cffbbc8bc Mon Sep 17 00:00:00 2001 From: Teknium <127238744+teknium1@users.noreply.github.com> Date: Sun, 3 May 2026 12:10:20 -0700 Subject: [PATCH] test(skills): add bytes-vs-str equivalence and on-disk hash parity tests Follow-up on #9925 cherry-pick adding two additional tests: - bytes content hashes identically to its str-decoded form - mixed bytes+str bundle hash equals the on-disk content_hash from skills_guard (the production invariant used to detect drift) Also map dodofun@126.com and 1615063567@qq.com in AUTHOR_MAP so the CI contributor check passes for the cherry-picked commit. Co-authored-by: LeonSGP43 Co-authored-by: zhao0112 <1615063567@qq.com> --- scripts/release.py | 2 ++ tests/tools/test_skills_hub.py | 47 ++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/scripts/release.py b/scripts/release.py index 9bc2e8c447..d7fab88b03 100755 --- a/scripts/release.py +++ b/scripts/release.py @@ -633,6 +633,8 @@ AUTHOR_MAP = { "cirwel@The-CIRWEL-Group.local": "CIRWEL", "molvikar8@gmail.com": "molvikar", "nftpoetrist@gmail.com": "nftpoetrist", + "dodofun@126.com": "colorcross", + "1615063567@qq.com": "zhao0112", "leozeli@qq.com": "leozeli", "linlehao@cuhk.edu.cn": "LehaoLin", "liutong@isacas.ac.cn": "I3eg1nner", diff --git a/tests/tools/test_skills_hub.py b/tests/tools/test_skills_hub.py index 40143adc84..1969272411 100644 --- a/tests/tools/test_skills_hub.py +++ b/tests/tools/test_skills_hub.py @@ -917,6 +917,53 @@ class TestCheckForSkillUpdates: assert digest.startswith("sha256:") + def test_bundle_content_hash_bytes_matches_str_equivalent(self): + """Bytes content must hash identically to its str-decoded form.""" + text_bundle = SkillBundle( + name="demo-skill", + files={ + "SKILL.md": "same content", + "references/checklist.md": "- [ ] security\n", + }, + source="github", + identifier="owner/repo/demo-skill", + trust_level="community", + ) + bytes_bundle = SkillBundle( + name="demo-skill", + files={ + "SKILL.md": b"same content", + "references/checklist.md": b"- [ ] security\n", + }, + source="github", + identifier="owner/repo/demo-skill", + trust_level="community", + ) + + assert bundle_content_hash(bytes_bundle) == bundle_content_hash(text_bundle) + + def test_bundle_content_hash_mixed_matches_on_disk(self, tmp_path): + """In-memory bundle hash must equal on-disk content_hash for mixed bytes+str.""" + from tools.skills_guard import content_hash + + bundle = SkillBundle( + name="demo-skill", + files={ + "SKILL.md": b"# Demo Skill\n", + "references/checklist.md": "- [ ] security\n", + }, + source="github", + identifier="owner/repo/demo-skill", + trust_level="community", + ) + skill_dir = tmp_path / "demo-skill" + skill_dir.mkdir() + (skill_dir / "SKILL.md").write_bytes(b"# Demo Skill\n") + (skill_dir / "references").mkdir() + (skill_dir / "references" / "checklist.md").write_text("- [ ] security\n") + + assert bundle_content_hash(bundle) == content_hash(skill_dir) + def test_reports_update_when_remote_hash_differs(self): lock = MagicMock() lock.list_installed.return_value = [{