From c686f189ba7f5605c7d0a40ce3e6e03919c10b17 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 22 Jan 2026 11:59:13 +0000 Subject: [PATCH 1/2] Initial plan From 004ca1e2a24229126c83d8b0fcce8e218dcded68 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 22 Jan 2026 12:06:23 +0000 Subject: [PATCH 2/2] Add improved test coverage for pkg/workflow/strings_test.go - Added nil slice tests for SortStrings and SortPermissionScopes - Added comprehensive nil options tests for SanitizeName - Added unicode character tests for ShortenCommand - Improved all assertion messages to include test case names for better debugging - All tests passing with proper edge case coverage Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com> --- pkg/workflow/strings_test.go | 89 ++++++++++++++++++++++++++++++++++-- 1 file changed, 84 insertions(+), 5 deletions(-) diff --git a/pkg/workflow/strings_test.go b/pkg/workflow/strings_test.go index 91b11168904..3269d6fdb35 100644 --- a/pkg/workflow/strings_test.go +++ b/pkg/workflow/strings_test.go @@ -52,11 +52,20 @@ func TestSortStrings(t *testing.T) { SortStrings(result) - assert.Equal(t, tt.expected, result, "SortStrings should return correctly sorted slice") + assert.Equal(t, tt.expected, result, "SortStrings failed for test case: %s", tt.name) }) } } +func TestSortStrings_NilSlice(t *testing.T) { + var nilSlice []string + + // Should not panic with nil slice + SortStrings(nilSlice) + + assert.Nil(t, nilSlice, "SortStrings should handle nil slice without panic") +} + func TestSortPermissionScopes(t *testing.T) { tests := []struct { name string @@ -98,11 +107,20 @@ func TestSortPermissionScopes(t *testing.T) { SortPermissionScopes(result) - assert.Equal(t, tt.expected, result, "SortPermissionScopes should return correctly sorted slice") + assert.Equal(t, tt.expected, result, "SortPermissionScopes failed for test case: %s", tt.name) }) } } +func TestSortPermissionScopes_NilSlice(t *testing.T) { + var nilSlice []PermissionScope + + // Should not panic with nil slice + SortPermissionScopes(nilSlice) + + assert.Nil(t, nilSlice, "SortPermissionScopes should handle nil slice without panic") +} + func TestSanitizeWorkflowName(t *testing.T) { tests := []struct { name string @@ -184,7 +202,7 @@ func TestSanitizeWorkflowName(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { result := SanitizeWorkflowName(tt.input) - assert.Equal(t, tt.expected, result, "SanitizeWorkflowName should sanitize input correctly") + assert.Equal(t, tt.expected, result, "SanitizeWorkflowName failed for test case: %s", tt.name) }) } } @@ -235,12 +253,22 @@ func TestShortenCommand(t *testing.T) { input: "\n\n\n", expected: " ", }, + { + name: "unicode characters", + input: "echo 你好世界 αβγ test", + expected: "echo 你好世界 α...", // Truncates at 20 bytes, not 20 characters + }, + { + name: "long unicode string", + input: "αβγδεζηθικλμνξοπρστυφχψω", + expected: "αβγδεζηθικ...", // Truncates at 20 bytes, not 20 characters + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { result := ShortenCommand(tt.input) - assert.Equal(t, tt.expected, result, "ShortenCommand should process input correctly") + assert.Equal(t, tt.expected, result, "ShortenCommand failed for test case: %s", tt.name) }) } } @@ -419,7 +447,58 @@ func TestSanitizeName(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { result := SanitizeName(tt.input, tt.opts) - assert.Equal(t, tt.expected, result, "SanitizeName should sanitize input according to options") + assert.Equal(t, tt.expected, result, "SanitizeName failed for test case: %s", tt.name) + }) + } +} + +func TestSanitizeName_NilOptions(t *testing.T) { + tests := []struct { + name string + input string + expected string + }{ + { + name: "nil options - empty string", + input: "", + expected: "", + }, + { + name: "nil options - only hyphens", + input: "---", + expected: "-", // Multiple hyphens consolidated to single hyphen + }, + { + name: "nil options - leading/trailing hyphens", + input: "-workflow-", + expected: "-workflow-", // Preserved with nil opts (TrimHyphens is false) + }, + { + name: "nil options - underscores replaced", + input: "test_workflow_name", + expected: "test-workflow-name", // Underscores replaced when not in PreserveSpecialChars + }, + { + name: "nil options - dots removed", + input: "workflow.test.name", + expected: "workflowtestname", // Dots removed when PreserveSpecialChars is empty + }, + { + name: "nil options - complex name", + input: "Test_Workflow.Name@123", + expected: "test-workflowname123", // Special chars removed when PreserveSpecialChars is empty + }, + { + name: "nil options - multiple special characters", + input: "workflow@#$%test", + expected: "workflowtest", // Special chars removed when PreserveSpecialChars is empty + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + result := SanitizeName(tt.input, nil) + assert.Equal(t, tt.expected, result, "SanitizeName with nil options failed for test case: %s", tt.name) }) } }