Skip to content

Commit c0e670f

Browse files
t3dotggclaude
andcommitted
fix(server): the background service picks up JAVA_HOME from the login shell
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 066c8fc commit c0e670f

2 files changed

Lines changed: 46 additions & 1 deletion

File tree

‎apps/server/src/os-jank.test.ts‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,46 @@ effectIt.effect("keeps mise's PATH record with the login shell PATH", () =>
9696
),
9797
);
9898

99+
effectIt.effect("hydrates a missing JAVA_HOME from the login shell and keeps an explicit one", () =>
100+
Effect.acquireUseRelease(
101+
Effect.sync(() =>
102+
vi
103+
.spyOn(NodeChildProcess, "execFileSync")
104+
.mockReturnValue(
105+
[
106+
"__T3CODE_ENV_PATH_START__",
107+
"/opt/homebrew/bin",
108+
"__T3CODE_ENV_PATH_END__",
109+
"__T3CODE_ENV_JAVA_HOME_START__",
110+
"/opt/homebrew/opt/openjdk@17",
111+
"__T3CODE_ENV_JAVA_HOME_END__",
112+
].join("\n"),
113+
),
114+
),
115+
() =>
116+
Effect.gen(function* () {
117+
const missing: NodeJS.ProcessEnv = { SHELL: "/bin/zsh", PATH: "/usr/bin" };
118+
const explicit: NodeJS.ProcessEnv = {
119+
SHELL: "/bin/zsh",
120+
PATH: "/usr/bin",
121+
JAVA_HOME: "/custom/jdk",
122+
};
123+
124+
for (const env of [missing, explicit]) {
125+
yield* fixPath().pipe(
126+
Effect.provideService(HostProcess.Platform, "darwin"),
127+
Effect.provideService(HostProcess.Environment, env),
128+
Effect.provide(NodeServices.layer),
129+
);
130+
}
131+
132+
assert.equal(missing.JAVA_HOME, "/opt/homebrew/opt/openjdk@17");
133+
assert.equal(explicit.JAVA_HOME, "/custom/jdk");
134+
}),
135+
(probe) => Effect.sync(() => probe.mockRestore()),
136+
),
137+
);
138+
99139
effectIt.effect("replaces a Path-spelled Windows PATH instead of adding a second key", () =>
100140
Effect.gen(function* () {
101141
const env: NodeJS.ProcessEnv = { Path: "C:\\Windows" };

‎apps/server/src/os-jank.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ function hydratePosixPath(env: NodeJS.ProcessEnv, platform: NodeJS.Platform): vo
2525
// mise's record of the PATH entries it added. It must travel with the
2626
// shell's PATH, or `mise x` can rebuild PATH behind a same-named wrapper
2727
// (`exec mise x claude -- claude`) that then re-runs itself forever.
28-
shellEnvironment = readEnvironmentFromLoginShell(shell, ["PATH", "__MISE_DIFF"]);
28+
shellEnvironment = readEnvironmentFromLoginShell(shell, ["PATH", "__MISE_DIFF", "JAVA_HOME"]);
2929
} catch (error) {
3030
logPathHydrationWarning(`Failed to read PATH from login shell ${shell}.`, error);
3131
}
@@ -42,6 +42,11 @@ function hydratePosixPath(env: NodeJS.ProcessEnv, platform: NodeJS.Platform): vo
4242
if (shellPath && shellEnvironment.__MISE_DIFF) {
4343
env.__MISE_DIFF = shellEnvironment.__MISE_DIFF;
4444
}
45+
// Android SDK tools are Java programs. A keg-only JDK (Homebrew's openjdk)
46+
// is only reachable through the JAVA_HOME the shell profile sets.
47+
if (!env.JAVA_HOME && shellEnvironment.JAVA_HOME) {
48+
env.JAVA_HOME = shellEnvironment.JAVA_HOME;
49+
}
4550
}
4651

4752
export function hydratePosixHome(

0 commit comments

Comments
 (0)