MCPcopy Create free account
hub / github.com/github/gh-aw / TestFixCommand_CommandToSlashCommandMigration

Function TestFixCommand_CommandToSlashCommandMigration

pkg/cli/fix_command_test.go:554–621  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

552}
553
554func TestFixCommand_CommandToSlashCommandMigration(t *testing.T) {
555 // Create a temporary directory for test files
556 tmpDir := t.TempDir()
557 workflowFile := filepath.Join(tmpDir, "test-workflow.md")
558
559 // Create a workflow with deprecated on.command field
560 content := `---
561on:
562 command: my-bot
563
564permissions:
565 contents: read
566---
567
568# Test Workflow
569
570This is a test workflow with slash command.
571`
572
573 if err := os.WriteFile(workflowFile, []byte(content), 0644); err != nil {
574 t.Fatalf("Failed to create test file: %v", err)
575 }
576
577 // Get the command migration codemod
578 commandCodemod := getCodemodByID("command-to-slash-command-migration")
579 if commandCodemod == nil {
580 t.Fatal("command-to-slash-command-migration codemod not found")
581 }
582
583 // Process the file
584 fixed, _, err := processWorkflowFileWithInfo(workflowFile, []Codemod{*commandCodemod}, true, false)
585 if err != nil {
586 t.Fatalf("Failed to process workflow file: %v", err)
587 }
588
589 if !fixed {
590 t.Error("Expected file to be fixed, but no changes were made")
591 }
592
593 // Read the updated content
594 updatedContent, err := os.ReadFile(workflowFile)
595 if err != nil {
596 t.Fatalf("Failed to read updated file: %v", err)
597 }
598
599 updatedStr := string(updatedContent)
600
601 // Debug: print the content to see what we got
602 t.Logf("Updated content:\n%s", updatedStr)
603
604 // Verify the change - check for the presence of slash_command
605 if !strings.Contains(updatedStr, "slash_command:") {
606 t.Errorf("Expected slash_command field, got:\n%s", updatedStr)
607 }
608
609 // Check that standalone "command" field was replaced (not part of slash_command)
610 lines := strings.SplitSeq(updatedStr, "\n")
611 for line := range lines {

Callers

nothing calls this directly

Calls 4

getCodemodByIDFunction · 0.85
ErrorMethod · 0.45
ErrorfMethod · 0.45

Tested by

no test coverage detected