























@@ -111,36 +111,21 @@ describe("getMinimalServicePathParts - Linux user directories", () => {
111111expect(result).toContain("/opt/fnm/current/bin");
112112});
113113114-it("includes version manager directories on macOS when HOME is set", () => {
114+it("uses only canonical system directories on macOS by default", () => {
115115const result = getMinimalServicePathParts({
116116platform: "darwin",
117117home: "/Users/testuser",
118118existsSync: allExist,
119119});
120120121-// Should include common user bin directories
122-expect(result).toContain("/Users/testuser/.local/bin");
123-expect(result).toContain("/Users/testuser/.npm-global/bin");
124-expect(result).toContain("/Users/testuser/bin");
125-126-// Should include version manager paths (macOS specific)
127-// Note: nvm has no stable default path, relies on user's shell config
128-expect(result).toContain("/Users/testuser/Library/Application Support/fnm/aliases/default/bin"); // fnm default on macOS
129-expect(result).toContain("/Users/testuser/.fnm/aliases/default/bin"); // fnm if customized to ~/.fnm
130-expect(result).toContain("/Users/testuser/.volta/bin");
131-expect(result).toContain("/Users/testuser/.asdf/shims");
132-expect(result).toContain("/Users/testuser/Library/pnpm"); // pnpm default on macOS
133-expect(result).toContain("/Users/testuser/.local/share/pnpm"); // pnpm XDG fallback
134-expect(result).toContain("/Users/testuser/.bun/bin");
135-136-// Should also include macOS system directories
137-expect(result).toContain("/opt/homebrew/bin");
138-expect(result).toContain("/usr/local/bin");
121+expect(result).toEqual(["/usr/local/bin", "/usr/bin", "/bin", "/usr/sbin", "/sbin"]);
122+expect(result.some((entry) => entry.startsWith("/Users/testuser/"))).toBe(false);
139123});
140124141-it("includes env-configured version manager dirs on macOS", () => {
125+it("can include env-configured version manager dirs on macOS when requested", () => {
142126const result = getMinimalServicePathPartsFromEnv({
143127platform: "darwin",
128+includeUserDirs: true,
144129env: {
145130HOME: "/Users/testuser",
146131FNM_DIR: "/Users/testuser/Library/Application Support/fnm",
@@ -158,22 +143,18 @@ describe("getMinimalServicePathParts - Linux user directories", () => {
158143expect(result).toContain("/Users/testuser/Library/pnpm");
159144});
160145161-it("places version manager dirs before system dirs on macOS", () => {
146+it("does not let version manager dirs precede system dirs on macOS by default", () => {
162147const result = getMinimalServicePathParts({
163148platform: "darwin",
164149home: "/Users/testuser",
165150existsSync: allExist,
166151});
167152168-// fnm on macOS defaults to ~/Library/Application Support/fnm
169-const fnmIndex = result.indexOf(
170-"/Users/testuser/Library/Application Support/fnm/aliases/default/bin",
171-);
172-const homebrewIndex = result.indexOf("/opt/homebrew/bin");
153+const fnmIndex = result.indexOf("/Users/testuser/.fnm/aliases/default/bin");
154+const systemIndex = result.indexOf("/usr/local/bin");
173155174-expect(fnmIndex).toBeGreaterThan(-1);
175-expect(homebrewIndex).toBeGreaterThan(-1);
176-expect(fnmIndex).toBeLessThan(homebrewIndex);
156+expect(fnmIndex).toBe(-1);
157+expect(systemIndex).toBe(0);
177158});
178159179160it("does not include Linux user directories on Windows", () => {
@@ -209,17 +190,18 @@ describe("getMinimalServicePathParts - Linux user directories", () => {
209190expect(result).not.toContain("/home/testuser/.local/share/pnpm");
210191});
211192212-it("omits hard-coded version-manager fallbacks on macOS when missing", () => {
193+it("omits all user PATH fallbacks on macOS even when HOME is set", () => {
213194const result = getMinimalServicePathParts({
214195platform: "darwin",
215196home: "/Users/testuser",
216197existsSync: noneExist,
217198});
218199219-expect(result).toContain("/Users/testuser/.local/bin");
220-expect(result).toContain("/Users/testuser/.npm-global/bin");
221-expect(result).toContain("/Users/testuser/bin");
222-expect(result).toContain("/Users/testuser/.nix-profile/bin");
200+expect(result).toEqual(["/usr/local/bin", "/usr/bin", "/bin", "/usr/sbin", "/sbin"]);
201+expect(result).not.toContain("/Users/testuser/.local/bin");
202+expect(result).not.toContain("/Users/testuser/.npm-global/bin");
203+expect(result).not.toContain("/Users/testuser/bin");
204+expect(result).not.toContain("/Users/testuser/.nix-profile/bin");
223205expect(result).not.toContain("/Users/testuser/.volta/bin");
224206expect(result).not.toContain("/Users/testuser/.asdf/shims");
225207expect(result).not.toContain("/Users/testuser/.bun/bin");
@@ -233,16 +215,16 @@ describe("getMinimalServicePathParts - Linux user directories", () => {
233215234216it("can omit missing stable user-bin defaults for service PATH audits", () => {
235217const result = getMinimalServicePathPartsFromEnv({
236-platform: "darwin",
237-env: { HOME: "/Users/testuser" },
238-existsSync: (candidate) => candidate === "/Users/testuser/.local/bin",
218+platform: "linux",
219+env: { HOME: "/home/testuser" },
220+existsSync: (candidate) => candidate === "/home/testuser/.local/bin",
239221includeMissingUserBinDefaults: false,
240222});
241223242-expect(result).toContain("/Users/testuser/.local/bin");
243-expect(result).not.toContain("/Users/testuser/.npm-global/bin");
244-expect(result).not.toContain("/Users/testuser/bin");
245-expect(result).not.toContain("/Users/testuser/.nix-profile/bin");
224+expect(result).toContain("/home/testuser/.local/bin");
225+expect(result).not.toContain("/home/testuser/.npm-global/bin");
226+expect(result).not.toContain("/home/testuser/bin");
227+expect(result).not.toContain("/home/testuser/.nix-profile/bin");
246228});
247229248230it("keeps env-configured roots when fallback directories are missing", () => {
@@ -371,14 +353,15 @@ describe("getMinimalServicePathParts - Nix Home Manager", () => {
371353expect(result).toContain("/home/testuser/.nix-profile/bin");
372354});
373355374-it("falls back to default Nix profile when NIX_PROFILES is absent on macOS", () => {
356+it("omits the default Nix profile from macOS service PATH by default", () => {
375357const result = getMinimalServicePathParts({
376358platform: "darwin",
377359home: "/Users/testuser",
378360existsSync: () => true,
379361});
380362381-expect(result).toContain("/Users/testuser/.nix-profile/bin");
363+expect(result).not.toContain("/Users/testuser/.nix-profile/bin");
364+expect(result).toEqual(["/usr/local/bin", "/usr/bin", "/bin", "/usr/sbin", "/sbin"]);
382365});
383366384367it("places rightmost NIX_PROFILES entry before leftmost on Linux", () => {
@@ -398,7 +381,7 @@ describe("getMinimalServicePathParts - Nix Home Manager", () => {
398381expect(userIdx).toBeLessThan(defaultIdx);
399382});
400383401-it("places rightmost NIX_PROFILES entry before leftmost on macOS", () => {
384+it("ignores NIX_PROFILES on macOS service PATH by default", () => {
402385const result = getMinimalServicePathPartsFromEnv({
403386platform: "darwin",
404387env: {
@@ -410,9 +393,9 @@ describe("getMinimalServicePathParts - Nix Home Manager", () => {
410393411394const userIdx = result.indexOf("/Users/testuser/.nix-profile/bin");
412395const defaultIdx = result.indexOf("/nix/var/nix/profiles/default/bin");
413-expect(userIdx).toBeGreaterThan(-1);
414-expect(defaultIdx).toBeGreaterThan(-1);
415-expect(userIdx).toBeLessThan(defaultIdx);
396+expect(userIdx).toBe(-1);
397+expect(defaultIdx).toBe(-1);
398+expect(result).toEqual(["/usr/local/bin", "/usr/bin", "/bin", "/usr/sbin", "/sbin"]);
416399});
417400418401it("includes single Nix profile from NIX_PROFILES on Linux", () => {
@@ -428,9 +411,10 @@ describe("getMinimalServicePathParts - Nix Home Manager", () => {
428411expect(result).toContain("/nix/var/nix/profiles/per-user/testuser/profile/bin");
429412});
430413431-it("includes single Nix profile from NIX_PROFILES on macOS", () => {
414+it("can include single Nix profile from NIX_PROFILES on macOS when requested", () => {
432415const result = getMinimalServicePathPartsFromEnv({
433416platform: "darwin",
417+includeUserDirs: true,
434418env: {
435419HOME: "/Users/testuser",
436420NIX_PROFILES: "/nix/var/nix/profiles/per-user/testuser/profile",
@@ -467,15 +451,12 @@ describe("buildMinimalServicePath", () => {
467451const splitPath = (value: string, platform: NodeJS.Platform) =>
468452value.split(platform === "win32" ? path.win32.delimiter : path.posix.delimiter);
469453470-it("includes Homebrew + system dirs on macOS", () => {
454+it("uses canonical launchd system dirs on macOS", () => {
471455const result = buildMinimalServicePath({
472456platform: "darwin",
473457});
474458const parts = splitPath(result, "darwin");
475-expect(parts).toContain("/opt/homebrew/bin");
476-expect(parts).toContain("/usr/local/bin");
477-expect(parts).toContain("/usr/bin");
478-expect(parts).toContain("/bin");
459+expect(parts).toEqual(["/usr/local/bin", "/usr/bin", "/bin", "/usr/sbin", "/sbin"]);
479460});
480461481462it("returns PATH as-is on Windows", () => {
@@ -622,6 +603,22 @@ describe("buildServiceEnvironment", () => {
622603expect(env.TMPDIR).toBe(path.join("/Users/user", ".openclaw", "tmp"));
623604});
624605606+it("uses a canonical system PATH for macOS LaunchAgents", () => {
607+const env = buildServiceEnvironment({
608+env: {
609+HOME: "/Users/user",
610+FNM_DIR: "/Users/user/Library/Application Support/fnm",
611+PNPM_HOME: "/Users/user/Library/pnpm",
612+VOLTA_HOME: "/Users/user/.volta",
613+ASDF_DATA_DIR: "/Users/user/.asdf",
614+},
615+port: 18789,
616+platform: "darwin",
617+});
618+619+expect(env.PATH).toBe("/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin");
620+});
621+625622it("falls back to os.tmpdir when TMPDIR is not set on Linux", () => {
626623const env = buildServiceEnvironment({
627624env: { HOME: "/home/user" },
@@ -701,6 +698,19 @@ describe("buildServiceEnvironment", () => {
701698"/home/user/.nvm/versions/node/v22.22.0/bin",
702699);
703700});
701+702+it("prepends explicit runtime directories to macOS LaunchAgent PATH", () => {
703+const env = buildServiceEnvironment({
704+env: { HOME: "/Users/user", VOLTA_HOME: "/Users/user/.volta" },
705+port: 18789,
706+platform: "darwin",
707+extraPathDirs: ["/opt/homebrew/Cellar/node/22.14.0/bin"],
708+});
709+710+expect(env.PATH).toBe(
711+"/opt/homebrew/Cellar/node/22.14.0/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin",
712+);
713+});
704714});
705715706716describe("buildNodeServiceEnvironment", () => {
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。