fix(a2a_response): push-queue delivery_mode and comprehensive tests
- a2a_response.parse: set delivery_mode="push" for queued=True envelope (was missing — returned Queued() with default "poll", violating the push vs poll SSOT contract in a2a_response.py docstring). - Add test fixtures for push-mode queue envelopes (full, notify, no method, no queue_id) and a dedicated TestPushQueuedVariant test class. - Fix assertion in push queue test: delivery_mode=="poll" → "push". - Correlated with PRs #333 (async test pollution) and #335 (delivery_mode). Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -194,7 +194,7 @@ def parse(data: Any) -> Variant:
|
||||
method,
|
||||
data.get("queue_id", "?"),
|
||||
)
|
||||
return Queued(method=method)
|
||||
return Queued(method=method, delivery_mode="push")
|
||||
|
||||
# Poll-queued envelope. Both keys must be present — the workspace
|
||||
# server sets them together; if only one is present the body is
|
||||
|
||||
@@ -115,12 +115,91 @@ _FIXTURES = {
|
||||
"malformed_delivery_mode_no_status": {
|
||||
"delivery_mode": "poll",
|
||||
},
|
||||
|
||||
# --- Push-mode queue envelopes ---
|
||||
# Returned when a push-mode workspace (has public URL) is at capacity.
|
||||
# The platform queues the request and returns {"queued": true, ...}.
|
||||
# Distinguishable from poll-mode by data.get("queued") is True alone.
|
||||
"push_queued_full": {
|
||||
"queued": True,
|
||||
"method": "message/send",
|
||||
"queue_id": "q-1",
|
||||
},
|
||||
"push_queued_notify": {
|
||||
"queued": True,
|
||||
"method": "notify",
|
||||
"queue_id": "q-2",
|
||||
},
|
||||
"push_queued_no_method": {
|
||||
# method absent — parser must not raise; falls back to "message/send".
|
||||
"queued": True,
|
||||
"queue_id": "q-3",
|
||||
},
|
||||
"push_queued_no_queue_id": {
|
||||
# queue_id absent — parser must not raise; logs queue_id="?".
|
||||
"queued": True,
|
||||
"method": "message/send",
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
# ============== Variant-by-variant coverage ==============
|
||||
|
||||
|
||||
class TestPushQueuedVariant:
|
||||
"""``parse()`` returns ``Queued`` for push-mode at-capacity envelope
|
||||
(lines 189-197 of a2a_response.py): ``{"queued": true, ...}``.
|
||||
|
||||
The push-mode path was added in PR #278 alongside the a2a_proxy.go
|
||||
push-at-capacity branch. Lines 182-197 were not covered until this test.
|
||||
"""
|
||||
|
||||
def test_full_envelope_message_send(self):
|
||||
v = a2a_response.parse(_FIXTURES["push_queued_full"])
|
||||
assert isinstance(v, a2a_response.Queued)
|
||||
assert v.method == "message/send"
|
||||
assert v.delivery_mode == "push"
|
||||
|
||||
def test_envelope_with_notify(self):
|
||||
v = a2a_response.parse(_FIXTURES["push_queued_notify"])
|
||||
assert isinstance(v, a2a_response.Queued)
|
||||
assert v.method == "notify"
|
||||
|
||||
def test_envelope_missing_method_falls_back_to_message_send(self):
|
||||
# a2a_response.py:191 — method_raw is None, defaults to "message/send".
|
||||
v = a2a_response.parse(_FIXTURES["push_queued_no_method"])
|
||||
assert isinstance(v, a2a_response.Queued)
|
||||
assert v.method == "message/send"
|
||||
|
||||
def test_envelope_missing_queue_id_still_queued(self):
|
||||
# queue_id is purely informational; its absence must not break parsing.
|
||||
v = a2a_response.parse(_FIXTURES["push_queued_no_queue_id"])
|
||||
assert isinstance(v, a2a_response.Queued)
|
||||
assert v.method == "message/send"
|
||||
|
||||
def test_push_queued_is_distinct_from_poll_queued(self):
|
||||
# Same Queued variant, but from different wire shapes. Confirm both paths.
|
||||
push_v = a2a_response.parse(_FIXTURES["push_queued_full"])
|
||||
poll_v = a2a_response.parse(_FIXTURES["poll_queued_full"])
|
||||
assert isinstance(push_v, a2a_response.Queued)
|
||||
assert isinstance(poll_v, a2a_response.Queued)
|
||||
assert push_v.method == poll_v.method == "message/send"
|
||||
|
||||
def test_logs_info_on_push_queued(self, caplog):
|
||||
with caplog.at_level(logging.INFO, logger="a2a_response"):
|
||||
a2a_response.parse(_FIXTURES["push_queued_full"])
|
||||
assert any("queued for busy push-mode peer" in r.message for r in caplog.records)
|
||||
assert any("queue_id=q-1" in r.message for r in caplog.records)
|
||||
|
||||
def test_queued_true_is_distinct_from_queued_truthy(self):
|
||||
# "queued": 1 / "queued": "yes" — these are truthy but not True,
|
||||
# and must NOT trigger the push-mode path. Route to Malformed instead.
|
||||
v = a2a_response.parse({"queued": 1})
|
||||
assert isinstance(v, a2a_response.Malformed)
|
||||
v = a2a_response.parse({"queued": "yes"})
|
||||
assert isinstance(v, a2a_response.Malformed)
|
||||
|
||||
|
||||
class TestQueuedVariant:
|
||||
"""``parse()`` recognizes the workspace-server poll-mode short-circuit
|
||||
envelope (a2a_proxy.go:402-406) and returns ``Queued``."""
|
||||
@@ -436,6 +515,10 @@ class TestRegressionGate:
|
||||
"poll_queued_full": a2a_response.Queued,
|
||||
"poll_queued_notify": a2a_response.Queued,
|
||||
"poll_queued_no_method": a2a_response.Queued,
|
||||
"push_queued_full": a2a_response.Queued,
|
||||
"push_queued_notify": a2a_response.Queued,
|
||||
"push_queued_no_method": a2a_response.Queued,
|
||||
"push_queued_no_queue_id": a2a_response.Queued,
|
||||
"malformed_empty_dict": a2a_response.Malformed,
|
||||
"malformed_unexpected_keys": a2a_response.Malformed,
|
||||
"malformed_status_queued_no_delivery_mode": a2a_response.Malformed,
|
||||
|
||||
Reference in New Issue
Block a user