feat(daemon): add auto_pull config parameter for periodic remote sync

Add --auto-pull flag to control whether the daemon periodically pulls from
remote to check for updates from other clones.

Configuration precedence:
1. --auto-pull CLI flag (highest)
2. BEADS_AUTO_PULL environment variable
3. daemon.auto_pull in database config
4. Default: true when sync.branch is configured

When auto_pull is enabled, the daemon creates a remoteSyncTicker that
periodically calls doAutoImport() to pull remote changes. When disabled,
users must manually run 'git pull' to sync remote changes.

Changes:
- cmd/bd/daemon.go: Add --auto-pull flag and config reading logic
- cmd/bd/daemon_event_loop.go: Gate remoteSyncTicker on autoPull parameter
- cmd/bd/daemon_lifecycle.go: Add auto-pull to status output and spawn args
- internal/rpc/protocol.go: Add AutoPull field to StatusResponse
- internal/rpc/server_core.go: Add autoPull to Server struct and SetConfig
- internal/rpc/server_routing_validation_diagnostics.go: Include in status
- Tests updated to pass autoPull parameter

Closes #TBD
This commit is contained in:
Charles P. Cross
2025-12-22 18:47:18 -05:00
parent 82cbd98e50
commit 03f5afb605
9 changed files with 133 additions and 17 deletions

View File

@@ -254,6 +254,68 @@ func TestSyncBranchPull_FetchesRemoteUpdates(t *testing.T) {
t.Log("Sync branch pull correctly fetches remote updates")
}
// =============================================================================
// AUTO-PULL CONFIGURATION TESTS
// =============================================================================
// TestAutoPullGatesRemoteSyncTicker validates that the remoteSyncTicker is only
// created when autoPull is true.
func TestAutoPullGatesRemoteSyncTicker(t *testing.T) {
// Read the daemon_event_loop.go file and check for autoPull gating
content, err := os.ReadFile("daemon_event_loop.go")
if err != nil {
t.Fatalf("Failed to read daemon_event_loop.go: %v", err)
}
code := string(content)
// Check that remoteSyncTicker is gated on autoPull
if !strings.Contains(code, "if autoPull") {
t.Fatal("autoPull check not found - remoteSyncTicker not gated on autoPull")
}
// Check that autoPull parameter exists in function signature
if !strings.Contains(code, "autoPull bool") {
t.Fatal("autoPull bool parameter not found in runEventDrivenLoop signature")
}
// Check for disabled message when autoPull is false
if !strings.Contains(code, "Auto-pull disabled") {
t.Fatal("Auto-pull disabled message not found")
}
t.Log("remoteSyncTicker is correctly gated on autoPull parameter")
}
// TestAutoPullDefaultBehavior validates that auto_pull defaults to true when
// sync.branch is configured.
func TestAutoPullDefaultBehavior(t *testing.T) {
// Read daemon.go and check for default behavior
content, err := os.ReadFile("daemon.go")
if err != nil {
t.Fatalf("Failed to read daemon.go: %v", err)
}
code := string(content)
// Check that auto_pull reads from daemon.auto_pull config
if !strings.Contains(code, "daemon.auto_pull") {
t.Fatal("daemon.auto_pull config check not found")
}
// Check that auto_pull defaults based on sync.branch
if !strings.Contains(code, "sync.branch") {
t.Fatal("sync.branch check for auto_pull default not found")
}
// Check for BEADS_AUTO_PULL environment variable
if !strings.Contains(code, "BEADS_AUTO_PULL") {
t.Fatal("BEADS_AUTO_PULL environment variable not checked")
}
t.Log("auto_pull correctly defaults to true when sync.branch is configured")
}
// =============================================================================
// HELPER FUNCTIONS
// =============================================================================