mirror of
https://github.com/chenhg5/cc-connect.git
synced 2026-07-03 12:28:10 +08:00
* feat(daemon): add CC_LOG_MAX_BACKUPS env var support (#1222) PR #1243 only addressed CC_LOG_MAX_SIZE while leaving the backup count hard-wired to one (.log.1). That still loses any post-mortem context older than one rotation, which is the same class of failure users reported on #1222. This change adds the matching knob so the post-mortem trail is configurable, with the same flag > env > default priority used for size. - daemon: add ParseLogBackups(s) (>=1, no unit suffix, error echoes input) and DefaultLogMaxBackups = 3. - daemon: extend RotatingWriter with maxBackups; rotateLocked walks the chain (delete .N, shift .(N-1) -> .N .. .1 -> .2, rename active -> .1, reopen) and a public Rotate() hook for tests/SIGHUP. - daemon: Config/Meta gain LogMaxBackups; Resolve() defaults to 3. - cmd/cc-connect: resolveLogMaxBackups + preScanLogMaxBackupsFlag + --log-max-backups flag; startup log now reports max_backups and its source. The rotating-writer setup happens before flag.Parse so the pre-scan keeps the flag effective there too. - daemon/launchd.go, daemon/systemd.go, daemon/windows.go: thread CC_LOG_MAX_BACKUPS through the service templates so a fresh install picks it up. - tests: TestParseLogBackups (19 subtests + error-echo), three new RotatingWriter tests (chain, disabled, fallback), four resolver tests + pre-scan tests in cmd/cc-connect. TestIssue1222_BackupRetention pins the new env-var behaviour as the regression test for the follow-up to #1222. * fix(daemon): silence errcheck on logrotate_test.go defer Close QA review (run 27109765660) flagged defer w.Close() in the 4 backup-related tests added by #1260. Wrap each in defer func() { _ = w.Close() }() so errcheck is satisfied without changing test semantics (temp-dir cleanup is best-effort). Verified locally: - golangci-lint --new-from-rev origin/main ./daemon/... -> 0 issues - go test -count=1 -tags no_web ./daemon/ ./cmd/cc-connect/ -> ok --------- Co-authored-by: cc-connect dev-claudecode <dev-claudecode@cc-connect.local> Co-authored-by: Claude <noreply@anthropic.com>