|
| 1 | +//go:build integration |
| 2 | + |
| 3 | +package workflow |
| 4 | + |
| 5 | +import ( |
| 6 | + "os" |
| 7 | + "path/filepath" |
| 8 | + "strings" |
| 9 | + "testing" |
| 10 | + |
| 11 | + "github.com/github/gh-aw/pkg/testutil" |
| 12 | + "github.com/stretchr/testify/assert" |
| 13 | + "github.com/stretchr/testify/require" |
| 14 | +) |
| 15 | + |
| 16 | +func TestAPMDependenciesCompilationSinglePackage(t *testing.T) { |
| 17 | + tmpDir := testutil.TempDir(t, "apm-deps-single-test") |
| 18 | + |
| 19 | + workflow := `--- |
| 20 | +engine: copilot |
| 21 | +on: workflow_dispatch |
| 22 | +permissions: |
| 23 | + issues: read |
| 24 | + pull-requests: read |
| 25 | +dependencies: |
| 26 | + - microsoft/apm-sample-package |
| 27 | +--- |
| 28 | +
|
| 29 | +Test with a single APM dependency |
| 30 | +` |
| 31 | + |
| 32 | + testFile := filepath.Join(tmpDir, "test-apm-single.md") |
| 33 | + err := os.WriteFile(testFile, []byte(workflow), 0644) |
| 34 | + require.NoError(t, err, "Failed to write test file") |
| 35 | + |
| 36 | + compiler := NewCompiler() |
| 37 | + err = compiler.CompileWorkflow(testFile) |
| 38 | + require.NoError(t, err, "Compilation should succeed") |
| 39 | + |
| 40 | + lockFile := strings.Replace(testFile, ".md", ".lock.yml", 1) |
| 41 | + content, err := os.ReadFile(lockFile) |
| 42 | + require.NoError(t, err, "Failed to read lock file") |
| 43 | + |
| 44 | + lockContent := string(content) |
| 45 | + |
| 46 | + assert.Contains(t, lockContent, "Install APM dependencies", |
| 47 | + "Lock file should contain APM dependencies step name") |
| 48 | + assert.Contains(t, lockContent, "microsoft/apm-action", |
| 49 | + "Lock file should reference the microsoft/apm-action action") |
| 50 | + assert.Contains(t, lockContent, "dependencies: |", |
| 51 | + "Lock file should use block scalar for dependencies input") |
| 52 | + assert.Contains(t, lockContent, "- microsoft/apm-sample-package", |
| 53 | + "Lock file should list the dependency package") |
| 54 | +} |
| 55 | + |
| 56 | +func TestAPMDependenciesCompilationMultiplePackages(t *testing.T) { |
| 57 | + tmpDir := testutil.TempDir(t, "apm-deps-multi-test") |
| 58 | + |
| 59 | + workflow := `--- |
| 60 | +engine: copilot |
| 61 | +on: workflow_dispatch |
| 62 | +permissions: |
| 63 | + issues: read |
| 64 | + pull-requests: read |
| 65 | +dependencies: |
| 66 | + - microsoft/apm-sample-package |
| 67 | + - github/awesome-copilot/skills/review-and-refactor |
| 68 | + - anthropics/skills/skills/frontend-design |
| 69 | +--- |
| 70 | +
|
| 71 | +Test with multiple APM dependencies |
| 72 | +` |
| 73 | + |
| 74 | + testFile := filepath.Join(tmpDir, "test-apm-multi.md") |
| 75 | + err := os.WriteFile(testFile, []byte(workflow), 0644) |
| 76 | + require.NoError(t, err, "Failed to write test file") |
| 77 | + |
| 78 | + compiler := NewCompiler() |
| 79 | + err = compiler.CompileWorkflow(testFile) |
| 80 | + require.NoError(t, err, "Compilation should succeed") |
| 81 | + |
| 82 | + lockFile := strings.Replace(testFile, ".md", ".lock.yml", 1) |
| 83 | + content, err := os.ReadFile(lockFile) |
| 84 | + require.NoError(t, err, "Failed to read lock file") |
| 85 | + |
| 86 | + lockContent := string(content) |
| 87 | + |
| 88 | + assert.Contains(t, lockContent, "Install APM dependencies", |
| 89 | + "Lock file should contain APM dependencies step name") |
| 90 | + assert.Contains(t, lockContent, "microsoft/apm-action", |
| 91 | + "Lock file should reference the microsoft/apm-action action") |
| 92 | + assert.Contains(t, lockContent, "- microsoft/apm-sample-package", |
| 93 | + "Lock file should include first dependency") |
| 94 | + assert.Contains(t, lockContent, "- github/awesome-copilot/skills/review-and-refactor", |
| 95 | + "Lock file should include second dependency") |
| 96 | + assert.Contains(t, lockContent, "- anthropics/skills/skills/frontend-design", |
| 97 | + "Lock file should include third dependency") |
| 98 | +} |
| 99 | + |
| 100 | +func TestAPMDependenciesCompilationNoDependencies(t *testing.T) { |
| 101 | + tmpDir := testutil.TempDir(t, "apm-deps-none-test") |
| 102 | + |
| 103 | + workflow := `--- |
| 104 | +engine: copilot |
| 105 | +on: workflow_dispatch |
| 106 | +permissions: |
| 107 | + issues: read |
| 108 | + pull-requests: read |
| 109 | +--- |
| 110 | +
|
| 111 | +Test without APM dependencies |
| 112 | +` |
| 113 | + |
| 114 | + testFile := filepath.Join(tmpDir, "test-apm-none.md") |
| 115 | + err := os.WriteFile(testFile, []byte(workflow), 0644) |
| 116 | + require.NoError(t, err, "Failed to write test file") |
| 117 | + |
| 118 | + compiler := NewCompiler() |
| 119 | + err = compiler.CompileWorkflow(testFile) |
| 120 | + require.NoError(t, err, "Compilation should succeed") |
| 121 | + |
| 122 | + lockFile := strings.Replace(testFile, ".md", ".lock.yml", 1) |
| 123 | + content, err := os.ReadFile(lockFile) |
| 124 | + require.NoError(t, err, "Failed to read lock file") |
| 125 | + |
| 126 | + lockContent := string(content) |
| 127 | + |
| 128 | + assert.NotContains(t, lockContent, "Install APM dependencies", |
| 129 | + "Lock file should not contain APM dependencies step when no dependencies specified") |
| 130 | + assert.NotContains(t, lockContent, "microsoft/apm-action", |
| 131 | + "Lock file should not reference microsoft/apm-action when no dependencies specified") |
| 132 | +} |
0 commit comments