Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions pkg/cli/codemod_allowed_repos_current_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ import (
)

func TestAllowedReposCurrentToGitHubRepositoryCodemod(t *testing.T) {
t.Parallel()
codemod := getAllowedReposCurrentToGitHubRepositoryCodemod()

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

t.Run("rewrites unquoted current value", func(t *testing.T) {
t.Parallel()
content := `---
engine: copilot
tools:
Expand Down Expand Up @@ -49,6 +52,7 @@ tools:
})

t.Run("rewrites quoted current value", func(t *testing.T) {
t.Parallel()
content := `---
engine: copilot
tools:
Expand All @@ -74,6 +78,7 @@ tools:
})

t.Run("rewrites single-quoted current value", func(t *testing.T) {
t.Parallel()
content := `---
engine: copilot
tools:
Expand All @@ -99,6 +104,7 @@ tools:
})

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

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

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

t.Run("preserves trailing comments", func(t *testing.T) {
t.Parallel()
content := `---
engine: copilot
tools:
Expand All @@ -200,6 +209,7 @@ tools:
})

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

t.Run("does not rewrite nested non-top-level tools github allowed-repos", func(t *testing.T) {
t.Parallel()
content := `---
engine: copilot
wrapper:
Expand Down Expand Up @@ -262,6 +273,7 @@ tools:
})

t.Run("does not rewrite nested custom github allowed-repos", func(t *testing.T) {
t.Parallel()
content := `---
engine: copilot
tools:
Expand Down
10 changes: 10 additions & 0 deletions pkg/cli/codemod_assign_to_agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
)

func TestGetAssignToAgentDefaultAgentCodemod(t *testing.T) {
t.Parallel()
codemod := getAssignToAgentDefaultAgentCodemod()

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

func TestAssignToAgentCodemod_BasicMigration(t *testing.T) {
t.Parallel()
codemod := getAssignToAgentDefaultAgentCodemod()

content := `---
Expand Down Expand Up @@ -51,6 +53,7 @@ safe-outputs:
}

func TestAssignToAgentCodemod_PreservesIndentation(t *testing.T) {
t.Parallel()
codemod := getAssignToAgentDefaultAgentCodemod()

content := `---
Expand Down Expand Up @@ -82,6 +85,7 @@ safe-outputs:
}

func TestAssignToAgentCodemod_PreservesComment(t *testing.T) {
t.Parallel()
codemod := getAssignToAgentDefaultAgentCodemod()

content := `---
Expand Down Expand Up @@ -109,6 +113,7 @@ safe-outputs:
}

func TestAssignToAgentCodemod_NoSafeOutputs(t *testing.T) {
t.Parallel()
codemod := getAssignToAgentDefaultAgentCodemod()

content := `---
Expand All @@ -131,6 +136,7 @@ engine: copilot
}

func TestAssignToAgentCodemod_NoAssignToAgent(t *testing.T) {
t.Parallel()
codemod := getAssignToAgentDefaultAgentCodemod()

content := `---
Expand Down Expand Up @@ -158,6 +164,7 @@ safe-outputs:
}

func TestAssignToAgentCodemod_NoDefaultAgent(t *testing.T) {
t.Parallel()
codemod := getAssignToAgentDefaultAgentCodemod()

content := `---
Expand Down Expand Up @@ -185,6 +192,7 @@ safe-outputs:
}

func TestAssignToAgentCodemod_SkipsWhenNameAlreadyExists(t *testing.T) {
t.Parallel()
codemod := getAssignToAgentDefaultAgentCodemod()

content := `---
Expand Down Expand Up @@ -214,6 +222,7 @@ safe-outputs:
}

func TestAssignToAgentCodemod_PreservesOtherSafeOutputs(t *testing.T) {
t.Parallel()
codemod := getAssignToAgentDefaultAgentCodemod()

content := `---
Expand Down Expand Up @@ -248,6 +257,7 @@ safe-outputs:
}

func TestAssignToAgentCodemod_RegisteredInAllCodemods(t *testing.T) {
t.Parallel()
codemods := GetAllCodemods()
var found bool
for _, c := range codemods {
Expand Down
5 changes: 5 additions & 0 deletions pkg/cli/codemod_bash_allowlist_unsupported_engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
)

func TestBashAllowlistUnsupportedEngineCodemod_Metadata(t *testing.T) {
t.Parallel()
codemod := getBashAllowlistUnsupportedEngineCodemod()

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

func TestBashAllowlistUnsupportedEngineCodemod_Apply(t *testing.T) {
t.Parallel()
codemod := getBashAllowlistUnsupportedEngineCodemod()

content := `---
Expand Down Expand Up @@ -150,6 +152,7 @@ tools:

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

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

content := `---
Expand Down
6 changes: 6 additions & 0 deletions pkg/cli/codemod_bash_anonymous_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
)

func TestBashAnonymousRemovalCodemod(t *testing.T) {
t.Parallel()
codemod := getBashAnonymousRemovalCodemod()

tests := []struct {
Expand Down Expand Up @@ -86,6 +87,7 @@ name: Test Workflow

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

func TestBashAnonymousCodemodWithComments(t *testing.T) {
t.Parallel()
codemod := getBashAnonymousRemovalCodemod()

input := `---
Expand All @@ -140,6 +143,7 @@ tools:
}

func TestBashAnonymousCodemodPreservesIndentation(t *testing.T) {
t.Parallel()
codemod := getBashAnonymousRemovalCodemod()

input := `---
Expand Down Expand Up @@ -172,6 +176,7 @@ tools:
}

func TestReplaceBashAnonymousWithTrue(t *testing.T) {
t.Parallel()
tests := []struct {
name string
lines []string
Expand Down Expand Up @@ -230,6 +235,7 @@ func TestReplaceBashAnonymousWithTrue(t *testing.T) {

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
result, modified := replaceBashAnonymousWithTrue(tt.lines)
assert.Equal(t, tt.modified, modified, "Modified status mismatch")
assert.Equal(t, tt.expectLines, result, "Output lines mismatch")
Expand Down
7 changes: 7 additions & 0 deletions pkg/cli/codemod_bash_single_quoted_args_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
)

func TestGetBashSingleQuotedArgsCodemod(t *testing.T) {
t.Parallel()
codemod := getBashSingleQuotedArgsCodemod()

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

func TestBashSingleQuotedArgsCodemod_RewritesSimpleSingleQuotedArg(t *testing.T) {
t.Parallel()
codemod := getBashSingleQuotedArgsCodemod()
content := `---
name: test
Expand Down Expand Up @@ -50,6 +52,7 @@ Test workflow body`
}

func TestBashSingleQuotedArgsCodemod_RewritesGlobPatterns(t *testing.T) {
t.Parallel()
codemod := getBashSingleQuotedArgsCodemod()
content := `---
name: test
Expand Down Expand Up @@ -78,6 +81,7 @@ body`
}

func TestBashSingleQuotedArgsCodemod_NoOpForAlreadySafeEntry(t *testing.T) {
t.Parallel()
codemod := getBashSingleQuotedArgsCodemod()
content := `---
name: test
Expand All @@ -101,6 +105,7 @@ body`
}

func TestBashSingleQuotedArgsCodemod_UnmatchedQuoteLeftUnchanged(t *testing.T) {
t.Parallel()
codemod := getBashSingleQuotedArgsCodemod()
content := `---
name: test
Expand All @@ -124,6 +129,7 @@ body`
}

func TestRewriteSingleQuotedBashArgs(t *testing.T) {
t.Parallel()
tests := []struct {
name string
input string
Expand Down Expand Up @@ -184,6 +190,7 @@ func TestRewriteSingleQuotedBashArgs(t *testing.T) {

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
got, safe, changed := rewriteSingleQuotedBashArgs(tt.input)
assert.Equal(t, tt.want, got)
assert.Equal(t, tt.wantSafe, safe)
Expand Down
6 changes: 6 additions & 0 deletions pkg/cli/codemod_bots_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
)

func TestGetBotsToOnBotsCodemod(t *testing.T) {
t.Parallel()
codemod := getBotsToOnBotsCodemod()

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

func TestBotsToOnBotsCodemod_SingleLineArray(t *testing.T) {
t.Parallel()
codemod := getBotsToOnBotsCodemod()

content := `---
Expand Down Expand Up @@ -68,6 +70,7 @@ bots: [dependabot, renovate]
}

func TestBotsToOnBotsCodemod_MultiLineArray(t *testing.T) {
t.Parallel()
codemod := getBotsToOnBotsCodemod()

content := `---
Expand Down Expand Up @@ -103,6 +106,7 @@ bots:
}

func TestBotsToOnBotsCodemod_NoOnBlock(t *testing.T) {
t.Parallel()
codemod := getBotsToOnBotsCodemod()

content := `---
Expand Down Expand Up @@ -130,6 +134,7 @@ engine: copilot
}

func TestBotsToOnBotsCodemod_NoChange_NoBots(t *testing.T) {
t.Parallel()
codemod := getBotsToOnBotsCodemod()

content := `---
Expand Down Expand Up @@ -158,6 +163,7 @@ engine: copilot
}

func TestBotsToOnBotsCodemod_NoChange_OnBotsExists(t *testing.T) {
t.Parallel()
codemod := getBotsToOnBotsCodemod()

content := `---
Expand Down
2 changes: 2 additions & 0 deletions pkg/cli/codemod_byok_copilot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
)

func TestByokCopilotFeatureRemovalCodemod(t *testing.T) {
t.Parallel()
codemod := getByokCopilotFeatureRemovalCodemod()

tests := []struct {
Expand Down Expand Up @@ -56,6 +57,7 @@ features:

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

Expand Down
Loading
Loading