|
18 | 18 | from google.adk.events.event import NodeInfo |
19 | 19 | from google.adk.events.request_input import RequestInput |
20 | 20 | from google.adk.workflow.utils._rehydration_utils import _ChildScanState |
| 21 | +from google.adk.workflow.utils._rehydration_utils import _process_content_object |
21 | 22 | from google.adk.workflow.utils._rehydration_utils import _reconstruct_node_states |
22 | 23 | from google.adk.workflow.utils._rehydration_utils import _unwrap_response |
23 | 24 | from google.adk.workflow.utils._rehydration_utils import _validate_resume_response |
@@ -103,6 +104,48 @@ def test_roundtrip_wrap_unwrap_dict(self): |
103 | 104 | assert _unwrap_response(_wrap_response(d)) == d |
104 | 105 |
|
105 | 106 |
|
| 107 | +# --- _process_content_object --- |
| 108 | + |
| 109 | + |
| 110 | +class TestProcessContentObject: |
| 111 | + |
| 112 | + def test_extracts_plain_text(self): |
| 113 | + content = types.Content(parts=[types.Part(text="hello world")]) |
| 114 | + event = Event(content=content, invocation_id="id") |
| 115 | + assert _process_content_object(event) == "hello world" |
| 116 | + |
| 117 | + def test_parses_json_text(self): |
| 118 | + content = types.Content(parts=[types.Part(text='{"foo": "bar"}')]) |
| 119 | + event = Event(content=content, invocation_id="id") |
| 120 | + assert _process_content_object(event) == {"foo": "bar"} |
| 121 | + |
| 122 | + def test_joins_multiple_parts(self): |
| 123 | + content = types.Content( |
| 124 | + parts=[types.Part(text="hello "), types.Part(text="world")] |
| 125 | + ) |
| 126 | + event = Event(content=content, invocation_id="id") |
| 127 | + assert _process_content_object(event) == "hello world" |
| 128 | + |
| 129 | + def test_filters_thought_parts(self): |
| 130 | + content = types.Content( |
| 131 | + parts=[ |
| 132 | + types.Part(text="thinking...", thought=True), |
| 133 | + types.Part(text='{"answer": 42}'), |
| 134 | + ] |
| 135 | + ) |
| 136 | + event = Event(content=content, invocation_id="id") |
| 137 | + assert _process_content_object(event) == {"answer": 42} |
| 138 | + |
| 139 | + def test_returns_none_for_no_content(self): |
| 140 | + event = Event(invocation_id="id") |
| 141 | + assert _process_content_object(event) is None |
| 142 | + |
| 143 | + def test_returns_none_for_empty_text(self): |
| 144 | + content = types.Content(parts=[types.Part(text=" ")]) |
| 145 | + event = Event(content=content, invocation_id="id") |
| 146 | + assert _process_content_object(event) is None |
| 147 | + |
| 148 | + |
106 | 149 | # --- _validate_resume_response --- |
107 | 150 |
|
108 | 151 |
|
@@ -192,7 +235,7 @@ def test_scan_message_as_output(self): |
192 | 235 | ) |
193 | 236 |
|
194 | 237 | assert "node_a@1" in results |
195 | | - assert results["node_a@1"].output == content |
| 238 | + assert results["node_a@1"].output == "hello" |
196 | 239 |
|
197 | 240 | def test_scan_descendant_interrupts(self): |
198 | 241 | event = Event( |
|
0 commit comments