Conversation
|
Fold opportunity from #601: Issue #601 proposes adding If you want to ship them together, consider folding before merge: expose Generated by Claude Code |
extract_webhook_result_data declared AdcpAsyncResponseData | None but every code path returned dict[str, Any] | None, forcing adopters to cast before using .get(). Return type corrected to dict[str, Any] | None and internal cast calls updated accordingly. create_mcp_webhook_payload and create_a2a_webhook_payload typed result narrowly as AdcpAsyncResponseData but accepted any BaseModel via hasattr check at runtime. Parameter widened to PydanticBaseModel | dict[str, Any] so callers pass any Pydantic model without type: ignore. Also drops the direct generated_poc import (CLAUDE.md layering rule) since AdcpAsyncResponseData is no longer referenced in this module, and fixes a bogus message= kwarg in the create_a2a_webhook_payload docstring example. https://claude.ai/code/session_013oiysa4CAeiSFFdnvFTHqh
…builders Adds TestWebhookPayloadBuilderPydanticModel covering the model_dump path in create_mcp_webhook_payload and create_a2a_webhook_payload (both completed and working status paths). Also fixes the result param docstring in create_mcp_webhook_payload to match the widened type. https://claude.ai/code/session_013oiysa4CAeiSFFdnvFTHqh
3cb642e to
00d93db
Compare
The fix removed the generated_poc/ import from webhooks.py, so the entry in _KNOWN_VIOLATIONS is now stale and the layering test fails on the "stale entries" branch. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Closes #598
Summary
Two webhook helpers in
src/adcp/webhooks.pydeclared type annotations that didn't match runtime behavior, forcing adopters to cast or add# type: ignorecomments.extract_webhook_result_data— declared return type wasAdcpAsyncResponseData | Nonebut every code path returnsdict[str, Any] | None. Thecast()calls inside the body were lies to mypy; callers that didresult.get(...)correctly got a type error. Return type corrected todict[str, Any] | None; docstring updated accordingly.create_mcp_webhook_payloadandcreate_a2a_webhook_payload—resultparameter was typed asAdcpAsyncResponseData | dict[str, Any](narrow discriminated union), but both functions already calledhasattr(result, "model_dump")at runtime and accepted any Pydantic model. Parameter widened toPydanticBaseModel | dict[str, Any]; docstrings updated.Also removes the direct import from
adcp/types/generated_poc/inwebhooks.py(a CLAUDE.md layering violation — that import path is forstable.py/aliases.py/_ergonomic.pyonly). The import is now unused after the above fixes.Fixes bogus
message=kwarg in thecreate_a2a_webhook_payloaddocstring example, which would raiseTypeErrorif copied verbatim.Not in scope / noted for follow-up:
WebhookSender.send_mcpinwebhook_sender.py:525has the same narrowAdcpAsyncResponseData | dict[str, Any] | Noneannotation and the samegenerated_poc/import. That file is separate from the callsites named in #598 — addressed in a follow-up.What tested
pytest tests/test_webhook_handling.py tests/test_webhooks_deliver.py tests/conformance/signing/— 164 passed, 15 skippedTestWebhookPayloadBuilderPydanticModel(4 tests) exercising themodel_dumppath in both builders via a plainBaseModelsubclass — previously untested code pathmypy src/adcp/webhooks.py— cleanruff check src/adcp/webhooks.py— cleanPre-PR review
Session: https://claude.ai/code/session_013oiysa4CAeiSFFdnvFTHqh
Generated by Claude Code