(t *testing.T)
| 13 | ) |
| 14 | |
| 15 | func TestIsCompiledUpToDate(t *testing.T) { |
| 16 | tmpDir := t.TempDir() |
| 17 | |
| 18 | // Minimal valid workflow markdown |
| 19 | mdContent := `--- |
| 20 | name: test-workflow |
| 21 | on: |
| 22 | workflow_dispatch: |
| 23 | engine: copilot |
| 24 | --- |
| 25 | |
| 26 | # Test Workflow |
| 27 | |
| 28 | A simple test workflow. |
| 29 | ` |
| 30 | |
| 31 | mdPath := filepath.Join(tmpDir, "test-workflow.md") |
| 32 | require.NoError(t, os.WriteFile(mdPath, []byte(mdContent), 0644), "Should write test workflow") |
| 33 | |
| 34 | // Compute the real frontmatter hash for the test markdown |
| 35 | cache := parser.NewImportCache("") |
| 36 | realHash, err := parser.ComputeFrontmatterHashFromFile(mdPath, cache) |
| 37 | require.NoError(t, err, "Should compute frontmatter hash") |
| 38 | |
| 39 | t.Run("matching hash returns Yes", func(t *testing.T) { |
| 40 | lockPath := filepath.Join(tmpDir, "test-workflow.lock.yml") |
| 41 | lockContent := `# gh-aw-metadata: {"schema_version":"v1","frontmatter_hash":"` + realHash + `"} |
| 42 | name: test-workflow |
| 43 | ` |
| 44 | require.NoError(t, os.WriteFile(lockPath, []byte(lockContent), 0644), "Should write lock file") |
| 45 | |
| 46 | result := isCompiledUpToDate(mdPath, lockPath) |
| 47 | assert.Equal(t, "Yes", result, "Matching hash should return Yes") |
| 48 | }) |
| 49 | |
| 50 | t.Run("mismatched hash returns No", func(t *testing.T) { |
| 51 | lockPath := filepath.Join(tmpDir, "mismatched.lock.yml") |
| 52 | lockContent := `# gh-aw-metadata: {"schema_version":"v1","frontmatter_hash":"0000000000000000000000000000000000000000000000000000000000000000"} |
| 53 | name: test-workflow |
| 54 | ` |
| 55 | require.NoError(t, os.WriteFile(lockPath, []byte(lockContent), 0644), "Should write lock file") |
| 56 | |
| 57 | result := isCompiledUpToDate(mdPath, lockPath) |
| 58 | assert.Equal(t, "No", result, "Mismatched hash should return No") |
| 59 | }) |
| 60 | |
| 61 | t.Run("legacy lock file without hash returns Yes", func(t *testing.T) { |
| 62 | lockPath := filepath.Join(tmpDir, "legacy.lock.yml") |
| 63 | lockContent := `# |
| 64 | # This file was automatically generated by gh-aw. DO NOT EDIT. |
| 65 | # |
| 66 | name: test-workflow |
| 67 | ` |
| 68 | require.NoError(t, os.WriteFile(lockPath, []byte(lockContent), 0644), "Should write legacy lock file") |
| 69 | |
| 70 | result := isCompiledUpToDate(mdPath, lockPath) |
| 71 | assert.Equal(t, "Yes", result, "Legacy lock file without hash should return Yes") |
| 72 | }) |
nothing calls this directly
no test coverage detected