Something went wrong. Try again.
MCP based ACP agent
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950"""UsageUpdate emission regression tests (hermetic — no LLM, no network).
Regression: the UsageUpdate sent from react_loop to expose context usage(% of the compaction threshold) to the ACP client was constructed WITHOUTthe required ``sessionUpdate`` discriminator, so pydantic raised aValidationError and the best-effort try/except swallowed it — Zed neverreceived the update and its token-usage ring stayed empty.
The SDK now defaults the discriminator (``session_update:Literal["usage_update"] = "usage_update"``), so the historical bug is nolonger reachable: omitting it produces the right payload instead of raisinginto a best-effort try/except. What Zed depends on is the wire shape, andthat is what both tests below pin."""
from acp.schema import UsageUpdate
def test_usage_update_discriminator_is_defaulted(): """Omitting sessionUpdate must still put it on the wire.
This used to assert the opposite — that omitting it raised — because the generated model had no default and the ValidationError was swallowed by the best-effort try/except around it. The SDK gained the default, so the guarantee is now stronger: there is no way to construct the update the react loop sends and lose the discriminator. """ payload = UsageUpdate(used=91266, size=190000).model_dump( by_alias=True, exclude_none=True ) assert payload == {"used": 91266, "size": 190000, "sessionUpdate": "usage_update"}
def test_usage_update_wire_format_matches_zed(): """Constructed as react_loop does, the payload must match what Zed's agent-client-protocol-schema deserializes: {"sessionUpdate": "usage_update", "used": N, "size": M}.""" update = UsageUpdate( session_update="usage_update", used=91266, size=190000, ) payload = update.model_dump(by_alias=True, exclude_none=True) assert payload == { "sessionUpdate": "usage_update", "used": 91266, "size": 190000, }