@@ -264,6 +264,49 @@ async def recorder(payload: Any, ctx: Any) -> Any:
264264 await aact (action , ctx , backend , strategy = None )
265265 assert observed [0 ].component_type == "Instruction"
266266
267+ async def test_component_pre_execute_payload_has_context_view (self ) -> None :
268+ """COMPONENT_PRE_EXECUTE payload.context_view contains the context snapshot."""
269+ from mellea .stdlib .components import Instruction
270+ from mellea .stdlib .functional import aact
271+
272+ observed : list [Any ] = []
273+
274+ @hook ("component_pre_execute" )
275+ async def recorder (payload : Any , ctx : Any ) -> Any :
276+ observed .append (payload )
277+ return None
278+
279+ register (recorder )
280+ backend = _MockBackend ()
281+ ctx = SimpleContext .from_previous (SimpleContext (), CBlock ("prior turn" ))
282+ action = Instruction ("Context view test" )
283+
284+ await aact (action , ctx , backend , strategy = None )
285+ assert observed [0 ].context_view is not None
286+ assert len (observed [0 ].context_view ) == 1
287+ assert isinstance (observed [0 ].context_view [0 ], CBlock )
288+
289+ async def test_component_pre_execute_empty_context_gives_empty_list (self ) -> None :
290+ """COMPONENT_PRE_EXECUTE on a fresh context gives an empty list, not None."""
291+ from mellea .stdlib .components import Instruction
292+ from mellea .stdlib .functional import aact
293+
294+ observed : list [Any ] = []
295+
296+ @hook ("component_pre_execute" )
297+ async def recorder (payload : Any , ctx : Any ) -> Any :
298+ observed .append (payload )
299+ return None
300+
301+ register (recorder )
302+ backend = _MockBackend ()
303+ ctx = SimpleContext ()
304+ action = Instruction ("Fresh context" )
305+
306+ await aact (action , ctx , backend , strategy = None )
307+ assert observed [0 ].context_view is not None
308+ assert observed [0 ].context_view == []
309+
267310 async def test_component_post_success_fires_in_aact (self ) -> None :
268311 """COMPONENT_POST_SUCCESS fires in aact() after successful generation."""
269312 from mellea .stdlib .components import Instruction
0 commit comments