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

Function TestWorkflowResolutionWindowsCompatibility

pkg/cli/workflows_path_test.go:138–225  ·  view source on GitHub ↗

TestWorkflowResolutionWindowsCompatibility tests the complete workflow resolution flow This test specifically addresses the issue reported in GitHub where Windows users experienced "workflow not found" errors due to path separator mismatches

(t *testing.T)

Source from the content-addressed store, hash-verified

136// This test specifically addresses the issue reported in GitHub where Windows users
137// experienced "workflow not found" errors due to path separator mismatches
138func TestWorkflowResolutionWindowsCompatibility(t *testing.T) {
139 // Create a temporary directory structure that mimics the user's setup
140 tempDir := testutil.TempDir(t, "test-*")
141 workflowsDir := filepath.Join(tempDir, ".github", "workflows")
142 if err := os.MkdirAll(workflowsDir, 0755); err != nil {
143 t.Fatalf("Failed to create workflows directory: %v", err)
144 }
145
146 // Create workflow files similar to the user's scenario
147 mdFile := filepath.Join(workflowsDir, "update-docs.md")
148 lockFile := filepath.Join(workflowsDir, "update-docs.lock.yml")
149
150 mdContent := []byte(`---
151on:
152 workflow_dispatch:
153permissions:
154 contents: read
155---
156# Update Documentation
157Test workflow for Windows path handling
158`)
159 if err := os.WriteFile(mdFile, mdContent, 0644); err != nil {
160 t.Fatalf("Failed to write markdown file: %v", err)
161 }
162
163 lockContent := []byte("name: update-docs\non:\n workflow_dispatch:\n")
164 if err := os.WriteFile(lockFile, lockContent, 0644); err != nil {
165 t.Fatalf("Failed to write lock file: %v", err)
166 }
167
168 // Change to the temp directory to simulate the user's working directory
169 originalDir, err := os.Getwd()
170 if err != nil {
171 t.Fatalf("Failed to get current directory: %v", err)
172 }
173 defer os.Chdir(originalDir)
174
175 if err := os.Chdir(tempDir); err != nil {
176 t.Fatalf("Failed to change directory: %v", err)
177 }
178
179 // Test 1: Read workflow file using relative path with getWorkflowsDir()
180 // This simulates the exact path used in resolveWorkflowFile
181 content, path, err := readWorkflowFile("update-docs.md", getWorkflowsDir())
182 if err != nil {
183 t.Errorf("Failed to read workflow file with getWorkflowsDir(): %v", err)
184 }
185
186 if string(content) != string(mdContent) {
187 t.Errorf("Content mismatch when reading with getWorkflowsDir()")
188 }
189
190 // Verify the returned path exists
191 if _, err := os.Stat(path); err != nil {
192 t.Errorf("Returned path does not exist: %s (error: %v)", path, err)
193 }
194
195 // Test 2: Verify lock file can be found using the same approach

Callers

nothing calls this directly

Calls 4

TempDirFunction · 0.92
readWorkflowFileFunction · 0.85
getWorkflowsDirFunction · 0.85
ErrorfMethod · 0.45

Tested by

no test coverage detected