Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

fix(env-path): find Podman and Docker Desktop on a Mac launched from Finder (#4520)

AdityaUmale3879f30d93ce
diff --git a/server/env-path.mac-runtimes.test.ts b/server/env-path.mac-runtimes.test.ts
new file mode 100644
index 0000000000..83d898eb5e
--- /dev/null
+++ b/server/env-path.mac-runtimes.test.ts
@@ -0,0 +1,46 @@
+import { mkdirSync, rmSync } from "node:fs";
+import { homedir } from "node:os";
+import { delimiter, join } from "node:path";
+import { afterEach, describe, expect, it, vi } from "vitest";
+
+// Podman's official macOS pkg lives in /opt/podman/bin, which a test cannot create, so only that path is faked as present.
+vi.mock("node:fs", async (importOriginal) => {
+ const fs = await importOriginal<typeof import("node:fs")>();
+ return { ...fs, existsSync: (path: Parameters<typeof fs.existsSync>[0]) => path === "/opt/podman/bin" || fs.existsSync(path) };
+});
+
+const { augmentedPath, resetPathCacheForTests } = await import("./env-path.ts");
+
+function withPlatform<T>(platform: NodeJS.Platform, run: () => T): T {
+ const real = process.platform;
+ Object.defineProperty(process, "platform", { value: platform });
+ try {
+ resetPathCacheForTests();
+ return run();
+ } finally {
+ Object.defineProperty(process, "platform", { value: real });
+ resetPathCacheForTests();
+ }
+}
+
+// #4520: a Finder-launched Mac app has a bare PATH, so Re-check said "Install a supported container runtime first"
+// although Podman (official pkg) and Docker Desktop (per-user install) both worked in Terminal.
+describe("augmentedPath on macOS container runtimes (#4520)", () => {
+ const dockerBin = join(homedir(), ".docker", "bin");
+
+ afterEach(() => rmSync(join(homedir(), ".docker"), { recursive: true, force: true }));
+
+ it("finds Podman's official pkg dir and Docker Desktop's per-user bin dir", () => {
+ mkdirSync(dockerBin, { recursive: true });
+ const parts = withPlatform("darwin", () => augmentedPath().split(delimiter));
+ expect(parts).toContain("/opt/podman/bin");
+ expect(parts).toContain(dockerBin);
+ });
+
+ it("leaves Linux unchanged", () => {
+ mkdirSync(dockerBin, { recursive: true });
+ const parts = withPlatform("linux", () => augmentedPath().split(delimiter));
+ expect(parts).not.toContain(dockerBin);
+ if (!(process.env.PATH ?? "").split(delimiter).includes("/opt/podman/bin")) expect(parts).not.toContain("/opt/podman/bin");
+ });
+});
diff --git a/server/env-path.ts b/server/env-path.ts
index c89d980354..e1a1b2875c 100644
--- a/server/env-path.ts
+++ b/server/env-path.ts
@@ -42,6 +42,11 @@ function knownDirs(): string[] {
join(home, ".deno", "bin"),
join(home, "bin"),
...nvmBinDirs(),
+ // Mac Local VM runtimes (#4520): Docker Desktop's per-user CLI install and Podman's official pkg.
+ ...(process.platform === "darwin" ? [
+ join(home, ".docker", "bin"),
+ ...(sealedFixture() ? [] : ["/opt/podman/bin"]),
+ ] : []),
];
}