Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions apps/server/src/os-jank.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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" };
Expand Down
7 changes: 6 additions & 1 deletion apps/server/src/os-jank.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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(
Expand Down
Loading