diff --git a/internal/temporalcli/commands.workflow_exec.go b/internal/temporalcli/commands.workflow_exec.go index cef46fdf2..badfee8ba 100644 --- a/internal/temporalcli/commands.workflow_exec.go +++ b/internal/temporalcli/commands.workflow_exec.go @@ -849,11 +849,36 @@ type structuredHistoryEvent struct { Time string `cli:",width=20"` // We're going to set width to a semi-reasonable number for good header // placement, but we expect it to extend past for larger - Type string `cli:",width=26"` + Type string `cli:",width=26"` + Details string } var structuredHistoryEventType = reflect.TypeOf(structuredHistoryEvent{}) +func compactHistoryDetails(event *history.HistoryEvent) string { + switch a := event.Attributes.(type) { + case *history.HistoryEvent_WorkflowExecutionStartedEventAttributes: + return a.WorkflowExecutionStartedEventAttributes.GetWorkflowType().GetName() + case *history.HistoryEvent_WorkflowTaskScheduledEventAttributes: + return a.WorkflowTaskScheduledEventAttributes.GetTaskQueue().GetName() + case *history.HistoryEvent_ActivityTaskScheduledEventAttributes: + return a.ActivityTaskScheduledEventAttributes.GetActivityType().GetName() + case *history.HistoryEvent_StartChildWorkflowExecutionInitiatedEventAttributes: + return a.StartChildWorkflowExecutionInitiatedEventAttributes.GetWorkflowType().GetName() + case *history.HistoryEvent_WorkflowExecutionSignaledEventAttributes: + return a.WorkflowExecutionSignaledEventAttributes.GetSignalName() + case *history.HistoryEvent_WorkflowExecutionUpdateAdmittedEventAttributes: + return a.WorkflowExecutionUpdateAdmittedEventAttributes.GetRequest().GetInput().GetName() + case *history.HistoryEvent_WorkflowExecutionUpdateAcceptedEventAttributes: + return a.WorkflowExecutionUpdateAcceptedEventAttributes.GetAcceptedRequest().GetInput().GetName() + case *history.HistoryEvent_TimerStartedEventAttributes: + if timeout := a.TimerStartedEventAttributes.GetStartToFireTimeout(); timeout != nil { + return timeout.AsDuration().String() + } + } + return "" +} + func (s *structuredHistoryIter) Next() (any, error) { event, err := s.NextRawEvent() if err != nil { @@ -868,9 +893,10 @@ func (s *structuredHistoryIter) Next() (any, error) { typeName = coloredEventType(event.EventType) } data := structuredHistoryEvent{ - ID: event.EventId, - Time: event.EventTime.AsTime().Format(time.RFC3339), - Type: typeName, + ID: event.EventId, + Time: event.EventTime.AsTime().Format(time.RFC3339), + Type: typeName, + Details: compactHistoryDetails(event), } // Follow continue as new (forward only; reverse traversal stays within the requested run) diff --git a/internal/temporalcli/commands.workflow_show_test.go b/internal/temporalcli/commands.workflow_show_test.go index 0f70449a5..d61cf938e 100644 --- a/internal/temporalcli/commands.workflow_show_test.go +++ b/internal/temporalcli/commands.workflow_show_test.go @@ -2,12 +2,36 @@ package temporalcli import ( "testing" + "time" "github.com/stretchr/testify/require" "go.temporal.io/api/enums/v1" historypb "go.temporal.io/api/history/v1" + updatepb "go.temporal.io/api/update/v1" + "google.golang.org/protobuf/types/known/durationpb" ) +func TestCompactHistoryDetails(t *testing.T) { + timer := &historypb.TimerStartedEventAttributes{StartToFireTimeout: durationpb.New(90 * time.Second)} + event := &historypb.HistoryEvent{Attributes: &historypb.HistoryEvent_TimerStartedEventAttributes{ + TimerStartedEventAttributes: timer, + }} + require.Equal(t, "1m30s", compactHistoryDetails(event)) + timer.StartToFireTimeout = nil + require.Empty(t, compactHistoryDetails(event)) + + // Accepted updates need not carry the original request. + accepted := &historypb.WorkflowExecutionUpdateAcceptedEventAttributes{} + updateEvent := &historypb.HistoryEvent{ + Attributes: &historypb.HistoryEvent_WorkflowExecutionUpdateAcceptedEventAttributes{ + WorkflowExecutionUpdateAcceptedEventAttributes: accepted, + }, + } + require.Empty(t, compactHistoryDetails(updateEvent)) + accepted.AcceptedRequest = &updatepb.Request{Input: &updatepb.Input{Name: "change-address"}} + require.Equal(t, "change-address", compactHistoryDetails(updateEvent)) +} + func TestSystemNexusOpDisplayName(t *testing.T) { const op = "SignalWithStartWorkflowExecution" // present in the global systemNexusOps registry const futureOp = "FutureUnregisteredOperation" // intentionally NOT in the global registry diff --git a/internal/temporalcli/commands.workflow_view_test.go b/internal/temporalcli/commands.workflow_view_test.go index 0d9c22313..f4bd34551 100644 --- a/internal/temporalcli/commands.workflow_view_test.go +++ b/internal/temporalcli/commands.workflow_view_test.go @@ -329,7 +329,7 @@ func (s *SharedServerSuite) testWorkflowShowFollow(detailed bool) { s.Contains(output, "input[0]: ignored") s.Contains(output, "signalName: my-signal") } else { - s.Contains(output, "WorkflowExecutionSignaled") + s.ContainsOnSameLine(output, "WorkflowExecutionSignaled", "my-signal") } }