-
Notifications
You must be signed in to change notification settings - Fork 132
Remove timeout_minutes from schema and add labels validation #14860
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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,48 @@ | ||||||||||||||||||||||
| package workflow | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| import ( | ||||||||||||||||||||||
| "fmt" | ||||||||||||||||||||||
| "strings" | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| "github.com/github/gh-aw/pkg/logger" | ||||||||||||||||||||||
| ) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| var labelsValidationLog = logger.New("workflow:labels_validation") | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| // validateLabels validates the labels field in the workflow frontmatter. | ||||||||||||||||||||||
| // It checks that: | ||||||||||||||||||||||
| // 1. Labels is an array (if present) | ||||||||||||||||||||||
| // 2. Each label is a non-empty string | ||||||||||||||||||||||
| // 3. Labels don't have leading or trailing whitespace | ||||||||||||||||||||||
|
Comment on lines
+12
to
+16
|
||||||||||||||||||||||
| // validateLabels validates the labels field in the workflow frontmatter. | |
| // It checks that: | |
| // 1. Labels is an array (if present) | |
| // 2. Each label is a non-empty string | |
| // 3. Labels don't have leading or trailing whitespace | |
| // validateLabels validates the labels field parsed from the workflow frontmatter. | |
| // It assumes that ParsedFrontmatter has been successfully populated and that | |
| // Labels is already a []string. It checks that: | |
| // 1. Each label is a non-empty string | |
| // 2. Labels don't have leading or trailing whitespace |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| //go:build !integration | ||
|
|
||
| package workflow | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestValidateLabels(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| labels []string | ||
| shouldErr bool | ||
| errorMsg string | ||
| }{ | ||
| { | ||
| name: "valid labels", | ||
| labels: []string{"automation", "security", "ci"}, | ||
| shouldErr: false, | ||
| }, | ||
| { | ||
| name: "no labels", | ||
| labels: []string{}, | ||
| shouldErr: false, | ||
| }, | ||
| { | ||
| name: "single valid label", | ||
| labels: []string{"docs"}, | ||
| shouldErr: false, | ||
| }, | ||
| { | ||
| name: "empty label", | ||
| labels: []string{"automation", "", "security"}, | ||
| shouldErr: true, | ||
| errorMsg: "labels[1] is empty", | ||
| }, | ||
| { | ||
| name: "label with leading whitespace", | ||
| labels: []string{"automation", " security", "ci"}, | ||
| shouldErr: true, | ||
| errorMsg: "labels[1] has leading or trailing whitespace", | ||
| }, | ||
| { | ||
| name: "label with trailing whitespace", | ||
| labels: []string{"automation", "security ", "ci"}, | ||
| shouldErr: true, | ||
| errorMsg: "labels[1] has leading or trailing whitespace", | ||
| }, | ||
| { | ||
| name: "label with both leading and trailing whitespace", | ||
| labels: []string{" automation "}, | ||
| shouldErr: true, | ||
| errorMsg: "labels[0] has leading or trailing whitespace", | ||
| }, | ||
| { | ||
| name: "whitespace-only label", | ||
| labels: []string{"automation", " ", "security"}, | ||
| shouldErr: true, | ||
| errorMsg: "labels[1] has leading or trailing whitespace", | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| workflowData := &WorkflowData{ | ||
| ParsedFrontmatter: &FrontmatterConfig{ | ||
| Labels: tt.labels, | ||
| }, | ||
| } | ||
|
|
||
| err := validateLabels(workflowData) | ||
|
|
||
| if tt.shouldErr { | ||
| require.Error(t, err, "Expected validation to fail") | ||
| if tt.errorMsg != "" { | ||
| assert.Contains(t, err.Error(), tt.errorMsg, "Error message should contain expected text") | ||
| } | ||
| } else { | ||
| assert.NoError(t, err, "Expected validation to pass") | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestValidateLabels_NilFrontmatter(t *testing.T) { | ||
| // Test with nil ParsedFrontmatter | ||
| workflowData := &WorkflowData{ | ||
| ParsedFrontmatter: nil, | ||
| } | ||
|
|
||
| err := validateLabels(workflowData) | ||
| assert.NoError(t, err, "Should handle nil frontmatter gracefully") | ||
| } | ||
|
Comment on lines
+88
to
+96
|
||
|
|
||
| func TestValidateLabels_NilWorkflowData(t *testing.T) { | ||
| // Test with nil workflowData | ||
| err := validateLabels(nil) | ||
| assert.NoError(t, err, "Should handle nil workflowData gracefully") | ||
| } | ||
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.
validateLabels() relies on workflowData.ParsedFrontmatter, but ParsedFrontmatter is best-effort and is explicitly set to nil when ParseFrontmatterConfig fails (e.g., when
engineuses the object formengine: { id: ... }). That means this new validation will silently no-op for many valid workflows. Consider validating labels from raw frontmatter (e.g., parse workflowData.FrontmatterYAML / keep the original frontmatter map on WorkflowData), or make ParseFrontmatterConfig tolerate the engine object form so ParsedFrontmatter is still populated.