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
@@ -0,0 +1,40 @@
import * as NodeOS from "node:os";
import { assert, it } from "vite-plus/test";

import { hydratePosixHome } from "./os-jank.ts";

it("hydrates HOME for minimal service environments from the user account", () => {
const env: NodeJS.ProcessEnv = {};

hydratePosixHome(env);

assert.equal(env.HOME, NodeOS.userInfo().homedir);
});

it("hydrates HOME independently of a blank process HOME", () => {
const originalHome = process.env.HOME;
const env: NodeJS.ProcessEnv = { HOME: " " };

try {
process.env.HOME = " ";
hydratePosixHome(env);
} finally {
if (originalHome === undefined) {
delete process.env.HOME;
} else {
process.env.HOME = originalHome;
}
}

assert.equal(env.HOME, NodeOS.userInfo().homedir);
});

it("preserves an explicitly configured HOME", () => {
const env: NodeJS.ProcessEnv = { HOME: "/custom/home" };

hydratePosixHome(env, () => {
throw new Error("HOME lookup should not run");
});

assert.equal(env.HOME, "/custom/home");
});
19 changes: 19 additions & 0 deletions apps/server/src/os-jank.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@ function hydratePosixPath(env: NodeJS.ProcessEnv, platform: NodeJS.Platform): vo
}
}

export function hydratePosixHome(
env: NodeJS.ProcessEnv,
resolveHomeDir = () => NodeOS.userInfo().homedir,
): void {
if ((env.HOME?.trim() ?? "").length > 0) return;

const homeDir = resolveHomeDir();
if (homeDir.length > 0) {
env.HOME = homeDir;
}
}
Comment thread
cursor[bot] marked this conversation as resolved.

export const fixPath = Effect.fn("fixPath")(function* (): Effect.fn.Return<
void,
never,
Expand Down Expand Up @@ -63,6 +75,13 @@ export const fixPath = Effect.fn("fixPath")(function* (): Effect.fn.Return<

if (platform !== "darwin" && platform !== "linux") return;

yield* Effect.sync(() => hydratePosixHome(env)).pipe(
Effect.catchDefect((defect) =>
Effect.sync(() => {
logPathHydrationWarning("Failed to hydrate HOME from the user account.", defect);
}),
),
);
yield* Effect.sync(() => hydratePosixPath(env, platform)).pipe(
Effect.catchDefect((defect) =>
Effect.sync(() => {
Expand Down
Loading