From 57f433ff714f5c78abe30780c1aa16b23d42c6e8 Mon Sep 17 00:00:00 2001 From: Michael Brooks Date: Wed, 18 Mar 2026 23:00:33 -0700 Subject: [PATCH 1/2] test: increase test coverage for platform activity Add tests for all activity log formatting functions including prettifyActivity event type routing, external auth, function execution, trigger, workflow, and datastore toString helpers. --- internal/pkg/platform/activity_test.go | 485 +++++++++++++++++++++++++ 1 file changed, 485 insertions(+) diff --git a/internal/pkg/platform/activity_test.go b/internal/pkg/platform/activity_test.go index b1a58695..fc05bbc3 100644 --- a/internal/pkg/platform/activity_test.go +++ b/internal/pkg/platform/activity_test.go @@ -384,6 +384,491 @@ func TestPlatformActivity_TriggerExecutedToString(t *testing.T) { } } +func Test_externalAuthMissingFunctionToString(t *testing.T) { + activity := api.Activity{ + Level: types.ERROR, + ComponentID: "comp1", + TraceID: "trace1", + Payload: map[string]interface{}{ + "function_id": "my_func", + }, + Created: 1686939542000000, + } + result := externalAuthMissingFunctionToString(activity) + assert.Contains(t, result, "Step function 'my_func' is missing") + assert.Contains(t, result, "comp1") + assert.Contains(t, result, "Trace=trace1") +} + +func Test_externalAuthMissingSelectedAuthToString(t *testing.T) { + activity := api.Activity{ + Level: types.ERROR, + ComponentID: "comp1", + TraceID: "trace1", + Payload: map[string]interface{}{ + "code": "wf_abc", + }, + Created: 1686939542000000, + } + result := externalAuthMissingSelectedAuthToString(activity) + assert.Contains(t, result, "Missing mapped token for workflow 'wf_abc'") + assert.Contains(t, result, "Trace=trace1") +} + +func Test_externalAuthResultToString(t *testing.T) { + tests := map[string]struct { + activity api.Activity + expectedResults []string + }{ + "completed auth result": { + activity: api.Activity{ + Level: types.INFO, + Payload: map[string]interface{}{ + "user_id": "U123", + "team_id": "T123", + "app_id": "A123", + "provider_key": "google", + }, + }, + expectedResults: []string{"Auth completed", "U123", "T123", "A123", "google"}, + }, + "failed auth result with error details": { + activity: api.Activity{ + Level: types.ERROR, + Payload: map[string]interface{}{ + "user_id": "U123", + "team_id": "T123", + "app_id": "A123", + "provider_key": "google", + "code": "invalid_grant", + "extra_message": "token expired", + }, + }, + expectedResults: []string{"Auth failed", "U123", "invalid_grant", "token expired"}, + }, + } + for name, tc := range tests { + t.Run(name, func(t *testing.T) { + result := externalAuthResultToString(tc.activity) + for _, expected := range tc.expectedResults { + assert.Contains(t, result, expected) + } + }) + } +} + +func Test_externalAuthStartedToString(t *testing.T) { + tests := map[string]struct { + activity api.Activity + expectedResults []string + }{ + "succeeded auth start": { + activity: api.Activity{ + Level: types.INFO, + Payload: map[string]interface{}{ + "user_id": "U123", + "team_id": "T123", + "app_id": "A123", + "provider_key": "google", + }, + }, + expectedResults: []string{"Auth start succeeded", "U123", "T123", "A123", "google"}, + }, + "failed auth start with error code": { + activity: api.Activity{ + Level: types.ERROR, + Payload: map[string]interface{}{ + "user_id": "U123", + "team_id": "T123", + "app_id": "A123", + "provider_key": "google", + "code": "auth_failed", + }, + }, + expectedResults: []string{"Auth start failed", "U123", "auth_failed"}, + }, + } + for name, tc := range tests { + t.Run(name, func(t *testing.T) { + result := externalAuthStartedToString(tc.activity) + for _, expected := range tc.expectedResults { + assert.Contains(t, result, expected) + } + }) + } +} + +func Test_externalAuthTokenFetchResult(t *testing.T) { + tests := map[string]struct { + activity api.Activity + expectedResults []string + }{ + "succeeded token fetch": { + activity: api.Activity{ + Level: types.INFO, + Payload: map[string]interface{}{ + "user_id": "U123", + "team_id": "T123", + "app_id": "A123", + "provider_key": "google", + }, + }, + expectedResults: []string{"Token fetch succeeded", "U123", "T123", "A123", "google"}, + }, + "failed token fetch with error code": { + activity: api.Activity{ + Level: types.ERROR, + Payload: map[string]interface{}{ + "user_id": "U123", + "team_id": "T123", + "app_id": "A123", + "provider_key": "google", + "code": "token_revoked", + }, + }, + expectedResults: []string{"Token fetch failed", "U123", "token_revoked"}, + }, + } + for name, tc := range tests { + t.Run(name, func(t *testing.T) { + result := externalAuthTokenFetchResult(tc.activity) + for _, expected := range tc.expectedResults { + assert.Contains(t, result, expected) + } + }) + } +} + +func Test_functionDeploymentToString(t *testing.T) { + activity := api.Activity{ + Level: types.INFO, + Payload: map[string]interface{}{ + "action": "deploye", + "user_id": "U123", + "team_id": "T123", + }, + Created: 1686939542000000, + } + result := functionDeploymentToString(activity) + assert.Contains(t, result, "Application deployed") + assert.Contains(t, result, "U123") + assert.Contains(t, result, "T123") +} + +func Test_functionExecutionOutputToString(t *testing.T) { + activity := api.Activity{ + Level: types.INFO, + ComponentID: "fn1", + TraceID: "trace1", + Payload: map[string]interface{}{ + "log": "hello world", + }, + Created: 1686939542000000, + } + result := functionExecutionOutputToString(activity) + assert.Contains(t, result, "Function output:") + assert.Contains(t, result, "hello world") + assert.Contains(t, result, "Trace=trace1") +} + +func Test_functionExecutionResultToString(t *testing.T) { + tests := map[string]struct { + activity api.Activity + expectedResults []string + }{ + "completed function execution": { + activity: api.Activity{ + Level: types.INFO, + ComponentID: "fn1", + TraceID: "trace1", + Payload: map[string]interface{}{ + "function_name": "my_function", + "function_type": "custom", + }, + Created: 1686939542000000, + }, + expectedResults: []string{"Function 'my_function' (custom function) completed", "Trace=trace1"}, + }, + "failed function execution with error": { + activity: api.Activity{ + Level: types.ERROR, + ComponentID: "fn1", + TraceID: "trace1", + Payload: map[string]interface{}{ + "function_name": "my_function", + "function_type": "custom", + "error": "something went wrong", + }, + Created: 1686939542000000, + }, + expectedResults: []string{"Function 'my_function' (custom function) failed", "something went wrong"}, + }, + "fatal function execution": { + activity: api.Activity{ + Level: types.FATAL, + Payload: map[string]interface{}{ + "function_name": "my_function", + "function_type": "builtin", + }, + }, + expectedResults: []string{"Function 'my_function' (builtin function) failed"}, + }, + } + for name, tc := range tests { + t.Run(name, func(t *testing.T) { + result := functionExecutionResultToString(tc.activity) + for _, expected := range tc.expectedResults { + assert.Contains(t, result, expected) + } + }) + } +} + +func Test_functionExecutionStartedToString(t *testing.T) { + activity := api.Activity{ + Level: types.INFO, + ComponentID: "fn1", + TraceID: "trace1", + Payload: map[string]interface{}{ + "function_name": "my_function", + "function_type": "custom", + }, + Created: 1686939542000000, + } + result := functionExecutionStartedToString(activity) + assert.Contains(t, result, "Function 'my_function' (custom function) started") + assert.Contains(t, result, "Trace=trace1") +} + +func Test_triggerPayloadReceivedOutputToString(t *testing.T) { + activity := api.Activity{ + Level: types.INFO, + ComponentID: "trigger1", + TraceID: "trace1", + Payload: map[string]interface{}{ + "log": "payload data here", + }, + Created: 1686939542000000, + } + result := triggerPayloadReceivedOutputToString(activity) + assert.Contains(t, result, "Trigger payload:") + assert.Contains(t, result, "payload data here") + assert.Contains(t, result, "Trace=trace1") +} + +func Test_workflowBillingResultToString(t *testing.T) { + tests := map[string]struct { + activity api.Activity + expectedResults []string + }{ + "billing result with workflow name": { + activity: api.Activity{ + Level: types.INFO, + ComponentID: "wf1", + TraceID: "trace1", + Payload: map[string]interface{}{ + "workflow_name": "My Workflow", + "is_billing_result": true, + "billing_reason": "execution", + }, + Created: 1686939542000000, + }, + expectedResults: []string{"Workflow 'My Workflow'", "billing reason 'execution'"}, + }, + "billing result without workflow name": { + activity: api.Activity{ + Level: types.INFO, + Payload: map[string]interface{}{ + "is_billing_result": true, + "billing_reason": "execution", + }, + }, + expectedResults: []string{"Workflow", "billing reason 'execution'"}, + }, + "excluded from billing": { + activity: api.Activity{ + Level: types.INFO, + Payload: map[string]interface{}{ + "workflow_name": "My Workflow", + "is_billing_result": false, + }, + }, + expectedResults: []string{"Workflow 'My Workflow'", "excluded from billing"}, + }, + } + for name, tc := range tests { + t.Run(name, func(t *testing.T) { + result := workflowBillingResultToString(tc.activity) + for _, expected := range tc.expectedResults { + assert.Contains(t, result, expected) + } + }) + } +} + +func Test_workflowBotInvitedToString(t *testing.T) { + activity := api.Activity{ + Level: types.INFO, + ComponentID: "wf1", + TraceID: "trace1", + Payload: map[string]interface{}{ + "channel_id": "C123", + "bot_user_id": "B123", + }, + Created: 1686939542000000, + } + result := workflowBotInvitedToString(activity) + assert.Contains(t, result, "Channel C123 detected") + assert.Contains(t, result, "Bot user B123 automatically invited") +} + +func Test_workflowCreatedFromTemplateToString(t *testing.T) { + activity := api.Activity{ + Level: types.INFO, + ComponentID: "wf1", + TraceID: "trace1", + Payload: map[string]interface{}{ + "workflow_name": "My Workflow", + "template_id": "tmpl_123", + }, + Created: 1686939542000000, + } + result := workflowCreatedFromTemplateToString(activity) + assert.Contains(t, result, "Workflow 'My Workflow' created from template 'tmpl_123'") +} + +func Test_workflowExecutionResultToString(t *testing.T) { + tests := map[string]struct { + activity api.Activity + expectedResults []string + }{ + "completed workflow execution": { + activity: api.Activity{ + Level: types.INFO, + Payload: map[string]interface{}{ + "workflow_name": "My Workflow", + }, + }, + expectedResults: []string{"Workflow 'My Workflow' completed"}, + }, + "failed workflow execution with error": { + activity: api.Activity{ + Level: types.ERROR, + Payload: map[string]interface{}{ + "workflow_name": "My Workflow", + "error": "step failed", + }, + }, + expectedResults: []string{"Workflow 'My Workflow' failed", "step failed"}, + }, + "fatal workflow execution": { + activity: api.Activity{ + Level: types.FATAL, + Payload: map[string]interface{}{ + "workflow_name": "My Workflow", + }, + }, + expectedResults: []string{"Workflow 'My Workflow' failed"}, + }, + } + for name, tc := range tests { + t.Run(name, func(t *testing.T) { + result := workflowExecutionResultToString(tc.activity) + for _, expected := range tc.expectedResults { + assert.Contains(t, result, expected) + } + }) + } +} + +func Test_workflowExecutionStartedToString(t *testing.T) { + activity := api.Activity{ + Level: types.INFO, + Payload: map[string]interface{}{ + "workflow_name": "My Workflow", + }, + } + result := workflowExecutionStartedToString(activity) + assert.Contains(t, result, "Workflow 'My Workflow' started") +} + +func Test_workflowPublishedToString(t *testing.T) { + activity := api.Activity{ + Level: types.INFO, + Payload: map[string]interface{}{ + "workflow_name": "My Workflow", + }, + } + result := workflowPublishedToString(activity) + assert.Contains(t, result, "Workflow 'My Workflow' published") +} + +func Test_workflowStepExecutionResultToString(t *testing.T) { + tests := map[string]struct { + activity api.Activity + expectedResults []string + }{ + "completed step": { + activity: api.Activity{ + Level: types.INFO, + Payload: map[string]interface{}{ + "function_name": "send_message", + }, + }, + expectedResults: []string{"Workflow step 'send_message' completed"}, + }, + "failed step": { + activity: api.Activity{ + Level: types.ERROR, + Payload: map[string]interface{}{ + "function_name": "send_message", + }, + }, + expectedResults: []string{"Workflow step 'send_message' failed"}, + }, + "fatal step": { + activity: api.Activity{ + Level: types.FATAL, + Payload: map[string]interface{}{ + "function_name": "send_message", + }, + }, + expectedResults: []string{"Workflow step 'send_message' failed"}, + }, + } + for name, tc := range tests { + t.Run(name, func(t *testing.T) { + result := workflowStepExecutionResultToString(tc.activity) + for _, expected := range tc.expectedResults { + assert.Contains(t, result, expected) + } + }) + } +} + +func Test_workflowStepStartedToString(t *testing.T) { + activity := api.Activity{ + Level: types.INFO, + Payload: map[string]interface{}{ + "current_step": float64(2), + "total_steps": float64(5), + }, + } + result := workflowStepStartedToString(activity) + assert.Contains(t, result, "Workflow step 2 of 5 started") +} + +func Test_workflowUnpublishedToString(t *testing.T) { + activity := api.Activity{ + Level: types.INFO, + Payload: map[string]interface{}{ + "workflow_name": "My Workflow", + }, + } + result := workflowUnpublishedToString(activity) + assert.Contains(t, result, "Workflow 'My Workflow' unpublished") +} + func Test_datastoreRequestResultToString(t *testing.T) { for name, tc := range map[string]struct { activity api.Activity From c177c35f17b8c9e2235a3032ea86a917f79ced83 Mon Sep 17 00:00:00 2001 From: Michael Brooks Date: Thu, 19 Mar 2026 12:00:40 -0700 Subject: [PATCH 2/2] test: expand slices to multi-line --- internal/pkg/platform/activity_test.go | 73 +++++++++++++++++++++----- 1 file changed, 61 insertions(+), 12 deletions(-) diff --git a/internal/pkg/platform/activity_test.go b/internal/pkg/platform/activity_test.go index fc05bbc3..33ea7dee 100644 --- a/internal/pkg/platform/activity_test.go +++ b/internal/pkg/platform/activity_test.go @@ -430,7 +430,13 @@ func Test_externalAuthResultToString(t *testing.T) { "provider_key": "google", }, }, - expectedResults: []string{"Auth completed", "U123", "T123", "A123", "google"}, + expectedResults: []string{ + "Auth completed", + "U123", + "T123", + "A123", + "google", + }, }, "failed auth result with error details": { activity: api.Activity{ @@ -444,7 +450,12 @@ func Test_externalAuthResultToString(t *testing.T) { "extra_message": "token expired", }, }, - expectedResults: []string{"Auth failed", "U123", "invalid_grant", "token expired"}, + expectedResults: []string{ + "Auth failed", + "U123", + "invalid_grant", + "token expired", + }, }, } for name, tc := range tests { @@ -472,7 +483,13 @@ func Test_externalAuthStartedToString(t *testing.T) { "provider_key": "google", }, }, - expectedResults: []string{"Auth start succeeded", "U123", "T123", "A123", "google"}, + expectedResults: []string{ + "Auth start succeeded", + "U123", + "T123", + "A123", + "google", + }, }, "failed auth start with error code": { activity: api.Activity{ @@ -485,7 +502,11 @@ func Test_externalAuthStartedToString(t *testing.T) { "code": "auth_failed", }, }, - expectedResults: []string{"Auth start failed", "U123", "auth_failed"}, + expectedResults: []string{ + "Auth start failed", + "U123", + "auth_failed", + }, }, } for name, tc := range tests { @@ -513,7 +534,13 @@ func Test_externalAuthTokenFetchResult(t *testing.T) { "provider_key": "google", }, }, - expectedResults: []string{"Token fetch succeeded", "U123", "T123", "A123", "google"}, + expectedResults: []string{ + "Token fetch succeeded", + "U123", + "T123", + "A123", + "google", + }, }, "failed token fetch with error code": { activity: api.Activity{ @@ -526,7 +553,11 @@ func Test_externalAuthTokenFetchResult(t *testing.T) { "code": "token_revoked", }, }, - expectedResults: []string{"Token fetch failed", "U123", "token_revoked"}, + expectedResults: []string{ + "Token fetch failed", + "U123", + "token_revoked", + }, }, } for name, tc := range tests { @@ -587,7 +618,10 @@ func Test_functionExecutionResultToString(t *testing.T) { }, Created: 1686939542000000, }, - expectedResults: []string{"Function 'my_function' (custom function) completed", "Trace=trace1"}, + expectedResults: []string{ + "Function 'my_function' (custom function) completed", + "Trace=trace1", + }, }, "failed function execution with error": { activity: api.Activity{ @@ -601,7 +635,10 @@ func Test_functionExecutionResultToString(t *testing.T) { }, Created: 1686939542000000, }, - expectedResults: []string{"Function 'my_function' (custom function) failed", "something went wrong"}, + expectedResults: []string{ + "Function 'my_function' (custom function) failed", + "something went wrong", + }, }, "fatal function execution": { activity: api.Activity{ @@ -673,7 +710,10 @@ func Test_workflowBillingResultToString(t *testing.T) { }, Created: 1686939542000000, }, - expectedResults: []string{"Workflow 'My Workflow'", "billing reason 'execution'"}, + expectedResults: []string{ + "Workflow 'My Workflow'", + "billing reason 'execution'", + }, }, "billing result without workflow name": { activity: api.Activity{ @@ -683,7 +723,10 @@ func Test_workflowBillingResultToString(t *testing.T) { "billing_reason": "execution", }, }, - expectedResults: []string{"Workflow", "billing reason 'execution'"}, + expectedResults: []string{ + "Workflow", + "billing reason 'execution'", + }, }, "excluded from billing": { activity: api.Activity{ @@ -693,7 +736,10 @@ func Test_workflowBillingResultToString(t *testing.T) { "is_billing_result": false, }, }, - expectedResults: []string{"Workflow 'My Workflow'", "excluded from billing"}, + expectedResults: []string{ + "Workflow 'My Workflow'", + "excluded from billing", + }, }, } for name, tc := range tests { @@ -759,7 +805,10 @@ func Test_workflowExecutionResultToString(t *testing.T) { "error": "step failed", }, }, - expectedResults: []string{"Workflow 'My Workflow' failed", "step failed"}, + expectedResults: []string{ + "Workflow 'My Workflow' failed", + "step failed", + }, }, "fatal workflow execution": { activity: api.Activity{