test: add coverage for GH#807 sync.branch main/master rejection

- Add TestSet cases for main/master rejection in syncbranch_test.go
- Add TestInitWithSyncBranch to verify --branch flag works
- Add TestInitWithoutBranchFlag to verify no auto-detection (root cause)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Steve Yegge
2025-12-30 18:19:53 -08:00
parent a190381de9
commit 202a617bb5
2 changed files with 119 additions and 1 deletions

View File

@@ -3,6 +3,7 @@ package syncbranch
import (
"context"
"os"
"strings"
"testing"
"github.com/steveyegge/beads/internal/storage/sqlite"
@@ -216,12 +217,39 @@ func TestSet(t *testing.T) {
t.Run("rejects invalid branch name", func(t *testing.T) {
store := newTestStore(t)
defer store.Close()
err := Set(ctx, store, "invalid..branch")
if err == nil {
t.Error("Set() expected error for invalid branch name, got nil")
}
})
// GH#807: Verify Set() rejects main/master (not just ValidateSyncBranchName)
t.Run("rejects main as sync branch", func(t *testing.T) {
store := newTestStore(t)
defer store.Close()
err := Set(ctx, store, "main")
if err == nil {
t.Error("Set() expected error for 'main', got nil")
}
if err != nil && !strings.Contains(err.Error(), "cannot use 'main'") {
t.Errorf("Set() error should mention 'cannot use main', got: %v", err)
}
})
t.Run("rejects master as sync branch", func(t *testing.T) {
store := newTestStore(t)
defer store.Close()
err := Set(ctx, store, "master")
if err == nil {
t.Error("Set() expected error for 'master', got nil")
}
if err != nil && !strings.Contains(err.Error(), "cannot use 'master'") {
t.Errorf("Set() error should mention 'cannot use master', got: %v", err)
}
})
}
func TestUnset(t *testing.T) {