1818replay interception.
1919"""
2020
21- from unittest .mock import MagicMock
22-
23- from google .adk .agents .context import Context
2421from google .adk .workflow ._base_node import BaseNode
2522from google .adk .workflow ._dynamic_node_scheduler import DynamicNodeRun
2623from google .adk .workflow ._node_state import NodeState
3027import pytest
3128
3229
33- def _make_parent_ctx ():
34- ctx = MagicMock (spec = Context )
35- ctx ._invocation_context = MagicMock ()
36- ctx .resume_inputs = {}
37- return ctx
38-
39-
4030def test_same_turn_completed ():
4131 """Same-turn completed run intercepts and returns cached output."""
4232 # Given a same-turn completed run
@@ -45,14 +35,11 @@ def test_same_turn_completed():
4535 output = 'cached-out' ,
4636 transfer_to_agent = 'target-agent' ,
4737 )
48- ctx = _make_parent_ctx ()
4938
5039 # When checked
5140 result = check_interception (
52- node_path = 'wf/node@1' ,
5341 node = BaseNode (name = 'node' ),
5442 current_run = run ,
55- curr_parent_ctx = ctx ,
5643 )
5744
5845 # Then it intercepts with cached results
@@ -67,14 +54,11 @@ def test_same_turn_waiting():
6754 run = DynamicNodeRun (
6855 state = NodeState (status = NodeStatus .WAITING , interrupts = ['fc-1' ]),
6956 )
70- ctx = _make_parent_ctx ()
7157
7258 # When checked
7359 result = check_interception (
74- node_path = 'wf/node@1' ,
7560 node = BaseNode (name = 'node' ),
7661 current_run = run ,
77- curr_parent_ctx = ctx ,
7862 )
7963
8064 # Then it intercepts and keeps waiting
@@ -91,14 +75,11 @@ def test_cross_turn_unresolved_interrupts_no_rerun():
9175 resolved_ids = {'fc-1' },
9276 )
9377 node = BaseNode (name = 'node' , rerun_on_resume = False )
94- ctx = _make_parent_ctx ()
9578
9679 # When checked
9780 result = check_interception (
98- node_path = 'wf/node@1' ,
9981 node = node ,
10082 recovered = recovered ,
101- curr_parent_ctx = ctx ,
10283 )
10384
10485 # Then it stays waiting on unresolved interrupts
@@ -116,14 +97,11 @@ def test_cross_turn_unresolved_interrupts_rerun():
11697 resolved_responses = {'fc-1' : 'ans' },
11798 )
11899 node = BaseNode (name = 'node' , rerun_on_resume = True )
119- ctx = _make_parent_ctx ()
120100
121101 # When checked
122102 result = check_interception (
123- node_path = 'wf/node@1' ,
124103 node = node ,
125104 recovered = recovered ,
126- curr_parent_ctx = ctx ,
127105 )
128106
129107 # Then it reruns with partial resolved inputs
@@ -140,14 +118,11 @@ def test_cross_turn_completed():
140118 route = 'route-a' ,
141119 )
142120 node = BaseNode (name = 'node' )
143- ctx = _make_parent_ctx ()
144121
145122 # When checked
146123 result = check_interception (
147- node_path = 'wf/node@1' ,
148124 node = node ,
149125 recovered = recovered ,
150- curr_parent_ctx = ctx ,
151126 )
152127
153128 # Then it fast-forwards with cached output and route
@@ -166,17 +141,11 @@ def test_cross_turn_all_resolved_no_rerun():
166141 resolved_responses = {'fc-1' : 'ans' },
167142 )
168143 node = BaseNode (name = 'node' , rerun_on_resume = False )
169- ctx = _make_parent_ctx ()
170- ctx .resume_inputs = {
171- 'fc-1' : {'result' : 'ans' }
172- } # Simulate FunctionResponse dict
173144
174145 # When checked
175146 result = check_interception (
176- node_path = 'wf/node@1' ,
177147 node = node ,
178148 recovered = recovered ,
179- curr_parent_ctx = ctx ,
180149 )
181150
182151 # Then it auto-completes
@@ -194,14 +163,11 @@ def test_cross_turn_all_resolved_rerun():
194163 resolved_responses = {'fc-1' : 'ans' },
195164 )
196165 node = BaseNode (name = 'node' , rerun_on_resume = True )
197- ctx = _make_parent_ctx ()
198166
199167 # When checked
200168 result = check_interception (
201- node_path = 'wf/node@1' ,
202169 node = node ,
203170 recovered = recovered ,
204- curr_parent_ctx = ctx ,
205171 )
206172
207173 # Then it reruns
0 commit comments