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

Function TestBodyHashStoredInLockMetadata

pkg/workflow/stale_check_test.go:183–224  ·  view source on GitHub ↗

TestBodyHashStoredInLockMetadata verifies that the body hash is computed and stored in the lock metadata when a workflow is compiled.

(t *testing.T)

Source from the content-addressed store, hash-verified

181// TestBodyHashStoredInLockMetadata verifies that the body hash is computed and stored in the
182// lock metadata when a workflow is compiled.
183func TestBodyHashStoredInLockMetadata(t *testing.T) {
184 workflowMD := `---
185engine: copilot
186on:
187 issues:
188 types: [opened]
189---
190This is the body of the workflow. It contains the agent instructions.
191
192## Steps
193
1941. Do something
1952. Do something else
196`
197
198 tmpDir := testutil.TempDir(t, "body-hash-test")
199 workflowPath := filepath.Join(tmpDir, "body-hash.md")
200 require.NoError(t, os.WriteFile(workflowPath, []byte(workflowMD), 0644))
201
202 compiler := NewCompiler()
203 err := compiler.CompileWorkflow(workflowPath)
204 require.NoError(t, err, "Workflow should compile without errors")
205
206 lockPath := stringutil.MarkdownToLockFile(workflowPath)
207 lockContent, err := os.ReadFile(lockPath)
208 require.NoError(t, err, "Lock file should be readable")
209
210 metadata, _, err := ExtractMetadataFromLockFile(string(lockContent))
211 require.NoError(t, err, "Lock metadata should be parseable")
212 require.NotNil(t, metadata, "Lock metadata should exist")
213
214 assert.Equal(t, LockSchemaV4, metadata.SchemaVersion, "Should use v4 schema with body hash")
215 assert.NotEmpty(t, metadata.BodyHash, "Body hash should be stored in lock metadata")
216 assert.Len(t, metadata.BodyHash, 64, "Body hash should be a 64-character hex string")
217
218 // Verify the body hash is recomputable
219 currentBodyHash, err := parser.ComputeBodyHashFromFile(workflowPath)
220 require.NoError(t, err, "Body hash should be recomputable from workflow file")
221
222 assert.Equal(t, currentBodyHash, metadata.BodyHash,
223 "Body hash in lock metadata should match recomputed hash")
224}
225
226// TestBodyHashChangesWhenBodyChanges verifies that modifying the body text produces a different hash.
227func TestBodyHashChangesWhenBodyChanges(t *testing.T) {

Callers

nothing calls this directly

Calls 6

CompileWorkflowMethod · 0.95
TempDirFunction · 0.92
MarkdownToLockFileFunction · 0.92
ComputeBodyHashFromFileFunction · 0.92
NewCompilerFunction · 0.85

Tested by

no test coverage detected