Skip to content

Commit 761e435

Browse files
Add t.Parallel() to safe codemod tests in pkg/cli
Reviewed 25 codemod test files (pkg/cli/codemod_allowed_repos_current_test.go through pkg/cli/codemod_github_app_client_id_test.go) for parallel-safety and added t.Parallel() to top-level tests and table-driven subtests that are demonstrably safe: pure functions operating on local content/frontmatter values, no t.Setenv/os.Setenv/os.Chdir, no shared mutable globals, and t.TempDir()-scoped file I/O only. Validated with go test -race for all modified tests and go test ./pkg/cli/... (pre-existing failures in compile_update_check_test.go and engine_definition_test.go are unrelated sandbox network restrictions, reproduced identically on main before these changes). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 996c9bf commit 761e435

24 files changed

Lines changed: 182 additions & 0 deletions

pkg/cli/codemod_allowed_repos_current_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ import (
1010
)
1111

1212
func TestAllowedReposCurrentToGitHubRepositoryCodemod(t *testing.T) {
13+
t.Parallel()
1314
codemod := getAllowedReposCurrentToGitHubRepositoryCodemod()
1415

1516
t.Run("metadata is populated", func(t *testing.T) {
17+
t.Parallel()
1618
assert.Equal(t, "allowed-repos-current-to-github-repository", codemod.ID)
1719
assert.NotEmpty(t, codemod.Name)
1820
assert.NotEmpty(t, codemod.Description)
@@ -21,6 +23,7 @@ func TestAllowedReposCurrentToGitHubRepositoryCodemod(t *testing.T) {
2123
})
2224

2325
t.Run("rewrites unquoted current value", func(t *testing.T) {
26+
t.Parallel()
2427
content := `---
2528
engine: copilot
2629
tools:
@@ -49,6 +52,7 @@ tools:
4952
})
5053

5154
t.Run("rewrites quoted current value", func(t *testing.T) {
55+
t.Parallel()
5256
content := `---
5357
engine: copilot
5458
tools:
@@ -74,6 +78,7 @@ tools:
7478
})
7579

7680
t.Run("rewrites single-quoted current value", func(t *testing.T) {
81+
t.Parallel()
7782
content := `---
7883
engine: copilot
7984
tools:
@@ -99,6 +104,7 @@ tools:
99104
})
100105

101106
t.Run("no-op when allowed-repos is already an expression", func(t *testing.T) {
107+
t.Parallel()
102108
content := `---
103109
engine: copilot
104110
tools:
@@ -124,6 +130,7 @@ tools:
124130
})
125131

126132
t.Run("no-op when allowed-repos is an array", func(t *testing.T) {
133+
t.Parallel()
127134
content := `---
128135
engine: copilot
129136
tools:
@@ -150,6 +157,7 @@ tools:
150157
})
151158

152159
t.Run("no-op when allowed-repos is set to all", func(t *testing.T) {
160+
t.Parallel()
153161
content := `---
154162
engine: copilot
155163
tools:
@@ -175,6 +183,7 @@ tools:
175183
})
176184

177185
t.Run("preserves trailing comments", func(t *testing.T) {
186+
t.Parallel()
178187
content := `---
179188
engine: copilot
180189
tools:
@@ -200,6 +209,7 @@ tools:
200209
})
201210

202211
t.Run("only treats whitespace-preceded hash as a comment marker", func(t *testing.T) {
212+
t.Parallel()
203213
content := `---
204214
engine: copilot
205215
tools:
@@ -225,6 +235,7 @@ tools:
225235
})
226236

227237
t.Run("does not rewrite nested non-top-level tools github allowed-repos", func(t *testing.T) {
238+
t.Parallel()
228239
content := `---
229240
engine: copilot
230241
wrapper:
@@ -262,6 +273,7 @@ tools:
262273
})
263274

264275
t.Run("does not rewrite nested custom github allowed-repos", func(t *testing.T) {
276+
t.Parallel()
265277
content := `---
266278
engine: copilot
267279
tools:

pkg/cli/codemod_assign_to_agent_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
)
1111

1212
func TestGetAssignToAgentDefaultAgentCodemod(t *testing.T) {
13+
t.Parallel()
1314
codemod := getAssignToAgentDefaultAgentCodemod()
1415

1516
assert.Equal(t, "assign-to-agent-default-agent-to-name", codemod.ID)
@@ -20,6 +21,7 @@ func TestGetAssignToAgentDefaultAgentCodemod(t *testing.T) {
2021
}
2122

2223
func TestAssignToAgentCodemod_BasicMigration(t *testing.T) {
24+
t.Parallel()
2325
codemod := getAssignToAgentDefaultAgentCodemod()
2426

2527
content := `---
@@ -51,6 +53,7 @@ safe-outputs:
5153
}
5254

5355
func TestAssignToAgentCodemod_PreservesIndentation(t *testing.T) {
56+
t.Parallel()
5457
codemod := getAssignToAgentDefaultAgentCodemod()
5558

5659
content := `---
@@ -82,6 +85,7 @@ safe-outputs:
8285
}
8386

8487
func TestAssignToAgentCodemod_PreservesComment(t *testing.T) {
88+
t.Parallel()
8589
codemod := getAssignToAgentDefaultAgentCodemod()
8690

8791
content := `---
@@ -109,6 +113,7 @@ safe-outputs:
109113
}
110114

111115
func TestAssignToAgentCodemod_NoSafeOutputs(t *testing.T) {
116+
t.Parallel()
112117
codemod := getAssignToAgentDefaultAgentCodemod()
113118

114119
content := `---
@@ -131,6 +136,7 @@ engine: copilot
131136
}
132137

133138
func TestAssignToAgentCodemod_NoAssignToAgent(t *testing.T) {
139+
t.Parallel()
134140
codemod := getAssignToAgentDefaultAgentCodemod()
135141

136142
content := `---
@@ -158,6 +164,7 @@ safe-outputs:
158164
}
159165

160166
func TestAssignToAgentCodemod_NoDefaultAgent(t *testing.T) {
167+
t.Parallel()
161168
codemod := getAssignToAgentDefaultAgentCodemod()
162169

163170
content := `---
@@ -185,6 +192,7 @@ safe-outputs:
185192
}
186193

187194
func TestAssignToAgentCodemod_SkipsWhenNameAlreadyExists(t *testing.T) {
195+
t.Parallel()
188196
codemod := getAssignToAgentDefaultAgentCodemod()
189197

190198
content := `---
@@ -214,6 +222,7 @@ safe-outputs:
214222
}
215223

216224
func TestAssignToAgentCodemod_PreservesOtherSafeOutputs(t *testing.T) {
225+
t.Parallel()
217226
codemod := getAssignToAgentDefaultAgentCodemod()
218227

219228
content := `---
@@ -248,6 +257,7 @@ safe-outputs:
248257
}
249258

250259
func TestAssignToAgentCodemod_RegisteredInAllCodemods(t *testing.T) {
260+
t.Parallel()
251261
codemods := GetAllCodemods()
252262
var found bool
253263
for _, c := range codemods {

pkg/cli/codemod_bash_allowlist_unsupported_engine_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
)
1313

1414
func TestBashAllowlistUnsupportedEngineCodemod_Metadata(t *testing.T) {
15+
t.Parallel()
1516
codemod := getBashAllowlistUnsupportedEngineCodemod()
1617

1718
assert.Equal(t, "bash-allowlist-unsupported-engine-guided-error", codemod.ID)
@@ -24,6 +25,7 @@ func TestBashAllowlistUnsupportedEngineCodemod_Metadata(t *testing.T) {
2425
}
2526

2627
func TestBashAllowlistUnsupportedEngineCodemod_Apply(t *testing.T) {
28+
t.Parallel()
2729
codemod := getBashAllowlistUnsupportedEngineCodemod()
2830

2931
content := `---
@@ -150,6 +152,7 @@ tools:
150152

151153
for _, tt := range tests {
152154
t.Run(tt.name, func(t *testing.T) {
155+
t.Parallel()
153156
newContent, applied, err := codemod.Apply(content, tt.frontmatter)
154157
assert.False(t, applied, "guided codemod never modifies the workflow")
155158
assert.Equal(t, content, newContent, "content must be preserved")
@@ -169,6 +172,7 @@ tools:
169172
// ApplyWithContext detects a bash restriction that originates solely from an imported file (not
170173
// the top-level workflow), which Apply cannot detect because it only sees raw frontmatter.
171174
func TestBashAllowlistUnsupportedEngineCodemod_ApplyWithContext_ImportedRestriction(t *testing.T) {
175+
t.Parallel()
172176
codemod := getBashAllowlistUnsupportedEngineCodemod()
173177

174178
dir := t.TempDir()
@@ -210,6 +214,7 @@ imports:
210214
// TestBashAllowlistUnsupportedEngineCodemod_ApplyWithContext_NoImportedRestriction verifies that
211215
// ApplyWithContext is a no-op when no bash restriction exists in the top-level or imported tools.
212216
func TestBashAllowlistUnsupportedEngineCodemod_ApplyWithContext_NoImportedRestriction(t *testing.T) {
217+
t.Parallel()
213218
codemod := getBashAllowlistUnsupportedEngineCodemod()
214219

215220
content := `---

pkg/cli/codemod_bash_anonymous_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
)
1313

1414
func TestBashAnonymousRemovalCodemod(t *testing.T) {
15+
t.Parallel()
1516
codemod := getBashAnonymousRemovalCodemod()
1617

1718
tests := []struct {
@@ -86,6 +87,7 @@ name: Test Workflow
8687

8788
for _, tt := range tests {
8889
t.Run(tt.name, func(t *testing.T) {
90+
t.Parallel()
8991
// Parse frontmatter to get the map
9092
result, err := parser.ExtractFrontmatterFromContent(tt.input)
9193
require.NoError(t, err, "Failed to parse test input frontmatter")
@@ -118,6 +120,7 @@ name: Test Workflow
118120
}
119121

120122
func TestBashAnonymousCodemodWithComments(t *testing.T) {
123+
t.Parallel()
121124
codemod := getBashAnonymousRemovalCodemod()
122125

123126
input := `---
@@ -140,6 +143,7 @@ tools:
140143
}
141144

142145
func TestBashAnonymousCodemodPreservesIndentation(t *testing.T) {
146+
t.Parallel()
143147
codemod := getBashAnonymousRemovalCodemod()
144148

145149
input := `---
@@ -172,6 +176,7 @@ tools:
172176
}
173177

174178
func TestReplaceBashAnonymousWithTrue(t *testing.T) {
179+
t.Parallel()
175180
tests := []struct {
176181
name string
177182
lines []string
@@ -230,6 +235,7 @@ func TestReplaceBashAnonymousWithTrue(t *testing.T) {
230235

231236
for _, tt := range tests {
232237
t.Run(tt.name, func(t *testing.T) {
238+
t.Parallel()
233239
result, modified := replaceBashAnonymousWithTrue(tt.lines)
234240
assert.Equal(t, tt.modified, modified, "Modified status mismatch")
235241
assert.Equal(t, tt.expectLines, result, "Output lines mismatch")

pkg/cli/codemod_bash_single_quoted_args_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
)
1212

1313
func TestGetBashSingleQuotedArgsCodemod(t *testing.T) {
14+
t.Parallel()
1415
codemod := getBashSingleQuotedArgsCodemod()
1516

1617
assert.Equal(t, "bash-single-quoted-args-rewrite", codemod.ID)
@@ -21,6 +22,7 @@ func TestGetBashSingleQuotedArgsCodemod(t *testing.T) {
2122
}
2223

2324
func TestBashSingleQuotedArgsCodemod_RewritesSimpleSingleQuotedArg(t *testing.T) {
25+
t.Parallel()
2426
codemod := getBashSingleQuotedArgsCodemod()
2527
content := `---
2628
name: test
@@ -50,6 +52,7 @@ Test workflow body`
5052
}
5153

5254
func TestBashSingleQuotedArgsCodemod_RewritesGlobPatterns(t *testing.T) {
55+
t.Parallel()
5356
codemod := getBashSingleQuotedArgsCodemod()
5457
content := `---
5558
name: test
@@ -78,6 +81,7 @@ body`
7881
}
7982

8083
func TestBashSingleQuotedArgsCodemod_NoOpForAlreadySafeEntry(t *testing.T) {
84+
t.Parallel()
8185
codemod := getBashSingleQuotedArgsCodemod()
8286
content := `---
8387
name: test
@@ -101,6 +105,7 @@ body`
101105
}
102106

103107
func TestBashSingleQuotedArgsCodemod_UnmatchedQuoteLeftUnchanged(t *testing.T) {
108+
t.Parallel()
104109
codemod := getBashSingleQuotedArgsCodemod()
105110
content := `---
106111
name: test
@@ -124,6 +129,7 @@ body`
124129
}
125130

126131
func TestRewriteSingleQuotedBashArgs(t *testing.T) {
132+
t.Parallel()
127133
tests := []struct {
128134
name string
129135
input string
@@ -184,6 +190,7 @@ func TestRewriteSingleQuotedBashArgs(t *testing.T) {
184190

185191
for _, tt := range tests {
186192
t.Run(tt.name, func(t *testing.T) {
193+
t.Parallel()
187194
got, safe, changed := rewriteSingleQuotedBashArgs(tt.input)
188195
assert.Equal(t, tt.want, got)
189196
assert.Equal(t, tt.wantSafe, safe)

pkg/cli/codemod_bots_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
)
1313

1414
func TestGetBotsToOnBotsCodemod(t *testing.T) {
15+
t.Parallel()
1516
codemod := getBotsToOnBotsCodemod()
1617

1718
assert.Equal(t, "bots-to-on-bots", codemod.ID)
@@ -22,6 +23,7 @@ func TestGetBotsToOnBotsCodemod(t *testing.T) {
2223
}
2324

2425
func TestBotsToOnBotsCodemod_SingleLineArray(t *testing.T) {
26+
t.Parallel()
2527
codemod := getBotsToOnBotsCodemod()
2628

2729
content := `---
@@ -68,6 +70,7 @@ bots: [dependabot, renovate]
6870
}
6971

7072
func TestBotsToOnBotsCodemod_MultiLineArray(t *testing.T) {
73+
t.Parallel()
7174
codemod := getBotsToOnBotsCodemod()
7275

7376
content := `---
@@ -103,6 +106,7 @@ bots:
103106
}
104107

105108
func TestBotsToOnBotsCodemod_NoOnBlock(t *testing.T) {
109+
t.Parallel()
106110
codemod := getBotsToOnBotsCodemod()
107111

108112
content := `---
@@ -130,6 +134,7 @@ engine: copilot
130134
}
131135

132136
func TestBotsToOnBotsCodemod_NoChange_NoBots(t *testing.T) {
137+
t.Parallel()
133138
codemod := getBotsToOnBotsCodemod()
134139

135140
content := `---
@@ -158,6 +163,7 @@ engine: copilot
158163
}
159164

160165
func TestBotsToOnBotsCodemod_NoChange_OnBotsExists(t *testing.T) {
166+
t.Parallel()
161167
codemod := getBotsToOnBotsCodemod()
162168

163169
content := `---

pkg/cli/codemod_byok_copilot_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
)
1212

1313
func TestByokCopilotFeatureRemovalCodemod(t *testing.T) {
14+
t.Parallel()
1415
codemod := getByokCopilotFeatureRemovalCodemod()
1516

1617
tests := []struct {
@@ -56,6 +57,7 @@ features:
5657

5758
for _, tt := range tests {
5859
t.Run(tt.name, func(t *testing.T) {
60+
t.Parallel()
5961
result, err := parser.ExtractFrontmatterFromContent(tt.input)
6062
require.NoError(t, err, "Failed to parse test input frontmatter")
6163

0 commit comments

Comments
 (0)