Skip to content
TypeScript

fix(server): the background service picks up JAVA_HOME from the login shell (#22856)

Theo Brownea7c22f12b7f6
diff --git a/apps/server/src/os-jank.test.ts b/apps/server/src/os-jank.test.ts
index d9ae788baad..fef7a2e440e 100644
--- a/apps/server/src/os-jank.test.ts
+++ b/apps/server/src/os-jank.test.ts
@@ -96,6 +96,46 @@ effectIt.effect("keeps mise's PATH record with the login shell PATH", () =>
),
);
+effectIt.effect("hydrates a missing JAVA_HOME from the login shell and keeps an explicit one", () =>
+ Effect.acquireUseRelease(
+ Effect.sync(() =>
+ vi
+ .spyOn(NodeChildProcess, "execFileSync")
+ .mockReturnValue(
+ [
+ "__T3CODE_ENV_PATH_START__",
+ "/opt/homebrew/bin",
+ "__T3CODE_ENV_PATH_END__",
+ "__T3CODE_ENV_JAVA_HOME_START__",
+ "/opt/homebrew/opt/openjdk@17",
+ "__T3CODE_ENV_JAVA_HOME_END__",
+ ].join("\n"),
+ ),
+ ),
+ () =>
+ Effect.gen(function* () {
+ const missing: NodeJS.ProcessEnv = { SHELL: "/bin/zsh", PATH: "/usr/bin" };
+ const explicit: NodeJS.ProcessEnv = {
+ SHELL: "/bin/zsh",
+ PATH: "/usr/bin",
+ JAVA_HOME: "/custom/jdk",
+ };
+
+ for (const env of [missing, explicit]) {
+ yield* fixPath().pipe(
+ Effect.provideService(HostProcess.Platform, "darwin"),
+ Effect.provideService(HostProcess.Environment, env),
+ Effect.provide(NodeServices.layer),
+ );
+ }
+
+ assert.equal(missing.JAVA_HOME, "/opt/homebrew/opt/openjdk@17");
+ assert.equal(explicit.JAVA_HOME, "/custom/jdk");
+ }),
+ (probe) => Effect.sync(() => probe.mockRestore()),
+ ),
+);
+
effectIt.effect("replaces a Path-spelled Windows PATH instead of adding a second key", () =>
Effect.gen(function* () {
const env: NodeJS.ProcessEnv = { Path: "C:\\Windows" };
diff --git a/apps/server/src/os-jank.ts b/apps/server/src/os-jank.ts
index b6d0d5a7ad7..dc912bf39c3 100644
--- a/apps/server/src/os-jank.ts
+++ b/apps/server/src/os-jank.ts
@@ -25,7 +25,7 @@ function hydratePosixPath(env: NodeJS.ProcessEnv, platform: NodeJS.Platform): vo
// mise's record of the PATH entries it added. It must travel with the
// shell's PATH, or `mise x` can rebuild PATH behind a same-named wrapper
// (`exec mise x claude -- claude`) that then re-runs itself forever.
- shellEnvironment = readEnvironmentFromLoginShell(shell, ["PATH", "__MISE_DIFF"]);
+ shellEnvironment = readEnvironmentFromLoginShell(shell, ["PATH", "__MISE_DIFF", "JAVA_HOME"]);
} catch (error) {
logPathHydrationWarning(`Failed to read PATH from login shell ${shell}.`, error);
}
@@ -42,6 +42,11 @@ function hydratePosixPath(env: NodeJS.ProcessEnv, platform: NodeJS.Platform): vo
if (shellPath && shellEnvironment.__MISE_DIFF) {
env.__MISE_DIFF = shellEnvironment.__MISE_DIFF;
}
+ // Android SDK tools are Java programs. A keg-only JDK (Homebrew's openjdk)
+ // is only reachable through the JAVA_HOME the shell profile sets.
+ if (!env.JAVA_HOME && shellEnvironment.JAVA_HOME) {
+ env.JAVA_HOME = shellEnvironment.JAVA_HOME;
+ }
}
export function hydratePosixHome(