* feat(daemon): unify auto-sync config for simpler agent workflows ## Problem Agents running `bd sync` at session end caused delays in the Claude Code "event loop", slowing development. The daemon was already auto-exporting DB→JSONL instantly, but auto-commit and auto-push weren't enabled by default when sync-branch was configured - requiring manual `bd sync`. Additionally, having three separate config options (auto-commit, auto-push, auto-pull) was confusing and could get out of sync. ## Solution Simplify to two intuitive sync modes: 1. **Read/Write Mode** (`daemon.auto-sync: true` or `BEADS_AUTO_SYNC=true`) - Enables auto-commit + auto-push + auto-pull - Full bidirectional sync - eliminates need for manual `bd sync` - Default when sync-branch is configured 2. **Read-Only Mode** (`daemon.auto-pull: true` or `BEADS_AUTO_PULL=true`) - Only receives updates from team - Does NOT auto-publish changes - Useful for experimental work or manual review before sharing ## Benefits - **Faster agent workflows**: No more `bd sync` delays at session end - **Simpler config**: Two modes instead of three separate toggles - **Backward compatible**: Legacy auto_commit/auto_push settings still work (treated as auto-sync=true) - **Adaptive `bd prime`**: Session close protocol adapts when daemon is auto-syncing (shows simplified 4-step git workflow, no `bd sync`) - **Doctor warnings**: `bd doctor` warns about deprecated legacy config ## Changes - cmd/bd/daemon.go: Add loadDaemonAutoSettings() with unified config logic - cmd/bd/doctor.go: Add CheckLegacyDaemonConfig call - cmd/bd/doctor/daemon.go: Add CheckDaemonAutoSync, CheckLegacyDaemonConfig - cmd/bd/init_team.go: Use daemon.auto-sync in team wizard - cmd/bd/prime.go: Detect daemon auto-sync, adapt session close protocol - cmd/bd/prime_test.go: Add stubIsDaemonAutoSyncing for testing * docs: add comprehensive daemon technical analysis Add daemon-summary.md documenting the beads daemon architecture, memory analysis (explaining the 30-35MB footprint), platform support comparison, historical problems and fixes, and architectural guidance for other projects implementing similar daemon patterns. Key sections: - Architecture deep dive with component diagrams - Memory breakdown (SQLite WASM runtime is the main contributor) - Platform support matrix (macOS/Linux full, Windows partial) - Historical bugs and their fixes with reusable patterns - Analysis of daemon usefulness without database (verdict: low value) - Expert-reviewed improvement proposals (3 recommended, 3 skipped) - Technical design patterns for other implementations * feat: add cross-platform CI matrix and dual-mode test framework Cross-Platform CI: - Add Windows, macOS, Linux matrix to catch platform-specific bugs - Linux: full tests with race detector and coverage - macOS: full tests with race detector - Windows: full tests without race detector (performance) - Catches bugs like GH#880 (macOS path casing) and GH#387 (Windows daemon) Dual-Mode Test Framework (cmd/bd/dual_mode_test.go): - Runs tests in both direct mode and daemon mode - Prevents recurring bug pattern (GH#719, GH#751, bd-fu83) - Provides DualModeTestEnv with helper methods for common operations - Includes 5 example tests demonstrating the pattern Documentation: - Add dual-mode testing section to CONTRIBUTING.md - Document RunDualModeTest API and available helpers Test Fixes: - Fix sync_local_only_test.go gitPull/gitPush calls - Add gate_no_daemon_test.go for beads-70c4 investigation * fix(test): isolate TestFindBeadsDir tests with BEADS_DIR env var The tests were finding the real project's .beads directory instead of the temp directory because FindBeadsDir() walks up the directory tree. Using BEADS_DIR env var provides proper test isolation. * fix(test): stop daemon before running test suite guard The test suite guard checks that tests don't modify the real repo's .beads directory. However, a background daemon running auto-sync would touch issues.jsonl during test execution, causing false positives. Changes: - Set BEADS_NO_DAEMON=1 to prevent daemon auto-start from tests - Stop any running daemon for the repo before taking the "before" snapshot - Uses exec to call `bd daemon --stop` to avoid import cycle issues * chore: revert .beads/issues.jsonl to upstream/main Per CONTRIBUTING.md, .beads/issues.jsonl should not be modified in PRs.
121 lines
3.3 KiB
Go
121 lines
3.3 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
|
|
t.Chdir(tempDir)
|
|
|
|
// 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
|
|
t.Chdir(cloneDir)
|
|
|
|
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
|
|
}
|