Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion pydantic_ai_slim/pydantic_ai/agent/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,9 @@ def to_file(
if not schema_path.is_absolute():
schema_ref = str(schema_path)
schema_path = path.parent / schema_path
else: # pragma: no cover
elif schema_path.is_relative_to(path.parent):
schema_ref = str(schema_path.relative_to(path.parent))
else:
schema_ref = str(schema_path)
self._save_schema(schema_path, custom_capability_types)

Expand Down
14 changes: 14 additions & 0 deletions tests/test_capabilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -2127,6 +2127,20 @@ def test_to_file_json(tmp_path: str):
assert schema_path.exists()


def test_to_file_json_with_absolute_schema_path(tmp_path: str):
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
import json

spec = AgentSpec(model='test', name='my-agent')
spec_path = Path(tmp_path) / 'agent.json'
schema_path = Path(tmp_path) / 'agent_schema.json'

spec.to_file(spec_path, schema_path=schema_path)

data = json.loads(spec_path.read_text(encoding='utf-8'))
assert data['$schema'] == 'agent_schema.json'
assert schema_path.exists()


def test_to_file_no_schema(tmp_path: str):
spec = AgentSpec(model='test')
spec_path = Path(tmp_path) / 'agent.yaml'
Expand Down
Loading