From 8f3f61c86aa5038d39fed1aeaa519e0ce5334c68 Mon Sep 17 00:00:00 2001 From: Daniel Samson <12231216+daniel-samson@users.noreply.github.com> Date: Wed, 11 Nov 2026 20:46:16 +0000 Subject: [PATCH] test: make liveness and search-path tests portable to macOS std.os.linux.getpid() is a raw Linux syscall (number 39), which maps to a different syscall on macOS, so it returned a bogus pid (or killed the test process with SIGSYS) when the suite ran on a Mac. Use the portable proc.currentPid() in the proc and recovery tests, and make the config search-path test expect the macOS user config dir on macOS. This clears the three pre-existing environment failures so 'zig build test' is green on both macOS and Linux. --- src/config.zig | 6 +++++- src/proc.zig | 2 +- src/recovery.zig | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/config.zig b/src/config.zig index 998768a..f85091d 100644 --- a/src/config.zig +++ b/src/config.zig @@ -563,7 +563,11 @@ test "search paths point at zag.conf" { try env.put("HOME", "/home/dan"); const paths = try searchPaths(arena.allocator(), &env); try std.testing.expectEqualStrings("/etc/zag/zag.conf", paths[0]); - try std.testing.expectEqualStrings("/home/dan/.config/zag/zag.conf", paths[1]); + const user_path = switch (builtin.os.tag) { + .macos => "/home/dan/Library/Application Support/zag/zag.conf", + else => "/home/dan/.config/zag/zag.conf", + }; + try std.testing.expectEqualStrings(user_path, paths[1]); } test "problems reports unknown names, bad types and ranges" { diff --git a/src/proc.zig b/src/proc.zig index 0630e8f..75ee488 100644 --- a/src/proc.zig +++ b/src/proc.zig @@ -185,7 +185,7 @@ test "signalTree kills the whole process group" { } test "isAlive" { - try std.testing.expect(isAlive(std.os.linux.getpid())); + try std.testing.expect(isAlive(currentPid())); try std.testing.expect(!isAlive(-1)); try std.testing.expect(!isAlive(0)); } diff --git a/src/recovery.zig b/src/recovery.zig index f828bb2..88b6540 100644 --- a/src/recovery.zig +++ b/src/recovery.zig @@ -73,7 +73,7 @@ test "stale and orphaned detection" { j.heartbeat = now - 60 * std.time.ns_per_s; try std.testing.expect(isStale(j, now, 30)); try std.testing.expect(isOrphaned(j, now, 30)); // pid does not exist - j.pid = std.os.linux.getpid(); + j.pid = proc.currentPid(); try std.testing.expect(!isOrphaned(j, now, 30)); // alive: stale but not orphaned j.pid = null; try std.testing.expect(isOrphaned(j, now, 30));