From f697225408e5821137961e2ddba9d8431de6abc6 Mon Sep 17 00:00:00 2001 From: Chad Retz Date: Mon, 25 Mar 2024 10:33:51 -0500 Subject: [PATCH] Do not use payload shorthand on workflow show --- temporalcli/commands.workflow_view.go | 10 ++++++++-- temporalcli/commands.workflow_view_test.go | 5 ++++- temporalcli/commandsmd/commands.md | 3 ++- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/temporalcli/commands.workflow_view.go b/temporalcli/commands.workflow_view.go index 145fa131..b9628b82 100644 --- a/temporalcli/commands.workflow_view.go +++ b/temporalcli/commands.workflow_view.go @@ -269,7 +269,7 @@ func (*TemporalWorkflowCountCommand) run(*CommandContext, []string) error { return fmt.Errorf("TODO") } -func (c *TemporalWorkflowShowCommand) run(cctx *CommandContext, args []string) error { +func (c *TemporalWorkflowShowCommand) run(cctx *CommandContext, _ []string) error { // Call describe cl, err := c.Parent.ClientOptions.dialClient(cctx) if err != nil { @@ -308,7 +308,13 @@ func (c *TemporalWorkflowShowCommand) run(cctx *CommandContext, args []string) e } outStruct := history.History{} outStruct.Events = events - if err := cctx.Printer.PrintStructured(&outStruct, printer.StructuredOptions{}); err != nil { + // We intentionally disable shorthand because "workflow show" for JSON needs + // to support SDK replayers which do not work with shorthand + jsonPayloadShorthand := false + err = cctx.Printer.PrintStructured(&outStruct, printer.StructuredOptions{ + OverrideJSONPayloadShorthand: &jsonPayloadShorthand, + }) + if err != nil { return fmt.Errorf("failed printing structured output: %w", err) } } diff --git a/temporalcli/commands.workflow_view_test.go b/temporalcli/commands.workflow_view_test.go index 3bc6a5bf..cd5ec467 100644 --- a/temporalcli/commands.workflow_view_test.go +++ b/temporalcli/commands.workflow_view_test.go @@ -2,6 +2,7 @@ package temporalcli_test import ( "context" + "encoding/base64" "encoding/json" "fmt" "strconv" @@ -256,7 +257,7 @@ func (s *SharedServerSuite) TestWorkflow_Show_JSON() { s.Context, client.StartWorkflowOptions{TaskQueue: s.Worker.Options.TaskQueue}, DevWorkflow, - "ignored", + "workflow-param", ) s.NoError(err) @@ -270,6 +271,8 @@ func (s *SharedServerSuite) TestWorkflow_Show_JSON() { out := res.Stdout.String() s.Contains(out, `"events": [`) s.Contains(out, `"eventType": "EVENT_TYPE_WORKFLOW_EXECUTION_STARTED"`) + // Make sure payloads are still encoded non-shorthand + s.Contains(out, base64.StdEncoding.EncodeToString([]byte(`"workflow-param"`))) // Send signals to complete s.NoError(s.Client.SignalWorkflow(s.Context, run.GetID(), "", "my-signal", nil)) diff --git a/temporalcli/commandsmd/commands.md b/temporalcli/commandsmd/commands.md index 89b3178a..4ed36ee5 100644 --- a/temporalcli/commandsmd/commands.md +++ b/temporalcli/commandsmd/commands.md @@ -886,7 +886,8 @@ Use the options listed below to change reset behavior. ### temporal workflow show: Show Event History for a Workflow Execution. The `temporal workflow show` command provides the [Event History](/concepts/what-is-an-event-history) for a -[Workflow Execution](/concepts/what-is-a-workflow-execution). +[Workflow Execution](/concepts/what-is-a-workflow-execution). With JSON output specified, this output can be given to +an SDK to perform a replay. Use the options listed below to change the command's behavior.