Files
ai-agent/backend/test_skills_merge.py
Gabriel Vidal 091fafd881 feat(skills): one catalog card per skill name
`complete` ships in both the homelab and the ai-agent repo, so /api/skills
listed it twice with the same (name-keyed) usage, counted twice in the
totals. merge_same_name keeps the repo's copy (else the newest) and lists
the others under `copies` — shown as a +source badge on the card; their
share refs stay pickable in Settings → Users.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-12 22:47:16 +02:00

38 lines
1.5 KiB
Python

"""dashboards.skills.merge_same_name: one catalog card per skill name."""
from dashboards.skills import merge_same_name
def _s(name, kind, source, updated, **kw):
return {"name": name, "sourceKind": kind, "source": source,
"dir": f"{source}/.claude/skills/{name}", "path": None,
"updatedAt": updated, "shareRef": None, "sharedWithGuests": False,
"description": kw.get("description", ""),
"triggerWords": kw.get("triggers", [])}
def test_the_repo_copy_leads_and_the_other_rides_along():
items = [
_s("complete", "project", "ai-agent", "2026-10-10", triggers=["close out"]),
_s("screenshot", "repo", "repo", "2026-10-09"),
_s("complete", "repo", "repo", "2026-10-01", description="Close out",
triggers=["wrap up"]),
]
out = merge_same_name(items)
assert [s["name"] for s in out] == ["complete", "screenshot"]
c = out[0]
assert c["source"] == "repo" and c["description"] == "Close out"
assert [x["source"] for x in c["copies"]] == ["ai-agent"]
assert c["triggerWords"] == ["wrap up", "close out"]
def test_two_project_copies_keep_the_newest():
out = merge_same_name([_s("x", "project", "a", "2026-01-01"),
_s("x", "project", "b", "2026-02-01")])
assert out[0]["source"] == "b" and out[0]["copies"][0]["source"] == "a"
def test_unique_names_are_untouched():
items = [_s("a", "repo", "repo", None), _s("b", "repo", "repo", None)]
assert merge_same_name(items) == items