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
84 changes: 42 additions & 42 deletions pkg/cli/fix_command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -542,12 +542,12 @@ This is a test workflow with slash command.
}

func TestFixCommand_SafeInputsModeRemoval(t *testing.T) {
// Create a temporary directory for test files
tmpDir := t.TempDir()
workflowFile := filepath.Join(tmpDir, "test-workflow.md")
// Create a temporary directory for test files
tmpDir := t.TempDir()
workflowFile := filepath.Join(tmpDir, "test-workflow.md")

// Create a workflow with deprecated safe-inputs.mode field
content := `---
// Create a workflow with deprecated safe-inputs.mode field
content := `---
on: workflow_dispatch
engine: copilot
safe-inputs:
Expand All @@ -563,51 +563,51 @@ safe-inputs:
This is a test workflow with safe-inputs mode field.
`

if err := os.WriteFile(workflowFile, []byte(content), 0644); err != nil {
t.Fatalf("Failed to create test file: %v", err)
}
if err := os.WriteFile(workflowFile, []byte(content), 0644); err != nil {
t.Fatalf("Failed to create test file: %v", err)
}

// Get the safe-inputs mode removal codemod
modeCodemod := getCodemodByID("safe-inputs-mode-removal")
if modeCodemod == nil {
t.Fatal("safe-inputs-mode-removal codemod not found")
}
// Get the safe-inputs mode removal codemod
modeCodemod := getCodemodByID("safe-inputs-mode-removal")
if modeCodemod == nil {
t.Fatal("safe-inputs-mode-removal codemod not found")
}

// Process the file
fixed, err := processWorkflowFile(workflowFile, []Codemod{*modeCodemod}, true, false)
if err != nil {
t.Fatalf("Failed to process workflow file: %v", err)
}
// Process the file
fixed, err := processWorkflowFile(workflowFile, []Codemod{*modeCodemod}, true, false)
if err != nil {
t.Fatalf("Failed to process workflow file: %v", err)
}

if !fixed {
t.Error("Expected file to be fixed, but no changes were made")
}
if !fixed {
t.Error("Expected file to be fixed, but no changes were made")
}

// Read the updated content
updatedContent, err := os.ReadFile(workflowFile)
if err != nil {
t.Fatalf("Failed to read updated file: %v", err)
}
// Read the updated content
updatedContent, err := os.ReadFile(workflowFile)
if err != nil {
t.Fatalf("Failed to read updated file: %v", err)
}

updatedStr := string(updatedContent)
updatedStr := string(updatedContent)

t.Logf("Updated content:\n%s", updatedStr)
t.Logf("Updated content:\n%s", updatedStr)

// Verify the change - mode field should be removed
if strings.Contains(updatedStr, "mode:") {
t.Errorf("Expected mode field to be removed, but it still exists:\n%s", updatedStr)
}
// Verify the change - mode field should be removed
if strings.Contains(updatedStr, "mode:") {
t.Errorf("Expected mode field to be removed, but it still exists:\n%s", updatedStr)
}

// Verify safe-inputs block and test-tool are preserved
if !strings.Contains(updatedStr, "safe-inputs:") {
t.Error("Expected safe-inputs block to be preserved")
}
// Verify safe-inputs block and test-tool are preserved
if !strings.Contains(updatedStr, "safe-inputs:") {
t.Error("Expected safe-inputs block to be preserved")
}

if !strings.Contains(updatedStr, "test-tool:") {
t.Error("Expected test-tool to be preserved")
}
if !strings.Contains(updatedStr, "test-tool:") {
t.Error("Expected test-tool to be preserved")
}

if !strings.Contains(updatedStr, "description: Test tool") {
t.Error("Expected test-tool description to be preserved")
}
if !strings.Contains(updatedStr, "description: Test tool") {
t.Error("Expected test-tool description to be preserved")
}
}
Loading
Loading