refactor(workflow): migrate resolve_test.go to testify assertions#34511
Merged
Conversation
11 tasks
Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Improve test quality of pkg/workflow/resolve_test.go
refactor(workflow): migrate resolve_test.go to testify assertions
May 24, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
Refactors pkg/workflow/resolve_test.go to use testify/assert + testify/require, reducing repetitive boilerplate and standardizing assertion style for workflow resolution tests.
Changes:
- Added
setupWorkflowDirhelper to centralize temp-dir + workflow-dir setup for multiple tests. - Migrated manual
if/t.Fatal/t.Errorfassertions totestifyassertions throughout the file. - Moved the legacy
contains/findSubstringtest helpers into a newhelpers_test.goto keep other tests compiling.
Show a summary per file
| File | Description |
|---|---|
| pkg/workflow/resolve_test.go | Migrates assertions to testify and extracts shared temp workflow-dir setup. |
| pkg/workflow/helpers_test.go | Adds a shared (deprecated) contains helper used by other tests in the package. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comments suppressed due to low confidence (1)
pkg/workflow/resolve_test.go:223
- Using
t.Chdir(projectRoot)changes the process working directory for the remainder of the test (global state). To keep the test hermetic and avoid cross-test interference, consider instead settingGH_AW_WORKFLOWS_DIRto an absolute path (e.g.,filepath.Join(projectRoot, constants.GetWorkflowDir())) and using absolute paths for theos.Statchecks.
t.Chdir(projectRoot)
- Files reviewed: 2/2 changed files
- Comments generated: 3
Comment on lines
+27
to
+33
| // changes the working directory to it, and returns the path to the workflows directory. | ||
| func setupWorkflowDir(t *testing.T) string { | ||
| t.Helper() | ||
| tempDir := testutil.TempDir(t, "test-*") | ||
| workflowsDir := filepath.Join(tempDir, constants.GetWorkflowDir()) | ||
| require.NoError(t, os.MkdirAll(workflowsDir, 0755), "failed to create workflows directory") | ||
| t.Chdir(tempDir) |
Comment on lines
310
to
+314
| t.Setenv("GH_AW_FEATURES", tt.featureValue) | ||
| } | ||
|
|
||
| result := shouldSkipFirewallWorkflow(tt.workflowName) | ||
| if result != tt.shouldSkip { | ||
| t.Errorf("shouldSkipFirewallWorkflow(%q) with GH_AW_FEATURES=%q = %v, expected %v", | ||
| tt.workflowName, tt.featureValue, result, tt.shouldSkip) | ||
| } | ||
| assert.Equal(t, tt.shouldSkip, result, |
Comment on lines
+5
to
+21
| // contains checks if a string contains a substring. | ||
| // Deprecated: prefer strings.Contains or assert.Contains in new tests. | ||
| func contains(s, substr string) bool { | ||
| return len(s) >= len(substr) && (s == substr || len(substr) == 0 || | ||
| (len(s) > len(substr) && s[len(s)-len(substr):] == substr) || | ||
| (len(s) > len(substr) && s[:len(substr)] == substr) || | ||
| (len(s) > len(substr) && findSubstring(s, substr))) | ||
| } | ||
|
|
||
| func findSubstring(s, substr string) bool { | ||
| for i := 0; i <= len(s)-len(substr); i++ { | ||
| if s[i:i+len(substr)] == substr { | ||
| return true | ||
| } | ||
| } | ||
| return false | ||
| } |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
pkg/workflow/resolve_test.gohad zero testify usage — relying entirely on manualif/t.Fatal/t.Errorfpatterns — plus duplicated setup boilerplate across six test functions and a buggy customcontainshelper that reimplementedstrings.Contains.Changes
testify/assertandtestify/requiresetupWorkflowDirhelper: Extracts the repeated temp-dir +MkdirAll+t.Chdirboilerplate into a single helper returning the workflows patht.Fatal(err)→require.NoError(t, err, "...")if err == nil { t.Errorf(...) }→require.Error/assert.Errorif result != expected { t.Errorf(...) }→assert.Equal/assert.ContainsTestResolveWorkflowName_ExistingAgenticWorkflow: Replaceos.Chdir+defer os.Chdirwitht.Chdirhelpers_test.go(new): Relocatescontains/findSubstringout ofresolve_test.go— they're still referenced bystep_order_validation_test.goandstep_order_validation_bug_detection_test.go, so removing them entirely would break the buildBefore / after: