From 27ca482b34b30ef3b1ec87dda51f7c65c8b6c373 Mon Sep 17 00:00:00 2001 From: Vernon Stinebaker Date: Tue, 5 May 2026 15:14:58 +0800 Subject: [PATCH] test(service): tighten systemctl status parsing --- src/service.zig | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/service.zig b/src/service.zig index 9d43d32..bf6241d 100644 --- a/src/service.zig +++ b/src/service.zig @@ -384,7 +384,9 @@ fn captureStatusDetail(status: *const CaptureStatus) []const u8 { fn isSystemctlMissingDetail(detail: []const u8) bool { return std.ascii.indexOfIgnoreCase(detail, "command not found") != null or - std.ascii.indexOfIgnoreCase(detail, "not found") != null; + std.ascii.indexOfIgnoreCase(detail, "systemctl: not found") != null or + std.ascii.indexOfIgnoreCase(detail, "systemctl not found") != null or + std.ascii.indexOfIgnoreCase(detail, "systemctl: no such file or directory") != null; } fn isSystemdUnavailableDetail(detail: []const u8) bool { @@ -408,3 +410,17 @@ test "preferredHomebrewShimPath resolves Linux Homebrew Cellar install" { test "preferredHomebrewShimPath ignores non-Cellar paths" { try std.testing.expect((try preferredHomebrewShimPath(std.testing.allocator, "/usr/local/bin/nullhub")) == null); } + +test "isSystemctlMissingDetail matches missing command output" { + try std.testing.expect(isSystemctlMissingDetail("systemctl: command not found")); + try std.testing.expect(isSystemctlMissingDetail("systemctl: not found")); +} + +test "isSystemctlMissingDetail ignores missing unit output" { + try std.testing.expect(!isSystemctlMissingDetail("Unit nullhub.service could not be found.")); +} + +test "isSystemdUnavailableDetail matches user bus errors" { + try std.testing.expect(isSystemdUnavailableDetail("Failed to connect to bus: No medium found")); + try std.testing.expect(isSystemdUnavailableDetail("System has not been booted with systemd as init system (PID 1). Can't operate.")); +}