Repository navigation
Render links on activity describe #1131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,177 @@ | ||
| package temporalcli | ||
|
|
||
| import ( | ||
| "bytes" | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/require" | ||
| "github.com/temporalio/cli/internal/printer" | ||
| activitypb "go.temporal.io/api/activity/v1" | ||
| callbackpb "go.temporal.io/api/callback/v1" | ||
| commonpb "go.temporal.io/api/common/v1" | ||
| enumspb "go.temporal.io/api/enums/v1" | ||
| nexuspb "go.temporal.io/api/nexus/v1" | ||
| "go.temporal.io/api/workflowservice/v1" | ||
| "go.temporal.io/sdk/client" | ||
| ) | ||
|
|
||
| func workflowEventLink() *commonpb.Link { | ||
| return &commonpb.Link{ | ||
| Variant: &commonpb.Link_WorkflowEvent_{ | ||
| WorkflowEvent: &commonpb.Link_WorkflowEvent{ | ||
| Namespace: "ns", | ||
| WorkflowId: "wf-id", | ||
| RunId: "run-id", | ||
| Reference: &commonpb.Link_WorkflowEvent_EventRef{ | ||
| EventRef: &commonpb.Link_WorkflowEvent_EventReference{ | ||
| EventId: 1, | ||
| EventType: enumspb.EVENT_TYPE_WORKFLOW_EXECUTION_STARTED, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| // TestNexusLinkStrings verifies that nexusLinkStrings converts supported common | ||
| // links into their Nexus link URLs and skips variants that have no Nexus | ||
| // equivalent. | ||
| func TestNexusLinkStrings(t *testing.T) { | ||
| activityLink := &commonpb.Link{ | ||
| Variant: &commonpb.Link_Activity_{ | ||
| Activity: &commonpb.Link_Activity{ | ||
| Namespace: "ns", | ||
| ActivityId: "act-id", | ||
| RunId: "run-id", | ||
| }, | ||
| }, | ||
| } | ||
| nexusOperationLink := &commonpb.Link{ | ||
| Variant: &commonpb.Link_NexusOperation_{ | ||
| NexusOperation: &commonpb.Link_NexusOperation{ | ||
| Namespace: "ns", | ||
| OperationId: "op-id", | ||
| RunId: "run-id", | ||
| }, | ||
| }, | ||
| } | ||
| workflowLink := &commonpb.Link{ | ||
| Variant: &commonpb.Link_Workflow_{ | ||
| Workflow: &commonpb.Link_Workflow{ | ||
| Namespace: "ns", | ||
| WorkflowId: "wf-id", | ||
| RunId: "run-id", | ||
| Reason: "started activity", | ||
| }, | ||
| }, | ||
| } | ||
| // A link with an unset (unsupported) variant, which must be skipped. | ||
| otherLink := &commonpb.Link{} | ||
|
|
||
| t.Run("nil and empty", func(t *testing.T) { | ||
| require.Nil(t, nexusLinkStrings(nil)) | ||
| require.Nil(t, nexusLinkStrings([]*commonpb.Link{})) | ||
| }) | ||
|
|
||
| t.Run("workflow event link", func(t *testing.T) { | ||
| got := nexusLinkStrings([]*commonpb.Link{workflowEventLink()}) | ||
| require.Equal(t, []string{ | ||
| "temporal:///namespaces/ns/workflows/wf-id/run-id/history?eventID=1&eventType=WorkflowExecutionStarted&referenceType=EventReference", | ||
| }, got) | ||
| }) | ||
|
|
||
| t.Run("activity and nexus operation links", func(t *testing.T) { | ||
| got := nexusLinkStrings([]*commonpb.Link{activityLink, nexusOperationLink}) | ||
| require.Len(t, got, 2) | ||
| require.Contains(t, got[0], "temporal://") | ||
| require.Contains(t, got[0], "act-id") | ||
| require.Contains(t, got[1], "temporal://") | ||
| require.Contains(t, got[1], "op-id") | ||
| }) | ||
|
|
||
| t.Run("workflow link", func(t *testing.T) { | ||
| got := nexusLinkStrings([]*commonpb.Link{workflowLink}) | ||
| require.Equal(t, []string{ | ||
| "temporal:///namespaces/ns/workflows/wf-id/run-id?reason=started+activity", | ||
| }, got) | ||
| }) | ||
|
|
||
| t.Run("skips unsupported variants and preserves order", func(t *testing.T) { | ||
| got := nexusLinkStrings([]*commonpb.Link{otherLink, workflowEventLink(), otherLink}) | ||
| require.Len(t, got, 1) | ||
| require.Contains(t, got[0], "wf-id") | ||
| }) | ||
| } | ||
|
|
||
| // TestPrintActivityDescription_LinksAndCallbacks verifies that activity describe | ||
| // renders the activity's Nexus links and its callbacks (including callback URL, | ||
| // links, and trigger) like workflow describe does. | ||
| func TestPrintActivityDescription_LinksAndCallbacks(t *testing.T) { | ||
| var buf bytes.Buffer | ||
| cctx := &CommandContext{Printer: &printer.Printer{Output: &buf}} | ||
|
|
||
| resp := &workflowservice.DescribeActivityExecutionResponse{ | ||
| Info: &activitypb.ActivityExecutionInfo{ | ||
| ActivityId: "act-1", | ||
| RunId: "run-1", | ||
| ActivityType: &commonpb.ActivityType{Name: "MyActivity"}, | ||
| Status: enumspb.ACTIVITY_EXECUTION_STATUS_RUNNING, | ||
| TaskQueue: "tq", | ||
| Attempt: 1, | ||
| Links: []*commonpb.Link{workflowEventLink()}, | ||
| }, | ||
| Callbacks: []*activitypb.CallbackInfo{ | ||
| { | ||
| Trigger: &activitypb.CallbackInfo_Trigger{ | ||
| Variant: &activitypb.CallbackInfo_Trigger_ActivityClosed{ | ||
| ActivityClosed: &activitypb.CallbackInfo_ActivityClosed{}, | ||
| }, | ||
| }, | ||
| Info: &callbackpb.CallbackInfo{ | ||
| Callback: &commonpb.Callback{ | ||
| Variant: &commonpb.Callback_Nexus_{ | ||
| Nexus: &commonpb.Callback_Nexus{Url: "http://callback.example/cb"}, | ||
| }, | ||
| Links: []*commonpb.Link{workflowEventLink()}, | ||
| }, | ||
| State: enumspb.CALLBACK_STATE_SUCCEEDED, | ||
| Attempt: 2, | ||
| }, | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| require.NoError(t, printActivityDescription(cctx, resp)) | ||
| out := buf.String() | ||
|
|
||
| // Execution info. | ||
| require.Contains(t, out, "act-1") | ||
| require.Contains(t, out, "MyActivity") | ||
| // Top-level activity Links section. | ||
| require.Contains(t, out, "Links: 1") | ||
| require.Contains(t, out, "temporal:///namespaces/ns/workflows/wf-id/run-id/history") | ||
| // Callbacks section with URL, trigger, link, and state. | ||
| require.Contains(t, out, "Callbacks: 1") | ||
| require.Contains(t, out, "http://callback.example/cb") | ||
| require.Contains(t, out, "ActivityClosed") | ||
| require.Contains(t, out, "Succeeded") | ||
| } | ||
|
|
||
| func TestPrintNexusOperationDescription_Links(t *testing.T) { | ||
| var buf bytes.Buffer | ||
| cctx := &CommandContext{Printer: &printer.Printer{Output: &buf}} | ||
|
|
||
| desc := &client.NexusOperationExecutionDescription{ | ||
| RawInfo: &nexuspb.NexusOperationExecutionInfo{ | ||
| Links: []*commonpb.Link{workflowEventLink()}, | ||
| }, | ||
| } | ||
| desc.OperationID = "op-1" | ||
| desc.OperationRunID = "run-1" | ||
|
|
||
| require.NoError(t, printNexusOperationDescription(cctx, desc)) | ||
| out := buf.String() | ||
| require.Contains(t, out, "op-1") | ||
| require.Contains(t, out, "Links: 1") | ||
| require.Contains(t, out, "temporal:///namespaces/ns/workflows/wf-id/run-id/history") | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't my change, it should be fixed but I think it should be in a separate PR since this will touch a lot of files