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

Function TestCleanupOrphanedIncludes

pkg/cli/commands_test.go:573–685  ·  view source on GitHub ↗

TestCleanupOrphanedIncludes tests that root workflow files are not removed as "orphaned" includes

(t *testing.T)

Source from the content-addressed store, hash-verified

571
572// TestCleanupOrphanedIncludes tests that root workflow files are not removed as "orphaned" includes
573func TestCleanupOrphanedIncludes(t *testing.T) {
574 // Create a temporary directory structure
575 tmpDir, err := os.MkdirTemp("", "test-cleanup-orphaned")
576 if err != nil {
577 t.Fatal(err)
578 }
579 defer os.RemoveAll(tmpDir)
580
581 // Create .github/workflows directory
582 workflowsDir := filepath.Join(tmpDir, constants.GetWorkflowDir())
583 if err := os.MkdirAll(workflowsDir, 0755); err != nil {
584 t.Fatal(err)
585 }
586
587 // Create shared subdirectory
588 sharedDir := filepath.Join(workflowsDir, "shared")
589 if err := os.MkdirAll(sharedDir, 0755); err != nil {
590 t.Fatal(err)
591 }
592
593 // Create root workflow files (these should NOT be considered orphaned)
594 rootWorkflows := []string{"daily-plan.md", "weekly-research.md", "action-workflow-assessor.md"}
595 for _, name := range rootWorkflows {
596 content := fmt.Sprintf(`---
597on:
598 workflow_dispatch:
599---
600
601# %s
602
603This is a root workflow.
604`, strings.TrimSuffix(name, ".md"))
605 if err := os.WriteFile(filepath.Join(workflowsDir, name), []byte(content), 0644); err != nil {
606 t.Fatal(err)
607 }
608 }
609
610 // Create include files in shared/ directory (these should be considered orphaned if not used)
611 includeFiles := []string{"shared/common.md", "shared/tools.md"}
612 for _, name := range includeFiles {
613 content := `---
614tools:
615 github:
616 allowed: []
617---
618
619This is an include file.
620`
621 if err := os.WriteFile(filepath.Join(workflowsDir, name), []byte(content), 0644); err != nil {
622 t.Fatal(err)
623 }
624 }
625
626 // Create one root workflow that actually uses an include
627 workflowWithInclude := `---
628on:
629 workflow_dispatch:
630---

Callers

nothing calls this directly

Calls 4

GetWorkflowDirFunction · 0.92
cleanupOrphanedIncludesFunction · 0.85
ErrorfMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected