Repository navigation
Commit 486f0f6
fix(client): normalize malformed agent card parsing errors (a2aproject#1307)
## Description
When an agent-card endpoint returns HTTP 200 with valid JSON such as
`null`, an array, a string, a number, or a boolean, the compatibility
helpers raise `AttributeError` or `TypeError`. Malformed nested legacy
fields can raise the same exceptions even when the root is an object.
These exceptions escape `A2ACardResolver.get_agent_card()` instead of
the documented `AgentCardResolutionError`.
Validate that the decoded value is a JSON object at the parser boundary.
Convert `TypeError` and `AttributeError` from the three compatibility
helpers into `ParseError`, retaining their original cause. The resolver
already wraps `ParseError` into `AgentCardResolutionError`; protobuf
parsing and signature verification retain their existing exception
handling.
Regression tests use `httpx.MockTransport` with real JSON decoding:
eight non-object roots and all six malformed nested cases from the
review (null/list capabilities, a null additional interface, null
skills/a null skill, and string security). Every new case failed before
its corresponding fix. The nested-field tests also verify the full
exception cause chain.
## Validation
- The Windows equivalents of `scripts/lint.sh` (`uv run --locked ruff
check --fix`, `ruff format`, and `ty check`) passed. `ty` exits
successfully with three existing unused-ignore warnings.
- `uv run --locked pytest tests/client/test_card_resolver.py -q`: **46
passed**.
- `uv run --locked pytest --ignore=tests/integration --cov=src
--cov-report=term-missing -q`: **1,788 passed, 169 skipped, 3 xfailed;
91% coverage**. `card_resolver.py` has **100% statement and branch
coverage**.
- With `PYTHONIOENCODING=utf-8`, sample integration smoke tests: **3
passed**.
- Full pytest was attempted on Windows and timed out in scenario
integration tests. A coverage run excluding only the scenario and sample
modules completed with **2,095 passed, 183 skipped, 3 xfailed and 8
fixture errors; 93% coverage**. The errors are in the previously
problematic cross-version server fixtures (startup / unavailable
`os.killpg`) and push-notification fixtures (a FastAPI local callable
cannot be pickled under Windows multiprocessing). These platform
limitations are outside this change.
- Updated GitHub Actions checks all passed, including the full Python
3.10–3.14 matrix, ACTS, ITK, lint and install checks. The same matrix
also passed before this follow-up.
AI assistance: OpenAI Codex (GPT-6) was used to implement, reproduce,
and test this change under the account owner's explicit authorization.
The follow-up implements the human maintainer's review request and
received another independent review before submission.
- [x] Followed the contributing guide and conventional-commit title
format.
- [x] Added failing regression cases and ran lint, formatting, type and
coverage checks.
---------
Co-authored-by: mykytanetipa <mykytanetipa@google.com>1 parent 5653daf commit 486f0f6
2 files changed
Lines changed: 81 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | | - | |
24 | | - | |
25 | | - | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
26 | 31 | | |
27 | 32 | | |
28 | 33 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
| 33 | + | |
33 | 34 | | |
34 | 35 | | |
35 | 36 | | |
| |||
310 | 311 | | |
311 | 312 | | |
312 | 313 | | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
313 | 386 | | |
314 | 387 | | |
315 | 388 | | |
| |||
0 commit comments