diff --git a/src/loopzero/runners.py b/src/loopzero/runners.py index 0e384789..45ae5637 100644 --- a/src/loopzero/runners.py +++ b/src/loopzero/runners.py @@ -517,10 +517,13 @@ def _codex_repository_skill_overrides(cwd: Path) -> list[str]: def _repository_skill_paths(cwd: Path) -> set[str]: tree, paths, seen = cwd.resolve(), set(), set() - pending = [cwd / ".agents" / "skills", cwd / ".codex" / "skills"] + roots = (cwd / ".agents", cwd / ".codex") + pending = list(roots) while pending: path = pending.pop() - if not os.path.lexists(path): + try: + path.lstat() + except FileNotFoundError: continue # Strict: a looping or dangling link fails closed; Codex might resolve it elsewhere. real = path.resolve(strict=True) @@ -530,6 +533,9 @@ def _repository_skill_paths(cwd: Path) -> set[str]: if path.name == "SKILL.md": paths.add(str(real)) continue + if path in roots: + pending.append(path / "skills") + continue if real in seen: continue seen.add(real) diff --git a/tests/test_runners.py b/tests/test_runners.py index 2cfa34e8..f70ab95e 100644 --- a/tests/test_runners.py +++ b/tests/test_runners.py @@ -1159,20 +1159,19 @@ def spy(path=".", *rest): @pytest.mark.parametrize("plant", [ - "too_many", "loop", "undecodable", "dangling", "root_loop:.agents/skills", "root_loop:.codex/skills"]) + "too_many", "loop", "undecodable", "dangling", "loop:.agents/skills", "loop:.codex/skills", + "loop:.agents", "loop:.codex", "dangling:.agents", "dangling:.codex"]) def test_codex_skill_lists_it_cannot_disable_fail_before_any_codex_call( repo, fake_bin: Path, fake_tool, fake_bwrap: Path, monkeypatch: pytest.MonkeyPatch, plant: str, ) -> None: if plant == "too_many": _plant_skills(repo) monkeypatch.setattr("loopzero.runners.CODEX_SKILL_OVERRIDE_LIMIT", 100) - elif plant in ("loop", "dangling"): - (repo / ".agents/skills").mkdir(parents=True) - (repo / ".agents/skills/x").symlink_to("x" if plant == "loop" else "/nonexistent/skills") - elif plant.startswith("root_loop:"): - root = repo / plant.partition(":")[2] - root.parent.mkdir(parents=True) - root.symlink_to(root.name) + elif plant != "undecodable": + kind, _, name = plant.partition(":") + link = repo / (name or ".agents/skills/x") + link.parent.mkdir(parents=True, exist_ok=True) + link.symlink_to(link.name if kind == "loop" else "missing") else: skill = repo / ".codex/skills" / os.fsdecode(b"\xff") skill.mkdir(parents=True)