From 3a4c4fa3266ae17c801020f20dcec96eb493d453 Mon Sep 17 00:00:00 2001 From: Daniel Samson <12231216+daniel-samson@users.noreply.github.com> Date: Thu, 12 Nov 2026 10:40:41 +0000 Subject: [PATCH] daemon: flush deprecation warnings into the log at startup The re-exec'd daemon inherits the buffered stderr writer over logs/zag.log from main.zig, so the deprecation warnings printed by Context.loadConfigOnce stayed in the buffer until the process exited and 'zag service logs' showed nothing right after starting with an old config. Flush stderr right after printing the warnings so they reach the log at startup, as the issue requires. e2e now starts the daemon with a config that still carries the deprecated load-level settings and asserts the warnings are in the log while the daemon is running; the settings themselves are ignored, so the effective config is unchanged for the rest of the suite. --- src/cli.zig | 3 +++ test/e2e.sh | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/cli.zig b/src/cli.zig index aeaf547..6133515 100644 --- a/src/cli.zig +++ b/src/cli.zig @@ -78,6 +78,9 @@ pub const Context = struct { for (self.config_deprecations.items) |w| { self.stderr.print("warning: {s}\n", .{w}) catch {}; } + // The daemon's stderr is a buffered writer over logs/zag.log; flush so the + // warnings reach the log at startup, not on process exit. + if (self.config_deprecations.items.len > 0) self.stderr.flush() catch {}; } else |err| { self.config_error = err; } diff --git a/test/e2e.sh b/test/e2e.sh index f938a65..0739361 100755 --- a/test/e2e.sh +++ b/test/e2e.sh @@ -62,9 +62,12 @@ contains "install --show prints files" "zag.conf" "$(Z config install --show)" # --- daemon ----------------------------------------------------------------------------- Z run echo hi >/dev/null 2>&1; [[ $? -eq 1 ]] && pass "run without service exits 1" || fail "run without service exits 1" -contains "service start" "Zag service started" "$(Z service start)" +# The daemon starts with the deprecated config: the removed settings must be ignored +# (effective config is the defaults) and its log must warn about them while it is running. +contains "service start" "Zag service started" "$("$ZAG" --barn-dir "$DIR" --config "$DIR/deprecated.conf" service start 2>&1)" contains "second start refused" "already running" "$(Z service start 2>&1)" contains "service status running" "running" "$(Z service status)" +contains "daemon log warns on deprecated settings at startup" "deprecated" "$(cat "$DIR/logs/zag.log" 2>/dev/null)" out=$(Z run -o json -t svc sh -c 'echo from-daemon') sid=$(json_field id "$out")