11from __future__ import annotations
22
3+ import json
4+
35import httpx
46import pytest
57
@@ -36,16 +38,31 @@ def handler(request: httpx.Request) -> httpx.Response:
3638
3739
3840def test_create_intent_success () -> None :
39- payload = {"intent_type" : "notify" , "recipient" : "agent://user/test" }
41+ payload = {
42+ "intent_type" : "notify.message.v1" ,
43+ "to_agent" : "agent://user/test" ,
44+ "from_agent" : "agent://user/self" ,
45+ "payload" : {"text" : "hello" },
46+ }
4047
4148 def handler (request : httpx .Request ) -> httpx .Response :
4249 assert request .method == "POST"
4350 assert request .url .path == "/v1/intents"
44- assert request .read () == b'{"intent_type":"notify","recipient":"agent://user/test"}'
51+ body = json .loads (request .read ().decode ("utf-8" ))
52+ assert body ["correlation_id" ] == "11111111-1111-1111-1111-111111111111"
53+ assert body ["intent_type" ] == "notify.message.v1"
54+ assert request .headers ["idempotency-key" ] == "idem-1"
4555 return httpx .Response (200 , json = {"intent_id" : "it_123" })
4656
4757 client = _client (handler )
48- assert client .create_intent (payload ) == {"intent_id" : "it_123" }
58+ assert (
59+ client .create_intent (
60+ payload ,
61+ correlation_id = "11111111-1111-1111-1111-111111111111" ,
62+ idempotency_key = "idem-1" ,
63+ )
64+ == {"intent_id" : "it_123" }
65+ )
4966
5067
5168def test_create_intent_raises_http_error () -> None :
@@ -55,6 +72,25 @@ def handler(request: httpx.Request) -> httpx.Response:
5572 client = _client (handler , api_key = "bad-token" )
5673
5774 with pytest .raises (AxmeHttpError ) as exc_info :
58- client .create_intent ({"intent_type" : "notify" })
75+ client .create_intent (
76+ {"intent_type" : "notify.message.v1" , "to_agent" : "agent://x" , "from_agent" : "agent://y" , "payload" : {}},
77+ correlation_id = "11111111-1111-1111-1111-111111111111" ,
78+ )
5979
6080 assert exc_info .value .status_code == 401
81+
82+
83+ def test_create_intent_raises_for_mismatched_correlation_id () -> None :
84+ client = _client (lambda request : httpx .Response (200 , json = {"intent_id" : "it_123" }))
85+
86+ with pytest .raises (ValueError , match = "payload correlation_id" ):
87+ client .create_intent (
88+ {
89+ "intent_type" : "notify.message.v1" ,
90+ "to_agent" : "agent://x" ,
91+ "from_agent" : "agent://y" ,
92+ "payload" : {},
93+ "correlation_id" : "22222222-2222-2222-2222-222222222222" ,
94+ },
95+ correlation_id = "11111111-1111-1111-1111-111111111111" ,
96+ )
0 commit comments