ReviewOS

also looking at this

pantry-pm/pantry

fix(services): launch postgres from a script, and find libs where they are

#258
Merged glennmichael123 wants to merge fix/243-systemd-user-unit into main
3 files +189 -29
packages/zig/test/services_test.zigmodified+12-5
Changes to packages/zig/test/services_test.zig
@@ -87,9 +87,13 @@ test "ServiceConfig creation - PostgreSQL" {
8787 try std.testing.expect(pg.keep_alive == true);
8888 try std.testing.expect(pg.auto_start == false);
8989
90 // Start command must contain the port and PGDATA path
91 try std.testing.expect(std.mem.indexOf(u8, pg.start_command, "5432") != null);
90 // Postgres self-initializes, so it launches via a generated start script
91 // (systemd mangles an inline shell command in ExecStart — #243). The port
92 // therefore lives in that script and in health_check, as it does for
93 // mysql and mariadb; the script's own contents are pinned in
94 // definitions.zig.
9295 try std.testing.expect(std.mem.indexOf(u8, pg.start_command, "postgres") != null);
96 try std.testing.expect(std.mem.indexOf(u8, pg.health_check.?, "5432") != null);
9397
9498 // Env vars: PGPORT and PGDATA must be set
9599 try std.testing.expect(pg.env_vars.get("PGPORT") != null);
@@ -107,7 +111,8 @@ test "ServiceConfig creation - PostgreSQL with custom port" {
107111 defer pg.deinit(allocator);
108112
109113 try std.testing.expect(pg.port.? == 9999);
110 try std.testing.expect(std.mem.indexOf(u8, pg.start_command, "9999") != null);
114 // In the generated start script and the health check, not in ExecStart.
115 try std.testing.expect(std.mem.indexOf(u8, pg.health_check.?, "9999") != null);
111116
112117 const pgport = pg.env_vars.get("PGPORT").?;
113118 try std.testing.expectEqualStrings("9999", pgport);
@@ -1641,7 +1646,8 @@ test "PostgreSQL WithContext - null project_root falls back gracefully" {
16411646 try std.testing.expect(pg.port.? == 5432);
16421647 try std.testing.expect(pg.start_command.len > 0);
16431648 const expected_library_var = if (builtin.os.tag == .macos) "DYLD_LIBRARY_PATH" else "LD_LIBRARY_PATH";
1644 try std.testing.expect(std.mem.indexOf(u8, pg.start_command, expected_library_var) != null);
1649 // The library path is set inside the generated start script now, so this
1650 // asserts it where it is still observable from the config.
16451651 try std.testing.expect(std.mem.indexOf(u8, pg.health_check.?, expected_library_var) != null);
16461652 try std.testing.expect(std.mem.indexOf(u8, pg.health_check.?, "pg_isready") != null);
16471653}
@@ -2208,7 +2214,8 @@ test "getServiceConfigWithPort - PostgreSQL with custom port" {
22082214
22092215 try std.testing.expectEqualStrings("postgres", config.name);
22102216 try std.testing.expect(config.port.? == 5433);
2211 try std.testing.expect(std.mem.indexOf(u8, config.start_command, "5433") != null);
2217 // Generated start script, so the port is in the health check (#243).
2218 try std.testing.expect(std.mem.indexOf(u8, config.health_check.?, "5433") != null);
22122219}
22132220
22142221test "getServiceConfigWithPort - MySQL with custom port" {