@@ -2090,6 +2090,7 @@ async def test_on_event_callback_ignores_empty_state_delta(
20902090 bq_plugin_inst,
20912091 mock_write_client,
20922092 invocation_context,
2093+ dummy_arrow_schema,
20932094 ):
20942095 """on_event_callback should not log when state_delta is empty."""
20952096 event = event_lib.Event(
@@ -6779,6 +6780,16 @@ def test_llm_response_view_exposes_finish_reason(self):
67796780 "JSON_VALUE(attributes, '$.finish_reason') AS finish_reason" in columns
67806781 )
67816782
6783+ @pytest.mark.parametrize("event_type", ["NODE_OUTPUT", "NODE_ERROR"])
6784+ def test_node_views_expose_workflow_identity(self, event_type):
6785+ """Workflow-node views expose stable node identity columns."""
6786+ columns = bigquery_agent_analytics_plugin._EVENT_VIEW_DEFS[event_type]
6787+
6788+ assert "JSON_VALUE(attributes, '$.adk.node.path') AS node_path" in columns
6789+ assert (
6790+ "JSON_VALUE(attributes, '$.adk.node.run_id') AS node_run_id" in columns
6791+ )
6792+
67826793 def test_config_create_views_default_true(self):
67836794 """Config create_views defaults to True."""
67846795 config = bigquery_agent_analytics_plugin.BigQueryLoggerConfig()
@@ -9665,6 +9676,139 @@ async def test_route_and_rewind_flat_under_attributes_adk(
96659676 assert "actions" not in adk
96669677
96679678
9679+ class TestWorkflowNodeEvents:
9680+ """Workflow node outputs and failures are observable through the plugin."""
9681+
9682+ @pytest.mark.asyncio
9683+ @pytest.mark.parametrize("output", [{"id": 7}, ["a", "b"], "done"])
9684+ async def test_node_output_preserves_payload_and_identity(
9685+ self,
9686+ output,
9687+ bq_plugin_inst,
9688+ mock_write_client,
9689+ invocation_context,
9690+ dummy_arrow_schema,
9691+ ):
9692+ """Function-node payloads produce one identity-bearing NODE_OUTPUT row."""
9693+ event = event_lib.Event(
9694+ author="step",
9695+ output=output,
9696+ node_info=event_lib.NodeInfo(path="wf@1/step@2"),
9697+ )
9698+
9699+ await bq_plugin_inst.on_event_callback(
9700+ invocation_context=invocation_context, event=event
9701+ )
9702+ await bq_plugin_inst.flush()
9703+
9704+ row = await _get_captured_event_dict_async(
9705+ mock_write_client, dummy_arrow_schema
9706+ )
9707+ assert row["event_type"] == "NODE_OUTPUT"
9708+ stored_output = (
9709+ json.loads(row["content"])
9710+ if isinstance(output, (dict, list))
9711+ else row["content"]
9712+ )
9713+ assert stored_output == output
9714+ node = json.loads(row["attributes"])["adk"]["node"]
9715+ assert node["path"] == "wf@1/step@2"
9716+ assert node["run_id"] == "2"
9717+
9718+ @pytest.mark.asyncio
9719+ async def test_output_and_state_delta_emit_separate_rows(
9720+ self,
9721+ bq_plugin_inst,
9722+ mock_write_client,
9723+ invocation_context,
9724+ dummy_arrow_schema,
9725+ ):
9726+ """A node event preserves both its state change and returned output."""
9727+ event = event_lib.Event(
9728+ author="step",
9729+ output={"result": 1},
9730+ actions=event_actions_lib.EventActions(state_delta={"count": 1}),
9731+ node_info=event_lib.NodeInfo(path="wf@1/step@2"),
9732+ )
9733+
9734+ await bq_plugin_inst.on_event_callback(
9735+ invocation_context=invocation_context, event=event
9736+ )
9737+ await bq_plugin_inst.flush()
9738+
9739+ rows = await _get_captured_rows_async(mock_write_client, dummy_arrow_schema)
9740+ assert [row["event_type"] for row in rows] == [
9741+ "STATE_DELTA",
9742+ "NODE_OUTPUT",
9743+ ]
9744+
9745+ @pytest.mark.asyncio
9746+ async def test_node_error_uses_sanitized_error_column(
9747+ self,
9748+ bq_plugin_inst,
9749+ mock_write_client,
9750+ invocation_context,
9751+ dummy_arrow_schema,
9752+ ):
9753+ """Workflow failures produce an error row with their node identity."""
9754+ event = event_lib.Event(
9755+ author="step",
9756+ error_code="ValueError",
9757+ error_message="invalid input",
9758+ node_info=event_lib.NodeInfo(path="wf@1/step@2"),
9759+ )
9760+
9761+ await bq_plugin_inst.on_event_callback(
9762+ invocation_context=invocation_context, event=event
9763+ )
9764+ await bq_plugin_inst.flush()
9765+
9766+ row = await _get_captured_event_dict_async(
9767+ mock_write_client, dummy_arrow_schema
9768+ )
9769+ assert row["event_type"] == "NODE_ERROR"
9770+ assert row["status"] == "ERROR"
9771+ assert row["error_message"] == "invalid input"
9772+ assert json.loads(row["content"])["error_code"] == "ValueError"
9773+
9774+ @pytest.mark.asyncio
9775+ @pytest.mark.parametrize(
9776+ "event",
9777+ [
9778+ event_lib.Event(
9779+ author="step",
9780+ output=None,
9781+ node_info=event_lib.NodeInfo(path="wf@1/step@2"),
9782+ ),
9783+ event_lib.Event(
9784+ author="agent",
9785+ content=types.Content(parts=[types.Part(text="answer")]),
9786+ output="answer",
9787+ node_info=event_lib.NodeInfo(
9788+ path="wf@1/agent@2", message_as_output=True
9789+ ),
9790+ ),
9791+ ],
9792+ ids=("none", "message-as-output"),
9793+ )
9794+ async def test_non_output_events_do_not_duplicate_node_rows(
9795+ self,
9796+ event,
9797+ bq_plugin_inst,
9798+ mock_write_client,
9799+ invocation_context,
9800+ dummy_arrow_schema,
9801+ ):
9802+ """Empty and message-delegated events do not add NODE_OUTPUT rows."""
9803+ await bq_plugin_inst.on_event_callback(
9804+ invocation_context=invocation_context, event=event
9805+ )
9806+ await bq_plugin_inst.flush()
9807+
9808+ rows = await _get_captured_rows_async(mock_write_client, dummy_arrow_schema)
9809+ assert all(row["event_type"] != "NODE_OUTPUT" for row in rows)
9810+
9811+
96689812class TestViewDefsRegistration:
96699813 """The plugin's own per-event-type view defs cover the new types."""
96709814
0 commit comments