Skip to content

Commit a55c97e

Browse files
mwrigemini-code-assist[bot]sokoliva
authored
fix: get_agent_card tailing slash when agent_card_path="" (#799) (#800)
Made a minor change to A2ACardResolver.get_agent_card() so it doesn't introduce an spurious trailing slash when agent_card_path is empty. This allows one to get the card from a card URL without having to break it into a base and relative card path component, it's arguably a bit odd but the empty agent_card_path is technically allowed and the result of that isn't right so I think it's a reasonable improvement, and one that as far as I can see can't reasonably be not backwards compatible for anyone. I changed one existing test, but only in a fashion such that it still tests the thing that it says it is testing... It is fine IF I understood the point of the test... # Description Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly: - [X] Follow the [`CONTRIBUTING` Guide](https://github.com/a2aproject/a2a-python/blob/main/CONTRIBUTING.md). - [X] Make your Pull Request title in the <https://www.conventionalcommits.org/> specification. - Important Prefixes for [release-please](https://github.com/googleapis/release-please): - `fix:` which represents bug fixes, and correlates to a [SemVer](https://semver.org/) patch. - `feat:` represents a new feature, and correlates to a SemVer minor. - `feat!:`, or `fix!:`, `refactor!:`, etc., which represent a breaking change (indicated by the `!`) and will result in a SemVer major. - [X] Ensure the tests and linter pass (Run `bash scripts/format.sh` from the repository root to format) - [X] Appropriate docs were updated (if necessary) Fixes #799 --------- Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Co-authored-by: Iva Sokolaj <102302011+sokoliva@users.noreply.github.com>
1 parent 0925f0a commit a55c97e

2 files changed

Lines changed: 20 additions & 2 deletions

File tree

src/a2a/client/card_resolver.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ async def get_agent_card(
7272
else:
7373
path_segment = relative_card_path.lstrip('/')
7474

75-
target_url = f'{self.base_url}/{path_segment}'
75+
target_url = (
76+
f'{self.base_url}/{path_segment}' if path_segment else self.base_url
77+
)
7678

7779
try:
7880
response = await self.httpx_client.get(

tests/client/test_card_resolver.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,23 @@ async def test_get_agent_card_root_path(
203203
mock_response.json.return_value = valid_agent_card_data
204204
mock_httpx_client.get.return_value = mock_response
205205
await resolver.get_agent_card(relative_card_path='/')
206-
mock_httpx_client.get.assert_called_once_with(f'{base_url}/')
206+
mock_httpx_client.get.assert_called_once_with(f'{base_url}')
207+
208+
@pytest.mark.asyncio
209+
async def test_get_agent_card_with_empty_resolver_agent_card_path(
210+
self,
211+
base_url,
212+
resolver,
213+
mock_httpx_client,
214+
mock_response,
215+
valid_agent_card_data,
216+
):
217+
"""Test fetching agent card when the resolver's agent_card_path is empty."""
218+
resolver.agent_card_path = ''
219+
mock_response.json.return_value = valid_agent_card_data
220+
mock_httpx_client.get.return_value = mock_response
221+
await resolver.get_agent_card()
222+
mock_httpx_client.get.assert_called_once_with(f'{base_url}')
207223

208224
@pytest.mark.asyncio
209225
async def test_get_agent_card_http_status_error(

0 commit comments

Comments
 (0)