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

Function TestReadLockFileFromHEAD_GitStates

pkg/workflow/compiler_test.go:1044–1095  ·  view source on GitHub ↗

TestReadLockFileFromHEAD_GitStates verifies readLockFileFromHEAD behavior across multiple repository states.

(t *testing.T)

Source from the content-addressed store, hash-verified

1042// TestReadLockFileFromHEAD_GitStates verifies readLockFileFromHEAD behavior across
1043// multiple repository states.
1044func TestReadLockFileFromHEAD_GitStates(t *testing.T) {
1045 t.Run("missing git root", func(t *testing.T) {
1046 compiler := NewCompiler()
1047 compiler.gitRoot = ""
1048
1049 _, err := compiler.readLockFileFromHEAD(filepath.Join(os.TempDir(), "nonexistent.lock.yml"))
1050 require.Error(t, err, "Missing git root should return an error")
1051 assert.Contains(t, err.Error(), "git root not available", "Error should explain missing git root")
1052 })
1053
1054 t.Run("returns committed content from HEAD", func(t *testing.T) {
1055 repoDir := testutil.TempDir(t, "read-head")
1056 runGitCommand(t, repoDir, "init")
1057 runGitCommand(t, repoDir, "config", "user.email", "test@example.com")
1058 runGitCommand(t, repoDir, "config", "user.name", "Test User")
1059
1060 lockFile := filepath.Join(repoDir, "workflow.lock.yml")
1061 committedContent := "name: committed\n"
1062 require.NoError(t, os.WriteFile(lockFile, []byte(committedContent), 0644), "Failed to write lock file")
1063 runGitCommand(t, repoDir, "add", "workflow.lock.yml")
1064 runGitCommand(t, repoDir, "commit", "-m", "add lock file")
1065
1066 require.NoError(t, os.WriteFile(lockFile, []byte("name: modified\n"), 0644), "Failed to modify lock file")
1067
1068 compiler := NewCompiler()
1069 compiler.gitRoot = repoDir
1070
1071 content, err := compiler.readLockFileFromHEAD(lockFile)
1072 require.NoError(t, err, "Reading committed lock file from HEAD should succeed")
1073 assert.Equal(t, committedContent, content, "HEAD content should be returned instead of working-tree content")
1074 })
1075
1076 t.Run("errors when lock file is absent in HEAD", func(t *testing.T) {
1077 repoDir := testutil.TempDir(t, "read-head-missing")
1078 runGitCommand(t, repoDir, "init")
1079 runGitCommand(t, repoDir, "config", "user.email", "test@example.com")
1080 runGitCommand(t, repoDir, "config", "user.name", "Test User")
1081
1082 readmeFile := filepath.Join(repoDir, "README.md")
1083 require.NoError(t, os.WriteFile(readmeFile, []byte("test\n"), 0644), "Failed to write README")
1084 runGitCommand(t, repoDir, "add", "README.md")
1085 runGitCommand(t, repoDir, "commit", "-m", "initial commit")
1086
1087 compiler := NewCompiler()
1088 compiler.gitRoot = repoDir
1089
1090 lockFile := filepath.Join(repoDir, "workflow.lock.yml")
1091 _, err := compiler.readLockFileFromHEAD(lockFile)
1092 require.Error(t, err, "Reading a non-existent lock file from HEAD should fail")
1093 assert.Contains(t, err.Error(), "not found in HEAD commit", "Error should indicate file is absent in HEAD")
1094 })
1095}

Callers

nothing calls this directly

Calls 6

readLockFileFromHEADMethod · 0.95
TempDirFunction · 0.92
NewCompilerFunction · 0.85
runGitCommandFunction · 0.85
RunMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected