TestCleanupOrphanedIncludes tests that root workflow files are not removed as "orphaned" includes
(t *testing.T)
| 571 | |
| 572 | // TestCleanupOrphanedIncludes tests that root workflow files are not removed as "orphaned" includes |
| 573 | func 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(`--- |
| 597 | on: |
| 598 | workflow_dispatch: |
| 599 | --- |
| 600 | |
| 601 | # %s |
| 602 | |
| 603 | This 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 := `--- |
| 614 | tools: |
| 615 | github: |
| 616 | allowed: [] |
| 617 | --- |
| 618 | |
| 619 | This 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 := `--- |
| 628 | on: |
| 629 | workflow_dispatch: |
| 630 | --- |
nothing calls this directly
no test coverage detected