Skip to content

Commit 4aca08a

Browse files
claudebokelley
authored andcommitted
fix(schemas): correct generator annotation in test, add clarifying comments
- Fix _bad_as_file return type to Iterator[Path] (mypy rejects -> None on a generator under @contextmanager) - Move test imports to module level per project convention - Add comment on intentional over-conservative '..' path-traversal guard - Add noqa comment on broad except in dynamic schema listing https://claude.ai/code/session_01TfYXsZysMjHdZBpJqkVW7P
1 parent c59f30a commit 4aca08a

2 files changed

Lines changed: 12 additions & 6 deletions

File tree

src/adcp/schemas/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ def load_schema(name: str) -> dict[str, Any]:
4444
``jsonschema`` is a required dependency of ``adcp``.
4545
"""
4646
# Guard against path traversal: reject names that could escape the package.
47+
# Intentionally conservative — any name containing ".." is rejected even if
48+
# it wouldn't actually traverse (e.g. "..future.json"); prefer a clear
49+
# "invalid" error over a subtle escape.
4750
if "/" in name or "\\" in name or ".." in name:
4851
raise FileNotFoundError(
4952
f"AdCP schema name {name!r} is invalid. "
@@ -67,7 +70,7 @@ def load_schema(name: str) -> dict[str, Any]:
6770
available = ", ".join(
6871
sorted(f.name for f in files("adcp.schemas").iterdir() if f.name.endswith(".json"))
6972
)
70-
except Exception:
73+
except Exception: # noqa: BLE001 — intentional: don't mask the real FileNotFoundError
7174
available = ADCP_AGENTS
7275

7376
raise FileNotFoundError(

tests/test_schemas_module.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
from __future__ import annotations
44

5+
from collections.abc import Iterator
6+
from contextlib import contextmanager
7+
from pathlib import Path
8+
from unittest.mock import patch
9+
510
import pytest
611

712
from adcp.schemas import ADCP_AGENTS, load_schema
@@ -45,13 +50,11 @@ def test_load_schema_rejects_path_traversal(traversal: str) -> None:
4550
load_schema(traversal)
4651

4752

48-
def test_load_schema_corrupted_schema_raises_file_not_found(tmp_path) -> None:
53+
def test_load_schema_corrupted_schema_raises_file_not_found(tmp_path: Path) -> None:
4954
"""A corrupted bundled file should surface as FileNotFoundError, not JSONDecodeError."""
50-
from contextlib import contextmanager
51-
from unittest.mock import patch
5255

53-
@contextmanager # type: ignore[misc]
54-
def _bad_as_file(resource) -> None: # type: ignore[misc]
56+
@contextmanager
57+
def _bad_as_file(resource: object) -> Iterator[Path]:
5558
bad = tmp_path / "bad.json"
5659
bad.write_text("not json", encoding="utf-8")
5760
yield bad

0 commit comments

Comments
 (0)