Fix CI regressions and stabilize tests
This commit is contained in:
@@ -15,43 +15,43 @@ func TestDetectExistingHooks(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer os.Chdir(oldDir)
|
||||
|
||||
|
||||
if err := os.Chdir(tmpDir); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
|
||||
// Initialize a git repository
|
||||
gitDir := filepath.Join(tmpDir, ".git")
|
||||
hooksDir := filepath.Join(gitDir, "hooks")
|
||||
if err := os.MkdirAll(hooksDir, 0750); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
setupHook string
|
||||
hookContent string
|
||||
wantExists bool
|
||||
wantIsBdHook bool
|
||||
name string
|
||||
setupHook string
|
||||
hookContent string
|
||||
wantExists bool
|
||||
wantIsBdHook bool
|
||||
wantIsPreCommit bool
|
||||
}{
|
||||
{
|
||||
name: "no hook",
|
||||
setupHook: "",
|
||||
wantExists: false,
|
||||
name: "no hook",
|
||||
setupHook: "",
|
||||
wantExists: false,
|
||||
},
|
||||
{
|
||||
name: "bd hook",
|
||||
setupHook: "pre-commit",
|
||||
hookContent: "#!/bin/sh\n# bd (beads) pre-commit hook\necho test",
|
||||
wantExists: true,
|
||||
name: "bd hook",
|
||||
setupHook: "pre-commit",
|
||||
hookContent: "#!/bin/sh\n# bd (beads) pre-commit hook\necho test",
|
||||
wantExists: true,
|
||||
wantIsBdHook: true,
|
||||
},
|
||||
{
|
||||
name: "pre-commit framework hook",
|
||||
setupHook: "pre-commit",
|
||||
hookContent: "#!/bin/sh\n# pre-commit framework\npre-commit run",
|
||||
wantExists: true,
|
||||
name: "pre-commit framework hook",
|
||||
setupHook: "pre-commit",
|
||||
hookContent: "#!/bin/sh\n# pre-commit framework\npre-commit run",
|
||||
wantExists: true,
|
||||
wantIsPreCommit: true,
|
||||
},
|
||||
{
|
||||
@@ -61,13 +61,13 @@ func TestDetectExistingHooks(t *testing.T) {
|
||||
wantExists: true,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
// Clean up hooks directory
|
||||
os.RemoveAll(hooksDir)
|
||||
os.MkdirAll(hooksDir, 0750)
|
||||
|
||||
|
||||
// Setup hook if needed
|
||||
if tt.setupHook != "" {
|
||||
hookPath := filepath.Join(hooksDir, tt.setupHook)
|
||||
@@ -75,13 +75,10 @@ func TestDetectExistingHooks(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Detect hooks
|
||||
hooks, err := detectExistingHooks()
|
||||
if err != nil {
|
||||
t.Fatalf("detectExistingHooks() error = %v", err)
|
||||
}
|
||||
|
||||
hooks := detectExistingHooks()
|
||||
|
||||
// Find the hook we're testing
|
||||
var found *hookInfo
|
||||
for i := range hooks {
|
||||
@@ -90,11 +87,11 @@ func TestDetectExistingHooks(t *testing.T) {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if found == nil {
|
||||
t.Fatal("pre-commit hook not found in results")
|
||||
}
|
||||
|
||||
|
||||
if found.exists != tt.wantExists {
|
||||
t.Errorf("exists = %v, want %v", found.exists, tt.wantExists)
|
||||
}
|
||||
@@ -116,26 +113,26 @@ func TestInstallGitHooks_NoExistingHooks(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer os.Chdir(oldDir)
|
||||
|
||||
|
||||
if err := os.Chdir(tmpDir); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
|
||||
// Initialize a git repository
|
||||
gitDir := filepath.Join(tmpDir, ".git")
|
||||
hooksDir := filepath.Join(gitDir, "hooks")
|
||||
if err := os.MkdirAll(hooksDir, 0750); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
|
||||
// Note: Can't fully test interactive prompt in automated tests
|
||||
// This test verifies the logic works when no existing hooks present
|
||||
// For full testing, we'd need to mock user input
|
||||
|
||||
|
||||
// Check hooks were created
|
||||
preCommitPath := filepath.Join(hooksDir, "pre-commit")
|
||||
postMergePath := filepath.Join(hooksDir, "post-merge")
|
||||
|
||||
|
||||
if _, err := os.Stat(preCommitPath); err == nil {
|
||||
content, _ := os.ReadFile(preCommitPath)
|
||||
if !strings.Contains(string(content), "bd (beads)") {
|
||||
@@ -145,7 +142,7 @@ func TestInstallGitHooks_NoExistingHooks(t *testing.T) {
|
||||
t.Error("pre-commit hook shouldn't be chained when no existing hooks")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if _, err := os.Stat(postMergePath); err == nil {
|
||||
content, _ := os.ReadFile(postMergePath)
|
||||
if !strings.Contains(string(content), "bd (beads)") {
|
||||
@@ -162,31 +159,28 @@ func TestInstallGitHooks_ExistingHookBackup(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer os.Chdir(oldDir)
|
||||
|
||||
|
||||
if err := os.Chdir(tmpDir); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
|
||||
// Initialize a git repository
|
||||
gitDir := filepath.Join(tmpDir, ".git")
|
||||
hooksDir := filepath.Join(gitDir, "hooks")
|
||||
if err := os.MkdirAll(hooksDir, 0750); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
|
||||
// Create an existing pre-commit hook
|
||||
preCommitPath := filepath.Join(hooksDir, "pre-commit")
|
||||
existingContent := "#!/bin/sh\necho existing hook"
|
||||
if err := os.WriteFile(preCommitPath, []byte(existingContent), 0700); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
|
||||
// Detect that hook exists
|
||||
hooks, err := detectExistingHooks()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
hooks := detectExistingHooks()
|
||||
|
||||
hasExisting := false
|
||||
for _, hook := range hooks {
|
||||
if hook.exists && !hook.isBdHook && hook.name == "pre-commit" {
|
||||
@@ -194,7 +188,7 @@ func TestInstallGitHooks_ExistingHookBackup(t *testing.T) {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if !hasExisting {
|
||||
t.Error("should detect existing non-bd hook")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user