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

Function TestRunListWorkflows_CompiledField

pkg/cli/list_workflows_command_test.go:146–210  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

144}
145
146func TestRunListWorkflows_CompiledField(t *testing.T) {
147 tmpDir := t.TempDir()
148
149 // Minimal valid workflow markdown
150 mdContent := `---
151name: test-workflow
152on:
153 workflow_dispatch:
154engine: copilot
155---
156
157# Test Workflow
158
159A simple test workflow.
160`
161 mdPath := filepath.Join(tmpDir, "test-workflow.md")
162 require.NoError(t, os.WriteFile(mdPath, []byte(mdContent), 0644), "Should write test workflow")
163
164 // Compute the real frontmatter hash
165 cache := parser.NewImportCache("")
166 realHash, err := parser.ComputeFrontmatterHashFromFile(mdPath, cache)
167 require.NoError(t, err, "Should compute frontmatter hash")
168
169 t.Run("compiled Yes when hash matches", func(t *testing.T) {
170 lockPath := filepath.Join(tmpDir, "test-workflow.lock.yml")
171 lockContent := `# gh-aw-metadata: {"schema_version":"v1","frontmatter_hash":"` + realHash + `"}
172name: test-workflow
173`
174 require.NoError(t, os.WriteFile(lockPath, []byte(lockContent), 0644), "Should write lock file")
175
176 output := captureListOutput(t, tmpDir, "")
177
178 var items []WorkflowListItem
179 require.NoError(t, json.Unmarshal([]byte(output), &items), "Should unmarshal JSON output")
180 require.Len(t, items, 1, "Should have one workflow")
181 assert.Equal(t, "Yes", items[0].Compiled, "Compiled should be Yes when hash matches")
182 })
183
184 t.Run("compiled No when hash mismatches", func(t *testing.T) {
185 lockPath := filepath.Join(tmpDir, "test-workflow.lock.yml")
186 lockContent := `# gh-aw-metadata: {"schema_version":"v1","frontmatter_hash":"0000000000000000000000000000000000000000000000000000000000000000"}
187name: test-workflow
188`
189 require.NoError(t, os.WriteFile(lockPath, []byte(lockContent), 0644), "Should write lock file with wrong hash")
190
191 output := captureListOutput(t, tmpDir, "")
192
193 var items []WorkflowListItem
194 require.NoError(t, json.Unmarshal([]byte(output), &items), "Should unmarshal JSON output")
195 require.Len(t, items, 1, "Should have one workflow")
196 assert.Equal(t, "No", items[0].Compiled, "Compiled should be No when hash mismatches")
197 })
198
199 t.Run("compiled NA when no lock file", func(t *testing.T) {
200 // Remove lock file
201 _ = os.Remove(filepath.Join(tmpDir, "test-workflow.lock.yml"))
202
203 output := captureListOutput(t, tmpDir, "")

Callers

nothing calls this directly

Calls 4

NewImportCacheFunction · 0.92
captureListOutputFunction · 0.85
RunMethod · 0.45

Tested by

no test coverage detected