Skip to content

The agent that grows with you

test(skills): duplicate names resolve the same way on every surface

kshitijk4poorf00e35f6809c
diff --git a/tests/agent/test_org_skill_namespace.py b/tests/agent/test_org_skill_namespace.py
index 397a347a692..39a396c8ab2 100644
--- a/tests/agent/test_org_skill_namespace.py
+++ b/tests/agent/test_org_skill_namespace.py
@@ -137,8 +137,11 @@ class TestListingCollisionsAndLabels:
)
_mark_active(skills, "org-1")
out = pb.build_skills_system_prompt()
- # BOTH entries flagged — neither silently wins.
- assert out.count("[name collision") == 2
+ # Neither silently wins: the org copy is flagged under the exact path skill_view loads, and the
+ # root-level personal copy (whose only path IS the bare name, so nothing can load it) is called out.
+ assert "- _org/org-1/k8s-debug: [name collision" in out
+ assert "- k8s-debug:" not in out
+ assert "A copy of k8s-debug is not listed" in out
def test_no_collision_flag_when_unique(self, tmp_path, monkeypatch):
skills, pb = self._render(tmp_path, monkeypatch)
diff --git a/tests/agent/test_skill_commands.py b/tests/agent/test_skill_commands.py
index 0127427d0a9..9ca3ee78494 100644
--- a/tests/agent/test_skill_commands.py
+++ b/tests/agent/test_skill_commands.py
@@ -548,6 +548,46 @@ class TestBuildPreloadedSkillsPrompt:
assert "enabled-skill" in prompt
+class TestDuplicateNamesAgreeAcrossSurfaces:
+ def test_every_surface_resolves_duplicates_like_skill_view(self, tmp_path, monkeypatch):
+ """#64392: list, prompt index, slash commands, skill_view, -s preload and cron agree. A same-tier
+ duplicate is advertised only by its exact path and every loader names those paths; a cross-tier
+ duplicate (same relative path, local + external) loads the local copy everywhere."""
+ import json
+
+ from agent import prompt_builder as pb, skill_utils
+ from cron.scheduler_prompt import _load_cron_skill_parts
+ from tools.skills_tool import skill_view, skills_list
+ local, ext = tmp_path / "local", tmp_path / "ext"
+ _make_skill(local, "dup-demo", category="a", body="BODY A")
+ (local / "a" / "dup-demo").rename(local / "a" / "one")
+ _make_skill(local, "dup-demo", category="b", body="BODY B")
+ (local / "b" / "dup-demo").rename(local / "b" / "two")
+ _make_skill(local, "xdup", category="productivity", body="LOCAL XDUP")
+ _make_skill(ext, "xdup", category="productivity", body="EXTERNAL XDUP")
+ monkeypatch.setattr(skills_tool_module, "SKILLS_DIR", local)
+ monkeypatch.setattr(skills_tool_module, "_SKILLS_CACHE", {})
+ monkeypatch.setattr(skill_utils, "get_external_skills_dirs", lambda: [ext])
+ monkeypatch.setattr(pb, "get_skills_dir", lambda: local)
+ monkeypatch.setattr(pb, "get_disabled_skill_names", lambda *a, **k: set())
+ monkeypatch.setattr(pb, "_skills_prompt_snapshot_path", lambda: tmp_path / "snap.json")
+ pb.clear_skills_system_prompt_cache()
+
+ ambiguous = "Ambiguous skill name dup-demo: use one of a/one, b/two"
+ assert sorted(s["name"] for s in json.loads(skills_list())["skills"]) == ["a/one", "b/two", "xdup"]
+ index = [ln.strip() for ln in pb.build_skills_system_prompt().splitlines() if ln.startswith(" - ")]
+ assert index == ["- a/one: Description for dup-demo.", "- b/two: Description for dup-demo.",
+ "- xdup: Description for xdup."]
+ assert sorted(scan_skill_commands()) == ["/xdup"]
+ assert json.loads(skill_view("dup-demo"))["load_names"] == ["a/one", "b/two"]
+ for ident in ("xdup", "productivity/xdup"):
+ assert "LOCAL XDUP" in json.loads(skill_view(ident))["content"]
+ _, loaded, missing = build_preloaded_skills_prompt(["dup-demo", "xdup", "a/one"])
+ assert (loaded, missing) == (["xdup", "dup-demo"], [ambiguous])
+ parts = _load_cron_skill_parts({"id": "j"}, ["dup-demo", "xdup"])
+ assert ambiguous in parts[0] and "LOCAL XDUP" in "\n".join(parts)
+
+
class TestBuildSkillInvocationMessage:
diff --git a/tests/tools/test_skills_tool.py b/tests/tools/test_skills_tool.py
index 051cf9998f1..b89a601caf0 100644
--- a/tests/tools/test_skills_tool.py
+++ b/tests/tools/test_skills_tool.py
@@ -879,36 +879,47 @@ class TestSkillViewCollisionDetection:
),
)
- def test_nested_local_collides_with_top_level_external(self, tmp_path):
- """The original bug scenario: nested local + top-level external,
- same name. Now refuses with both paths surfaced."""
- local_dir = tmp_path / "local"
- external_dir = tmp_path / "external"
- local_dir.mkdir()
- external_dir.mkdir()
-
- _make_skill(
- local_dir,
- "explore-codebase",
- category="foundations/runtime",
- body="LOCAL VERSION",
- )
- _make_skill(external_dir, "explore-codebase", body="EXTERNAL VERSION")
-
- p1, p2 = self._patch_dirs(local_dir, [external_dir])
- with p1, p2:
- raw = skill_view("explore-codebase")
-
- result = json.loads(raw)
- assert result["success"] is False
- assert "Ambiguous skill name 'explore-codebase'" in result["error"]
- assert "matches" in result
- assert len(result["matches"]) == 2
- # Both paths surfaced
- assert any(os.path.join("foundations", "runtime") in p for p in result["matches"])
- assert any("external" in p for p in result["matches"])
- assert "hint" in result
+ @pytest.mark.parametrize("winner_tier, loser_tier, winner_rel, loser_rel, lookup", [
+ # The original 59da8ec4e scenario (nested local + top-level external) used to refuse; the
+ # documented precedence now picks local, matching skills_list / the prompt index / slash.
+ ("local", "external", "foundations/runtime/explore-codebase", "explore-codebase", "explore-codebase"),
+ # Same relative path in both roots: on main no identifier could load either copy.
+ ("local", "external", "productivity/xdup", "productivity/xdup", "productivity/xdup"),
+ ("local", "external", "productivity/xdup", "productivity/xdup", "xdup"),
+ ("create_dir", "external", "brain/note", "note", "note"),
+ ("local", "create_dir", "note", "brain/note", "note"),
+ ("project", "local", "deploy", "ops/deploy", "deploy"),
+ ])
+ def test_higher_tier_wins_cross_directory_collision(
+ self, tmp_path, caplog, winner_tier, loser_tier, winner_rel, loser_rel, lookup):
+ """project > local > create_dir > external: the higher tier loads, the shadowed copy is
+ reported by skills_list neither as a row nor as a guess, and a warning names it."""
+ from agent import skill_utils
+ tiers = {t: tmp_path / t for t in ("project", "local", "create_dir", "external")}
+ for root in tiers.values():
+ root.mkdir()
+ for tier, rel in ((winner_tier, winner_rel), (loser_tier, loser_rel)):
+ *cat, leaf = rel.split("/")
+ _make_skill(tiers[tier], leaf, category="/".join(cat) or None,
+ frontmatter_extra=f"x-tier: {tier}\n", body=f"{tier.upper()} VERSION")
+ p1, p2 = self._patch_dirs(tiers["local"], [tiers["external"]])
+ with p1, p2, caplog.at_level("WARNING"), \
+ patch.object(skill_utils, "get_skill_create_dir", return_value=tiers["create_dir"]), \
+ patch.object(skill_utils, "get_project_skills_dirs", return_value=[tiers["project"]]), \
+ patch.object(skill_utils, "iter_project_skill_files",
+ lambda d: skill_utils.iter_skill_index_files(d, "SKILL.md")):
+ skills_tool_module._SKILLS_CACHE.clear()
+ skill_utils._WARNED_SHADOWS.clear()
+ result = json.loads(skill_view(lookup))
+ listed = json.loads(skills_list())["skills"]
+ assert result["success"] is True, result
+ assert f"{winner_tier.upper()} VERSION" in result["content"]
+ assert f"{loser_tier.upper()} VERSION" not in result["content"]
+ leaf = winner_rel.rsplit("/", 1)[-1]
+ assert [s["name"] for s in listed if s["name"].endswith(leaf)] == [leaf]
+ assert any("shadowed" in r.getMessage() and str(tiers[loser_tier]) in r.getMessage()
+ for r in caplog.records)
def test_support_markdown_does_not_collide_with_real_skill(self, tmp_path):
"""Supporting reference docs named <skill>.md are not skills.
@@ -1076,7 +1087,8 @@ class TestSameRootDuplicationResolves:
result = json.loads(skill_view("dup"))
assert result["success"] is False, result
- assert "Ambiguous" in result["error"]
+ assert "Ambiguous skill name 'dup': use one of cat-a/dup, cat-b/dup" in result["error"]
+ assert result["load_names"] == ["cat-a/dup", "cat-b/dup"]
assert len(result["matches"]) == 2