55import json
66
77import pytest
8- from truth_hitl .event_handlers import build_event_handlers
8+ import truth_hitl .event_handlers as event_handlers
9+ from truth_hitl .adapters import build_hitl_adapters
10+ from truth_hitl .review_manager import ReviewManager
911
1012
1113class FakeEvent :
@@ -20,7 +22,7 @@ def body_as_str(self) -> str:
2022
2123@pytest .mark .asyncio
2224async def test_handle_hitl_job_enqueues_item ():
23- handlers = build_event_handlers ()
25+ handlers = event_handlers . build_event_handlers ()
2426 handler = handlers ["hitl-jobs" ]
2527
2628 payload = {
@@ -44,7 +46,7 @@ async def test_handle_hitl_job_enqueues_item():
4446
4547@pytest .mark .asyncio
4648async def test_handle_hitl_job_skips_missing_entity_id ():
47- handlers = build_event_handlers ()
49+ handlers = event_handlers . build_event_handlers ()
4850 handler = handlers ["hitl-jobs" ]
4951
5052 payload = {
@@ -57,7 +59,7 @@ async def test_handle_hitl_job_skips_missing_entity_id():
5759
5860@pytest .mark .asyncio
5961async def test_handle_hitl_job_skips_missing_attr_id ():
60- handlers = build_event_handlers ()
62+ handlers = event_handlers . build_event_handlers ()
6163 handler = handlers ["hitl-jobs" ]
6264
6365 payload = {
@@ -68,5 +70,62 @@ async def test_handle_hitl_job_skips_missing_attr_id():
6870
6971
7072def test_build_event_handlers_includes_hitl_jobs ():
71- handlers = build_event_handlers ()
73+ handlers = event_handlers . build_event_handlers ()
7274 assert "hitl-jobs" in handlers
75+
76+
77+ @pytest .mark .asyncio
78+ async def test_handle_hitl_job_accepts_enhanced_ui_payload_shapes (monkeypatch ):
79+ review_manager = ReviewManager ()
80+
81+ def _stub_build_hitl_adapters ():
82+ return build_hitl_adapters (review_manager = review_manager )
83+
84+ monkeypatch .setattr (event_handlers , "build_hitl_adapters" , _stub_build_hitl_adapters )
85+
86+ handlers = event_handlers .build_event_handlers ()
87+ handler = handlers ["hitl-jobs" ]
88+
89+ payload = {
90+ "event_type" : "proposed_attribute" ,
91+ "data" : {
92+ "entity_id" : "prod-100" ,
93+ "attr_id" : "attr-200" ,
94+ "field_name" : "material" ,
95+ "proposed_value" : "Organic Cotton" ,
96+ "confidence" : 0.92 ,
97+ "source" : "ai" ,
98+ "product_title" : "Heritage Shirt" ,
99+ "category_label" : "Apparel" ,
100+ "reasoning" : [
101+ "Image texture suggests cotton" ,
102+ "Catalog title includes 'cotton'" ,
103+ ],
104+ "source_assets" : [
105+ "https://cdn.example.com/products/prod-100/front.jpg" ,
106+ {
107+ "url" : "https://cdn.example.com/products/prod-100/zoom.jpg" ,
108+ "asset_id" : "dam-200" ,
109+ "kind" : "image" ,
110+ },
111+ ],
112+ "source_type" : "hybrid" ,
113+ },
114+ }
115+
116+ await handler (None , FakeEvent (payload ))
117+
118+ queued = review_manager .get_by_entity ("prod-100" )
119+ assert len (queued ) == 1
120+ assert queued [0 ].reasoning == [
121+ "Image texture suggests cotton" ,
122+ "Catalog title includes 'cotton'" ,
123+ ]
124+ assert queued [0 ].source_assets == [
125+ "https://cdn.example.com/products/prod-100/front.jpg" ,
126+ {
127+ "url" : "https://cdn.example.com/products/prod-100/zoom.jpg" ,
128+ "asset_id" : "dam-200" ,
129+ "kind" : "image" ,
130+ },
131+ ]
0 commit comments