Files
beads/cmd/bd/sync_local_only_test.go
Steve Yegge 82902432f5 test: Tag 16 slow integration tests with build tags
Identified and tagged obviously-slow integration tests with
`//go:build integration` to exclude them from default test runs.

This is step 1 of fixing test performance. The real fix is in
bd-1rh: refactoring tests to use shared DB setup instead of
creating 279 separate databases.

Tagged files:
- cmd/bd: 8 files (CLI tests, git ops, performance benchmarks)
- internal: 8 files (integration tests, E2E tests)

Issues:
- bd-1rh: Main issue tracking test performance
- bd-c49: Audit all tests and create grouping plan (next step)
- bd-y6d: POC refactor of create_test.go

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-21 14:40:22 -05:00

137 lines
3.7 KiB
Go

//go:build integration
// +build integration
package main
import (
"context"
"os"
"os/exec"
"path/filepath"
"testing"
)
// TestLocalOnlyMode tests that daemon works with local git repos (no remote)
func TestLocalOnlyMode(t *testing.T) {
if testing.Short() {
t.Skip("Skipping integration test in short mode")
}
// Create temp directory for local-only repo
tempDir := t.TempDir()
// Initialize local git repo without remote
runGitCmd(t, tempDir, "init")
runGitCmd(t, tempDir, "config", "user.email", "test@example.com")
runGitCmd(t, tempDir, "config", "user.name", "Test User")
// Change to temp directory so git commands run in the test repo
oldDir, err := os.Getwd()
if err != nil {
t.Fatalf("Failed to get working dir: %v", err)
}
defer os.Chdir(oldDir)
if err := os.Chdir(tempDir); err != nil {
t.Fatalf("Failed to change to temp dir: %v", err)
}
// Verify no remote exists
cmd := exec.Command("git", "remote")
output, err := cmd.Output()
if err != nil {
t.Fatalf("Failed to check git remotes: %v", err)
}
if len(output) > 0 {
t.Fatalf("Expected no remotes, got: %s", output)
}
ctx := context.Background()
// Test hasGitRemote returns false
if hasGitRemote(ctx) {
t.Error("Expected hasGitRemote to return false for local-only repo")
}
// Test gitPull returns nil (no error)
if err := gitPull(ctx); err != nil {
t.Errorf("gitPull should gracefully skip when no remote, got error: %v", err)
}
// Test gitPush returns nil (no error)
if err := gitPush(ctx); err != nil {
t.Errorf("gitPush should gracefully skip when no remote, got error: %v", err)
}
// Create a dummy JSONL file to commit
beadsDir := filepath.Join(tempDir, ".beads")
if err := os.MkdirAll(beadsDir, 0750); err != nil {
t.Fatalf("Failed to create .beads dir: %v", err)
}
jsonlPath := filepath.Join(beadsDir, "issues.jsonl")
if err := os.WriteFile(jsonlPath, []byte(`{"id":"test-1","title":"Test"}`+"\n"), 0644); err != nil {
t.Fatalf("Failed to write JSONL: %v", err)
}
// Test gitCommit works (local commits should work fine)
runGitCmd(t, tempDir, "add", ".beads")
if err := gitCommit(ctx, jsonlPath, "Test commit"); err != nil {
t.Errorf("gitCommit should work in local-only mode, got error: %v", err)
}
// Verify commit was created
cmd = exec.Command("git", "log", "--oneline")
output, err = cmd.Output()
if err != nil {
t.Fatalf("Failed to check git log: %v", err)
}
if len(output) == 0 {
t.Error("Expected at least one commit in git log")
}
}
// TestWithRemote verifies hasGitRemote detects remotes correctly
func TestWithRemote(t *testing.T) {
if testing.Short() {
t.Skip("Skipping integration test in short mode")
}
// Create temp directories
tempDir := t.TempDir()
remoteDir := filepath.Join(tempDir, "remote")
cloneDir := filepath.Join(tempDir, "clone")
// Create bare remote
if err := os.MkdirAll(remoteDir, 0750); err != nil {
t.Fatalf("Failed to create remote dir: %v", err)
}
runGitCmd(t, remoteDir, "init", "--bare")
// Clone it
runGitCmd(t, tempDir, "clone", remoteDir, cloneDir)
// Change to clone directory
oldDir, err := os.Getwd()
if err != nil {
t.Fatalf("Failed to get working dir: %v", err)
}
defer os.Chdir(oldDir)
if err := os.Chdir(cloneDir); err != nil {
t.Fatalf("Failed to change to clone dir: %v", err)
}
ctx := context.Background()
// Test hasGitRemote returns true
if !hasGitRemote(ctx) {
t.Error("Expected hasGitRemote to return true when origin exists")
}
// Verify git pull doesn't error (even with empty remote)
// Note: pull might fail with "couldn't find remote ref", but that's different
// from the fatal "'origin' does not appear to be a git repository" error
gitPull(ctx) // Just verify it doesn't panic
}