Files
cc-connect/daemon/launchd_test.go
T
cg33andClaude a456ab3bd4 fix(daemon): macOS launchd do not respawn on clean exit (#153) (#304)
LaunchAgent used KeepAlive=true, so launchd restarted cc-connect after
every process exit, including graceful SIGTERM shutdown. That looked like
"stop then immediate restart" and could make tooling that waits for the
Unix API socket to disappear hang if the service respawned quickly.

Use KeepAlive with SuccessfulExit=true so only unclean exits are restarted,
matching systemd Restart=on-failure behavior.

Existing installs: re-run `cc-connect daemon install --force` to refresh
the plist.

Fixes #153

Made-with: Cursor

Co-authored-by: Claude <noreply@anthropic.com>
2026-03-24 14:15:51 +08:00

27 lines
698 B
Go

//go:build darwin
package daemon
import (
"strings"
"testing"
)
func TestBuildPlist_KeepAliveDoesNotRestartOnCleanExit(t *testing.T) {
cfg := Config{
BinaryPath: "/opt/cc-connect/cc-connect",
WorkDir: "/tmp/wd",
LogFile: "/tmp/log",
LogMaxSize: 10485760,
EnvPATH: "/usr/bin",
}
xml := buildPlist(cfg)
if !strings.Contains(xml, "<key>SuccessfulExit</key>") {
t.Fatal("plist should use KeepAlive dict with SuccessfulExit so exit 0 does not respawn")
}
// Boolean KeepAlive causes launchd to restart after every exit, including SIGTERM shutdown.
if strings.Contains(xml, "<key>KeepAlive</key>\n\t<true/>") {
t.Fatal("plist must not use boolean KeepAlive true")
}
}