Skip to content

Commit e2e1de2

Browse files
committed
fix(server): include provider paths in minimal launchd environments
1 parent dd7878c commit e2e1de2

2 files changed

Lines changed: 30 additions & 20 deletions

File tree

‎apps/server/src/cloud/bootService.test.ts‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ it.layer(NodeServices.layer)("boot service install", (it) => {
284284
true,
285285
);
286286
expect(yield* fs.readFileString(plan.unitPath)).toContain(
287-
` <key>PATH</key>\n <string>${macInstallerPath}</string>`,
287+
` <key>PATH</key>\n <string>${macInstallerPath}:/usr/local/bin:/usr/sbin:/sbin</string>`,
288288
);
289289
expect(parseServiceState(yield* fs.readFileString(statePath))).toEqual({
290290
protocol: SERVICE_LAUNCHER_PROTOCOL,
@@ -335,6 +335,18 @@ it.layer(NodeServices.layer)("boot service install", (it) => {
335335
}),
336336
);
337337

338+
it.effect("adds missing provider directories to a minimal installer PATH", () =>
339+
Effect.gen(function* () {
340+
const { service, fs } = yield* makeHarness("darwin", false, "/usr/bin:/bin");
341+
const plan = yield* service.install;
342+
343+
expect(yield* fs.readFileString(plan.unitPath)).toContain(
344+
" <key>PATH</key>\n <string>/usr/bin:/bin:/opt/homebrew/bin:/usr/local/bin:/usr/sbin:/sbin</string>",
345+
);
346+
expect((yield* service.status).current).toBe(true);
347+
}),
348+
);
349+
338350
it.effect("keeps an installed launch agent current when the process PATH changes", () =>
339351
Effect.gen(function* () {
340352
const { service, makeService } = yield* makeHarness("darwin");
@@ -356,7 +368,7 @@ it.layer(NodeServices.layer)("boot service install", (it) => {
356368
const plist = yield* fs.readFileString(plan.unitPath);
357369

358370
expect(plist).toContain(
359-
" <key>PATH</key>\n <string>/opt/homebrew/bin:/usr/bin</string>",
371+
" <key>PATH</key>\n <string>/opt/homebrew/bin:/usr/bin:/usr/local/bin:/bin:/usr/sbin:/sbin</string>",
360372
);
361373
expect(plist).not.toContain("\u0001");
362374
expect((yield* service.status).current).toBe(true);

‎apps/server/src/cloud/bootService.ts‎

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -459,28 +459,26 @@ export const make = Effect.fn("cloud.boot_service.make")(function* (input: {
459459
const path = yield* Path.Path;
460460
const runner = yield* ProcessRunner.ProcessRunner;
461461
const host = input.host ?? { execPath: hostExecPath };
462-
const xmlSafeInstallerPath = installerPath
463-
.split(":")
464-
.filter((directory) =>
462+
const xmlSafeInstallerDirectories = installerPath.split(":").filter(
463+
(directory) =>
464+
directory.length > 0 &&
465465
Array.from(directory).every((character) => {
466466
const code = character.charCodeAt(0);
467467
return code >= 0x20 || code === 0x09 || code === 0x0a || code === 0x0d;
468468
}),
469-
)
470-
.join(":");
471-
const environmentPath =
472-
xmlSafeInstallerPath ||
473-
Array.from(
474-
new Set([
475-
path.dirname(host.execPath),
476-
"/opt/homebrew/bin",
477-
"/usr/local/bin",
478-
"/usr/bin",
479-
"/bin",
480-
"/usr/sbin",
481-
"/sbin",
482-
]),
483-
).join(":");
469+
);
470+
const environmentPath = Array.from(
471+
new Set([
472+
...xmlSafeInstallerDirectories,
473+
path.dirname(host.execPath),
474+
"/opt/homebrew/bin",
475+
"/usr/local/bin",
476+
"/usr/bin",
477+
"/bin",
478+
"/usr/sbin",
479+
"/sbin",
480+
]),
481+
).join(":");
484482

485483
const detectedManager = selectBootServiceManager({
486484
platform,

0 commit comments

Comments
 (0)