Skip to content

Commit 0762ef0

Browse files
fix(skills): surface inaccessible skill dirs via on_error
Path.is_dir() returns False for OSError on Python 3.14+, so a permission failure while probing an enumerated child was silently skipped and never reached on_error. Probe with Path.stat() + stat.S_ISDIR and route OSError through the same on_error/logging path as other listing failures. Fixes google#7749
1 parent bdb1ced commit 0762ef0

2 files changed

Lines changed: 53 additions & 4 deletions

File tree

‎src/google/adk/skills/_utils.py‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import logging
2222
import pathlib
2323
import re
24+
import stat
2425
from typing import Any
2526
from typing import Callable
2627
from typing import cast
@@ -598,19 +599,21 @@ def _list_skills_in_dir(
598599
return skills
599600

600601
for skill_dir in sorted(skills_base_path.iterdir()):
601-
if not skill_dir.is_dir():
602-
continue
603-
604602
skill_id = skill_dir.name
605603
try:
604+
# Use Path.stat() + S_ISDIR so OSError (e.g. PermissionError) still
605+
# surfaces on Python 3.14+, where Path.is_dir() returns False instead
606+
# of raising (https://docs.python.org/3.14/library/pathlib.html).
607+
if not stat.S_ISDIR(skill_dir.stat().st_mode):
608+
continue
606609
frontmatter = _read_skill_properties(skill_dir)
607610
if skill_id != frontmatter.name:
608611
raise ValueError(
609612
f"Skill name '{frontmatter.name}' does not match directory"
610613
f" name '{skill_id}'."
611614
)
612615
skills[skill_id] = frontmatter
613-
except (FileNotFoundError, ValueError, ValidationError) as e:
616+
except (FileNotFoundError, ValueError, ValidationError, OSError) as e:
614617
if on_error is not None:
615618
on_error(skill_id, e)
616619
continue

‎tests/unittests/skills/test__utils.py‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616

1717
import asyncio
1818
import builtins
19+
import errno
20+
import os
21+
import stat
1922
import io
2023
import pathlib
2124
import struct
@@ -716,6 +719,49 @@ def strict(skill_id, error):
716719
list_skills_in_dir(_skills_dir_with_one_invalid(tmp_path), on_error=strict)
717720

718721

722+
723+
def test_list_skills_in_dir_reports_inaccessible_child_via_on_error(
724+
tmp_path, monkeypatch
725+
):
726+
"""Permission failures while probing a child must reach on_error.
727+
728+
Python 3.14+ Path.is_dir() returns False for OSError instead of raising.
729+
Listing must use Path.stat() so the failure stays observable on every
730+
supported Python version (google/adk-python#7749).
731+
"""
732+
skills_dir = tmp_path / "skills"
733+
skills_dir.mkdir()
734+
blocked = skills_dir / "blocked-skill"
735+
blocked.mkdir()
736+
(blocked / "SKILL.md").write_text(
737+
"---\nname: blocked-skill\ndescription: x\n---\n", encoding="utf-8"
738+
)
739+
740+
real_stat = os.stat
741+
blocked_path = os.fspath(blocked.resolve())
742+
743+
def fake_stat(path, *args, **kwargs):
744+
if os.fspath(path) == blocked_path:
745+
raise PermissionError(
746+
errno.EACCES, "controlled metadata permission failure", os.fspath(path)
747+
)
748+
return real_stat(path, *args, **kwargs)
749+
750+
errors: list[tuple[str, Exception]] = []
751+
752+
def on_error(skill_id, error):
753+
errors.append((skill_id, error))
754+
755+
monkeypatch.setattr(os, "stat", fake_stat)
756+
skills = list_skills_in_dir(skills_dir, on_error=on_error)
757+
758+
assert skills == {}
759+
assert len(errors) == 1
760+
assert errors[0][0] == "blocked-skill"
761+
assert isinstance(errors[0][1], PermissionError)
762+
763+
764+
719765
def test__load_skill_from_zip_bytes():
720766
"""Tests loading a skill directly from in-memory zip file bytes."""
721767

0 commit comments

Comments
 (0)