@@ -275,6 +275,111 @@ func TestEmitResponse_Text_WithError(t *testing.T) {
275275 }
276276}
277277
278+ func TestEmitRequest_Text_OperationMeta (t * testing.T ) {
279+ var buf bytes.Buffer
280+ inspector := NewInspector ("text" , WithOutput (& buf ))
281+
282+ meta := & pipelinev1alpha1.StepMeta {
283+ StepName : "my-operation-step" ,
284+ FunctionName : "my-operation-function" ,
285+ TraceId : "trace-op-abc" ,
286+ SpanId : "span-op-def" ,
287+ StepIndex : 0 ,
288+ Iteration : 0 ,
289+ Timestamp : timestamppb .New (time .Date (2026 , 1 , 15 , 10 , 30 , 0 , 0 , time .UTC )),
290+ Context : & pipelinev1alpha1.StepMeta_OperationMeta {
291+ OperationMeta : & pipelinev1alpha1.OperationMeta {
292+ OperationName : "reconcile" ,
293+ OperationUid : "op-uid-789" ,
294+ },
295+ },
296+ }
297+
298+ req := & pipelinev1alpha1.EmitRequestRequest {
299+ Request : []byte (`{"operation":"reconcile"}` ),
300+ Meta : meta ,
301+ }
302+
303+ _ , _ = inspector .EmitRequest (context .Background (), req )
304+
305+ want := "=== REQUEST ===\n " +
306+ " Operation: reconcile\n " +
307+ " Op UID: op-uid-789\n " +
308+ " Step: my-operation-step (index 0, iteration 0)\n " +
309+ " Function: my-operation-function\n " +
310+ " Trace ID: trace-op-abc\n " +
311+ " Span ID: span-op-def\n " +
312+ " Timestamp: 2026-01-15T10:30:00.000Z\n " +
313+ " Payload:\n " +
314+ " operation: reconcile\n " +
315+ "\n \n "
316+ if diff := cmp .Diff (want , buf .String ()); diff != "" {
317+ t .Errorf ("EmitRequest text output mismatch (-want +got):\n %s" , diff )
318+ }
319+ }
320+
321+ func TestEmitRequest_JSON_OperationMeta (t * testing.T ) {
322+ var buf bytes.Buffer
323+ inspector := NewInspector ("json" , WithOutput (& buf ))
324+
325+ meta := & pipelinev1alpha1.StepMeta {
326+ TraceId : "trace-op-123" ,
327+ SpanId : "span-op-456" ,
328+ StepIndex : 0 ,
329+ Iteration : 0 ,
330+ FunctionName : "function-operation" ,
331+ Timestamp : timestamppb .New (time .Now ()),
332+ Context : & pipelinev1alpha1.StepMeta_OperationMeta {
333+ OperationMeta : & pipelinev1alpha1.OperationMeta {
334+ OperationName : "reconcile" ,
335+ OperationUid : "op-uid-abc" ,
336+ },
337+ },
338+ }
339+
340+ req := & pipelinev1alpha1.EmitRequestRequest {
341+ Request : []byte (`{"operation":"reconcile"}` ),
342+ Meta : meta ,
343+ }
344+
345+ _ , err := inspector .EmitRequest (context .Background (), req )
346+ if err != nil {
347+ t .Fatalf ("EmitRequest failed: %v" , err )
348+ }
349+
350+ output := buf .String ()
351+ if ! strings .Contains (output , `"type":"REQUEST"` ) {
352+ t .Errorf ("expected type REQUEST in output, got: %s" , output )
353+ }
354+ if ! strings .Contains (output , `"functionName":"function-operation"` ) {
355+ t .Errorf ("expected functionName in output, got: %s" , output )
356+ }
357+
358+ // Verify it's valid JSON.
359+ var result map [string ]any
360+ if err := json .Unmarshal ([]byte (output ), & result ); err != nil {
361+ t .Errorf ("output is not valid JSON: %v" , err )
362+ }
363+
364+ // Verify meta is included and contains operationMeta.
365+ metaVal , ok := result ["meta" ].(map [string ]any )
366+ if ! ok {
367+ t .Fatalf ("expected meta field in output, got: %s" , output )
368+ }
369+
370+ opMeta , ok := metaVal ["operationMeta" ].(map [string ]any )
371+ if ! ok {
372+ t .Fatalf ("expected operationMeta in meta, got: %v" , metaVal )
373+ }
374+
375+ if opMeta ["operationName" ] != "reconcile" {
376+ t .Errorf ("expected operationName 'reconcile', got: %v" , opMeta ["operationName" ])
377+ }
378+ if opMeta ["operationUid" ] != "op-uid-abc" {
379+ t .Errorf ("expected operationUid 'op-uid-abc', got: %v" , opMeta ["operationUid" ])
380+ }
381+ }
382+
278383func TestDecodeJSONPayload (t * testing.T ) {
279384 tests := []struct {
280385 name string
0 commit comments